Skip to content

Instantly share code, notes, and snippets.

@ghiculescu
ghiculescu / deploy.rb
Last active December 21, 2015 18:59
Capistrano tasks to deploy Jekyll blog via :copy
set :application, `your_app_name`
set :repository, '_site'
set :scm, :none
set :deploy_via, :copy
set :copy_compression, :gzip
set :use_sudo, false
set :user, `name_of_a_user_on_your_vps` # by default this could be "root" but it's good practice to create another user
set :deploy_to, `path_on_vps_to_deploy_to` # for example, "/home/#{user}/blog" - you can use other variables (defined using `set`) here, eg. user
@ghiculescu
ghiculescu / .gitignore
Last active December 21, 2015 18:59
Capistrano Jekyll .gitignore
_site
Capfile
config
@ghiculescu
ghiculescu / gist:6352625
Created August 27, 2013 11:58
Jekyll nginx config
server {
listen 80; # listen on http (port 80)
server_name blog.example.com; # the domain name people will access your site at
root /home/deployer/docs; # path to deploy to, eg: "/home/#{user}/docs". this should match whatever was in your Capistrano deploy file.
expires 1d; # how long should static files be cached for, see http://nginx.org/en/docs/http/ngx_http_headers_module.html for options.
}
@ghiculescu
ghiculescu / README.md
Last active September 22, 2015 03:12 — forked from evs/README.md
credit card checking puzzle

Checking Credit Cards

Problem

Before submitting a credit card to a payment gateway it's important that we run some sanity checks on the number.

A common check that is performed upfront is to validate the card type based on the starting digits and length of card number. The main patterns that we care about are as follows:

+============+=============+===============+

| Card Type | Begins With | Number Length |

@ghiculescu
ghiculescu / pre-commit
Created September 7, 2015 07:52 — forked from bestie/pre-commit
Rails Git pre-commit hook for ensuring schema.rb and migration changes commit atomically
#!/usr/bin/env ruby
# based on https://gist.github.com/bestie/1223064
# Ensures that if a new migration is added, rake db:migrate is also run (and thus the schema.rb file is updated)
def schema_modified?
%x[ git status |grep schema.rb ] != ''
end
# regex for typical migration
@ghiculescu
ghiculescu / gist:264e78233a48d2d2a689
Last active September 16, 2015 06:02
ruby workshop
# welcome to Ruby. i'm a comment.
# > irb
# `irb` is the command line ruby console. it opens up a REPL - an interactive terminal that you can evaluate ruby statements in. similar to python's `python`.
# in Cloud9, choose "Runner: Shell command" from the dropdown at the bototm (near CWD). Then run "irb" as your command.
1 + 1
# => 2
@ghiculescu
ghiculescu / gist:8f1a00e40a5094fbbfe3
Last active October 29, 2015 01:18 — forked from ivanvanderbyl/gist:4222308
Postgres 9.1 to 9.2 upgrade guide for Ubuntu 12.04
sudo add-apt-repository ppa:pitti/postgresql
sudo apt-get update
sudo apt-get install postgresql-9.2 postgresql-server-dev-9.2 postgresql-contrib-9.2
sudo su -l postgres
# http://makandracards.com/makandra/18643-how-the-change-the-locale-of-a-postgresql-cluster
pg_lsclusters
pg_dropcluster --stop 9.2 main
pg_createcluster --start 9.2 main # --locale en_AU.UTF-8 <-- set this based on the current cluster's locale
my_set = JillSet.new
my_set.insert("alex") # returns true
my_set.insert("jill") # returns true
my_set.has?("jill") # returns true
my_set.has?("Jill") # returns false
my_set.items # returns ["alex", "jill"]
++[[]][+[]]+[]+[]+!+[]+"luv"
Calculator = {}
function Calculator:new (o, input) -- the "account" example at http://www.lua.org/cgi-bin/demo made me think that you could just make classes, didn't realise the importance of all this boilerplate
o = o or {name=name}
setmetatable(o, self)
self.__index = self
self.input = input
self.calculation = "(%d+) ?([+-/*]) ?(%d+)" -- not sure if i'm a fan of lua not supporting all regex features - http://lua-users.org/wiki/PatternsTutorial - but i suspect the benefits will be obvious after more digging