Skip to content

Instantly share code, notes, and snippets.

View deepakkumarnd's full-sized avatar
🏠
Working from home

Deepak Kumar deepakkumarnd

🏠
Working from home
View GitHub Profile
@deepakkumarnd
deepakkumarnd / tweet_command.py
Created November 14, 2012 13:26
tweet using command line
#!/usr/bin/python
# tweet-1.0
# @author deepakkumar
# replace the user and passwd with your username and password
# the log will be available in file tweetlog in the current directory
import os
import sys
import time
@deepakkumarnd
deepakkumarnd / roulette.rb
Created November 14, 2012 17:14
One small ruby puzzle
class Roulette
def method_missing(name, *args)
person = name.to_s.capitalize
3.times do
number = rand(10) + 1
puts "#{number}..."
end
"#{person} got a #{number}"
end
end
@deepakkumarnd
deepakkumarnd / gist:6449513
Created September 5, 2013 12:34
revert by overwriting the history - can be used to fixing typo unwanted commits etc
git reset --hard[--soft] commit-id
git commit # if there is something needs to be changed
git push origin branch-name -f # -f will forcefully rewrite the history on remote branch
@deepakkumarnd
deepakkumarnd / gist:6449523
Created September 5, 2013 12:35
server benchmarking tools
# Apache Benchmarking tool - ab
ab can simulate a high load on the server.
eg: ab -n 1000 -c 10 -g test_data_1.txt http://www.your-domain.com/index.html
commonly used options
-n number of requests. Default is 1 which is useless.
-c concurrent requests. Default 1
@deepakkumarnd
deepakkumarnd / network ping
Last active December 26, 2015 12:19
Pings the local network and counts the nodes which are up.
#!/bin/bash
set count = 0
for i in 192.168.150.{1..255}
do
ping -c2 -t2 $i > /dev/null
if [ $? -eq 0 ]
then
echo "$i is up"
set count = $count + 1
fi
/*
Getip: This program takes a hostname as argument and outputs its ip address
Usage: ./getip <hostname>
Program Name: getip.c
Author Deepak Kumar
Email: deepakkumarnd@gmail.com
*/
#include<stdio.h>
@deepakkumarnd
deepakkumarnd / git branch name
Created December 21, 2013 06:13
Get Git Current Branch name
git rev-parse --abbrev-ref HEAD
$ rails new app_name --skip-active-record
Gemfile
gem 'mongoid', github: 'mongoid/mongoid'
$ rails g mongoid:config
Gemfile
#lib/role_constraint.rb
class RoleConstraint
def initialize(*roles)
@roles = roles
end
def matches?(request)
@roles.include? request.env['warden'].user.try(:role)
end
$ tar -zcvf logs.tar.gz *.log
or
$ tar -zcvf logs.tar.gz folder_name
$ tar -zcvf data.tgz *.doc #gzip
$ tar -zcvf pics.tar.gz *.jpg *.png #gzip
$ tar -jcvf data.tbz2 *.doc #bzip2