Skip to content

Instantly share code, notes, and snippets.

@jtsaito
jtsaito / podcasts.txt
Last active December 21, 2015 23:29
Some podcasts I like to listen to
Some Podcasts
The format of the list entries is as follows.
Title of podcast (ratio of decent to boaring shows)
Url of show
Frenquency and duration of shows
Remarks
class GooglePlayVerification
require 'google/api_client'
# Refer:
# https://code.google.com/p/google-api-ruby-client/issues/detail?id=72
# and
# http://jonathanotto.com/blog/google_oauth2_api_quick_tutorial.html
# and
# http://milancermak.wordpress.com/2012/08/24/server-side-verification-of-google-play-subsc/
GOOGLE_KEY = 'xxx-xxx.apps.googleusercontent.com'
@jtsaito
jtsaito / gist:29a5eb41b054dad6e82c
Last active December 14, 2015 09:48
On Provisioning a Simple Rails App with OpsWorks

Fourteen-step procedure

... which I followed for setting up a simple Rails App on Opsworks.

  1. Set up an IAM role for ssh to the instances later
  2. Set up a Stack
  3. Set up a Layer RDS instace (used MySQL)
  4. Set up the RDS' VPC id, endpoint, master user, password
  5. Create a database for the App and a user to connect to it using the db master user
  6. Add the RDS details in the database section of the custom JSON (see custom json below)
@jtsaito
jtsaito / gist:0ee8f8527b7fa9e2bc47
Last active August 29, 2015 14:05
Tokyo, places and food

Some Placs in Tokyo

  • Itoya on the Ginza (銀座): for some reason Japan is great at stationaries. The mother of all stationaries is Itoya on the Ginza ("Tokyo's Ku'Damm"). You can easily spend one or two hours at Itoya. Sony's flagg ship store is also located here together with plenty of camera stores and luxury reatilers. Also, don't forget to visit a Japanese department store (they are quite a culture of their own allbeit fading, Mitsukoshi Department Store)
  • Shinjuku Gyouen (新宿区): my favorite garden in Tokyo, hang out with some food you bring a long from a convenience store. There is an admission of a few hundred Yen per person.
  • Tokyo City Hall and Shinjuku (新宿区): free great view from the top flor (thus much cheaper than the Tokyo Tower). walkable from Shinjuku station. There are plenty of Pachinko parlors and game centers close to Shinjuku station. Also just walk around inside the statio
@jtsaito
jtsaito / gist:46bea2949f27cc4e4915
Last active August 29, 2015 14:07
Adding a new receipt to OPS Works Custom Cookbooks
  1. Checkout Custom Cookbooks git repo, edit cookbook sub directory you want to edit (e.g, "my-backup")
  2. Make your changes, upload branch
  3. Include recipe (e.g., "my-backup::monitoring") to your OPS Works layer's Custom Cookbooks
  4. Set branch in OPS Works Stack settings
  5. Update cookbooks (Deployments => Run Command)
  6. Trigger setup (Deployments => Setup)
  7. Find site-cookbooks directory on instance node
  8. Edit cookboooks on instance node and trigger setup to run remote changes
@jtsaito
jtsaito / gist:6d20c9bea528452168a0
Last active August 29, 2015 14:10
Inserting into an ActiveRecord table without instantiating the model

There are several reasons why one would avoid creating records through ActiveRecord::Base models. One reason is speed for batch inserts, another one is avoiding callbacks or overwritten method calls.

In such cases ActiveRecord::Base#connection.execute or similary methods can be used. They can be combined with Areal for generating SQL code (or other representations) as follows.

Suppose we have an ActiveRecord model User with attributes name (String) and zipcode (integer). The following snippet adds a new record.

insert_manager = Arel::InsertManager.new(ActiveRecord::Base)
table = User.arel_table
arel_attributes = [[table[:name], "John Doe"], [table[:zipcode], "55555"]]
@jtsaito
jtsaito / rails_backport.md
Created January 9, 2015 14:44
Note on backporting an ActiveRecord method from Rails 4.1 to Rails 2.3

This is a simple example for a backport of the ActiveRecord::Persistence#update_columns method which does not exists in Rails 2.3 but in Rails.

Create a ruby file config/iniitilizers/active_record_backport.rb and run a simple class_eval on the extended class, e.g. ActiveRecord::Persistence.

  ActiveRecord::Persistence.class_eval do

    # backport from Rails 4.1.0
    # see https://github.com/rails/rails/blob/4-1-stable/activerecord/lib/active_record/persistence.rb#L271
    def update_columns(attributes)
@jtsaito
jtsaito / gist:1d572909a6555ba85855
Last active August 29, 2015 14:13
Note on jQuery's autocomplete plugin

jQuery's Autocompletion plugin comes with jQuery UI. The plugin autocompletes "any field that receives an input." Below is an example from the malt-mate app in coffee script. It fetches the autocomplete values from remote. Moreover, the code does away with the default behaviour of displaying values for labels in the <input type="text"> . (By default, labels are displayed on select but values are displayed on focus.)

<input id="distillery-autocomplete">
<input hidden=true id="distillery-autocomplete-value" type="text" name="distillery-id">
    $("#distillery-autocomplete").autocomplete(
      delay: 500                        # delay between attempts to fetch data
@jtsaito
jtsaito / gist:29b34ecd19fef276ca73
Created April 16, 2015 10:49
Fix for race conditions in controllers

The following invalidates the ActiveRecord::QueryCache.

In an initializer for patching ActiveRecord:

ActiveRecord::Base.class_eval do
 
  def self.race_condition_safe(&block)
    begin
 yield

How to get to Alt-Lichtenrade by public transport

There are two ways to get to Alt-Lichtenrade by public transport, by U-Bahn or by S-Bahn.

U6

  • travel by U6 to terminal Alt-Mariendorf
  • hop on bus, either
    • Bus M76 (-> Lichtenrade), get out at Grimmstrasse, then 4 minute walk
    • or Bus X76 (-> Lichtenrade), Goethestr./Potsdamer Str.