Skip to content

Instantly share code, notes, and snippets.

View algogrit's full-sized avatar

Gaurav Agarwal algogrit

View GitHub Profile

Ruby 2.0.0 in detail

Keyword arguments

def wrap(string, before: "<", after: ">")
  "#{before}#{string}#{after}" # no need to retrieve options from a hash
end

# optional

wrap("foo") #=> ""

#!/usr/bin/env ruby
rss = '.+?Rss:\s+(\d+)'
share = '.+?Shared_Clean:\s+(\d+)'
share << '.+?Shared_Dirty:\s+(\d+)'
priv = '.+?Private_Clean:\s+(\d+)'
priv << '.+?Private_Dirty:\s+(\d+)'
MEM_REGEXP = /\[heap\]#{rss}#{share}#{priv}/m
def mem_usage_linux
# configuration for osx clipboard support
set-option -g default-command "reattach-to-user-namespace -l sh"
@algogrit
algogrit / .irbrc
Created June 27, 2013 17:11 — forked from patmcnally/.irbrc
# load libraries
require 'rubygems' rescue nil
require 'wirble'
#require 'json'
alias q exit
class Object
def local_methods
(methods - Object.instance_methods).sort
(ns wikiparse
(:require [clojure.java.io :as io]
[clojure.data.xml :as xml]
[clojure.zip :as zip]
[clojure.data.zip :as dzip]
[clojure.data.zip.xml :as zxml])
(:import [ org.apache.commons.compress.compressors.bzip2 BZip2CompressorInputStream])
(:gen-class :main true))
(defn bz2-reader
@algogrit
algogrit / install_git-multi.sh
Created July 25, 2013 14:35
Install git multi
mkdir -p ~/bin
curl https://raw.github.com/gauravagarwalr/Script-BackUp/master/OS%20X/Custom-Git-Commands/git-multi > ~/bin/git-multi
chmod 744 ~/bin/git-multi
echo $SHELL | grep 'zsh'
is_bourne_shell=$?
adding_bin_to_path="export PATH=~/bin:\$PATH"
if [ $is_bourne_shell ] ; then
@algogrit
algogrit / earlier.js
Last active December 23, 2015 18:31
Airbrake wrap / notice annotations
renderWrapper = airBrakeClient.wrap(render);
@algogrit
algogrit / debugging.rb
Created December 10, 2013 07:14
Snippets for RoR
# Displaying queries in the rails console
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.connection_pool.clear_reloadable_connections!
@algogrit
algogrit / networking
Created December 22, 2013 16:53
Useful UNIX Tools
# Netcat - Swiss army knife?!
- nc / netcat
Helps in looking at the tcp or udp packets flowing.
- netstat
Lists all process/port combinations.
@algogrit
algogrit / hi8-fetch.py
Created February 12, 2016 18:21 — forked from celoyd/hi8-fetch.py
Fetch and untile tiled Himawari-8 images from the http://himawari8.nict.go.jp PNG endpoint
import requests as req
import sys
from dateutil.parser import parse
from PIL import Image
from StringIO import StringIO
# hi8-fetch.py <date> <zoom level> <output>
# E.g.: hi8-fetch.py 2016-01-13T22:10:00 8 2016-01-13T221000-z8.png
# Fetch Himawari-8 full disks at a given zoom level.
# Valid zoom levels seem to be powers of 2, 1..16, and 20.