Skip to content

Instantly share code, notes, and snippets.

View sidravic's full-sized avatar

Siddharth sidravic

View GitHub Profile
@sidravic
sidravic / event_machine_server.rb
Created March 3, 2011 06:16
Event Machine server in event_machine_twitter_app with deferred update (using EM.defer)
require 'rubygems'
require 'eventmachine'
require 'socket'
require 'json'
require 'hashie'
require File.expand_path("twitter_lib.rb", __FILE__ + "/..")
require File.expand_path("tweet_Fetcher.rb", __FILE__ + "/..")
class Echo < EM::Connection
@sidravic
sidravic / Timer
Created April 7, 2011 06:43
Simple Timer class which updates every ten seconds.
<div class="timer-status"> </div>
<script>
$(document).ready(function(){
timer = function(){
var self = this;
var _timer_count = 0;
var timer_id = null;
self.startTimer = function(callback){
posts.tags.first.name # business money finance investment
@sidravic
sidravic / Gemfile
Created April 19, 2012 16:14
mailman_guide
gem 'daemons'
gem 'mailman', require: false
gem 'maildir'
gem 'mail'
package main
import (
"fmt"
"http"
"io/ioutil"
"os"
)
func main() {
// This will parse your JSON
type APIResponse struct{
StatusCode string `json:"status_code"`
OperationStatus bool `json:"status"`
Errors string `json:"error_messages, omitempty"`
ApplicationID string `json:"application_id, omitempty"`
QueueID int64 `json:"queue_id, omitempty"`
}
// 1 hour later I realized this won't return parsed values but defaults for the data types
# Guide
# Configure the essential configurations below and do the following:
#
# Repository Creation:
# cap deploy:repository:create
# git add .
# git commit -am "initial commit"
# git push origin master
#
# Initial Deployment:
Kaminari.paginate_array([{:a => 1}, {:b => 2}, {:c => 3}, {:d => 4}]).page(1).per(1)
=> [{:a=>1}]
[10] pry(main)> Kaminari.paginate_array([{:a => [1,2,3,4]}, {:b => [123,123,1231,231]}, {:c => [123123]}, {:d => [:asd, :asdasd]}]).page(1).per(1)
=> [{:a=>[1, 2, 3, 4]}]
[11] pry(main)> Kaminari.paginate_array([{:a => [1,2,3,4]}, {:b => [123,123,1231,231]}, {:c => [123123]}, {:d => [:asd, :asdasd]}]).page(1).per(2)
=> [{:a=>[1, 2, 3, 4]}, {:b=>[123, 123, 1231, 231]}]
[12] pry(main)> Kaminari.paginate_array([{:a => [1,2,3,4]}, {:b => [123,123,1231,231]}, {:c => [123123]}, {:d => [:asd, :asdasd]}]).page(1).per(3)
=> [{:a=>[1, 2, 3, 4]}, {:b=>[123, 123, 1231, 231]}, {:c=>[123123]}]
@sidravic
sidravic / torquebox_init_script.rb
Created March 19, 2015 08:47
A basic init script to start and stop torquebox. Copy this script to the /etc/init.d/ folder
#!/usr/bin/env ruby
require "fileutils"
puts "Using system RVM"
#system("/bin/bash --login && rvm use system")
puts "Initializing PID and Log files"
PIDFOLDER = "/opt/pids"
PIDFILE = "/opt/pids/torquebox.pid"
LOGFILE = "/var/log/torquebox/torquebox.log"
FileUtils.mkdir_p(PIDFOLDER) unless Dir.exists?(PIDFILE)
@sidravic
sidravic / factory-shared.es5.js
Created December 12, 2015 18:25 — forked from PatrickJS/factory-shared.es5.js
Different examples of OOP "class" with "inheritance" done using JavaScript including languages that transpile into js. Take notice to the amount of boilerplate that's needed in ES5 compared to ES6. These examples all have the same interface with pros/cons for each pattern. If they seem similar that's whole point especially the difference between…
var EventEmitter = require('events').EventEmitter;
var _ = require('lodash');
// Factory shared
var makePerson = function() {
var person = {};
EventEmitter.call(person);
person.wallet = 0;
_.extend(person, personMethods)
return person;