Skip to content

Instantly share code, notes, and snippets.

View h0lyalg0rithm's full-sized avatar

Suraj Shirvankar h0lyalg0rithm

View GitHub Profile
defmodule Factorial do
def factorial(n) when n>1 do
n * factorial(n-1)
end
def factorial(n) when n <=1 do
1
end
end
@h0lyalg0rithm
h0lyalg0rithm / equality.rb
Last active August 29, 2015 14:13
Ruby equality
van_glory = Game.new title: ‘Van Glory’
fates = Game.new title: ‘Fates Forever’
van_gloryless = Game.new title: ‘Van Glory’
van_glory === van_glory # true
fates === van_glory # false
van_gloryless === van_glory # false
def do_job
return if @cleaning
puts "Starting cleanup"
@cleaning = true
sleep(10) # simulate killing of sinatra app
puts "Completed"
exit
end
while true
trap('INT') { do_job }
--color
--require spec_helper
@h0lyalg0rithm
h0lyalg0rithm / keyboard-int.sh
Created August 7, 2015 21:18
Keyboard Maestro Task
osascript -e 'tell application "Keyboard Maestro Engine" to do script "Keyboard International"'
@h0lyalg0rithm
h0lyalg0rithm / database.sql
Last active August 29, 2015 14:26
PostgreSQL benchmark
CREATE TABLE test (
id serial NOT NULL primary key,
name text
desc1 text
desc2 text
);
CREATE INDEX alll ON test(name, desc1, desc2);
CREATE INDEX name ON test(name);
CREATE INDEX more ON test(name, desc1);
CREATE INDEX more1 ON test(name, desc2);
@h0lyalg0rithm
h0lyalg0rithm / item.rb
Last active August 29, 2015 14:27
Table inheritance
class Item < ItemTemplate
self.primary_key = "id"
end
@h0lyalg0rithm
h0lyalg0rithm / new.html.haml
Last active September 13, 2015 17:58
Devise Registration
.container
.row
.col-md-4.col-md-offset-4
.login-panel.panel.panel-default
.panel-heading
%h3.panel-title Sign up
.panel-body
%div
= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f|
= devise_error_messages!
@h0lyalg0rithm
h0lyalg0rithm / Capfile
Last active September 13, 2015 18:14
Static Deployments with Capistrano
require 'capistrano/setup'
require 'capistrano/deploy'
@h0lyalg0rithm
h0lyalg0rithm / example.com
Created September 21, 2015 19:05
Simple configuration for PHP + nginx
server {
listen 80;
root /var/www/app/current;
index index.php index.html index.htm;
server_name example.com;
location / {
try_files $uri $uri/ =404;