Skip to content

Instantly share code, notes, and snippets.

@ghiculescu
ghiculescu / keys.rb
Created January 31, 2022 19:48 — forked from archan937/keys.rb
List all Memcached keys using Ruby
# inspired by https://gist.github.com/archan937/f441146e1aeaa9da138e337514ee4000
require "net-telnet"
def keys(hosts, port, pattern = nil)
[hosts].flatten.each do |host|
slabs = {}
telnet = Net::Telnet::new("Host" => host, "Port" => port, "Timeout" => 30)
telnet.cmd("String" => "stats items", "Match" => /^END/) do |stats|
slabs = Hash[stats.scan(/STAT items:(\d+):number (\d+)/)]
@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
@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 / 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 |