Skip to content

Instantly share code, notes, and snippets.

@focusaurus
focusaurus / Model.coffee
Created July 19, 2012 01:51
Add named get/set methods to backbone models
addConvenienceMethods = ->
for prop, value of this.attributes
((prop) ->
#Define a setter/getter function
this[prop] = (newValue...) ->
if newValue.length
this.set prop, newValue[0]
return this
else
return this.get prop
@focusaurus
focusaurus / tipper.js
Created March 14, 2012 13:22
Clearest example of closures ever?
var tipper = function (percentage) {
return function tip(total) {
return total + (total * (percentage / 100));
};
};
var generous = tipper(20);
var normal = tipper(18);
var stingy = tipper(8);
@focusaurus
focusaurus / closures.coffee
Created October 15, 2011 02:01
Closures in coffeescript
makeLogger = (prefix) ->
(message) -> console.log "#{prefix.toUpperCase()}: #{message}"
fooLogger = makeLogger 'foo'
barLogger = makeLogger 'bar'
fooLogger n for n in [1..10]
barLogger n for n in [1..10]
fooLogger n for n in [11..20]
@focusaurus
focusaurus / default.rb
Created August 19, 2011 21:58
Chef Recipe
require 'rubygems'
require 'json'
CONF_PATH = '/tmp/clouddial_conf.json'
cookbook_file CONF_PATH do
source File.basename CONF_PATH
mode '0444'
backup false
end
@focusaurus
focusaurus / debug.coffee
Created March 30, 2011 03:14
CoffeeScript Introspection Function
debug = (obj, seen)->
printProps = (obj)->
#Edge case to handle is [1,2,3][9] = 'foo'
#Need to factor the conditional out to check if the prop is a number less
#than the array's length
return ((if ! /^\d+$/.test prop then prop + ": " + debug(obj[prop], seen) \
else '') for prop of obj).join(', ')
seen = seen or []
if obj in seen
@focusaurus
focusaurus / comcast.sh
Created September 17, 2015 13:25
using the "comcast" utility to throttle network traffic to a specific application
# https://github.com/tylertreat/Comcast
# In this example, the application I want to throttle is on TCP port 9110
comcast="${HOME}/projects/comcast/bin/comcast"
throttle() {
local profile="${1-wifi}"
local bandwidth=30000
local latency=40
@focusaurus
focusaurus / atom packages
Created January 13, 2015 04:58
Atom text editor setup 2015-01-12
atom-beautify
atom-color-highlight
autoclose-html
autocomplete-plus
git-blame
git-plus
jsdoc
jsformat
language-docker
language-dockerfile
@focusaurus
focusaurus / gist:03b814ea78e3952749dd
Created June 26, 2015 23:25
DB integrity checker instructions

Hi friend! So I just put up an alpha of my data analyzer that can scan any mongodb or couchdb server you can access from your laptop (including your local dev ones). It works by ssh tunneling and the "UI" is all ssh.

Could you give it a try and see what it says about your data?

Here's how to run it:

  1. ssh setup@carson.peterlyons.com
  • use password "password" when prompted
  1. Answer the questions about your db server it asks you
  • it will print another longer ssh command
@focusaurus
focusaurus / gist:b7f59b029f66e6b661cf
Created June 18, 2015 01:46
Review: Metaprogramming in ES6: Symbols and why they're awesome
class BoringClass  
end  
class CoolClass  
  def ==(other_object)
   other_object.is_a? MyClass
  end
end  
BoringClass.new == BoringClass.new #=> false  
CoolClass.new == CoolClass.new #=> true! 
@focusaurus
focusaurus / moin_to_markdown.py
Created September 2, 2014 02:46
Use for inspiration only. Very much a 1-off tool limited to a specific migration's needs.
#!/usr/bin/python
# This is a simple script to convert a very limited set of MoinMoin wiki syntax
#to markdown. I am using it in my migration from MoinMoin to a gitit+markdown
#wiki.
DO_GIT = False
#DISABLED#DO_GIT = True
import os
import re
REPLACEMENTS = (
("(./)", "[x]"),