Skip to content

Instantly share code, notes, and snippets.

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include "http_parser.h"
#define MAX_DATA 1024
int on_message_begin(http_parser *parser)
@oscardelben
oscardelben / debugger.rb
Created July 6, 2012 15:56
Minimal debugger written in Ruby
class Foo
def speak
'hello'
end
end
my_proc = Proc.new do |event, file, line, id, binding, classname|
printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname
while cmd = gets.chomp do
if cmd == 'n'
<form class="my_form">
<a class="my_link"></a>
</form>
<script type="text/javascript">
$('.my_form').live('ajax:success',
// this gets triggered when I click on my_link, I don't want that
)
$('.my_link').live('ajax:success',
while read rev; do
git diff $rev |
grep foo;
done
@oscardelben
oscardelben / gist:1396518
Created November 26, 2011 23:38
Javascript, the bad parts
class User
setName: (name) ->
@name = name
class Programmer
user = new User
programmer = new Programmer
user.setName.apply programmer, ['Oscar']
def distribution_chart_helper(width,height,sent,click, hist_sent, hist_click)
max_val = [sent,click, 1].max
hist_max_val = [hist_sent, hist_click, 1].max
hist_sent = max_val.to_f * hist_sent / hist_max_val.to_f
hist_click = max_val.to_f * hist_click / hist_max_val.to_f
data = [sent,click, hist_sent, hist_click].map{|d| [d,0.01].max}.join("|")
legend = "sent|clicks"
data_labels = (0..1).map{|i| "N*f0*,000000,#{i},-1,11"}.join("|")
def oauth
OAuth::Consumer.new(
consumer_key,
consumer_secret,
{
:site => 'https://api.login.yahoo.com',
:scheme => :query_string,
:http_method => :get,
:request_token_path => '/oauth/v2/get_request_token',
:access_token_path => '/oauth/v2/get_token',
import oauth.oauth as oauth
import httplib
class ZooppaClient(object):
# consumer_key, consumer_secret are your api key and secret as strings
def __init__(self, consumer_key, consumer_secret):
self.consumer = oauth.OAuthConsumer(consumer_key, consumer_secret)
self.host = 'localhost'
self.port = 3000
if self.port == 80:
module ActiveRecord
module Acts
module TaggableOn
module SingletonMethods
def find_options_for_tag_counts(options = {})
options.assert_valid_keys :start_at, :end_at, :conditions, :at_least, :at_most, :order, :limit, :on, :id
scope = scope(:find)
start_at = sanitize_sql(["#{Tagging.table_name}.created_at >= ?", options.delete(:start_at)]) if options[:start_at]
end_at = sanitize_sql(["#{Tagging.table_name}.created_at <= ?", options.delete(:end_at)]) if options[:end_at]
Exercise 1.14
Order of growth is O(3n) NOTE: this is my result by I've seen elsewhere different results.
Exercise 1.15
p is evaluated 5 times
order of growth is O(log n) because the amount of resource needed is constant.