Skip to content

Instantly share code, notes, and snippets.

View ssoroka's full-sized avatar
👾

Steven Soroka ssoroka

👾
View GitHub Profile
#!/usr/bin/env bash
export RUBY_HEAP_MIN_SLOTS=800000
export RUBY_HEAP_FREE_MIN=100000
export RUBY_HEAP_SLOTS_INCREMENT=300000
export RUBY_HEAP_SLOTS_GROWTH_FACTOR=1
export RUBY_GC_MALLOC_LIMIT=79000000
alias flow='ps vx | grep -iE "\b(adium|messages|mail|skype|twitter|propane|flint|sparrow)\b" | grep -v grep | cut -f1 -d" " | xargs kill; osascript -e "tell Application \"iTunes\" to play" 2&> /dev/null; echo "FLOW MODE ENABLED: Distractions closed; tunes playing"'
alias flowish='ps vx | grep -iE "\b(mail|skype|twitter|propane|flint|sparrow)\b" | grep -v grep | cut -f1 -d" " | xargs kill; osascript -e "tell Application \"iTunes\" to play" 2&> /dev/null; echo "FLOW MODE ENABLED: Distractions closed; tunes playing"'
export HISTFILESIZE=100000
# insert at the top of boot.rb for FUN!
require 'benchmark'
$level ||= 0
$file ||= File.open('require_tree.log', 'w')
$pending_writes = []
Object.class_eval do
def __trace_requires(arg, &block)
val = nil
time = nil
$pending_writes << [$level, arg]
@ssoroka
ssoroka / ar_factory_test.rb
Created March 25, 2013 20:26
Make your data layer an implementation detail. :)
require 'test_helper'
class ARFactory
def self.new(table_name)
Class.new(ActiveRecord::Base) do
self.table_name = table_name
end
end
end
@ssoroka
ssoroka / eyes.rb
Created April 11, 2013 03:09
If we know the odds of parents having children with certain eye colors, and the current eye color distributions, we can simulate random generations and see what happens! http://www.statisticbrain.com/eye-color-distribution-percentages/ https://twitter.com/scienceporn/status/322099933484314624
# given eye color distribution from:
# http://www.statisticbrain.com/eye-color-distribution-percentages/
# ignoring the yellow specs, basically:
# blue 32%, green 12%, brown 41% = 85%
# thus..
# blue 38%, green 14%, brown 48% = 100%
#
# also given the image from here..
# https://twitter.com/scienceporn/status/322099933484314624
#
@ssoroka
ssoroka / gist:5824696
Last active December 18, 2015 18:19
Ember issues.

ember issues

  • update docs that use {{#each controller}} to {{#each model}} and/or explain the difference.
  • assert errors or log debug info when templates reference undefined attributes in development
  • need larger project examples of ember in live use for a production application. docs are inconsistent and too shallow on scope
  • Horrible gotchya: Passing a second argument to {{render}} creates a new controller (like {{control}} would) rather than reusing the existing one (without warning or documentation). This makes perfect sense once you understand it, but there's no indication that this is happening except that properties you set on the controller are missing. I'd love a developer mode that tells you everything Ember is generating silently for you (controllers, routes, new instances, missing attributes, etc)
  • defining a route with nothing in it is not the same as the auto generated one (it overwrites the default setupController or model?). No ideas why.
  • attributes absolutely need a readOn
App.SortedElementsView = Ember.View.extend Ember.TargetActionSupport,
target: Ember.computed.alias('controller')
action: 'sort'
classNames: ['sorted-elements']
attributeBindings: ['id', 'fields']
elementClass: 'sortable-element'
didInsertElement: () ->
elements = ".#{@get('elementClass')}"
Em.run.next () =>
hookupSortable = () =>
@ssoroka
ssoroka / state_machine.rb
Created August 22, 2013 03:35
State machine in < 100 lines of ruby. No guards. (could be implemented trivially)
module StateMachine
def self.included(klass)
klass.send(:extend, ClassMethods)
klass.instance_eval do
after_initialize :set_initial_state
end
end
module ClassMethods
def state_column
@ssoroka
ssoroka / user.js.coffee
Last active December 21, 2015 12:48
a "method_missing" example in ember.js. Catch setting undefined properties and serialize them to an "optionsString" property as a string of JSON.
App.User = DS.Model.extend
name: DS.attr 'string'
email: DS.attr 'string'
# dynamically defined properties are serialized as a string of JSON here:
optionsString: DS.attr 'string'
# optionsData lets us deal with the string as a JSON object
optionsData: ((k,v) ->
if arguments.length == 2
@set('optionsString', JSON.stringify(v))
@ssoroka
ssoroka / unicorn_init.sh
Last active August 29, 2015 13:58
for use with curl | sed
#!/bin/sh
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Manage unicorn server
# Description: Start, stop, restart unicorn server for a specific application.
### END INIT INFO
upstream unicorn {
server unix:/var/run/.unicorn.sock fail_timeout=0;
}
server {
listen 80 default_server deferred;
server_name example.com;
root /home/username/apps/projectname/current/public;
location ^~ /assets/ {