Skip to content

Instantly share code, notes, and snippets.

View therahulprasad's full-sized avatar
😀

Rahul Prasad therahulprasad

😀
View GitHub Profile
@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 / 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
#!/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
package main
import (
"encoding/json"
"fmt"
)
type node struct {
value string
expiry float64
@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;*/
#! /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
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(),
@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.';
}