Skip to content

Instantly share code, notes, and snippets.

View joshuapinter's full-sized avatar
🎯
Focusing

Joshua Pinter joshuapinter

🎯
Focusing
View GitHub Profile
@mcasimir
mcasimir / static_map_helper.rb
Created May 24, 2012 01:32
Google Maps Static map helper for Ruby on Rails
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)
@thbar
thbar / _readme.md
Created May 28, 2012 15:17
Global "spinner" with jQuery, KnockOut.js and CoffeeScript

I wanted a quick "data is synchronizing" global spinner for WiseCash - here is what I came up with.

@shunchu
shunchu / convert-seconds-into-hh-mm-ss-in-ruby.rb
Created July 25, 2012 07:58
Convert seconds into HH:MM:SS in Ruby
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
@daronco
daronco / have_attr_accessor.rb
Created November 23, 2012 00:13
Shoulda matcher have_attr_accessor
# 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)
@tenbits
tenbits / exif-date-touch.js
Last active April 13, 2024 18:30
nodejs script to set a file modification date from EXIF
/**
* Change file modification time to the date from EXIF
*
* System Requirements:
*
* > npm install -g includejs
* > npm install -g exif
*
* Usage:
*
@stevenharman
stevenharman / defaults.rb
Last active July 7, 2021 14:36
A subtle difference between Ruby's Hash.fetch(:key, :default) vs. (Hash[:key] || :default)
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
@caleb531
caleb531 / snap-to-grid.js
Last active May 21, 2018 08:37
Makes a jCanvas layer draggable along a defined grid
// 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,
@mobilemind
mobilemind / git-tag-delete-local-and-remote.sh
Last active May 24, 2024 01:23
how to delete a git tag locally and remote
# 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
@yoon
yoon / gist:8876313
Last active September 28, 2023 13:06
zip a folder with rubyzip
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
@bendyorke
bendyorke / benchmark.rb
Created May 20, 2014 06:54
Benchmarking sampling of a hash
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