Skip to content

Instantly share code, notes, and snippets.

View dahal's full-sized avatar
🌟
captableinc/captable

Puru Dahal dahal

🌟
captableinc/captable
View GitHub Profile

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

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt

Capybara

save_and_open_page

Matchers

have_button(locator)
@dahal
dahal / README.md
Created August 30, 2014 01:15 — forked from cjolly/README.md

Stop Versioning Rails Secret Tokens

After reading Code Climate's Rails' Insecure Defaults I realized I was guilty of breaking rule 3. Versioned Secret Tokens. Here's how I fixed it.

Use dotenv in development and test environments:

# Gemfile
gem 'dotenv-rails', groups: [:development, :test]
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
# NullStorage provider for CarrierWave for use in tests. Doesn't actually
# upload or store files but allows test to pass as if files were stored and
# the use of fixtures.
class NullStorage
attr_reader :uploader
def initialize(uploader)
@uploader = uploader
end
#
# Wide-open CORS config for nginx
#
location / {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
#
#Using gem aws-sdk for a ror application for uploading images to s3
#Uploading images to a fixed bucket with different folders for each object or application.
#The s3 keeps a limitation on the number of buckets creattion whereas there is no
#limitation for content inside a bucket.
#
#This code will upload image for a user to s3 using aws-sdk gem. The bucket and the image uploaded are made public
#so that the images uploaded are directly accessible. The input is takes is the image complete path
#where it is present, folder in which it should be uploaded and user_id for whom it should
#be uploaded.
#
@dahal
dahal / sudoku.rb
Last active August 29, 2015 14:14 — forked from JohnathanWeisner/sudoku.rb
# From
#
# $*.map{|a|(i=a=~/0/)?(v=*?1..?9).fill{|j|v-=[a[j+i-k=i%9],a[
# k+j*=9],a[j%26+i-i%3-i%27+k]]}+v.map{|k|$*<<$`+k+$'}:p(a)}
#
#
# To
start = Time.now
counter = 1
var SudokuSolver = function SudokuSolver(board) {
this.board = board;
};
SudokuSolver.prototype.solve = function() {
var zeroFound = this.board.match(/0/);
if (!zeroFound) return this.board;
var index = zeroFound.index;
for (var possibility = 1; possibility < 10; possibility++) {