Skip to content

Instantly share code, notes, and snippets.

@aceakash
aceakash / gist:08f15650a4231e65fb96
Last active August 29, 2015 14:03
Show current git branch in Bash
# Open ~/.bashrc and add the following lines
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
export GIT_PS1_SHOWDIRTYSTATE=1
export PS1='\[\033[01;32m\]\u@\h\[\033[01;34m\] \w\[\033[01;33m\]$(__git_ps1)\[\033[01;34m\] \$\[\033[00m\] '
@aceakash
aceakash / gist:90c760077b5934ee2d37
Created August 21, 2014 09:53
Capybara cheat sheet
# find a button by id, name or value; then click it
find_button('save').click
@aceakash
aceakash / gist:471d021b663d3a7089ec
Last active August 29, 2015 14:09
Common shell commands I can't seem to remember
# ----------------- tar-zip a folder
tar -zcvf path/archive-name.tar.gz directory-path/
# e.g.
tar -zcvf ~/nginx-all.tar.gz /etc/nginx/
# ----------------- copy contents of a folder
cp -a /source/. /dest/
# ----------------- download a file off a remote server
scp USERNAME@REMOTE_HOST:FILE_NAME_IN_HOME_DIR LOCAL_DIR
@aceakash
aceakash / gist:14e5d9fe31db5da8452e
Last active August 29, 2015 14:10
Groovy cheat sheet
// Execute shell command and retrieve output with 'execute'
"groovy -v".execute().text
//---------------------------------------
// repeating something a fixed number of times with 'times'
// accessing the only value in a closure with 'it'
3.times { println "Hello! This is $it" }
//---------------------------------------
@aceakash
aceakash / gulpfile.js
Last active August 29, 2015 14:11
Gulp config for jasmine and coffeescript
var gulp = require('gulp');
var jasmine = require('gulp-jasmine');
require('coffee-script/register');
gulp.task('test', function () {
return gulp.src('*.spec.coffee')
.pipe(jasmine());
});
@aceakash
aceakash / javascript-recipes.js
Created December 20, 2014 10:40
JavaScript recipes
// --------------------------------------------
// You have a value that is either a scalar or an array. You want an array in either case.
function ensureArray(scalarOrArray) {
return [].concat(scalarOrArray);
}
// --------------------------------------------
// You want a clone of an array.
function cloneArray(originalArray) {
return originalArray.slice(0);
@aceakash
aceakash / tar.js
Created December 20, 2014 21:37
Tar each folder in current folder to its own tarball
var fs = require('fs');
var _ = require('lodash');
var sys = require('sys');
var exec = require('child_process').exec;
function puts(error, stdout, stderr) {
sys.puts(stdout)
}
_(fs.readdirSync('.'))
@aceakash
aceakash / Sum of intervals.md
Last active August 29, 2015 14:15
Sum of intervals problem

Write a function called sumIntervals that accepts an array of intervals, and returns the sum of all the interval lengths.

Overlapping intervals should only be counted once.

Intervals

Intervals are represented by a pair of integers in the form of an array. The first value of the interval will always be less than the second value. Interval example: [1, 5] is an interval from 1 to 5. The length of this interval is 4.

@aceakash
aceakash / .eslintrc
Created July 26, 2015 10:05
ESLint Configuration for Node.js/ES6
{
"rules": {
"indent": [2, 2],
"quotes": [2, "single"],
"linebreak-style": [2, "unix"],
"semi": [2, "always"],
"no-underscore-dangle": 0,
"curly": 0,
"no-use-before-define": [2, "nofunc"],
"spaced-comment": [2, "always"],
@aceakash
aceakash / consumer.rb
Created October 3, 2015 19:29
RabbitMQ simple send-receive in Ruby
require 'bunny'
conn = Bunny.new
conn.start
ch = conn.create_channel
q = ch.queue('hello')
begin
puts " [*] Waiting for messages in #{q.name}. To exit press CTRL+C"
q.subscribe(:block => true) do |delivery_info, properties, body|