View gist:4578ed310cb4a16cea7902f8f454a99e
flat = (l = ->(x) { x.flat_map {|e| Array === e ? l.(e) : e } })
flat.([1, 2, 3, [4, 5, [6], [ ] ] ])
#==> [1,2,3,4,5,6]
View application.html.slim
doctype html
html
head
link rel="stylesheet" href=asset("application.css")
script rel="javascript" type="text/javascript" src=asset("ng_application.js")
body
== yield
View symbolize.rb
Symbolize = (l = ->(h) { h.inject({}) { |m, (k,v)| m[(String === k ? k.to_sym : k)] = (Hash === v ? l.(v) : v); m }})
# Example:
hash = { 'task' => { 'description' => 'Ab@ @example @cd', 'target' => { 'label' => 'cd' } } }
Symbolize.(hash)
# => { :task => { :description => "Ab@ @example @cd", :target => { :label => "cd" } } }
View rails-business-logic-architecture.md
View Deploying Sharetribe to Heroku.md

Deploying to Heroku

  1. Deploy the app to heroku following heroku normal instructions (add link to heroku help)

  2. Set heroku environment variables

    Make sure all the options in config.yml are properly set then run:

     bundle exec rake heroku:config
    
View hn_seach.js
function query() {
var
// HN is done with very unsemantic classes.
job_list = Array.prototype.slice.call(document.querySelectorAll('.c5a,.cae,.c00,.c9c,.cdd,.c73,.c88')),
query_list = Array.prototype.slice.call(arguments),
shown = 0, total = job_list.length;
// Traverses up the dom stack trying to find a match of a specific class
function up_to(node, klass) {
if (node.classList.contains(klass)) {
View fixtures.rake
#put in lib/tasks/fixtures.rake
namespace :db do
namespace :fixtures do
desc 'Create YAML test fixtures from data in an existing database.
Defaults to development database. Set RAILS_ENV to override.'
task :dump => :environment do
sql = "SELECT * FROM %s"
skip_tables = ["schema_migrations"]
ActiveRecord::Base.establish_connection(:development)
(ActiveRecord::Base.connection.tables - skip_tables).each do |table_name|
View apache_bench.sh
1.
LOGIN_PAGE=http://localhost/users/sign_in
curl --cookie-jar cookie_file $LOGIN_PAGE | grep csrf-token
2.
<meta content="csrf-token" name="csrf-token" />
View tmux-cheatsheet.markdown

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
View gist:f14ad6545e24d25eec02
require 'google_drive'
client = Google::APIClient.new(application_name: 'Google Drive Ruby test', application_version: '0.0.1')
key = Google::APIClient::KeyUtils.load_from_pkcs12(
'path to your p12 key file (all the path with file name)',
'your secret here given at download file it seems to be always the same: notasecret')
asserter = Google::APIClient::JWTAsserter.new(
'service account - email address - here',
['https://www.googleapis.com/auth/drive'],