Skip to content

Instantly share code, notes, and snippets.

View mbriggs's full-sized avatar

Matt Briggs mbriggs

View GitHub Profile
queue = []
['hello', 'x', 'world'].each do |word|
queue << word and puts "Added to queue" unless word.length < 2
end
puts queue.inspect
# Output:
# Added to queue
# Added to queue
# ["hello", "world"
#Newbie programmer
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
print factorial(6)
#First year programmer, studied Pascal
public static string EscapeXml( this string s )
{
string xml = s;
if ( !string.IsNullOrEmpty( xml ) )
{
// replace literal values with entities
xml = xml.Replace( "&", "&amp;" );
xml = xml.Replace( "&lt;", "&lt;" );
xml = xml.Replace( "&gt;", "&gt;" );
xml = xml.Replace( "\"", "&quot;" );
@mbriggs
mbriggs / webapp.rb
Created December 10, 2010 22:56 — forked from igrigorik/webapp.rb
require 'rubygems'
require 'rack'
class Object
def webapp
class << self
define_method :call do |env|
func, *attrs = env['PATH_INFO'].split('/').reject(&:empty?)
[200, {}, send(func, *attrs)]
end
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl http://npmjs.org/install.sh | sh
// most of render()
this.el.html(this.template())
this.$('input[name=id]').val(this.endpoint.get('id'))
this.$('input[name=group]').val(this.endpoint.get('group'))
this.$('input[name=name]').val(this.endpoint.get('name'))
this.$('input[name=route]').val(this.endpoint.get('route'))
this.$('textarea[name=sample_xml]').val(this.endpoint.get('sample_xml'))
(defun find-functional-test (test-file)
(find-file (replace-regexp-in-string "_test" "" test-file
(replace-regexp-in-string "test\\/functional"
"app\/controllers\/"
test-file))))
(defun test ()
(let ((a 1)
(b (+ a 2)))
(message b)))
(test)
Debugger entered--Lisp error: (void-variable a)
(+ a 2)
@mbriggs
mbriggs / gist:1453590
Created December 9, 2011 22:25
making mingle nice
{
"mingle.local": {
"_enabled": true,
"_rules": {
"#card-index": {
"font-size": "5em",
"color": "#0076BA"
},
"#show_enumeratedpropertydefinition_479_drop_link": {
"font-weight": "bold",
// 1: how could you rewrite the following to make it shorter?
if (foo) {
bar.doSomething(el);
} else {
bar.doSomethingElse(el);
}