inssserv: warning: script ‘mathkernel’ missing LSB tags

Wolfram Mathematica is one of the default packages installed on Raspbian. The package contains an init script that does not have the LSB headers. This causes insserv to echo a bunch of errors.

To fix this issue you need to add the code below to the following file: /etc/init.d/mathkernel

### BEGIN INIT INFO
# Provides: mathkernel
# Required-Start: $local_fs
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: mathkernel
### END INIT INFO
inssserv: warning: script ‘mathkernel’ missing LSB tags

80Legs file extractor

#!/usr/bin/python
 
# Original Code
# github.com/turian/py80legsformat by Joseph Turian
 
import csv
import hashlib
import os
import struct
import sys
import zipfile
from cStringIO import StringIO
from optparse import OptionParser
 
class EightyLegs:
 def __init__(self, filename):
 self.filename = filename
 self.directory = filename.split('.')[0]
 
 def read(self, file):
 assert(struct.calcsize("i")) == 4
 
 l = file.read(2*4)
 (classID, versionID) = struct.unpack("ii", l)
 assert (classID, versionID) == (218217067, 1)
 
 l = "not EOF"
 data = []
 l = file.read(1*4)
 while l != "":
 (URLSIZE,) = struct.unpack("i", l)
 url = file.read(URLSIZE).decode("utf-8")
 l = file.read(1*4)
 (DATASIZE,) = struct.unpack("i", l)
 data = str(file.read(DATASIZE))
 yield (url, data)
 l = file.read(1*4)
 
 def read_zip(self, file):
 zip = zipfile.ZipFile(file, 'r')
 for info in zip.infolist():
 fname = info.filename 
 if fname.endswith('.80'):
 data = zip.read(fname)
 for r in self.read(StringIO(data)):
 yield r
 
 def parse(self):
 if not os.path.exists(self.directory):
 os.makedirs(self.directory)
 
 tsv = csv.writer(open("%s.tsv" % self.directory, 'w'), delimiter='\t', lineterminator='\n')
 
 if self.filename.endswith('.zip'):
 e = self.read_zip(open(self.filename))
 else:
 e = self.read(open(self.filename))
 
 for url, data in e:
 print url
 f = open("%s/%s.html" % (self.directory, hashlib.md5(url).hexdigest()), 'w')
 f.write(data)
 tsv.writerow([hashlib.md5(url).hexdigest(), url])
 
def main():
 usage = 'Usage: %prog -f 19970_20966_a_1.zip or %prog -f 19970_20966_a_1.80'
 parser = OptionParser(usage=usage)
 parser.add_option('-f', '--file', dest='filename', help='input file')
 
 (options, args) = parser.parse_args()
 
 if options.filename is None:
 parser.print_help()
 sys.exit(0)
 
 legs = EightyLegs(options.filename)
 legs.parse()
 
if __name__ == '__main__':
 main()
80Legs file extractor

Encrypting and Decrypting with python and nodejs

crypto.js

var crypto = require('crypto');

var password = 'secret';
var input = 'hello world';

var encrypt = function (input, password, callback) {
    var m = crypto.createHash('md5');
    m.update(password)
    var key = m.digest('hex');

    m = crypto.createHash('md5');
    m.update(password + key)
    var iv = m.digest('hex');

    var data = new Buffer(input, 'utf8').toString('binary');

    var cipher = crypto.createCipheriv('aes-256-cbc', key, iv.slice(0,16));
    var encrypted = cipher.update(data, 'binary') + cipher.final('binary');
    var encoded = new Buffer(encrypted, 'binary').toString('base64');

    callback(encoded);
};

var decrypt = function (input, password, callback) {
    // Convert urlsafe base64 to normal base64
    var input = input.replace(/\-/g, '+').replace(/_/g, '/');
    // Convert from base64 to binary string
    var edata = new Buffer(input, 'base64').toString('binary')

    // Create key from password
    var m = crypto.createHash('md5');
    m.update(password)
    var key = m.digest('hex');

    // Create iv from password and key
    m = crypto.createHash('md5');
    m.update(password + key)
    var iv = m.digest('hex');

    // Decipher encrypted data
    var decipher = crypto.createDecipheriv('aes-256-cbc', key, iv.slice(0,16));
    var decrypted = decipher.update(edata, 'binary') + decipher.final('binary');
    var plaintext = new Buffer(decrypted, 'binary').toString('utf8');

    callback(plaintext);
};

encrypt(input, password, function (encoded) {
    console.log(encoded);
    decrypt(encoded, password, function (output) {
        console.log(output);
    });
});

crypto.py

from Crypto.Cipher import AES
from hashlib import md5
import base64


password = 'secret'
input = 'hello world'

BLOCK_SIZE = 16

def pad (data):
    pad = BLOCK_SIZE - len(data) % BLOCK_SIZE
    return data + pad * chr(pad)

def unpad (padded):
    pad = ord(padded[-1])
    return padded[:-pad]

def _encrypt(data, nonce, password):
    m = md5()
    m.update(password)
    key = m.hexdigest()

    m = md5()
    m.update(password + key)
    iv = m.hexdigest()

    data = pad(data)

    aes = AES.new(key, AES.MODE_CBC, iv[:16])

    encrypted = aes.encrypt(data)
    return base64.urlsafe_b64encode(encrypted)

def _decrypt(edata, nonce, password):
    edata = base64.urlsafe_b64decode(edata)

    m = md5()
    m.update(password)
    key = m.hexdigest()

    m = md5()
    m.update(password + key)
    iv = m.hexdigest()

    aes = AES.new(key, AES.MODE_CBC, iv[:16])
    return unpad(aes.decrypt(edata))

output = _encrypt(input, "", password)
print(output)
plaintext = _decrypt(output, "", password)
print("'" + plaintext + "'")

Reference: http://stackoverflow.com/questions/10548973/encrypting-and-decrypting-with-python-and-nodejs

Encrypting and Decrypting with python and nodejs

Testing REST API Calls using Curl

#!/bin/bash
AUTH="user:password"
BASE="http://example.com/"
METHOD=$1
DEST="$BASE$2"
XML=$3
 
# make sure args were passed
if [ $# -eq 0 ]; then
        echo "usage: ./`basename $0` HTTP-METHOD DESTINATION_URI [XML]"
        echo "example: ./`basename $0` POST "/accounts" \"<account><name>ed</name><email>ed@ed.com</email></account>\""
        exit 1
fi
 
# execute CURL call
curl -H 'Accept: application/xml' -H 'Content-Type: application/xml' -w '\nHTTP STATUS: %{http_code}\nTIME: %{time_total}\n' \
-X $METHOD \
-d "$XML" \
-u "$AUTH" \
"$DEST"
 
exit 0
Testing REST API Calls using Curl

Specify which Index to use during a SELECTDa

MySQL by default will always use the best index for a SELECT. MySQL is not perfect and at times will mess this up by using a wrong index. In such cases you can force MySQL to use a specific index or otherwise ask it to ignore a specific index.

SELECT * FROM table1 
    USE INDEX (col1_index,col2_index)
        WHERE col1=1 AND col2=2 AND col3=3;
SELECT * FROM table1 
 IGNORE INDEX (col3_index)
        WHERE col1=1 AND col2=2 AND col3=3;
Specify which Index to use during a SELECTDa