Skip to content

Instantly share code, notes, and snippets.

View jfeldstein's full-sized avatar

Jordan Feldstein jfeldstein

View GitHub Profile
@jfeldstein
jfeldstein / gist:1300087
Created October 20, 2011 00:31
Ruby is Just Like PHP, Except for a Few Things
###Ruby is Just Like PHP, Except for a Few Things###
After a few attempts and failures to learn Ruby, it finally clicked when I accepted that Ruby was just different than PHP. After that, learning was easy. 
If you're trying to learn Ruby as well, I'll do my best to compare Ruby to PHP (and sometimes javascript) which I found confusing, unexpected or tricky. When I can, I’ll try to explain why these "peculiarities" exist. 
- Syntax differences in Ruby
- Classes, Objects and Scope
## Ruby Syntax##
==> Downloading http://www.rabbitmq.com/releases/rabbitmq-server/v2.7.1/rabbitmq
File already downloaded in /Users/Jordan/Library/Caches/Homebrew
==> make
==> Exit Status: 2
http://github.com/mxcl/homebrew/blob/master/Library/Formula/rabbitmq.rb#L16
==> Environment
HOMEBREW_VERSION: 0.8.1
HEAD: 684e3f8a155dc34ca96c61e7945a9d4406795c06
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CELLAR: /usr/local/Cellar
@jfeldstein
jfeldstein / gist:4218255
Created December 5, 2012 18:35
Happened the first but not the second time:
1.9.2-p320 :034 > resp = api.get_order 'JJOI11M7LN'
MultiJson::DecodeError: 757: unexpected token at '<script type="text/javascript" src="https://sealserver.trustwave.com/seal.js?style=invert&size=65x36&code=55ad3fdf8f8f4a928e1c73ca8049d95d"></script>
{"id":"JJOI11M7LN","order_status":"approved","start_time":"2012-11-29 00:00:00","end_time":"2013-01-13 00:00:00","package_id":"LDWROVFINC","price":1275,"client":"Philly.com","Campaigns":[{"type":"cpm","delivery_status":"running","zone_id":"CUVM0V2AGW","website_id":"8E362LINC7","website_name":"NewsWorks","website_url":"http:\/\/www.newsworks.org\/","impressions":102000}],"FrequencyCapping":{"views":5,"period":24,"period_unit":"hour","id":"FC5_24H"},"GeoTargeting":[{"id":"GEOUS","description":"Includes all 50 states"}]}'
from /Users/jordan_isocket/.rvm/gems/ruby-1.9.2-p320/gems/json-1.7.5/lib/json/common.rb:155:in `parse'
from /Users/jordan_isocket/.rvm/gems/ruby-1.9.2-p320/gems/json-1.7.5/lib/json/common.rb:155:in `parse'
from /Users/jordan_isocket/.rvm/gems/r
@jfeldstein
jfeldstein / gist:4218258
Created December 5, 2012 18:36
second but not 1st or 3rd onward
1.9.2-p320 :005 > resp = api.get_order 'IPWXS8ZFSF'
=> #<Buyads::Response::Base:0x007fd26e6a0de0 @response={"id"=>"IPWXS8ZFSF", "order_status"=>"canceled", "start_time"=>"2012-08-10 00:00:00", "end_time"=>"2012-08-25 00:00:00", "package_id"=>"5DV2MO84UJ", "price"=>1200, "client"=>"Jacob Markowitz <jacob@gurumedia.biz>", "Campaigns"=>[{"type"=>"cpm", "delivery_status"=>"unregistered", "zone_id"=>"AG3B1Y4P7E", "website_id"=>"HQ5ROAFWWF", "website_name"=>"Skinny VS Curvy", "website_url"=>"http://skinnyvscurvy.com", "impressions"=>600000}]}>
1.9.2-p320 :006 > resp = api.get_order 'IPWXS8ZFSF'
MultiJson::DecodeError: 757: unexpected token at '<script type="text/javascript" src="https://sealserver.trustwave.com/seal.js?style=invert&size=65x36&code=55ad3fdf8f8f4a928e1c73ca8049d95d"></script>
{"id":"IPWXS8ZFSF","order_status":"canceled","start_time":"2012-08-10 00:00:00","end_time":"2012-08-25 00:00:00","package_id":"5DV2MO84UJ","price":1200,"client":"Jacob Markowitz <jacob@gurumedia.biz>","Campaigns":[{"type":"cpm
@jfeldstein
jfeldstein / retention.csv
Created April 29, 2013 03:25
Ruby script for calculating your app's retention curve: http://jfeldstein.com/?p=59
We can make this file beautiful and searchable if this error is corrected: It looks like row 7 should actually have 1 column, instead of 2. in line 6.
require 'mysql2'
require 'date'
require 'csv'
# Init values
results = []
(1..48).each do |i|
results[i] = {active_count:0, total_count: 0}
end
@jfeldstein
jfeldstein / application.js
Last active December 17, 2015 14:39
Tracking an event with Segment IO, and displaying a chart of each user's usage stats to that user.
// Add the following line:
//= require ./keentivate/index.js
// Before the line:
//= require_tree .
@jfeldstein
jfeldstein / get_campaigns.js
Created August 2, 2013 20:55
Persistent referrer and UTM campaign tracking for Segment.io
getReferrerTraits = function() {
// Requires: jQuery, jQuery.cookie, segment.io
// TODO: Update referralHost:blackList with your domain, so we only track external referrers.
var analytics_args = [],
analytics_traits,
acquisitionSource,
firstReferrer,
firstCampaign,
@jfeldstein
jfeldstein / gist:7149939
Created October 25, 2013 05:47
Charts, mah dog.
<html>
<head>
<script src="./js/jquery.js"></script>
<script src="./js/underscore.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/funnel.js"></script>
<script type="text/javascript" src="http://www.highcharts.com/highslide/highslide-full.min.js"></script>
<script type="text/javascript" src="http://www.highcharts.com/highslide/highslide.config.js" charset="utf-8"></script>
<link rel="stylesheet" type="text/css" href="http://www.highcharts.com/highslide/highslide.css" />
@jfeldstein
jfeldstein / Parse-Gotchas.coffee
Last active December 30, 2015 07:09
List of gotchas for dealing with "bugs" in Parse's javascript SDK
## Fetch related when fetching
fetch: (options) ->
console.log("Fetching order")
# Does not work when order is created by rotateOrder, and does not have an .id specified.
(OrderModel.__super__.fetch.apply(this, [])).then =>
@fetch_related().then ->
options.success() if options.success?
@jfeldstein
jfeldstein / Gruntfile.with-phonegap.js
Created December 6, 2013 02:16
How to modify the default Gruntfile generated by generator-backbone to support building assets into a Phonegap app nested inside the project.
// ...
module.exports = function (grunt) {
// ...
// configurable paths
var yeomanConfig = {
app: 'app',
dist: 'dist',
phonegap: 'phonegap/www'