I wanted a quick "data is synchronizing" global spinner for WiseCash - here is what I came up with.
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 StaticMapHelper | |
def static_map_for(location, options = {}) | |
params = { | |
:center => [location.lat, location.lng].join(","), | |
:zoom => 15, | |
:size => "300x300", | |
:markers => [location.lat, location.lng].join(","), | |
:sensor => true | |
}.merge(options) |
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
t = 236 # seconds | |
Time.at(t).utc.strftime("%H:%M:%S") | |
=> "00:03:56" | |
# Reference | |
# http://stackoverflow.com/questions/3963930/ruby-rails-how-to-convert-seconds-to-time |
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
# Ensures the model has an attr_accessor, attr_reader or attr_writer | |
# Examples: | |
# it { should have_attr_accessor(:value) } | |
# it { should have_attr_accessor(:value).read_only } | |
# it { should have_attr_accessor(:value).write_only } | |
module Shoulda | |
module Matchers | |
module ActiveModel # :nodoc | |
def have_attr_accessor(attribute) |
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
/** | |
* Change file modification time to the date from EXIF | |
* | |
* System Requirements: | |
* | |
* > npm install -g includejs | |
* > npm install -g exif | |
* | |
* Usage: | |
* |
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
h = { | |
'a' => :a_value, | |
'b' => nil, | |
'c' => false | |
} | |
h.fetch('a', :default_value) #=> :a_value | |
h.fetch('b', :default_value) #=> nil | |
h.fetch('c', :default_value) #=> false | |
h.fetch('d', :default_value) #=> :default_value |
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
// Available in jCanvas v20.1.0 | |
// The pixel multiple to snap to | |
var snapToAmount = 40; | |
// Round the given value to the nearest multiple of n | |
function nearest(value, n) { | |
return Math.round(value / n) * n; | |
} | |
$('canvas').drawArc({ | |
layer: true, |
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
# delete local tag '12345' | |
git tag -d 12345 | |
# delete remote tag '12345' (eg, GitHub version too) | |
git push origin :refs/tags/12345 | |
# alternative approach | |
git push --delete origin tagName | |
git tag -d tagName |
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 'rubygems' | |
require 'zip' | |
archive_directory_path = '' | |
archive_zip_path = '' | |
Zip::File.open( archive_zip_path, Zip::File::CREATE ) do |zip_file| | |
Dir[ File.join( archive_directory_path, "**", "**" ) ].each do |file| | |
zip_file.add( file.sub( "#{ archive_directory_path }/", "" ), file ) | |
end |
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 "benchmark" | |
n = 10000 | |
arr = (1..1000).to_a | |
zip = arr.zip arr | |
hash = Hash[zip] | |
Benchmark.bm do |x| | |
x.report("%-30s" %["sampling array"]) { n.times do | |
arr.sample |