This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'set' | |
# copy a string to the clipboard | |
def cp(string = IRB.CurrentContext.last_value) | |
IO.popen('xclip -sel clip', 'w') { |f| f << string.to_s } | |
string | |
end | |
if ARGV[0] && ARGV[0][0].downcase == 't' | |
@lines = "....#..... | |
.........# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
MIN_CHARGE_LEVEL=${1:-40} | |
MAX_CHARGE_LEVEL=${2:-60} | |
while true | |
do | |
battery_level=`cat /sys/class/power_supply/BAT0/capacity` | |
if [ ! $battery_level ]; then | |
echo 'No battery found' | |
exit | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'set' | |
# copy a string to the clipboard | |
def cp(string = IRB.CurrentContext.last_value) | |
IO.popen('xclip -sel clip', 'w') { |f| f << string.to_s } | |
string | |
end | |
if ARGV[0] && ARGV[0][0].downcase == 't' | |
@lines = "".split("\n") | |
elsif ARGV[0] && ARGV[0][0].downcase == 'c' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
heroku pgbackups:capture $1 --expire | |
if [ "$?" == 0 ] | |
then | |
rake db:drop db:create | |
curl -o heroku_db_backup.dump `heroku pgbackups:url $1` | |
pg_restore --verbose --clean --no-acl --no-owner -h localhost `ruby -e "require 'yaml';db = YAML::load(File.read 'config/database.yml')['development']; puts ' -U ' + (db['username'] || 'postgres') + ' -d ' + db['database']"` heroku_db_backup.dump | |
rm heroku_db_backup.dump | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Spree | |
Payment.class_eval do | |
def complete_or_partial_capture!(amount) | |
return false if amount <= 0 || self.state != 'pending' | |
# if it's close to total payment, round up or down to total payment | |
# this is to counteract rounding errors from tax calculations | |
amount = self.amount if ((amount-0.02)..(amount+0.02)).include?(self.amount) | |
# check to make sure there is enough money authorized for this payment | |
return false if amount > self.amount | |
if amount < self.amount # split the payment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add this to an initializer file to extend ActiveRecord | |
# You can pass in an array of hashes. The key/values of your hashes will be joined w/ ANDs | |
# The hashes in the array will be joined w/ ORs | |
# You can also pass in an array of strings or arrays | |
class ActiveRecord::Base | |
def self.any_of( queries ) | |
queries = queries.map do |query| | |
query = where( query ) if [ String, Hash ].any? { |type| query.kind_of? type } | |
query = where( *query ) if query.kind_of?( Array ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# this is pretty rough, but I hope it helps! | |
# | |
# if you run into any problems, this is a big help: | |
# https://developers.google.com/oauthplayground/ | |
require 'net/http' | |
require 'json' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
script_console_running = ENV.include?('RAILS_ENV') && IRB.conf[:LOAD_MODULES] && IRB.conf[:LOAD_MODULES].include?('console_with_helpers') | |
if script_console_running # log SQL for Rails 2 | |
require 'logger' | |
Object.const_set(:RAILS_DEFAULT_LOGGER, Logger.new(STDOUT)) | |
end | |
# log SQL for Rails 3 | |
ActiveRecord::Base.logger = Logger.new(STDOUT) if defined? Rails::Console | |
require 'bigdecimal' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# thanks to railscasts: | |
# http://railscasts.com/episodes/48-console-tricks-revised?view=comments | |
# add this to your ~/.irbrc file | |
class Object | |
# look up source location of a method | |
def sl(method_name) | |
self.method(method_name).source_location |