Skip to content

Instantly share code, notes, and snippets.

View cmthakur's full-sized avatar
🎯
Focusing

Chandra M. Thakur cmthakur

🎯
Focusing
View GitHub Profile
@cmthakur
cmthakur / Jenkins shell
Created November 8, 2012 08:10
Jenkins Shell
#!/bin/bash -e
if [[ $BUILD_NUMBER == 1 ]]
then
mkdir -p tmp/{media/final_outputs,pids,cache}
fi
./configure
perl -pi -e "s/mero_test/${JOB_NAME}/g" $WORKSPACE/config/mongoid.yml
@cmthakur
cmthakur / Linux Commands
Created March 27, 2013 04:01
Linux Commands
# Find ports
> netstat -tan | grep LIST
@cmthakur
cmthakur / gist:5386284
Last active December 16, 2015 05:39
display hour:minutes:seconds
String.prototype.toHHMMSS = function () {
sec_numb = parseInt(this, 10); // don't forget the second parm
var hours = Math.floor(sec_numb / 3600);
var minutes = Math.floor((sec_numb - (hours * 3600)) / 60);
var seconds = sec_numb - (hours * 3600) - (minutes * 60);
if (hours < 10) {hours = "0"+hours;}
if (minutes < 10) {minutes = "0"+minutes;}
if (seconds < 10) {seconds = "0"+seconds;}
var time = hours+':'+minutes+':'+seconds;
@cmthakur
cmthakur / gist:5403530
Created April 17, 2013 11:22
Highstock with hourly data
$(function() {
// See source code from the JSONP handler at https://github.com/highslide-software/highcharts.com/blob/master/samples/data/from-sql.php
$.getJSON('http://www.highcharts.com/samples/data/from-sql.php?callback=?', function(data) {
// Add a null value for the end date
data = [].concat(data, [[Date.UTC(2011, 9, 14, 19, 59), null, null, null, null]]);
// create the chart
window.chart = new Highcharts.StockChart({
@cmthakur
cmthakur / gist:5450609
Last active December 16, 2015 14:39
Top Useful LInks( for Ruby development)
#Sinatra Authenication Example
https://github.com/timmillwood/millwoodonline
http://skli.se/2013/03/08/sinatra-warden-auth/
http://codebiff.com/post/roll-your-own-sinatra-authentication.html
require 'sinatra/base'
require 'rack/flash'
require 'warden'
require 'slim'
require 'sequel'
require 'sqlite3'
DB = Sequel.sqlite
DB.create_table :users do
primary_key :id
@cmthakur
cmthakur / gist:5468675
Created April 26, 2013 16:47
Shortcuts commands for postgres Sql
Command Description
d This command is in general the shortcut for “describe”. In other database systems the “desc” keyword is used instead.
dt Displays all your user defined tables.
dT Displays all your user defined data types.
df Displays all your user defined functions.
di Displays all your user defined indexes.
dv Displays all your user defined views.
dn Displays all namespaces.
du Displays all users.
l Displays all databases.
@cmthakur
cmthakur / check card with Luh algorithm
Created June 24, 2013 13:42
Credit cards use a check digit algorithm called the Luhn algorithm. Write a function that takes one parameter, the credit card number, and returns true or false depending on whether the number is a valid number. Similarly, write a second function that takes a number of any length and calculates the Luhn check digit and returns the original numbe…
def find_checksum(card_number)
number_arr = card_number.to_s.reverse.scan(/\d/).map { |x| x.to_i }
number_arr = number_arr.each_with_index.map { |d, i|
d *= 2 if i.even?
d > 9 ? d - 9 : d
}
sum = number_arr.inject(0) { |m, x| m + x }
mod = 10 - sum % 10
mod==10 ? 0 : mod
@cmthakur
cmthakur / gist:5850868
Created June 24, 2013 15:26
Show the code you would use for a database migration that added a field “permalink” to an existing table called “post”. The migration is to also create a permalink for every existing Post record based on the “title” field. You can use any method you want to convert title to become permalink, the only requirements being permalink must be based on…
rails g migration AddColumnPermalinkToPost permalink:string
require 'uri'
class Post < ActiveRecord::Base
# Dummy url
URL = "localhost:3000/"
before_save :update_permalink
@cmthakur
cmthakur / Ember Js
Created July 6, 2013 08:56
Ember js
http://glennstovall.com/blog/2013/06/27/angularjs-an-overview/?utm_source=javascriptweekly&utm_medium=email
http://net.tutsplus.com/tutorials/javascript-ajax/building-a-web-app-from-scratch-in-angularjs/?utm_source=javascriptweekly&utm_medium=email
http://emberjs.com/guides/concepts/core-concepts/