Archive

Nginx configuration

nginx.conf
user francesco staff;
worker_processes 1;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
include /usr/local/etc/nginx/sites-enabled/*.conf;
}

[windows] nginx.conf
#user nobody;
worker_processes 1;

error_log logs/error.log;
error_log logs/error.log notice;
error_log logs/error.log info;

pid logs/nginx.pid;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
sendfile on;
keepalive_timeout 65;
include c:/nginx/conf/sites/*.conf;
}

default.conf
server {
listen 80;
server_name localhost;
root /Users/francesco/workspace/hackweb;

location / {
index index.php index.html index.htm;
autoindex on;
}

location ~ \.php {
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
}
}

[hackweb] default.conf
server {
listen 80;
server_name localhost;
root c:/Users/Francesco/workspace/hackweb/hackweb/www;
index index.php index.html index.htm;
port_in_redirect on;
client_max_body_size 100M;
fastcgi_read_timeout 1800;
error_page 404 /index.php;

location / {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
#
# Custom headers and headers various browsers *should* be OK with but aren't
#
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
#
# Tell client that this pre-flight info is valid for 20 days
#
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain; charset=utf-8';
add_header 'Content-Length' 0;
return 204;
}
autoindex on;
try_files $uri $uri/ /index.php$is_args$args;
}

# if (!-e $request_filename) {
# rewrite ^(.*)$ $scheme://$http_host/index.php break;
# }

# if (-d $request_filename) {
# rewrite ^(.*)$ $scheme://$http_host/index.php break;
# rewrite [^/]$ $scheme://$http_host/index.php permanent;
# rewrite [^/]$ $scheme://$http_host$uri/ permanent;
# }
location ~ /\. {
deny all;
}

location ~* /(?:uploads|files)/.*\.php$ {
deny all;
}

location = /favicon.ico {
log_not_found off;
access_log off;
}

location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
access_log off;
}

location ~ \.php {
try_files $uri =404;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9123;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_index index.php;
}
}

[windows] init.bat
@ECHO OFF
REM Start Nginx
taskkill /IM "nginx.exe" /F
taskkill /IM "php-cgi.exe" /F
tasklist /FI "IMAGENAME eq nginx.exe" 2>NUL | find /I /N "nginx.exe">NUL
IF NOT "%ERRORLEVEL%"=="0" (
REM Nginx is NOT running, so start it
c:
cd C:\nginx
start nginx.exe
ECHO Nginx started.
ECHO Starting PHP FastCGI...
c:\bin\RunHiddenConsole.exe C:\php\php-cgi.exe -b 127.0.0.1:9123
) else (
ECHO Nginx is already running.
)

CRC16 in big endian order

// CRC16 in big endian order
const crcArr = new Uint8Array(2);
crcArr[0] = crcByte1;
crcArr[1] = crcByte2;
const buffer = crcArr.buffer;
const datav = new DataView(buffer);
const uint16 = datav.getUint16(0, false); // big endian
byteArr[index++] = uint16 & 0xff;
byteArr[index++] = uint16 >> 8;

Android local.properties for Windows

Path for windows:
sdk.dir=C\:\\android-sdk

Virtualbox Android debug

Forward ports in VirtualBox

adb kill-server
export ADB_SERVER_SOCKET=tcp:10.0.2.2:5037

Connect phone
Check with
adb devices

Linux startup script

Create script in /etc/init.d

sudo nano /etc/init.d/NameOfYourScript

The following is an example based on starting up the no-ip service [/usr/local/bin/noip], but change the name of the script and the command to start and stop it and it would work for any command.

#! /bin/sh
# /etc/init.d/noip### BEGIN INIT INFO
# Provides:          noip
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Simple script to start a program at boot
# Description:       A simple script from www.stuffaboutcode.comwhich will start / stop a program a boot / shutdown.
### END INIT INFO

# If you want a command to always run, put it here

# Carry out specific functions when asked to by the system
case "$1" in
start)
echo "Starting noip"
# run application you want to start
/usr/local/bin/noip2
;;
stop)
echo "Stopping noip"
# kill application you want to stop
killall noip2
;;
*)
echo "Usage: /etc/init.d/noip {start|stop}"
exit 1
;;
esac

exit 0

Warning – its important you test your script first and make sure it doesn’t need a user to provide a response, press “y” or similar, because you may find it hangs the raspberry pi on boot waiting for a user (who’s not there) to do something!

Make script executable

sudo chmod 755 /etc/init.d/NameOfYourScript


Test starting the program

sudo /etc/init.d/NameOfYourScript start


Test stopping the program

sudo /etc/init.d/NameOfYourScript stop


Register script to be run at start-up
To register your script to be run at start-up and shutdown, run the following command:

sudo update-rc.d NameOfYourScript defaults

Note – The header at the start is to make the script LSB compliant and provides details about the start up script and you should only need to change the name.  If you want to know more about creating LSB scripts for managing services, see http://wiki.debian.org/LSBInitScripts

If you ever want to remove the script from start-up, run the following command:

sudo update-rc.d -f  NameOfYourScript remove