Skip to content

Instantly share code, notes, and snippets.

@athap
athap / permutations.go
Created February 27, 2016 21:53
Golang: Print all permutation of a string
package main
import "fmt"
/*
Return all permutations of a string
Example,
Find all perm of abc:
@athap
athap / Fibonacci log n solution
Created August 3, 2012 06:09
Fibonacci sequence in log(n) using matrix multiplication
/*
* | 1 1 |n |Fn+1 Fn |
* | 1 0 | = |Fn Fn-1 |
*
* Figure 1
*/
public int FibonacciLogN(int n)
{
if(n <= 0)
return 0;
@athap
athap / Vim Paste Mode
Created January 19, 2016 02:25
Fix Vim paste indent issue. When copying text using ctrl-c
Before pasting
:set paste
After Paste
:set nopaste
+web:
+ build: .
+ ports:
+ - '9292:9292'
+ volumes:
+ - '.:/var/app'
+ tty: true
+ command: ["rerun", "--force-polling", "foreman", "start"]
FROM ruby:2.2.0
RUN mkdir -p /var/app
COPY Gemfile* /var/app/
WORKDIR /var/app
ENV environment=development
RUN bundle install
@athap
athap / config_files.js.coffee
Last active December 10, 2015 09:48
Content of application.js for adding Require.js to Backbone.js application
-----------------------------------------------
application.js
-----------------------------------------------
require [
'backbone',
'path/to/router/with/index/handler'],
(Backbone, IndexRouter) ->
$ ->
Main = new IndexRouter()
@athap
athap / scraper options
Created October 14, 2015 15:45
scraper options
./script/scraper --help
Usage: scraper [options] [sources ...]
Specific Options:
-l, --limit N Limit operations to N listings.
-t, --throttle N Random amount of time to throttle between url gets.
-c, --command [COMMAND] Which types of scraping command you want to run (all harvest collect scrape rescrape all_agents new_agents fix_agents quick_harvest_and_close quick_close validate)
-s, --sourceid id Scrapes a single listing using its source id.
-o, --office office_key(s) Scrapes office's listings using its office key (for MRIS and ListHub scrapers). Can be comma-delimited.
-e, --env [ENVIRONMENT] Which types of evironment you want to run in (prod gamma beta dev)
@athap
athap / JQuery Flash Messages
Created September 1, 2012 17:43
Rails like flash messages using JQuery for JS or AJAX calls
# This gist shows how to display Rails like flash messages while handling AJAX or JS requests
# Note - This might not be the best way to do this but it works for me
Step 1. Create a partial which will contain the message to be displayed
Example - _success.html.erb
<div id="flash_message">
<p>Success</p>
</div>
Step 2. In the Controller, add code to call this partial on a JS request
@athap
athap / download_xls.rb
Created June 17, 2012 03:22
Downloading data as xls or Excel without a Gem
# This gist demonstrates - How to download data from database in excel or xls format in Ruby on Rails
# Tested with - Ruby 1.9.3, rails 3.2.1, db - postgres
class DownloadsController < ApplicationController
before_filter :define_header, :except => :index
def index
...
end
u = User.find 1
// page 1
c1 = u.comments.where(disabled: 0).limit(50).page(1).per(20)
id1 = c1.map(&:id)
//page2
c2 = u.comments.where(disabled: 0).limit(50).page(2).per(20)
id2 = c2.map(&:id)