Skip to content

Instantly share code, notes, and snippets.

View Radagaisus's full-sized avatar

Almog Melamed Radagaisus

View GitHub Profile
@Radagaisus
Radagaisus / tangle.css
Created December 22, 2011 22:23
verdict.coffe - tangle.js for jQuery (but smaller)
.CursorDragHorizontal {
cursor: col-resize;
}
/* TKToggle */
.TKToggle {
color: #46f;
border-bottom: 1px dashed #46f;
@Radagaisus
Radagaisus / schemer.rkt
Created December 23, 2011 19:11
The Little Schemer
; some of this functions, specifically ones from the early chapters, aren't tested,
; as I schemed through them.
; atom?
(define atom?
(lambda (x)
(and (not (pair? x)) (not (null? x)))))
; lat?
(define lat?
@Radagaisus
Radagaisus / jsonp.coffee
Created March 29, 2012 21:08
JSONP in 12 lines of Coffee
# JSONP
# Usage: jsonp 'http://google.com/', (data) -> console.log data
# Adapted from https://github.com/msingleton/TinyP
( ($, d) ->
$.jsonp = (url, callback) ->
# Create a random function name
text = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz$_'
c = (text[Math.floor(Math.random() * 54)] for i in [1..20]).join('')
# Add the script
@Radagaisus
Radagaisus / magic-numbers.scala
Created March 31, 2012 15:21
The Joy of Scala
scala> 4 + "1.0"
res12: String = 41.0
scala> "1.0" + 4
res13: java.lang.String = 1.04
@Radagaisus
Radagaisus / inheritance.coffee
Created April 8, 2012 02:11
Inheriting like a Boss
class Zero
@create: ->
class OrpheusInner extends @
attributes: []
attr: (x) -> @attributes.push x
return new OrpheusInner()
class One extends Zero
constructor: ->
@attr 'bloob'
# Thank you ZapaaJS!
# congrats to require() for making nodejs so awful
# for dividing code to files.
include = (file, args...) ->
file = require file
file.include.apply(this, args)
file
# index.coffee
@Radagaisus
Radagaisus / Async.coffee
Created June 19, 2012 16:38
Some Coffee Sugar for Async
async = require 'async'
# Async needs some coffee script suger
###
Parallel
---------------------------------------------------
// an example using an object instead of an array
async.parallel({
one: function(callback){
@Radagaisus
Radagaisus / sentences.coffee
Created July 4, 2012 21:37
from array, get a: 2
does = from = (arr, using) ->
for i in arr when using[0] i
return using[1] i
return using[2]
get = (obj) ->
for key,val of obj
return [
(i) -> i[key] is val
(i) -> i
@logs = []
for msg_type, log_level in ['error', 'warn', 'info', 'debug']
do (msg_type, log_level) ->
@[msg_type] = (msg = '', data = {}) ->
# Add to logs
@logs.push
type: msg_type
msg: msg
@Radagaisus
Radagaisus / oneliner-filter.coffee
Created August 3, 2012 18:36
I wonder if this is better or worse
getQuantity: (item_id) -> (i.quantity for i in items when i.id is item_id)[0]
# Or:
getQuantity: (item_id) ->
for i in @items
return i.quantity if i.item_id is item_id
undefined