Skip to content

Instantly share code, notes, and snippets.

View toddsiegel's full-sized avatar

Todd Siegel toddsiegel

  • Solera Software, Inc.
  • Denver, CO
View GitHub Profile
@toddsiegel
toddsiegel / gist:4243843
Created December 9, 2012 08:01
Array#move: Move the first matched element in an array. Safely wraps and supports negative distances
class Array
def move(element, distance)
current_pos = index(element)
return self if current_pos.nil?
new_pos = (current_pos+distance) - ((current_pos+distance)/length)*length
delete(element)
insert(new_pos, element)
end
end
@toddsiegel
toddsiegel / gist:4286455
Created December 14, 2012 15:57
Ruby anagram finder that fit in a tweet.
IO.readlines("/usr/share/dict/words").map{|w| w.chomp}.select{|w| w.downcase.chars.sort.join == word.chars.sort.join}.reject{|w| w == word}
# invoices_controller.rb
helper_method :available_filters
def index
@invoices = Invoice.send(filter_scope)
end
private
def available_filters
[~/Projects/exercism]$ ruby ruby/rna-transcription/rna-transcription_test.rb
Run options: --seed 51147
# Running tests:
EEEEE
Finished tests in 0.001201s, 4163.1973 tests/s, 0.0000 assertions/s.
1) Error:
@toddsiegel
toddsiegel / gist:7474971
Last active August 18, 2023 21:59
Dependecy Injection
class Payment
def process(gateway)
gateway.verify(self) # duck typed.
end
end
class PaymentTest
def test_process
payment = Payment.new
payment.process(MockGatway.new)
@toddsiegel
toddsiegel / gist:9453514
Created March 9, 2014 19:52
Queries To Help with Tuning MySQL
-- Determine size of databases
-- Source: http://stackoverflow.com/questions/1733507/how-to-get-size-of-mysql-database
SELECT table_schema "DB Name", Round(Sum(data_length + index_length) / 1024 / 1024, 1) "DB Size in MB"
FROM information_schema.tables
GROUP BY table_schema;
-- Size in MB of the innodb_buffer_pool_size. Default is 128 MB.
-- More here: http://dev.mysql.com/doc/refman/5.5/en/innodb-parameters.html#sysvar_innodb_buffer_pool_size
SELECT @@innodb_buffer_pool_size / 1024 / 1024
@toddsiegel
toddsiegel / tmux-cheatsheet.md
Last active February 27, 2017 16:23 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@toddsiegel
toddsiegel / minimal_csp.txt
Last active May 25, 2017 15:56
A default, minimal content security policy
# This allows stylesheets, scripts and images from the same origin host, but nothing else.
Content-Security-Policy: default-src 'none'; script-src 'self'; style-src 'self'; img-src 'self'
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
# Linux Primer
## Where am I?
It can be intimidating when you are first confronted with prompt because you do not no where you are and what to do. This first section aims to help you orient yourself on any Linux system.
### The `pwd` command
`pwd`