Skip to content

Instantly share code, notes, and snippets.

View jufemaiz's full-sized avatar
🔌
CTO at @enosi

Joel Courtney jufemaiz

🔌
CTO at @enosi
View GitHub Profile
@webframp
webframp / keybase.md
Created July 25, 2017 18:14
Signing git commits on github using keybase.io gpg key

Probably one of the easiest things you'll ever do with gpg

Install Keybase: https://keybase.io/download and Ensure the keybase cli is in your PATH

First get the public key

keybase pgp export | gpg --import

Next get the private key

@caged
caged / postgres-ordered-sets.md
Last active April 5, 2016 03:13
Examples of ordered set aggregates in Postgres

Examples of ordered set aggregates in Postgres.

SELECT round(avg(pie)::numeric, 2),
       percentile_cont(array[0.25, 0.5, 0.75, 0.95]) WITHIN GROUP (ORDER BY pie) AS percentiles
FROM player_stats_advanced
WHERE permode = 'pergame';

round | percentiles

@damontorgerson
damontorgerson / gist:2231f42302da9f9f078b
Created November 30, 2014 23:53
Launch SIDEKIQ in Amazon Elastic Beanstalk (AMI 1.0.9)
files:
"/etc/rsyslog.d/11-sidekiq.conf":
mode: '000644'
content: |
EB_CONFIG_APP_LOGS=$(/opt/elasticbeanstalk/bin/get-config container -k app_log_dir)
$InputFileName $EB_CONFIG_APP_LOGS/sidekiq.log
$InputFileTag sidekiq
$InputFileStateFile sidekiq-state
$InputFileSeverity info
@drnic
drnic / cf-aws-dns-small.yml
Last active December 18, 2015 14:39
Deployment manifest for cf-release bosh release on aws used by cf-docs
# Ensure:
# * "cf" security group has all ports open (until ports required are better understood)
# * replace 'YOUR-BOSH-UUID' with UUID from "bosh status"
# * replace 2.3.4.5 with an elastic IP from target AWS region
# * replace 'mycloud.com' with your base domain that maps *.DOMAIN to your IP address
#
# Also:
# * your microbosh has port 53 (UDP or TCP) open for internal DNS
#
# Optional:
@jeremy
jeremy / gist:4035286
Created November 7, 2012 23:15
Enumerable#associate

We've seen lots of Ruby feature requests about converting an Enumerable to a Hash: to_h, map_hash, map_to, each_with_hash, etc. Let's look at one common, simple case of this.

Building a key/value mapping from a collection of keys is awkward. We commonly see Hash[*collection.map { |element| [element, calculate(element)] }] or collection.each_with_object({}) { |element, hash| hash[element] = calculate(element) }. Both are verbose. They require boilerplate code that's not relevant to the programmer's intent: to associate an enumerable of keys with calculated values.

Ruby has the idea of an association already: a key and value paired together. It's used by Array#assoc to look up a value from a list of pairs and by Hash#assoc to return a key/value pair. Building up a mapping of key/value pairs is associating keys with values.

So! Consider Enumerable#associate which builds a mapping by associating keys with values:

# Associate filenames with URLs. Before:
@kwiest
kwiest / gist:2714778
Created May 16, 2012 23:08
Migration example
# Migration (created from Devise)
class DeviseCreateUsers < ActiveRecord::Migration
def self.up
create_table(:users) do |t|
t.database_authenticatable :null => false
t.recoverable
t.rememberable
t.trackable
t.string :name
@jlong
jlong / uri.js
Created April 20, 2012 13:29
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@cramforce
cramforce / de.json
Created August 29, 2011 19:39
lang.json
{
"locale": "de",
"text": {
"#authors": [
{
"name": "Malte Ubl",
"screen-name": "cramforce"
}
],
"tweet": {
@torsten
torsten / proxy.rb
Last active March 12, 2023 21:44
A quick HTTP proxy server in Ruby.
#!/usr/bin/env ruby
# A quick and dirty implementation of an HTTP proxy server in Ruby
# because I did not want to install anything.
#
# Copyright (C) 2009-2014 Torsten Becker <torsten.becker@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,