Skip to content

Instantly share code, notes, and snippets.

@shernshiou
shernshiou / createtable.js
Created May 15, 2018 06:19
Knex createtable sqlite uuid
let uuidGenerationRaw = connection.client.config.client === 'sqlite3' ?
`(lower(hex(randomblob(4))) || '-' || lower(hex(randomblob(2))) || '-4' || substr(lower(hex(randomblob(2))),2) || '-' || substr('89ab',abs(random()) % 4 + 1, 1) || substr(lower(hex(randomblob(2))),2) || '-' || lower(hex(randomblob(6))))` :
`uuid_generate_v4()`;
connection.schema.createTableIfNotExists('notification', (table) => {
table.uuid('id').primary().defaultTo(connection.raw(uuidGenerationRaw));
// ... rest of the columns
}),
var source = require('vinyl-source-stream');
var gulp = require('gulp');
var gutil = require('gulp-util');
var browserify = require('browserify');
var reactify = require('reactify');
var watchify = require('watchify');
var notify = require("gulp-notify");
var scriptsDir = './scripts';
var buildDir = './build';
sudo su - postgres -c "psql template1 -p 5433 -c 'CREATE EXTENSION IF NOT EXISTS hstore;'"
sudo su - postgres -c "psql template1 -p 5433 -c 'CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";'"
sudo su - postgres -c "service postgresql stop"
sudo su - postgres -c '/usr/lib/postgresql/9.4/bin/pg_upgrade -b /usr/lib/postgresql/9.3/bin -B /usr/lib/postgresql/9.4/bin -d /var/lib/postgresql/9.3/main/ -D /var/lib/postgresql/9.4/main/ -o "-c config_file=/etc/postgresql/9.3/main/postgresql.conf" -O "-c config_file=/etc/postgresql/9.4/main/postgresql.conf"'
sudo apt-get remove postgresql-9.3 -y
sudo sed -i "s:5433:5432:g" /etc/postgresql/9.4/main/postgresql.conf
sudo service postgresql restart
@shernshiou
shernshiou / upgrade script
Created April 23, 2014 10:44
Upgrading from Postgresql 9.1 to Postgresql 9.3
sudo -H -u postgres /usr/lib/postgresql/9.3/bin/pg_upgrade \
-b /usr/lib/postgresql/9.1/bin \
-B /usr/lib/postgresql/9.3/bin \
-d /var/lib/postgresql/9.1/main \
-D /var/lib/postgresql/9.3/main \
-o ' -c config_file=/etc/postgresql/9.1/main/postgresql.conf' \
-O ' -c config_file=/etc/postgresql/9.3/main/postgresql.conf'
./configure \
--prefix=/usr/share/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/access.log \
--user=www-data \
--group=www-data \
# Blog running on Ghost in Nodejs
server {
listen 80;
server_name blog.shernshiou.com;
#access_log /var/log/nginx/log/blog.access.log;
client_max_body_size 5M;
location / {
proxy_pass http://LOCALHOST:GHOST_PORT/;
proxy_set_header Host $host;
@shernshiou
shernshiou / gist:1369609
Created November 16, 2011 08:52
Recursive
//Recursive function that add a+1 until it reach 10
int myFunction(int a)
{
if(myFunction(a+1) > 10)
return a;
}