Skip to content

Instantly share code, notes, and snippets.

View therahulprasad's full-sized avatar
😀

Rahul Prasad therahulprasad

😀
View GitHub Profile
@therahulprasad
therahulprasad / gist:4581301
Created January 20, 2013 20:03
Ask for confirmation when tries to close window.
/*
Set needToConfirm variable to true when you want to prevent closing.
For example: If you have made an http call to insert comment (You can set it as true untill you get a success or failure response)
*/
var needToConfirm = true;
function confirmExit() {
if (needToConfirm) {
return 'Please while the comment is being uploaded.';
}
function serverReachable() {
// IE vs. standard XHR creation
var x = new ( window.ActiveXObject || XMLHttpRequest )( "Microsoft.XMLHTTP" ),
s;
x.open(
// requesting the headers is faster, and just enough
"HEAD",
// append a random string to the current hostname,
// to make sure we're not hitting the cache
"//" + window.location.hostname + "/?rand=" + Math.random(),
#! /bin/sh
### BEGIN INIT INFO
# Provides: openerp-server
# Required-Start: $syslog
# Required-Stop: $syslog
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Short-Description: OpenERP Server - the server
# Description: OpenERP is a complete ERP and CRM software
### END INIT INFO
@therahulprasad
therahulprasad / YiiImageFromDatabaseBlob
Created June 4, 2013 14:24
Get image from database (blog). And render it using Image magick in Yii. Resize it according to preset and cache it in disk.
public function actionImage($id, $preset = 'original', $type='circuit') {
// If image exists in cache and its last modified date is same as circuit last modofied date // Load it
$model = $this->loadModel($id);
$modified_date = strtotime($model->update_time);
/*$a = filemtime("cache/circuits/circuit/{$preset}/{$model->id}.png");
echo "$a";
echo "$modified_date";
exit;*/
package main
import (
"encoding/json"
"fmt"
)
type node struct {
value string
expiry float64
#!/bin/bash
# bash generate random alphanumeric string
#
# bash generate random 32 character alphanumeric string (upper and lowercase) and
NEW_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
# bash generate random 32 character alphanumeric string (lowercase only)
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1
@therahulprasad
therahulprasad / auto-remove-chef-node.sh
Created June 29, 2015 20:58
Automatically remove deleted EC2 instances (chef nodes) from chef-server
#!/bin/bash |" Press <F1>, ? for help
# Author: Rahul Prasad (http://www.rahulprasad.com) |" No tags found.
# README |~
# aws cli must be configured |~
# for knife to work from other directory, copy .chef folder from chef-repo to the working directory
@therahulprasad
therahulprasad / main.go
Last active February 1, 2016 15:10
streadway/amqp bug infinite loop when rabbitmq shuts down
package main
import (
"fmt"
"github.com/streadway/amqp"
"log"
"os"
"os/signal"
"syscall"
)
@therahulprasad
therahulprasad / countries.sql
Created February 18, 2016 14:48 — forked from adhipg/countries.sql
Sql dump of all the Countries, Country Codes, Phone codes.
CREATE TABLE IF NOT EXISTS `country` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`iso` char(2) NOT NULL,
`name` varchar(80) NOT NULL,
`nicename` varchar(80) NOT NULL,
`iso3` char(3) DEFAULT NULL,
`numcode` smallint(6) DEFAULT NULL,
`phonecode` int(5) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
@therahulprasad
therahulprasad / gist:fe332cd26e74fea1488b
Created February 19, 2016 14:44
Google Contacts API v3 Javascript sample
<html>
<head>
<script src="https://apis.google.com/js/client.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script>
function auth() {
var config = {
'client_id': 'OAUTH_CLIENT_ID',
'scope': 'https://www.google.com/m8/feeds'
};