Skip to content

Instantly share code, notes, and snippets.

@max-mapper
max-mapper / index.html
Created March 29, 2014 18:17
load a <script> tag from a gist raw url
<!doctype html>
<html>
<head>
<style type="text/css">
html, body { margin: 0; padding: 0; }
</style>
</head>
<body>
<script type='text/javascript'>
function loadRaw(gistID) {
@Integralist
Integralist / Ruby Lambdas.md
Last active August 8, 2023 05:10
Ruby lambdas

Lambda: standard

# Creating a lambda
l = lambda { |name| "Hi #{name}!" }

# Executing the lambda
l.call("foo") # => Hi foo!
# config/routes.rb
resources :documents do
scope module: 'documents' do
resources :versions do
post :restore, on: :member
end
resource :lock
end
end
@Kartones
Kartones / postgres-cheatsheet.md
Last active April 22, 2024 17:18
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@pcreux
pcreux / 000_postgresql_fancy_datatypes
Last active March 18, 2022 16:51
Postgresql fancy datatypes with Rails / ActiveRecord. Run it with `rake`!
# Postgresql fancy datatypes!
* array
* hstore (=~ hash)
* json
* jsonb
Philippe Creux - [@pcreux](http://twitter.com/pcreux)
@iansheridan
iansheridan / closures.rb
Created July 7, 2014 15:27
A demonstration of Ruby closures by Paul Cantrell
# CLOSURES IN RUBY Paul Cantrell http://innig.net
# Email: username "cantrell", domain name "pobox.com"
# I recommend executing this file, then reading it alongside its output.
#
# Alteratively, you can give yourself a sort of Ruby test by deleting all the comments,
# then trying to guess the output of the code!
# A closure is a block of code which meets three criteria:
#
@joejag
joejag / peach.rb
Created August 14, 2014 13:06
Parallel each method for ruby
class Array
def peach(&block)
threads = []
self.each do |item|
threads << Thread.new do
block.call(item)
end
end
threads.each {|t| t.join }
end
@Andrew-Max
Andrew-Max / gist:305483febc3c367dbf57
Last active June 13, 2022 07:55
Route lifecycle hooks guide from Ember meetup lightning talk
App.LibraryRoute = App.ApplicationRoute.extend({
activate: function () {
//no longer enter
this._super();
only called once on entering a route.
},
beforeModel: function () {
// any state you want in place before the model is initialized, this is called before any model promises are resolved
// also could be used to conditionally prevent access to a route by throwing transition.abort
@bendc
bendc / functional-utils.js
Last active September 15, 2023 12:12
A set of pure ES2015 functions aimed to make functional JavaScript more idiomatic.
// array utils
// =================================================================================================
const combine = (...arrays) => [].concat(...arrays);
const compact = arr => arr.filter(Boolean);
const contains = (() => Array.prototype.includes
? (arr, value) => arr.includes(value)
: (arr, value) => arr.some(el => el === value)
@cflee
cflee / ruby-blocks-procs-lambdas.md
Created January 14, 2015 07:10
Discoveries about Ruby Blocks, Procs and Lambdas

Ruby: Blocks, Procs, Lambdas

Note that for blocks, {} and do ... end are interchangeable. For brevity, only the former will be listed here.

Version differences

Pre-1.9, lambda and proc are synonyms. Essentially the difference is between proc and block.

def method(&block) p block.class; p block.inspect; end
l = lambda { 5 }