Skip to content

Instantly share code, notes, and snippets.

@adimasuhid
adimasuhid / gist:2d01342c435133fe1dd3ebc86626cf15
Last active July 4, 2017 05:25
Module to Flatten Arrays
#
# flattener.rb
#
module Flattener
class ::InvalidInputError < StandardError; end
def self.execute(array)
raise InvalidInputError unless can_be_flattened?(array)
process(array)
@adimasuhid
adimasuhid / Pivotal Tracker Responses
Last active August 29, 2015 14:01
Pivotal Tracker JSON Response
Story Creation:
{
"kind": "story_create_activity",
"guid": "1081752_16",
"project_version": 16,
"message": "Ace Dimasuhid added this feature",
"highlight": "added",
"changes": [
{
"kind": "story",
@adimasuhid
adimasuhid / gist:9773742
Created March 25, 2014 23:30
Butterfly proto config
var config = require("../config/config.js")
function getUrl(name) {
return "http://" + config.ip + ":3003/media/" + name
}
video1 = {
id: 1,
transitions: {
initial: getUrl(""),
@adimasuhid
adimasuhid / gist:9268911
Created February 28, 2014 10:41
Piliponi Use
class Numbers
extend Piliponi
def self.csv_to_array(num_array, map_num)
num_array.collect{ |num| clean num[map_num] }
end
def self.rejected(numbers)
numbers.select{ |num| !plausible? num }
end
@adimasuhid
adimasuhid / gist:9086107
Created February 19, 2014 04:33
New GTLDS Yaml (New Gtlds from ICANN)
values:
- "AAA"
- "AARP"
- "ABARTH"
- "ABB"
- "ABBOTT"
- "ABBVIE"
- "ABC"
- "ABLE"
- "ABOGADO"
//This is an example of how to scrape the web using PhantomJS and jQuery:
//source: http://snippets.aktagon.com/snippets/534-How-to-scrape-web-pages-with-PhantomJS-and-jQuery
//http://phantomjs.org/
var page = new WebPage(),
url = 'http://localhost/a-search-form',
stepIndex = 0;
/**
* From PhantomJS documentation:
require 'sinatra'
require 'action_mailer'
class Mailer < ActionMailer::Base
def contact
mail(
:to => "[email protected]",
:from => "[email protected]",
:subject => "Test") do |format|
format.text

Deploy Rails app to digitalocean with nginx, unicorn, capistrano & postgres

Create droplet of your liking (ubuntu 12.10 x32)

ssh to root in terminal with your server ip

ssh [email protected]

Add ssh fingerprint and enter password provided in email

@adimasuhid
adimasuhid / gist:7853146
Created December 8, 2013 03:48
Backbone BaseView for handling zombies in large applications
//Backbone Baseview for handling zombies in large applications
//From Backbone Fundamentals by Addy Osmani
var BaseView = function(options){
this.bindings = [];
Backbone.View.apply(this.[options]);
};
_.extend(BaseView.prototype, Backbone.View.prototype, {
bindTo: function(model, ev, callback){
@adimasuhid
adimasuhid / gist:7462623
Last active December 28, 2015 07:09
Active Record Full Text Search Module
module FullSearchable
def searchable(scope_name, *attrs)
raise ArgumentError if attrs.blank?
define_singleton_method("#{scope_name}") do |terms|
return if terms.blank?
composed_scope = self.scoped
terms.downcase.split(' ') .each do |term|
composed_scope = composed_scope.where(create_query(attrs, term))