Skip to content

Instantly share code, notes, and snippets.

@kgrz
kgrz / gist:2880883
Created June 6, 2012 09:24 — forked from kaiwren/gist:1283905
Steve Yegge's SOA post

From: https://raw.github.com/gist/933cc4f7df97d553ed89/24386c6a79bb4b31fb818b70b34c5eab7f12e1ff/gistfile1.txt

Stevey's Google Platforms Rant

I was at Amazon for about six and a half years, and now I've been at Google for that long. One thing that struck me immediately about the two companies -- an impression that has been reinforced almost daily -- is that Amazon does everything wrong, and Google does everything right. Sure, it's a sweeping generalization, but a surprisingly accurate one. It's pretty crazy. There are probably a hundred or even two hundred different ways you can compare the two companies, and Google is superior in all but three of them, if I recall correctly. I actually did a spreadsheet at one point but Legal wouldn't let me show it to anyone, even though recruiting loved it.

Order.class_eval do
def define_state_machine
redefine_states!
go_to_state :address
go_to_state :delivery
go_to_state :payment, :if => lambda { payment_required? }
go_to_state :confirm, :if => lambda { confirmation_required? }
go_to_state :complete
remove_transition :from => :delivery, :to => :confirm
end
@kgrz
kgrz / faraday-em-http.rb
Created November 10, 2012 16:01 — forked from igrigorik/faraday-em-http.rb
using Faraday with EM-Synchrony & EM-Http
require 'faraday'
require 'net/http'
require 'pp'
# Repos:
# https://github.com/technoweenie/faraday
# https://github.com/pengwynn/faraday_middleware
# Blog posts:
# http://adventuresincoding.com/2010/09/writing-modular-http-client-code-with-faraday
@kgrz
kgrz / soundcloud.rb
Last active December 11, 2015 01:29 — forked from anonymous/soundcloud.rb
Soundcloud Sinatra authorization example. Created the anonymous gist by mistake and hence, forked it here. This is an example to explain the auth-flow and probably has bugs.
# Soundcloud, after authorization, redirects to a pre-registered URL
# with the user's code, access_token embedded in the URL which may
# be an issue!
# Alternatively, modify the #authorize_url() method such that the url
# that gets generated has a parameter "response_type" of "code" instead
# of "code_and_token" which is the default.
require 'sinatra'
require 'soundcloud'

Render and Redirect

The normal controller/view flow is to display a view template corresponding to the current controller action, but sometimes we want to change that. We use render in a controller when we want to respond within the current request, and redirect_to when we want to spawn a new request.

Render

The render method is very overloaded in Rails. Most developers encounter it within the view template, using render :partial => 'form' or render @post.comments, but here we'll focus on usage within the controller.

:action

class Demo < Prawn::Document
def flower
0.step(270, 90) do |angle|
rotate(angle, :origin => [100, 100]) do
fill_color(random_color)
polygon [100, 100], [150, 150], [200, 100]
fill_and_stroke
end
end
end
// Q sample by Jeff Cogswell
/*===========
We want to call these three functions in sequence, one after the other:
First we want to call one, which initiates an ajax call. Once that ajax call
is complete, we want to call two. Once two's ajax call is complete, we want
to call three.
BUT, we don't want to just call our three functions in sequence, as this
@kgrz
kgrz / README.md
Created March 14, 2014 12:05 — forked from domenic/README.md

The scenario:

  • We are writing a digital textbook-reading app.
  • Most of the time you have a "basic" license for your textbook, but one (and only one) of your computers can request an "enhanced" license.
  • You can only print from the computer with the enhanced license.

The problem statement:

I wasn't first to get the key. Nor was I second, third, or even fourth. I'm probably not even the
10th to get it. But I'm happy that I was able to prove to myself that I too could do it.
The sleepless adventure began yesterday afternoon, 2014-04-12 15:19:04.827516279 -0700.
First, I have to admit I was a skeptic. Like the handful of other dissenters, I had initially
believed that it would be highly improbable under normal conditions to obtain the private key
through exploiting Heartbleed. So this was my motivation for participating in Cloudflare's
challenge. I had extracted a lot of other things with Heartbleed, but I hadn't actually set out to
extract private keys. So I wanted to see first-hand if it was possible or not.
// Source: https://groups.google.com/forum/#!topic/angular/hVrkvaHGOfc
// jsFiddle: http://jsfiddle.net/pkozlowski_opensource/PxdSP/14/
// author: Pawel Kozlowski
var myApp = angular.module('myApp', []);
//service style, probably the simplest one
myApp.service('helloWorldFromService', function() {
this.sayHello = function() {
return "Hello, World!"