Skip to content

Instantly share code, notes, and snippets.

@KarlHerler
KarlHerler / hoppity.rb
Created January 6, 2011 11:58
part of the hoppity puzzle
def hoppity(x)
(1..(x)).each do |i|
x = (i%3==0 && i%5==0) ? "Hop" : (i%3==0) ? "Hoppity" : (i%5==0) ? "Hophop" : nil
puts x if x
end
end
@KarlHerler
KarlHerler / gist:917390
Created April 13, 2011 11:39
computes relative bg size to factual 100% even at relative sizes.
$(this).attr('backround-size', (10000/parseInt($("this").width())+"%"));
//or
function bgsize(width) { return 10000/width; }
@KarlHerler
KarlHerler / ro5.sml
Created April 27, 2011 19:02
SML is not always a pretty language.
fun xadd(t1 :moneh, t2 :moneh) = if ((#2 t1)+(#2 t2))>100 then (((#1 t1)+(#1 t2)+1), ((#2 t1)+(#2 t2)-100)) else if ((#2 t1)+(#2 t2)<0) then (((#1 t1)+(#1 t2)-1), (((#2 t1)+(#2 t2))+100)) else (((#1 t1)+(#1 t2)), ((#2 t1)+(#2 t2)));
@KarlHerler
KarlHerler / attend_parse.js
Created May 23, 2011 14:01
Gets attendees from a specific facebook event (based on a eventid) and returns their name
var request = require('request'),
jsdom = require('jsdom'),
sys = require('sys');
function getAttendees(eventID, accessToken, callback) {
var attendees;
console.log("fetching: "+"https://graph.facebook.com/"+eventID+"/attending?access_token="+accessToken);
request({uri:"https://graph.facebook.com/"+eventID+"/attending?access_token="+accessToken}, function (error, response, body) {
console.log("sucess!");
if (!error && response.statusCode == 200) {
@KarlHerler
KarlHerler / work.js
Created June 9, 2011 05:22
Loads some data from mongodb in node and parses it a bit
function loadData(req, res, next) {
/* Loads all data. */
/*var filter = {}
if(req.params.tag) {
console.log("fetching data for tag: "+req.params.tag)
filter = {"tag": req.params.tag}
}*/
WorkInstance.find({}, ['_id','tag', 'start', 'stop'], {sort:[['start', -1]]}, function(err, docs) {
@KarlHerler
KarlHerler / maksuturva.rb
Created June 14, 2011 11:05
Lab version of the algorithm for creating a hash to maksutruva's payment gateway, it's madness
#!/usr/bin/env ruby
require 'sinatra'
require 'digest/sha1'
def getShit(keys)
hashprimer = ""
keys.each do |k|
hashprimer = hashprimer + params[k]+"&" if k=="pmt_action"
hashprimer = hashprimer + params[k]+"&" if k=="pmt_version"
hashprimer = hashprimer + params[k]+"&" if k=="pmt_selleriban"
@KarlHerler
KarlHerler / readme.md
Created June 20, 2011 06:26
Staging changes to a readme file
@KarlHerler
KarlHerler / gist:1035363
Created June 20, 2011 09:30
Headers for maksuturva
{"log":
{"version":"1.2" ,
"creator":
{"name":"WebInspector" ,
"version":"535.1"} ,
"pages":[
{"startedDateTime":"2011-06-20T09:25:50.941Z" ,
"id":"https://maksuturva.fi/NewPaymentExtended.pmt" ,
"title":"" ,
@KarlHerler
KarlHerler / flags.js
Created June 29, 2011 18:40
Trivial views with Backbone makes me all happy inside
var Flags = Backbone.View.extend({
el: $('#main'),
initialize: function() {
_.bindAll(this, 'render');
this.render();
},
render: function() {
var append="";
append += '<div id="flag-0" class="one smaller"></div><div id="flag-1" class="two smaller"></div>'
@KarlHerler
KarlHerler / routes.js
Created July 6, 2011 05:22
A express route
app.get('/:user/:tag', work.loadData, function(req, res) {
var uname = (req.session) ? (req.session.user===undefined) ? "" : req.session.user.name : "";
res.render('index', {
title: req.params.tag,
page: "index",
data: req.workDatas,
username: uname,
tracking: true
})
});