Skip to content

Instantly share code, notes, and snippets.

View l0gicpath's full-sized avatar

Hady Mahmoud l0gicpath

View GitHub Profile
/* Ismael Celis 2010
Simplified WebSocket events dispatcher (no channels, no users)
var socket = new FancyWebSocket();
// bind to server events
socket.bind('some_event', function(data){
alert(data.name + ' says: ' + data.message)
});
@l0gicpath
l0gicpath / dnsd.rb
Created December 9, 2011 05:14 — forked from peterc/dnsd.rb
Simple, scrappy UDP DNS server in Ruby (with protocol annotations)
# Simple, scrappy UDP DNS server in Ruby (with protocol annotations)
# By Peter Cooper
#
# MIT license
#
# * Not advised to use in your production environment! ;-)
# * Requires Ruby 1.9
# * Supports A and CNAME records
# * See http://www.ietf.org/rfc/rfc1035.txt for protocol guidance
# * All records get the same TTL
@l0gicpath
l0gicpath / rails_bootstrap_delete_confirmation_modal.md
Created September 21, 2012 03:36 — forked from postpostmodern/rails_bootstrap_delete_confirmation_modal.md
A nice delete confirmation modal in Rails courtesy of Bootstrap

Here's what you get.

Some CoffeeScript (verbosely commented for clarity)

# Override Rails handling of confirmation

$.rails.allowAction = (element) ->
  # The message is something like "Are you sure?"
  message = element.data('confirm')
@l0gicpath
l0gicpath / accepts_new_nested_associations.rb
Created November 5, 2012 04:26 — forked from Zequez/accepts_new_nested_associations.rb
Allow existing associations in accepts_nested_attributes_for
module ActiveRecord::NestedAttributes
module ClassMethods
def accepts_nested_attributes_for(*attr_names)
options = { :allow_destroy => false, :update_only => false }
options.update(attr_names.extract_options!)
# Modified stuff
#options.assert_valid_keys(:allow_destroy, :reject_if, :limit, :update_only)
options.assert_valid_keys(:allow_destroy, :reject_if, :limit, :update_only, :allow_existing)
# This is an incomplete implementation.
module MongoMapper
module NestedAttributes
def self.included(base)
base.extend(ClassMethods)
base.send :include, InstanceMethods
end
module ClassMethods
def accepts_nested_attributes_for(*attr_names)
/* Abstract event binding
Example:
var MyEventEmitter = function(){};
MyEventEmitter.prototype = new AbstractEventsDispatcher;
var emitter = new MyEventEmitter();
// Bind to single event
emitter.bind('foo_event', function(data){ alert(data)} );
/*
MAKE the whole block actionable with CSS only.
<div id="block" title="read more about ...">
<h3><a href="...">Some title here</a></h3>
<p>bla bla bla .... bla!</p>
</div>
*/
(function(global) {
var silpUrl = '//s3-eu-west-1.amazonaws.com/silp.shootitlive.com/js/silp.min.js';
// Globals
if(!global.Silp) { global.Silp = {}; };
var Silp = global.Silp;
// To keep track of which embeds we have already processed
if(!Silp.foundEls) Silp.foundEls = [];
# coding=UTF-8
from __future__ import division
import nltk
from collections import Counter
# This is a simple tool for adding automatic hashtags into an article title
# Created by Shlomi Babluki
# Sep, 2013

Retirement Calculator

  • ages are in years
  • contribution, and savings are in dollars
  • avg_annual_return is a ratio, so 1.07 is a 7% annual return

let's say I'm 25 years old, I am going to contribute $2000/yr in bonds (~5% return), and I've already invested $5700 in bonds