Skip to content

Instantly share code, notes, and snippets.

@websymphony
websymphony / postgresql_recursive.sql
Created June 19, 2019 23:32 — forked from dankrause/postgresql_recursive.sql
An example of creating a recursive postgresql query to generate data about parent-child relationships within a single table.
CREATE TABLE test
(
id INTEGER,
parent INTEGER
);
INSERT INTO test (id, parent) VALUES
(1, NULL),
(2, 1),
@websymphony
websymphony / ecto_table_with_uuid_primary_key.exs
Last active September 7, 2016 07:46
Use UUIDs as primary key with Ecto - Phoenix Framework
defmodule Blog.Repo.Migrations.CreatePost do
use Ecto.Migration
def up do
create table(:posts, primary_key: false) do
add :id, :uuid, primary_key: true
add :title, :string
add :body, :text
@websymphony
websymphony / vim-cheatsheet
Last active August 29, 2015 13:57
Vim Cheatsheet
####
TEXT Manipulation
####
di' " Delete inside ''
di"
di[
di(
di{
cit " Change inside tag.
@websymphony
websymphony / sort.rb
Created February 4, 2013 20:49
Sorting a ruby array of objects by an attribute that could be nil.
foo=[nil, -3, 100, 4, 6, nil, 4, nil, 23]
foo.sort{|a,b|( a and b ) ? a <=> b : ( a ? -1 : 1 ) }
RESULT=> [-3, 4, 4, 6, 23, 100, nil, nil, nil]
@websymphony
websymphony / postgres_utf8_encoding_fix
Created October 20, 2012 16:56
Change postgres default template1 to UTF8 encoding
amit@rb:~$ psql -U postgres
psql (9.0.3)
Type "help" for help.
postgres=# update pg_database set datallowconn = TRUE where datname = 'template0';
UPDATE 1
postgres=# \c template0
You are now connected to database "template0".
template0=# update pg_database set datistemplate = FALSE where datname = 'template1';
UPDATE 1
@websymphony
websymphony / ubuntu_steps
Created October 7, 2012 18:19 — forked from johnrees/_ubuntu_steps.sh
Standard Rails 3.* setup for Ubuntu 12.04 LTS 32
# As root user
sudo su
# Update the OS
apt-get update -y
apt-get dist-upgrade -y
apt-get upgrade -y
# Setup Hostname & TimeZone
@websymphony
websymphony / sublime_text_shortcuts
Last active October 1, 2015 00:18 — forked from axelav/gist:1839777
Sublime Text 2 - Useful Shortcuts for Mac OS X
Sublime Text 2 - Useful Shortcuts (Mac OS X)
============================================
General
-------
---------- -------------------------------------
**⌘T** go to file
**⌘⌃P** go to project
**⌘R** go to methods
$(function(){
var tracker_arr = new Array();
$(window).bind('mousemove',function(e){
var tracker_obj = {};
tracker_obj['x'] = e.pageX;
tracker_obj['y'] = e.pageY;
tracker_arr.push(tracker_obj);
});
$("#show").click(function(e){
@websymphony
websymphony / JSfunctionSkeleton.js
Created October 13, 2010 15:42
JSfunctionSkeleton
var skeleton = function(){
// private variables *******
var x;
// private functions
// initialization *******
( function init () {
// only call private functions or variables!
} ) ();
@websymphony
websymphony / URI_Parsing.js
Created October 12, 2010 20:45
URI_Parsing
/*URl Parsing Function*/
function parseUri(str) {
var o = parseUri.options,
m = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
uri = {},
i = 14;
while (i--) uri[o.key[i]] = m[i] || "";
uri[o.q.name] = {};