Skip to content

Instantly share code, notes, and snippets.

View k2052's full-sized avatar
🦄
awesome

K k2052

🦄
awesome
View GitHub Profile
@k2052
k2052 / README.md
Created July 11, 2011 16:23
If God Was A Programmer

The Universe.

Worked on this last week. Not quite complete, very early alpha. Use at your own risk!

Getting started

  1. $ gem source --add http://god.org
  2. $ gem install strings
  3. $ gem install atoms

History

This all started when I moved to a design-in-browser workflow over the winter.

Designing in the browser is a workflow pain, jumping back into photoshop & shiny up a design is a productivity killer. I try to work in code as long as possible and avoid PS. I originally started out with an HTML/CSS to PSD converter using the PS API, although I got pretty far I quickly discovered it was going to be too slow. Parse HTML and for everything element create relevant layers, PS could barely handle it much less perform effectively.

I had two options; 1. Reverse engineer a PSD format writer or 2. Start work on a app that could speak both graphics and HTML. The latter seemed like an easier task so here I am.

The Basics.

@k2052
k2052 / group_by_date_mongodb.js
Created August 30, 2011 18:36
Group By Date Mongodb
/*
* JavaScript Pretty Date
* Copyright (c) 2008 John Resig (jquery.com)
* Licensed under the MIT license.
*/
// Takes an ISO time and returns a string representing how
// long ago the date represents.
function prettyDate(time) {
var date = time,
@k2052
k2052 / gear.md
Created October 3, 2011 00:12
Zombie Apocalypse Survival Guide.

The shit you'll need.

@k2052
k2052 / setup_new_mac_environment.md
Created January 18, 2012 19:34
Setup New Mac Environment

General

  • Disable caps lock key (Sys Pref => Keyboard => Modifier Keys)
  • System Pref -> Security -> Sleep Password

Apps

@k2052
k2052 / addbinary.rb
Created January 20, 2012 22:55
Add two binary strings using ruby.
class Numeric
def ones_complement(bits)
self ^ ((1 << bits) - 1)
end
end
def addbinary(b1, b2)
result = ''
carry = 0
  • Angers someone = 0.50 (negative or positiving depending on whether or not that person is liked)
  • Long term Physical Health = 0.98
  • Long term Mental Health = 0.95
  • Short term Mental Health = 0.99
  • Short term Physical Health = 0.85
  • Endangers Self = -0.80
  • Causes Someone to develop emotional attachment = -0.95
@k2052
k2052 / howNotToBuildLoopsInCoffescript.coffee
Created February 12, 2012 20:33
For loops in coffeescript. Be careful how you port your code.
# This will never end because i++ wont be reached more than three times.
i = 0
i = 0
while i <= 10
continue if i is 3
console.log "The number is " + i
console.log "\n"
i++
@k2052
k2052 / scriptingCSH.rb
Created February 14, 2012 07:18
make sure to install rbappscript first. Then you'll need the MakeCustomShape action installed from here http://cl.ly/2x3Z2j3a2B0X292b1f1S. Theoretically that is it. Works for me, hopefully for you as well.
require 'rubygems'
require 'appscript'
# Make sure to open your apps first. Appscript can get ahead of itself and not wait for them to load so it will fail
# Set your dir with AI files and thats it
dirname = "/Users/kenerickson/testCSH"
ai = Appscript.app.by_id('com.adobe.illustrator')
ps = Appscript.app.by_id('com.adobe.photoshop')
# ps = Appscript.app("/Applications/Adobe Photoshop CS3/Adobe Photoshop CS3.app")
@k2052
k2052 / application.rb
Created March 13, 2012 01:05
How to use QuickLook in Macruby
require 'rubygems' # disable this for a deployed application
require 'hotcocoa'
framework 'Quartz'
# This Needs to conformal to QLPreviewItem
class Item
attr_accessor :previewItemURL
end
module QLookBehaviors