Skip to content

Instantly share code, notes, and snippets.

View tadman's full-sized avatar
🤔
Enumerating

Scott Tadman tadman

🤔
Enumerating
View GitHub Profile
10.print "HELLO WORLD"
20.goto 10
#!/usr/bin/env ruby
require 'benchmark'
count = 10e6.to_i
Benchmark.bm do |x|
x.report(:mod) { count.times { |n| n % 2 == 0 } }
x.report(:and) { count.times { |n| n & 1 == 0 } }
x.report(:odd) { count.times { |n| n.even? } }

Please, before you write any more SQL interfacing code, you must read up on proper SQL escaping to avoid severe SQL injection bugs like the ones you have here. Also, mysql_query should not be used in new applications. It's a deprecated interface that's being removed from future versions of PHP. A modern replacement like PDO is not hard to learn and is a safer way to compose queries. $_POST data never goes directly in a query.

@tadman
tadman / config-environments-development.rb
Created June 4, 2014 18:01
PostageApp Delivery System for use with Devise
config.action_mailer.delivery_method = :postageapp
@tadman
tadman / powr.rb
Created June 24, 2014 15:57
Simple Pow Ruby process manager
#!/usr/bin/env ruby
# == Dependencies ===========================================================
require 'optparse'
require 'open3'
# == Constants ==============================================================
PATH_LENGTH_MAX = 255
@tadman
tadman / molasses.rb
Created August 12, 2014 17:33
Handyman's Secret Weapon
# Molasses
# ---------
#
# Ths tool produces log/molasses.log that records query activity and a
# concise summary of the number of calls made for the rendering of each
# page. By default this behavior is only engaged in the development
# environment.
module Molasses
def self.logger
@tadman
tadman / genssl.sh
Last active August 29, 2015 14:05
SSL Certificate Generation Boilerplate
#!/bin/sh
PF=`ruby -rsecurerandom -e 'puts SecureRandom.base64(40).gsub(/\W/, "")[0,24]'`
echo $PF > $1.pf
openssl genrsa -des3 -passout pass:$PF -out $1.key 2048
openssl rsa -in $1.key -out $1.pem -passin pass:$PF
@tadman
tadman / hash_transform_values.rb
Created September 10, 2014 19:33
Hash#transform_values
class Hash
def transform_values(recursive = true, &block)
Hash[
map do |k, v|
[
k,
(v.is_a?(Hash) && recursive) ? v.transform_values(&block) : yield(v)
]
end
]
@tadman
tadman / postageapp.rb
Created September 26, 2014 18:26
Cc: and Bcc: support patches
class PostageApp::Mailer
def mail(headers = nil, &block)
# Guard flag to prevent both the old and the new API from firing
# Should be removed when old API is removed
@_mail_was_called = true
m = @_message
# Call all the procs (if any)
class_default = self.class.default
default_values = class_default.merge(self.class.default) do |k,v|
@tadman
tadman / call_methods.rb
Created January 27, 2015 19:42
Comparison of various block delegation methods in Ruby
#!/usr/bin/env ruby
require 'benchmark'
def with_call(object, &block)
block.call(object)
end
def with_proc(object)
Proc.new.call(object)