Skip to content

Instantly share code, notes, and snippets.

View carlosdavis's full-sized avatar

Carlos Drew d'Avis carlosdavis

  • Quite Fine
  • Seattle, WA
View GitHub Profile
@glpunk
glpunk / method_missing_test.rb
Last active September 7, 2018 14:03
getter and setter through method_missing to manipulate a hash inside a ruby class #ruby
class Test
def initialize
@hash = {prop1: 'prop 1 value', prop2: 'prop2 value'}
end
def method_missing(m, *args)
#setter
if /^(\w+)=$/ =~ m
@hash[:"#{$1}"] = args[0]
end
@maccman
maccman / counter.sql
Created July 7, 2013 03:11
Postgres counter cache using triggers.
--
-- Name: c_posts_voted(); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION c_posts_voted() RETURNS trigger
LANGUAGE plpgsql
AS $$ BEGIN
UPDATE "posts" SET voted_user_ids = array_append(voted_user_ids, NEW.user_id) WHERE "id" = NEW.post_id;
RETURN NEW;
END;
@ThaiWood
ThaiWood / xkcd_passphrase.rb
Created May 28, 2013 02:33
A small Ruby script to generate passwords a la XKCD (http://xkcd.com/936/) using a wordlist seeded from a news article and words chosen using random atmospheric noise
#!/usr/bin/ruby
require 'net/http'
require 'nokogiri'
require 'rss'
require 'open-uri'
google_news_query = 'http://news.google.com/news/feeds?q=apologize&output=rss'
google_news_result_url = ''
wordlist = Array.new
@jsvine
jsvine / draft.md
Created August 10, 2012 14:10
Brute-Forcing a Word Puzzle

All this week, I've been trying to chip away at Allen R. Morgan's "Twice Removed" puzzle on page 50 of the August 5, 2012 New York Times Magazine. The rules:

For each word below, add the same pair of letters *twice* 
to complete a longer word. For example, if you were given 
MOTE, you would add ON twice to make MONOTONE.

After a few days, I'd found just four of the 24 words. Pathetic. After moping for a bit, I tried brute-forcing the answers. The strategy was simple, but radically different from how you or I would try solving the puzzle by hand. The steps:

  1. Get a big list of English words.
@simme
simme / Install_tmux
Created October 19, 2011 07:55
Install and configure tmux on Mac OS X
# First install tmux
brew install tmux
# For mouse support (for switching panes and windows)
# Only needed if you are using Terminal.app (iTerm has mouse support)
Install http://www.culater.net/software/SIMBL/SIMBL.php
Then install https://bitheap.org/mouseterm/
# More on mouse support http://floriancrouzat.net/2010/07/run-tmux-with-mouse-support-in-mac-os-x-terminal-app/
@knzconnor
knzconnor / 1_intro_to_subject.rb
Created February 8, 2011 07:45
A pattern for testing class methods in ruby with rspec explicit subjects
# RSpec's subject method, both implicitly and explicitly set, is useful for
# declaratively setting up the context of the object under test. If you provide a
# class for your describe block, subject will implicitly be set to a new instance
# of this class (with no arguments passed to the constructor). If you want
# something more complex done, such as setting arguments, you can use the
# explicit subject setter, which takes a block.
describe Person do
context "born 19 years ago" do
subject { Person.new(:birthdate => 19.years.ago }
it { should be_eligible_to_vote }
@shripadk
shripadk / gist:552554
Created August 27, 2010 00:59
Setting up Heroku Hostname SSL with GoDaddy SSL Cert
How to setup Heroku Hostname SSL with GoDaddy SSL Certificate and Zerigo DNS
Heroku recently added an exciting new 'Hostname SSL' option. This option offers the broad compatibility of IP-based SSL, but at 1/5 the price ($20 / month at the time of this writing).
The following tutorial explains how to use Heroku's new 'Hostname SSL' option on your Heroku project. Before we begin, let's list what we're using here:
* Heroku Hostname SSL
* GoDaddy Standard SSL Certificate
* Zerigo DNS
attachments: parent_id, asset_id
domain_names: organisation_id
event_memberships: user_id, event_id
events: editor_id
group_actions: user_id, group_id
groups: user_id
icons: parent_id
invitations: sender_id
legacy_actions: item_upon_id
news_items: author_id