Skip to content

Instantly share code, notes, and snippets.

View TikiTDO's full-sized avatar

TikiTDO TikiTDO

  • Toronto, Canada
View GitHub Profile
@TikiTDO
TikiTDO / cb_for_dan.cc
Created August 23, 2012 23:17
C++ Callbacks
#include <stdio.h>
// Typedef for functions like "hi"
typedef int (*FPN)(int);
// Typedef for functions like "bye"
typedef int (*sFPN)(int, FPN);
// A function that takes an int num, and returns an int (num + 1)
int hi(int num) {
return num + 1;
@TikiTDO
TikiTDO / sort1mb.cpp
Created October 28, 2012 08:49 — forked from preshing/sort1mb.cpp
Sort one million 8-digit numbers in 1MB RAM
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
typedef unsigned int u32;
typedef unsigned long long u64;
//-------------------------------------------------------------------------
// WorkArea
//-------------------------------------------------------------------------
@TikiTDO
TikiTDO / loan.rb
Created November 5, 2012 17:10
Stuff
class Loan
def initialize(amount, term_in_months, rate)
@principle = amount
@term = term_in_months
@rate = rate
# Calcluate Initial Interest
@interest = some_formula
end
@TikiTDO
TikiTDO / override.js
Last active December 11, 2015 17:18
Extends mousetrap.js to provide a special bind which overrides any further events, including browser behaviour
/**
* Adds a bindOverride and possibly bindOverrideGlobal [if bind global is installed]
* These methods override default broser behaviour before calling the callback
*
* usage:
* Mousetrap.bindGlobal('ctrl+s', _saveChanges);
*/
Mousetrap = (function(Mousetrap) {
Mousetrap.bindOverride = function(keys, callback, action) {
var override_callback = function(e) {
@TikiTDO
TikiTDO / micro_profile.rb
Last active December 12, 2015 13:39
Useful little debug tool to place various time reference points into a program. Useful for coarse profiling when excessive detail is not required.
def time_point(name)
$time_points ||= {}
$time_points[name] = [] if !$time_points.has_key? name
$time_points[name] << Time.now
end
def time_report
return if !defined? $time_points
report_time = Time.now
report = "Since %-30s: %f seconds"
@TikiTDO
TikiTDO / alias_args.rb
Last active December 13, 2015 18:58
Alias methods, but add some static arguments before or after the call
# Usage:
# class Thing
# def method_name(*args)
# args
# end
# alias_shift_arg(:method_changed, :method_name, 1, 2, 3)
# end
# thing = Thing.new
# thing.method_name("a").inspect #=> ["a"]
# thing.method_changed("a").inspect #=> [1, 2, 3, "a"]
class OrderCoupon
include Mongoid::Document
field :code, type: String
field :discount, type: Integer
field :discount_type, type: String # Flat Price, Percentage
field :expiration, type: Date
belongs_to :order
module ZZ
def self.prepended(target)
puts "included"
end
def hi
puts 123
super
end
end
module CC
class A
def normal
@a = nil
@a ||= 1
end
def other_
@b = nil
@b = 1 if !@b
end
# Extracts the SourceElementsNode within the function bodyof the
def extract_context()
@parser.extract({
get: :value,
type: Array,
call: {
get: :first,
type: ExpressionStatementNode,
call: {
get: :value,