Skip to content

Instantly share code, notes, and snippets.

@jtsaito
jtsaito / aws_api_gateway.md
Created August 28, 2015 10:36
AWS API Gateway Example

AWS API Gateway allows developers to put a uniform API between your services and clients. A servcie could for instance be your custom app or just an AWS Labmda.

The official walkthrough for making Lambda calls from the AWS Gateway works out of the box. It describes how to make a GET and a POST request and map them to self-defined Lambdas.

When I was testing the walkthrough the example was only slightly outdated as follows. When making stages (something akin to Rails environements for the API Gateway), methods must be registered in a sperate effort as follows.

(1) In the dashboard, select your API.

@jtsaito
jtsaito / aws_api_gateway.md
Created August 28, 2015 10:36
AWS API Gateway Example

AWS API Gateway allows developers to put a uniform API between your services and clients. A servcie could for instance be your custom app or just an AWS Labmda.

The official walkthrough for making Lambda calls from the AWS Gateway works out of the box. It describes how to make a GET and a POST request and map them to self-defined Lambdas.

When I was testing the walkthrough the example was only slightly outdated as follows. When making stages (something akin to Rails environements for the API Gateway), methods must be registered in a sperate effort as follows.

(1) In the dashboard, select your API.

@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.
@jtsaito
jtsaito / aws_dynmamodb_aws_cli.md
Last active December 2, 2015 08:27
Get DynamoDB item with aws cli

Prerequisites

  1. Created a dynamo db table. We use "travis-ci-deloy-test" with number key "created_at".
  2. Setup aws cli command line tool.
  3. Stored an item with with number key and attribute (in this example, foo: "finger_print").
  4. Set credentials for the table for aws client config (e.g. by setting values in ~/.aws/credentials).

Querying items

First, prepare the query key in a file query_key.json describing the key as json.