Skip to main content

Messages

This section allows you to view all Messages made by this member. Note that you can only see Messages made in areas you currently have access to.

Messages - tino

16
PHP Code / Lazy Load Class
Code: [Select]
class MyClass {
    public function __construct() {
        echo 'I am initialized!';
    }
}

$getMyClass = function() {
    $myClass = new MyClass();
    return $myClass;
};


Code: [Select]
$myClass = $getMyClass();
17
Tutorials / Postfix call script via bcc
Code: [Select]
vim /etc/postfix/master.cf

Add the following
Code: [Select]
  -o receive_override_options=no_address_mappings

Just below the
Code: [Select]
smtp      inet  n       -       -       -       -       smtpd

Setup the recipient bcc

Code: [Select]
vim /etc/postfix/recipient_bcc

Add the following as appropriate

Code: [Select]
upload@tinoest.co.uk upload-script@localhost

Run postmap so postfix can read it.

Code: [Select]
 postmap /etc/postfix/recipient_bcc 


Setup the transport

Code: [Select]
vim /etc/postfix/transport

Add the following as appropriate

Code: [Select]
upload-script@localhost :

Run postmap so postfix can read it.

Code: [Select]
 postmap /etc/postfix/transport 

edit the main.cf

Code: [Select]
 vim /etc/postfix/main.cf 

Add the following:

Code: [Select]
recipient_bcc_maps = hash:/etc/postfix/recipient_bcc
transport_maps = hash:/etc/postfix/transport


Also ensure that localhost is in the mydestination list

Edit the /etc/aliases file

Code: [Select]
vim /etc/aliases

Add the following, to point to the relevant file you wish to parse the data

Code: [Select]
upload-script: "|/usr/bin/postfix-parse"




Then restart postfix

Code: [Select]
systemcntl restart postfix 
18
Tutorials / LTSP Debian Jessie Install
Install the required files

Code: [Select]
apt-get install ltsp-server dnsmasq

Build the client

Code: [Select]
ltsp-build-client --arch i386

Edit the exports file

Code: [Select]
vim  /etc/exports 

Add the following to the bottom

Code: [Select]
/opt/ltsp       *(ro,no_root_squash,async,no_subtree_check)

Restart the Service

Code: [Select]
invoke-rc.d nfs-kernel-server reload

Just to be sure...

Code: [Select]
service nfs-kernel-server restart

Create the DNS masq files

Code: [Select]
ltsp-config dnsmasq

Amend one of the created files

Code: [Select]
vim /opt/ltsp/i386/etc/ltsp/update-kernels.conf

Change the following line:

Code: [Select]
CMDLINE_NFS="root=/dev/nfs ip=dhcp boot=nfs"

To

Code: [Select]
CMDLINE_NFS="root=/dev/nfs ip=dhcp boot=nfs nfsroot=/opt/ltsp/i386"
IPAPPEND=3

Update everything.

Code: [Select]

ltsp-chroot /usr/share/ltsp/update-kernels

ltsp-update-kernels

19
MySQL / MySQL ORDER BY
Code: [Select]
ORDER BY status ASC; will return 1,2,3,4.

Code: [Select]
ORDER BY status DESC; will return 4,3,2,1.

Code: [Select]
ORDER BY FIELD(status, 3, 2, 4, 1);
20
PostgreSQL / Auto Increment
Code: [Select]
CREATE SEQUENCE teams_id_seq;
ALTER TABLE teams ALTER id SET DEFAULT nextval('teams_id_seq');
ALTER SEQUENCE teams_id_seq OWNER TO elabftw;
ALTER SEQUENCE teams_id_seq OWNED BY teams.id;
22
PostgreSQL / timestamp round function
Code: [Select]
CREATE FUNCTION ts_round( timestamptz, INT4 ) RETURNS TIMESTAMPTZ AS $$
    SELECT 'epoch'::timestamptz + '1 second'::INTERVAL * ( $2 * ( extract( epoch FROM $1 )::INT4 / $2 ) );
$$ LANGUAGE SQL;
23
PostgreSQL / PostgreSQL upgrade instructions
Download the new postgresql version

untar , then

Code: [Select]
 
./configure
make

Stop the old server
Code: [Select]
sudo /usr/local/pgsql/bin/pgsql.sh stop

Move the old server directory

Code: [Select]
mv /usr/local/pgsql /usr/local/pgsql-9.1.24

Now install the new server

Code: [Select]
make install

cd into the contrib/pg_upgrade directory.

Code: [Select]
make
make install

cd into the contrib/pg_upgrade_support directory.

Code: [Select]
make
make install

run the following, changing the directories to be the correct ones. old => new

Code: [Select]
su postgres

Create the new data directory

Code: [Select]
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data

Code: [Select]
/usr/local/pgsql/bin/pg_upgrade -b /usr/local/pgsql-9.1.24/bin/  -B /usr/local/pgsql/bin/ -d /usr/local/pgsql-9.1.24/data  -D /usr/local/pgsql/data

Copy the pgsql.sh file to the new bin location.

Code: [Select]
cp /usr/local/pgsql-9.1.24/bin/pgsql.sh /usr/local/pgsql/bin/

Code: [Select]
mkdir /usr/local/pgsql/log

Code: [Select]
chown postgres:postgres /usr/local/pgsql/log

edit the pg_hba.conf file and add the following to the end

Code: [Select]
# Allow any user from host 192.168.1.x to connect to
# any database if the user's password is correctly supplied.
# TYPE  DATABASE        USER            ADDRESS                 METHOD
host    all             all             192.168.1.0/24          md5

start the server again.
24
C Code / WatchDog Timer
Code: [Select]
#include <avr/sleep.h>
#include <avr/power.h>
#include <avr/wdt.h>

/*

 Watchdog Timer Prescale Select
 
 WDP3   WDP2 WDP1 WDP0   Number of WDT     Typical Time-out at Oscillator Cycles     VCC = 5.0V
 
 0    0    0      0             2K (2048) cycles       16 ms
 0    0    0      1             4K (4096) cycles       32 ms
 0    0    1      0             8K (8192) cycles       64 ms
 0    0    1      1            16K (16384) cycles      0.125 s
 0    1    0      0            32K (32768) cycles      0.25 s
 0    1    0      1            64K (65536) cycles      0.5 s
 0    1    1      0            128K (131072) cycles    1.0 s
 0    1    1      1            256K (262144) cycles    2.0 s
 1    0    0      0            512K (524288) cycles    4.0 s
 1    0    0      1            1024K (1048576) cycles  8.0 s
 
 */

unsigned int i = 0;

void setup(void) {

  Serial.begin(57600);

  MCUSR &= ~(1 << WDRF);                           // reset status flag
  WDTCSR |= (1 << WDCE) | (1 << WDE);              // enable configuration changes
  WDTCSR = (1<< WDP0) | ( 1 << WDP3);              // set the prescalar = 9
  WDTCSR |= (1 << WDIE);                           // enable interrupt mode
 
}


void loop(void) {

  set_sleep_mode(SLEEP_MODE_PWR_DOWN);             // select the watchdog timer mode
  sleep_enable();                                  // enable the sleep mode ready for use
  sleep_mode();                                    // trigger the sleep

  Serial.print("Woken ");
  Serial.println(i++);
  Serial.flush();
  sleep_disable();                                 // prevent further sleeps


}

ISR(WDT_vect) {
}