Skip to content

Instantly share code, notes, and snippets.

fourseven / gist:9259219
Last active Aug 29, 2015
Ruby vs ObjC named params
View gist:9259219
I have:
def self.find_bot_for_user_from_token(current_user, oauth_token)
Using named params it would be (requires 2.1 to not have defaults):
def self.find_bot(for_user:, from_token:)
puts for_user
View 99_bottles.rb
def b i=1,w=nil
"#{i} bottle#{:s if i>1} of beer#{" on the wall" if w}"
puts *99.downto(2).map {|n| "#{b n,1}, #{b n}.\nTake one down and pass it around, #{b n-1,1}.\n\n"}
puts "#{b 1,1}, #{b}.\nGo to the store and buy some more, #{b 99,1}.\n\n"
View fizzbuzz.rb
o="Fizz" if i%3==0
o+="Buzz" if i%5==0
puts o==""?l:o}
View SQLcleanup
Hash Semi Join (cost=1374.03..1852.31 rows=59 width=62) (actual time=22.141..23.774 rows=1 loops=1)
Nested Loop Anti Join (cost=19.22..235.45 rows=33 width=62) (actual time=0.046..0.047 rows=1 loops=1)


It's useful to know the memory characteristics of different Ruby versions.

2.0 Uses less memory, but is slower - GC blocks while running

2.1 Generational GC - more memory, but faster GC meaning faster apps (split: old / young heap spaces)

2.2 Introduces incremental GC - marks in steps, reducing stop-the-world time, making OOB GC redundant.

fourseven / retina-sprites.css.scss
Created Aug 16, 2012
A compass function to handle spriting with normal and retina images automatically.
View retina-sprites.css.scss
// @Mixin Retina Sprite Sass
// ======================================================
// This requires two folders full of *.png files, normal and then
// 2x resolution. Please ensure that they have the same number and names
// of files.
// I've written this based off other efforts on the web, but none did
// both background-images and a set of sprites automatically.
// Still very much a work in progress.
// To use see the bottom three lines.
fourseven / dabblet.css
Created Mar 11, 2013
The first commented line is your dabblet’s title
View dabblet.css
* The first commented line is your dabblet’s title
.parent {
border: 1px solid red;
.child {
View dabblet.css
* border-box
* {box-sizing: border-box;}
.non-border-box {
box-sizing: content-box;
div {
border: 2px solid blue;
fourseven / classes.rb
Created Jun 27, 2013
Notes/examples for better code
View classes.rb
class MailerContact
def initialize(first_name, last_name)
@first_name, @last_name = first_name, last_name
def full_name
"#{@first_name} #{@last_name}"
fourseven / aws_iot.ino
Created Jul 26, 2017
Code for my temperature sensor
View aws_iot.ino
#include <Arduino.h>
#include <Stream.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
// DHT22 -,
#include "DHT.h"
#include "sha256.h"