Skip to content

Instantly share code, notes, and snippets.

View vishaltelangre's full-sized avatar

Vishal Telangre vishaltelangre

View GitHub Profile
@vishaltelangre
vishaltelangre / create_if.js
Created January 2, 2014 10:12
Function to create iframes with ease
function createIframe(id, targetEle, src, content, style){
var iframe = document.createElement('iframe');
(iframe.frameElement || iframe).style.cssText = style || "width: 0; height: 0; border: 0";
iframe.id = id;
iframe.src = src || "javascript:false";
$(targetEle).append(iframe);
if(src) return iframe;
var doc = iframe.contentWindow.document;
@vishaltelangre
vishaltelangre / emacs_keybindings
Last active January 1, 2016 05:22
Fundamental Emacs Keybindings #emacs
* Movement
------------
C-v Move next screen
M-v Move backwords one screen
C-f Move forward a character
C-b Move backward a character
M-f Move forward a word
@vishaltelangre
vishaltelangre / async_test_suite.html
Created November 30, 2013 21:40
A simple asynchronous test suite - from JS Ninja book by John Resig
<html>
<head>
<title>Test Suite</title>
<script>
(function() {
var queue = [], paused = false, results;
this.test = function(name, fn) {
queue.push(function() {
results = document.getElementById("results");
results = assert(true, name).appendChild(
var pubsub = {};
(function(q) {
var topics = {}, subUid = -1;
q.subscribe = function(topic, func) {
if (!topics[topic]) {
topics[topic] = [];
}
var token = (++subUid).toString();
topics[topic].push({
token: token,
var pluralForms = {
"en" : function ( x ) {
if ( x === 1 ) {
return 0;
}
return 1;
},
"fr" : function ( x ) {
if ( x > 1 ) {
return 1;
@vishaltelangre
vishaltelangre / dynamic_fn.js
Last active December 28, 2015 20:49
call function dynamically with indefinite # of arguments #js
function execFn( fn ) {
var context;
// check passed in 'this' a.k.a. 'arguments[0]' & set context
context = ( typeof this === "undefined" || typeof this === "null" )
? window
: this;
// locate 'fn' in 'context' or it's a raw function
fn = ( typeof fn === "function" )
? fn
: context[fn];
@vishaltelangre
vishaltelangre / jquery-cachefy.coffee
Created November 12, 2013 12:43
Tiny jQuery plugin to load js files and cache 'em. [#cachefy]
#
## Cachefy (jQuery Plugin)
## @copyright: 2013 (c) Vishal Telangre <the@vishaltelangre.com>
## @license: MIT
## @desc: Tiny jQuery plugin to load js files and cache 'em.
#
#
jQuery.cachefy = (url, options) ->
# Default settings
settings =
@vishaltelangre
vishaltelangre / ar_mysql_connect.rb
Created November 7, 2013 15:01
connection w/ a non-standard mysql db using active-record and retrieving tables
#! /usr/bin/env ruby
#
# Establishes connection with a MySQL db and access its tables
# which have non-standard names, such as user, accounts.
#
require 'active_support/inflector'
require 'active_record'
require 'mysql2'
# See list of running daemons
service --status-all
# List of daemons managed by Upstart
initctl list
# To disable a upstart service
echo 'manual' > /etc/init/<service_name>.override
@vishaltelangre
vishaltelangre / gist:7150780
Created October 25, 2013 07:31
libre office convert file to pdf
libreoffice --headless --invisible --nologo --convert-to pdf *.html