Skip to content

Instantly share code, notes, and snippets.

View gouravtiwari's full-sized avatar

Gourav Tiwari gouravtiwari

View GitHub Profile
# Assuming you have homebrew installed on mac
export G=gource;D=./test-me.log;($G --output-custom-log - --path $D | grep -v '|D|') | ($G --path - --log-format custom --max-files 0 --file-idle-time 0 --time-scale 4 --seconds-per-day 0.00001 --max-file-lag 1 --auto-skip-seconds 0.000000000001 --bloom-intensity 1 --bloom-multiplier 1 --hide dirnames,filenames,users --elasticity 0.4 --stop-at-end --transparent)
#!/usr/bin/env bash
# This script prints out all of your Redis keys and their size in a human readable format
# Copyright 2013 Brent O'Connor
# License: http://www.apache.org/licenses/LICENSE-2.0
human_size() {
awk -v sum="$1" ' BEGIN {hum[1024^3]="Gb"; hum[1024^2]="Mb"; hum[1024]="Kb"; for (x=1024^3; x>=1024; x/=1024) { if (sum>=x) { printf "%.2f %s\n",sum/x,hum[x]; break; } } if (sum<1024) print "1kb"; } '
}
#!/usr/bin/env bash
# This script prints out all of your Redis keys and their size in a human readable format
# Copyright 2013 Brent O'Connor
# License: http://www.apache.org/licenses/LICENSE-2.0
human_size() {
awk -v sum="$1" ' BEGIN {hum[1024^3]="Gb"; hum[1024^2]="Mb"; hum[1024]="Kb"; for (x=1024^3; x>=1024; x/=1024) { if (sum>=x) { printf "%.2f %s\n",sum/x,hum[x]; break; } } if (sum<1024) print "1kb"; } '
}
@gouravtiwari
gouravtiwari / exception_examples_in_ruby.rb
Created July 3, 2014 08:28
Exception examples in Ruby
class MyError < StandardError
attr_accessor :name
def initialize(name)
@name = name
end
end
def test(value)
trial = 0
@gouravtiwari
gouravtiwari / libv8-3.16.14.3-error.rb
Created December 17, 2013 08:07
libv8-3.16.14.3-error on suse linux for localize gem
Using jquery-rails (2.2.1)
Using launchy (2.1.2)
Installing libv8 (3.16.14.3)
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/usr/local/bin/ruby extconf.rb
creating Makefile
Compiling v8 for x64
Using python 2.6.0
Unable to find a compiler officially supported by v8.
@gouravtiwari
gouravtiwari / msql-rhel-fix
Last active December 30, 2015 20:09
mysql rhel error
Starting MySQL... ERROR! The server quit without updating PID file (/var/lib/mysql/servername.pid)
OR
Starting MySQL.The server quit without updating PID file (/[FAILED]mysql/servername.pid).
sestatus
echo 0 > /selinux/enforce
sestatus
require 'csv'
class Exporter
DEFAULT_EXPORT_TABLES = [ Invoice, InvoiceItem, Item, Merchant, Transaction, User ]
DESTINATION_FOLDER = "tmp/"
def self.export_tables_to_csv(tables = DEFAULT_EXPORT_TABLES)
tables.each { |klass| export_table_to_csv(klass) }
end
@gouravtiwari
gouravtiwari / jenkins_setup.sh
Last active April 24, 2019 21:00
Jenkins setup on SUSE
# 1. Install jenkins
sudo zypper addrepo http://pkg.jenkins-ci.org/opensuse/ jenkins
sudo zypper install jenkins
# You would be asked something like this:
# Do you want to reject the key, trust temporarily, or trust always? [r/t/a/?] (r): t
# Overall download size: 115.9 MiB. After the operation, additional 159.9 MiB will be used.
# Continue? [y/n/?] (y): y
# 2. Start jenkins
sudo /etc/init.d/jenkins start
@gouravtiwari
gouravtiwari / passenger_for_ruby_2.0.sh
Created September 30, 2013 15:55
passenger with nginx setup
gem install passenger
passenger-install-nginx-module
sudo -E /usr/local/bin/ruby /usr/local/lib/ruby/gems/2.0.0/gems/passenger-4.0.19/bin/passenger-install-nginx-module
vi /opt/nginx/conf/nginx.conf
# Add in http block:
# passenger_root /usr/local/lib/ruby/gems/2.0.0/gems/passenger-4.0.19;
# passenger_ruby /usr/local/bin/ruby;
@gouravtiwari
gouravtiwari / attr_accessible_solution_rails_3_and_4.rb
Created September 29, 2013 16:00
Fix for mass assignment for rails engine gem to work on rails-3 and rails-4 both
# If it is Rails-3 then using attar_accessible in model:
def self.needs_attr_accessible?
Rails::VERSION::MAJOR == 3
end
if needs_attr_accessible?
attr_accessible :list_of_attributes
end