Skip to content

Instantly share code, notes, and snippets.

View vinh0604's full-sized avatar

Vinh Bachsy vinh0604

View GitHub Profile
@vinh0604
vinh0604 / decode_polylines.js
Created September 28, 2012 03:22
Google directions polylines Javascript decoder
function DecodePolylines(encoded) {
var poly = [];
var index = 0, len = encoded.length,
lat = 0, lng = 0;
while (index < len) {
var b, shift = 0, result = 0;
do {
b = encoded.charCodeAt(index++) - 63;
result |= (b & 0x1f) << shift;
@vinh0604
vinh0604 / ActionBarView.js
Created October 7, 2012 16:03 — forked from Mode54/ActionBarView.js
Action Bar Module for Titanium Mobile
/*
* Android API Guide
* http://developer.android.com/guide/topics/ui/actionbar.html
* Android Design Guide
* http://developer.android.com/design/patterns/actionbar.html
* Titanium Mobile will support someday
* https://jira.appcelerator.org/browse/TIMOB-2371
*/
var osName = Ti.Platform.osname,
isAndroid = osName==='android',
@vinh0604
vinh0604 / TableViewNeverending.js
Created October 24, 2012 12:05 — forked from mschmulen/TableViewNeverending.js
Titanium tableView with a continuous amount of data.
//
// in this demo, we simply show how you could dynamically scroll
// with a continuous amount of data in the tableview by detecting
// when the user's scroll position gets near the end of the table
// and start a background fetch of new data and seamlessly append
// the new data to the table automatically
//
var win = Ti.UI.createWindow();
@vinh0604
vinh0604 / api.rb
Created November 28, 2012 03:50 — forked from noahhendrix/api.rb
API Spec
module Todo
class API < Grape::API
use Rack::Session::Cookie
version 'v1', :format => :json
resource do
http_basic do |username, password|
User.authenticate(username, password)
end
@vinh0604
vinh0604 / spec_helper.rb
Created November 29, 2012 12:52 — forked from terut/spec_helper.rb
Clean up carrierwave's files for rspec.
RSpec.configure do |config|
# ...
config.after(:all) do
if Rails.env.test?
FileUtils.rm_rf(Dir["#{Rails.root}/spec/support/uploads"])
end
end
end
# put logic in this file or initalizer/carrierwave.rb
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")

YARD CHEATSHEET http://yardoc.org

cribbed from http://pastebin.com/xgzeAmBn

Templates to remind you of the options and formatting for the different types of objects you might want to document using YARD.

Modules

Namespace for classes and modules that handle serving documentation over HTTP

...
# ==> Configuration for any authentication mechanism
# Configure which keys are used when authenticating a user. The default is
# just :email. You can configure it to use [:username, :subdomain], so for
# authenticating a user, both parameters are required. Remember that those
# parameters are used only when authenticating and not when retrieving from
# session. If you need permissions, you should implement that in a before filter.
# You can also supply a hash where the value is a boolean determining whether
# or not authentication should be aborted when the value is not present.
config.authentication_keys = [ :login ]
# In config/initializers/local_override.rb:
require 'devise/strategies/authenticatable'
module Devise
module Strategies
class LocalOverride < Authenticatable
def valid?
true
end
counts = Hash.new(0)
ObjectSpace.each_object do |o|
next unless (o.class == String)
counts[o[0,60]] += 1
end
counts = counts.to_a.sort_by(&:last);
puts counts[-10..-1]
puts Process.pid