Skip to content

Instantly share code, notes, and snippets.

View burlesona's full-sized avatar

Andrew Burleson burlesona

  • CoSell
  • Austin, TX
View GitHub Profile
# Not that this is an impressive demo, but it makes the point that Ruby
# does in fact have the ability to create "pure" functions and pass them
# as arguments to higher order functions. People get hung up on the syntax
# but it's not really that complicated.
make_adder = method def make_adder(num)
->(input){ input + num }
end
make_add_twice = method def make_add_twice(adder, num)
@burlesona
burlesona / console.rb
Created July 18, 2017 20:02
Ruby console file for an app
#!/usr/bin/env ruby
require 'rubygems'
require 'bundler/setup'
require_relative 'environment'
require 'models'
require 'helpers'
require 'pry'
Pry.start self
@burlesona
burlesona / nginx.conf
Created May 9, 2017 04:48
Default nginx conf. Because these default things can be hard to find.
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
@burlesona
burlesona / lookup.rb
Created April 2, 2017 17:37
For GT NS6262 class, a script to get IP addresses from hostnames
require 'resolv'
filename = ARGV[0]
batch_size = ARGV[1].to_i
outfile = File.open('ip-addresses.txt','w+')
domains = File.readlines(filename)
groups = domains.each_slice(batch_size)
threads = []
results = []
groups.each_with_index do |group,index|
@burlesona
burlesona / keybase.md
Created September 20, 2016 16:17
Keybase Proof

Keybase proof

I hereby claim:

  • I am burlesona on github.
  • I am burlesona (https://keybase.io/burlesona) on keybase.
  • I have a public key whose fingerprint is 11DB FA34 1EF9 CF16 2955 D274 E038 68E9 30CF 7D68

To claim this, I am signing this object:

@burlesona
burlesona / ruby_methods.rb
Created July 21, 2016 14:33
Ruby Method Fun
# BEFORE RUBY 2.0
def method(argument,hash)
end
method 1, :foo => "bar", :baz => "qux"
method 1, {:foo => "bar", :baz => "qux"} #identical
method(1, {:foo => "bar", :baz => "qux"}) #identical
@burlesona
burlesona / gist:b6d126844a7391a183ac
Created March 24, 2015 14:04
sinatra stack traces are too long
NameError: NameError: uninitialized constant WorkOrdersRouter::WorkOrdersView
/~/app/routers/work_orders_router.rb:11:in `block (2 levels) in <class:WorkOrdersRouter>'
/~/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/bundler/gems/sinatra-9929353e6c59/lib/sinatra/base.rb:1610:in `call'
/~/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/bundler/gems/sinatra-9929353e6c59/lib/sinatra/base.rb:1610:in `block in compile!'
/~/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/bundler/gems/sinatra-9929353e6c59/lib/sinatra/base.rb:974:in `[]'
/~/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/bundler/gems/sinatra-9929353e6c59/lib/sinatra/base.rb:974:in `block (3 levels) in route!'
/~/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/bundler/gems/sinatra-9929353e6c59/lib/sinatra/base.rb:993:in `route_eval'
/~/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/bundler/gems/sinatra-9929353e6c59/lib/sinatra/base.rb:974:in `block (2 levels) in route!'
/~/.rbenv/v
@burlesona
burlesona / method_objects.rb
Last active August 29, 2015 14:13
Methods returning symbols is nice
foo = method def foo
def a(num)
3 * num.to_i
end
n = yield if block_given?
a(n || 3)
rescue
"oops!"
end
@burlesona
burlesona / hash_date.rb
Created January 11, 2015 02:10
Hash <-> Date
class Hash
def to_date
Date.new fetch(:year), fetch(:month), fetch(:day)
end
end
class Date
def to_hash
{year: year, month: month, day: day}
end
@burlesona
burlesona / gist:11407802
Last active August 29, 2015 14:00
ST2 Settings
{
"color_scheme": "Packages/Color Scheme - Default/SpecialsBoard.tmTheme",
"ensure_newline_at_eof_on_save": true,
"file_exclude_patterns":
[
".DS_Store",
".tags*",
"*.pyc",
"*.pyo",
"*.exe",