Skip to content

Instantly share code, notes, and snippets.

@jrmoran
jrmoran / posterous-disqus.rb
Created January 31, 2012 08:35
Exporting Posterous comments to Disqus
require 'posterous'
require 'time'
# Add your credentials Here
Posterous.config = {
'username' => '<email-address>',
'password' => '<password>',
'api_token' => '<api-token>'
}
@jrmoran
jrmoran / app.coffee
Created January 16, 2012 20:57
Precompiled Haml templates with CoffeeScript
companies = [{"id":1,"ticker":"AAPL","name":"Apple Inc"},
{"id":2,"ticker":"ABC","name":"Amerisourcebergen Corp"},
{"id":3,"ticker":"ABT","name":"Abbott Labs"},
{"id":4,"ticker":"ACE","name":"Ace Ltd"},
{"id":5,"ticker":"ADBE","name":"Adobe Sys Inc"}]
_.templateSettings = interpolate :/\{\{(.+?)\}\}/g
$ ->
@jrmoran
jrmoran / App.coffee
Created January 16, 2012 09:54
Backbone and CoffeeScript
$ ->
# Inspired in
# [this](http://adamjspooner.github.com/coffeescript-meet-backbonejs/)
#
# Live sample [here](http://jrmoran.com/playground/backbone-coffeescript/)
# override backbone sync, so when we remove/save items no server calls
# are made
Backbone.sync = (method, model, success, error) -> success()
@jrmoran
jrmoran / loader.js
Created January 14, 2012 04:55
dynamic script loader
var myLoader = function(filename, fun) {
var head = document.getElementsByTagName('head')[0],
script = document.createElement('script');
script.type = 'text/javascript';
script.src = filename;
if(typeof fun === 'function'){ script.onload = fun; }
head.appendChild(script);
};
timeIt = (f)->
start = Date.now()
f()
console.log 'time: ', Date.now() - start, 'ms'
adder = ->
total = 0
((n = 0)-> total += n)
timeIt ->
@jrmoran
jrmoran / Cakefile
Created December 30, 2011 01:44
Cakefile to document, compile, join and minify CoffeeScript files for client side apps.
# Cakefile to document, compile, join and minify CoffeeScript files for
# client side apps. Just edit the config object literal.
#
# -jrmoran
fs = require 'fs'
{exec, spawn} = require 'child_process'
# order of files in `inFiles` is important
config =
@jrmoran
jrmoran / movistar.rb
Created December 26, 2011 06:12
movistar_captcha
# Jaime Moran
require 'net/http'
def download_captcha file_name
uri = URI.parse('http://www.corporativo.telefonica.com.sv/EnviarSMSSV/faces/' +
'EnviarSMS.jsp?vrClientId=form1:imageEx1')
headers = { 'user-agent' => 'Mozilla/4.0 (Compatible; MSIE 4.0)' }
http = Net::HTTP.start(uri.host, uri.port)
response = http.request_get(uri.path, headers)
@jrmoran
jrmoran / buzzify.clj
Created December 18, 2011 10:16
fizzbuzz
(defn buzziffy [a b x]
(cond (and (zero? (mod x a)) (zero? (mod x b))) "FizzBuzz"
(zero? (mod x a)) "Fizz"
(zero? (mod x b)) "Buzz"
:else x))
(println (apply str (map #(str (buzziffy 3 5 %) "\n")
(range 1 100))))
@jrmoran
jrmoran / standard_deviation.py
Created December 18, 2011 02:20
standard deviation
def std(nums): return math.sqrt(sum([pow(n - sum(nums)/len(nums),2) for n in nums])/len(nums))
@jrmoran
jrmoran / truthy.js
Created December 9, 2011 03:48
Weird JS
p = console.log;
// # objects are truthy
var b = new Boolean(); // Never use the Boolean constructor
p( b.toString() ); // 'false'
p( b == false ); // true, use strict equality comparison with ===
p( b === false ); // false
p( b ? 'yeah' : 'nope' ); // yeah