Skip to content

Instantly share code, notes, and snippets.

View itsbth's full-sized avatar

Bjørn Tore Håvie itsbth

View GitHub Profile
@itsbth
itsbth / main.coffee
Created December 22, 2011 10:09
Uploaded by UploadToGist for Sublime Text 2
WORLD_SIZE = [0..31]
BLOCKS = _([1, 1, 33, 34, 50]).reverse()
Vector =
add: (a, b) ->
{x: a.x + b.x, y: a.y + b.y}
subtract: (a, b) ->
{x: a.x - b.x, y: a.y - b.y}
multiply: (a, b) ->
{x: a.x * b, y: a.y * b}
@itsbth
itsbth / RailsHelper.py
Created December 22, 2011 15:43
Uploaded by UploadToGist for Sublime Text 2
import re
import sublime_plugin
from os import path
IS_RAILS = re.compile(r'(/app/(controllers|helpers|mailers|models)/|/config/routes|/db/migrate/).+\.rb$')
class GuessRubyTypeListener(sublime_plugin.EventListener):
def on_load(self, view):
name = view.file_name()
@itsbth
itsbth / dupes.js.coffee
Created December 24, 2011 13:02
Uploaded by UploadToGist for Sublime Text 2
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
$ ->
$('#dupe_image').data('n', 0).attr(id: 'dupe_image_0', name: 'dupe[image][0]').change ->
$this = $(this)
n = $this.data('n') + 1
parent = $this.unbind('change').parents('.clearfix')[0]
$parent = $(parent)
$node = $(parent).clone()
@itsbth
itsbth / dupes.js.coffee
Created December 27, 2011 16:17
Uploaded by UploadToGist for Sublime Text 2
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
#= require Markdown.Converter.js
#= require Markdown.Sanitizer.js
$ ->
converter = Markdown.getSanitizingConverter()
$('#dupe_description').keyup (evt) ->
$('#md_preview').html converter.makeHtml $(this).val()
@itsbth
itsbth / app.coffee
Created January 1, 2012 01:41
Uploaded by UploadToGist for Sublime Text 2
http = require 'http'
server = http.createServer (req, res) ->
res.writeHead 200
res.end "Hello, World!"
server.listen 8080
@itsbth
itsbth / app.coffee
Created January 1, 2012 03:35
Uploaded by UploadToGist for Sublime Text 2
fs = require 'fs'
connect = require 'connect'
io = require 'socket.io'
coffee = require 'coffee-script'
coffee_cache = {}
server = connect.createServer(
connect.static(__dirname + '/public')
(req, res, next) ->
@itsbth
itsbth / AST.coffee
Created January 2, 2012 16:26
Uploaded by UploadToGist for Sublime Text 2
class Scope
constructor: (@values={}) ->
get: (name) -> @values[name]
set: (name, value) -> @values[name] = value
class Node
class Statement extends Node
execute: (scope) ->
throw new Exception("WAT DO")
@itsbth
itsbth / crack.rb
Created January 3, 2012 20:18 — forked from anonymous/crack.rb
#!/usr/bin/env ruby
if ?A.is_a? String
ab = (?A..?Z).to_a
else
ab = (?A..?Z).map {|c| c.chr}
end
n = $<.readline.to_i
str = $<.read
puts str.split('').map {|oc| c = oc.upcase; if ab.include? c then r = ab[(ab.index(c) - n) % ab.length]; c == oc ? r : r.downcase else c end }.join
@itsbth
itsbth / grammar.coffee
Created January 5, 2012 19:58
Uploaded by UploadToGist for Sublime Text 2
{Parser} = require 'jison'
# Stolen from coffee-script
# Since we're going to be wrapped in a function by Jison in any case, if our
# action immediately returns a value, we can optimize by removing the function
# wrapper and just returning the value directly.
unwrap = /^function\s*\(\)\s*\{\s*return\s*([\s\S]*);\s*\}/
# Our handy DSL for Jison grammar generation, thanks to
@itsbth
itsbth / grammar.coffee
Created January 5, 2012 20:54
Uploaded by UploadToGist for Sublime Text 2
{Parser} = require 'jison'
# Stolen from coffee-script
# Since we're going to be wrapped in a function by Jison in any case, if our
# action immediately returns a value, we can optimize by removing the function
# wrapper and just returning the value directly.
unwrap = /^function\s*\(\)\s*\{\s*return\s*([\s\S]*);\s*\}/
# Our handy DSL for Jison grammar generation, thanks to