Skip to content

Instantly share code, notes, and snippets.

View syntacticsugar's full-sized avatar
🎯
Focusing

RomyRomy syntacticsugar

🎯
Focusing
View GitHub Profile
@syntacticsugar
syntacticsugar / gist:3936358
Created October 23, 2012 02:39 — forked from lfborjas/gist:817504
Filter even numbers in a list; fork it for maximum fun!
#these are meant to be run in a REPL, and the java one in beanshell of something of the sort:
#ruby
[1,2,3,4].select{ |x| x.even? }
#python
[x for x in [1,2,3,4] if not x%2]
#or, more norvingly
filter(lambda x: not x%2, [1,2,3,4])
#clojure
@syntacticsugar
syntacticsugar / david_albert_is_awesome_factorial.rb
Created October 22, 2012 21:02
Ruby Or-Equals ||= weirdness
@factorial_results = {}
def factorial(num)
start = Time.now
raise "num has to be greater than 0" if num < 0
return 1 if num == 0
if @factorial_results.has_key?(num)
puts "found it!"
@syntacticsugar
syntacticsugar / strong_fail.clj
Created October 22, 2012 06:36
error message from misaki server
Caused by java.lang.RuntimeException: Unable to resolve symbol: necessarily in this context
at misaki.compiler.default.evaluator$evaluate_to_function$fn__139 / invoke (evaluator.clj:62)
at misaki.compiler.default.evaluator$evaluate_to_function / invoke (evaluator.clj:62)
at misaki.compiler.default.template$load_template$fn__247 / invoke (template.clj:82)
at misaki.compiler.default.template$load_template / invoke (template.clj:89)
at misaki.compiler.default.core$file__GT_template_sexp / doInvoke (core.clj:193)
at misaki.compiler.default.core$generate_post_content / invoke (core.clj:95)
at misaki.compiler.default.core$get_post_info$fn__2230 / invoke (core.clj:108)
at misaki.compiler.default.core$get_compile_fn$fn__2277 / invoke (core.clj:221)
at misaki.compiler.default.core$compile_STAR_ / invoke (core.clj:229)
@syntacticsugar
syntacticsugar / smoking_lisp_through_ruby.rb
Created October 20, 2012 22:52
wherein i lose my shit and go to town playing with Rubified `car`/`cdr`
Death-Lair-of-Killer-Bambi:Desktop stickycake$ irb
cannot load such file -- irb/autocompletion
1.9.3-p194 :001 > boys = %w{jarry larry parry gary}
=> ["jarry", "larry", "parry", "gary"]
1.9.3-p194 :002 > boys.is_a(Array)
NoMethodError: undefined method `is_a' for ["jarry", "larry", "parry", "gary"]:Array
from (irb):2
from /Users/stickycake/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `<main>'
1.9.3-p194 :003 > boys.is_a?(Array)
=> true
# -*- encoding: utf-8 -*-
require 'sinatra'
require 'slim'
require 'warden'
require 'dm-core'
require 'dm-migrations'
DataMapper::Logger.new(STDOUT, :debug)
@syntacticsugar
syntacticsugar / mvc_summary.md
Created October 17, 2012 21:40
topfunky/peepcode's "16 Ruby on Rails Solid Workflow Tips"

http://www.codercaste.com/2011/02/11/10-ruby-on-rails-3-tips-that-will-make-you-a-better-rails-programmer/

Understand What a Model, Controller, View, and Helper are

Rails heavily depends on the model view controller (MVC) design pattern. Every one of them has a specific job and jeopardizing them is never a good idea. A controller is responsible for handling Rails requests and passing data from a model to a view. You can think of the controller as a manager between the logic of your program and the actual view that a user actually sees. Generally, a controller should have very few code. It should just execute some functions and retrieve instance variables to be used directly in a view. Moreover, it is used to do redirects with redirect_to and the likes.

A model is where your actual business logic is. The body of your main functions should always lie inside a model that is responsible for handling that data. Since a model operates on data, it’s pretty sensible that a model actually represents a database ta

@syntacticsugar
syntacticsugar / Gemfile
Created October 16, 2012 22:49 — forked from fairchild/Gemfile
An example sinatra omniauth client app
source :rubygems
gem 'sinatra'
gem 'json'
gem 'omniauth'
gem 'omniauth-oauth2'
gem 'omniauth-github'
# gem 'omniauth-att', :path => File.expand_path("./../../omniauth-att", __FILE__)
gem 'thin'
@syntacticsugar
syntacticsugar / crapload_of_data.sql
Created October 8, 2012 21:31
Learn SQL Hard Way - snippets
INSERT INTO pet (id, name, breed, age, dead)
VALUES (5, "shimmer", "unicorn", 500, 1);
INSERT INTO pet (id, name, breed, age, dead)
VALUES (6, "water bottle", "faun", 4, 1);
INSERT INTO pet (id, name, breed, age, dead)
VALUES (7, "luis", "elephant", 282, 1);
INSERT INTO pet (id, name, breed, age, dead)
@syntacticsugar
syntacticsugar / gist:3722018
Created September 14, 2012 13:49
attempting to stall game with bundler and ashton
Death-Lair-of-Killer-Bambi:blobs stickycake$ bundle install
Fetching gem metadata from http://rubygems.org/....
Using gosu (0.7.45)
Using opengl (0.8.0.pre1)
Using ashton (0.0.1alpha) from git://github.com/Spooner/ashton.git (at master) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/Users/stickycake/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
creating extconf.h
creating Makefile
@syntacticsugar
syntacticsugar / huffman.py
Created August 4, 2012 18:10 — forked from ryanwitt/huffman.py
silly huffman coding example
__all__ = (
'build',
'endode',
'decode',
)
phrase = 'A man a plan a canal Panama'.lower()
def build(phrase):
"""