This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
/* | |
Return all permutations of a string | |
Example, | |
Find all perm of abc: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* | 1 1 |n |Fn+1 Fn | | |
* | 1 0 | = |Fn Fn-1 | | |
* | |
* Figure 1 | |
*/ | |
public int FibonacciLogN(int n) | |
{ | |
if(n <= 0) | |
return 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Before pasting | |
:set paste | |
After Paste | |
:set nopaste |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+web: | |
+ build: . | |
+ ports: | |
+ - '9292:9292' | |
+ volumes: | |
+ - '.:/var/app' | |
+ tty: true | |
+ command: ["rerun", "--force-polling", "foreman", "start"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM ruby:2.2.0 | |
RUN mkdir -p /var/app | |
COPY Gemfile* /var/app/ | |
WORKDIR /var/app | |
ENV environment=development | |
RUN bundle install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
----------------------------------------------- | |
application.js | |
----------------------------------------------- | |
require [ | |
'backbone', | |
'path/to/router/with/index/handler'], | |
(Backbone, IndexRouter) -> | |
$ -> | |
Main = new IndexRouter() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
./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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
NewerOlder