Skip to content

Instantly share code, notes, and snippets.

@quackingduck
quackingduck / app.rb
Created February 12, 2011 10:55
A one-file MacRuby app
#!/usr/bin/env macruby
framework 'AppKit'
# Inspired by: http://cocoawithlove.com/2010/09/minimalist-cocoa-programming.html
# Inits NSApp
NSApplication.sharedApplication
# Allows an app without an applicaiton bundle or info.plist to still be an app
#!/usr/bin/env macruby
framework 'AppKit'
module AppDelegate
extend self
def applicationDidFinishLaunching(notification)
voice_type = "com.apple.speech.synthesis.voice.GoodNews"
@voice = NSSpeechSynthesizer.alloc.initWithVoice(voice_type)
@quackingduck
quackingduck / config.ru
Created May 6, 2012 23:23
Rack config for a static site
# A config.ru useful for serving static sites from the "Bamboo" heroku stack.
#
# Interface:
#
# Url Path | Action
# -------- | -------------------------------------------------------------
# / | contents of: index.html OR
# | contents of: 404.html OR
# | default 404 message
# |
@quackingduck
quackingduck / parse_msg.coffee
Created December 20, 2012 02:06
Parse a json encoded hashmap or return an empty one and print a warning
# Parse a json encoded hashmap or return an empty one and print a warning
parseMsg = (jsonStr) ->
try json = JSON.parse jsonStr
catch err then handleParseErr err, jsonStr
json ? {}
handleParseErr = (err, jsonStr) ->
console.error '[WARN]','JSON parser:', err, 'input json was:', jsonStr
#!/bin/bash
if [ ! -r "/usr/local/git" ] || [ ! -f /usr/bin/git ]; then
echo "Git doesn't appear to be installed via this installer. Aborting"
exit 1
fi
echo "This will uninstall git by removing /usr/local/git/**/*, /etc/paths.d/git, /etc/manpaths.d/git"
printf "Type 'yes' if you sure you wish to continue: "
read response
if [ "$response" == "yes" ]; then
sudo rm -rf /usr/local/git/
@quackingduck
quackingduck / js_classes.js
Last active December 20, 2015 02:29
javascript madness __proto__ and prototype and class
// OBJECT PROGRAMMING
avi = {
walk: function() { console.log(this.name + ' is walking') },
name: 'Avi'
}
avi.walk()
avi.lastName = 'Kaufman'
echo hello from gist
#!/bin/bash
# Given some html (on stdin), wraps it in html that applies the same aesthetic
# that github uses for rendering markdown-processed content
# Usage:
# markdown < in.md | ghstyles > out.html
# If you have node.js installed I recommend the [marked] processor. It's fast,
# supports "github flavored" markdown by default and has no dependencies
var nestedListMatch = function(lists, match) {
var firstItem = lists[0];
if(firstItem === match) {
return match;
}else if (Array.isArray(firstItem)){
var result = nestedListMatch(firstItem, match)
if(result === match) {