Skip to content

Instantly share code, notes, and snippets.

View chug2k's full-sized avatar

Charles Lee chug2k

  • San Francisco, CA
View GitHub Profile

But to see if I can explain delegates and blocks. I'll start with blocks first.

A block is just a function assigned to a variable. I think you have some C background, right? Well if you ever worked with function pointers, blocks and function pointers are kind of the same thing. But let's imagine a function. I won't use Objective C here, just a fake language I made up now.

void sayHello(name) {
   print("hello " + name);
}
@chug2k
chug2k / gist:9264490
Created February 28, 2014 03:14
Resig Intro
// Simple JavaScript Templating
// John Resig - http://ejohn.org/ - MIT Licensed
(function(){
var cache = {};
this.tmpl = function tmpl(str, data){
// Figure out if we're getting a template, or if we need to
// load the template - and be sure to cache the result.
var fn = !/\W/.test(str) ?
cache[str] = cache[str] ||
@chug2k
chug2k / gist:9181609
Created February 24, 2014 03:40
sample database.yml for justin
development:
adapter: postgresql
encoding: utf8
database: justin_dev
pool: 5
username:
password:
test: &TEST
adapter: postgresql
$('.like-button').on('click', function(evt) {
evt.preventDefault();
var $btn = $(evt.currentTarget);
$.post('/likes/ ' + $btn.data('bookmark-id'))
.success(function(response) {
$btn.removeClass('like-button').addClass('unlike-button');
$btn.text('unlike');
// Show flash message, instead probably.
alert('You just liked something successfully');
}).fail(function(response) {
@chug2k
chug2k / ifstatements.rb
Created October 9, 2013 01:37
Simple conversation bot
# We're going to write a very simple conversation bot.
def get_response(prompt)
if prompt.include?("hello")
"Hello! How are you?"
elsif prompt.include?("bye")
"Bye! It was great talking to you!"
else
"I do not understand what you mean by: \"#{prompt}\""
end
def almost_done(a, b, c)
puts "#{a} is almost done with #{b}, #{c}, and #{d}!"
end
d = "this section of quizzes!"
almost_done("breakfast", "lunch", "dinner")
def foo(a, b)
a + b + foo
end
foo("1, 2")
my_array = [1,2,3]
my_array.each do |number|
puts "I can count to #{number}"
puts "but that is all."
def add(a,b)
a + " plus " + b
end
add(1,2)
def say_hello
print "#{hello}!"
end
say_hello