Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style id="jsbin-css">
.toast {
position: fixed;
bottom: 10px;
(function (global, factory) {
if (typeof define === "function" && define.amd) {
define(['exports'], factory);
} else if (typeof exports !== "undefined") {
factory(exports);
} else {
var mod = {
exports: {}
};
factory(mod.exports);
@vsr
vsr / error
Created September 30, 2014 15:56
shelve DB crashing on concurrent access
Traceback (most recent call last):
File "shelvetest.py", line 11, in <module>
data[date] = "".join( [random.choice(string.letters[:26]) for i in xrange(315)] )
File "/usr/lib/python2.7/shelve.py", line 133, in __setitem__
self.dict[key] = f.getvalue()
File "/usr/lib/python2.7/bsddb/__init__.py", line 279, in __setitem__
_DeadlockWrap(wrapF) # self.db[key] = value
File "/usr/lib/python2.7/bsddb/dbutils.py", line 68, in DeadlockWrap
return function(*_args, **_kwargs)
File "/usr/lib/python2.7/bsddb/__init__.py", line 278, in wrapF
@vsr
vsr / gist:016cd6c28ce57422720c
Created August 5, 2014 07:28
Hotel Listing
<div class="container" >
<div class="row">
<div class="col-md-4">
Search term
<input type="text" ng-model="searchTerm" class="form-control" />
</div>
<div class="col-md-3" >
<select ng-model="descLimit">
<option value="10">10</option>
@vsr
vsr / hello.c
Created November 25, 2013 16:20
The program opens a file, prints in a loop and then closes it. Moving the file to another location, (`mv file.txt file1.txt`) during the loop does not cause any exception or error. At the end of the program, `file1.txt` has the proper output.
#include <stdio.h>
main(){
printf("Hello there!\n");
FILE *f = fopen("/tmp/file.txt", "w");
if(f == NULL){
printf("Error opening file!\n");
return 1;
}
@vsr
vsr / Gruntfile.js
Created November 15, 2013 21:07
First, basic Gruntfile.js
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
options: {
separator: ';',
},
js: {
@vsr
vsr / ga-log.js
Created September 14, 2012 12:55
JavaScript error logging with GA
// Google Analytics event tracking (Report available at Content->Events in GA)
function gatrack(){
var args = Array.prototype.slice.call(arguments),
params = ['_trackEvent'].concat(args);
if(typeof _gaq !== 'undefined') {
window.setTimeout(function(){ _gaq.push(params); }, 0);
}
}
@vsr
vsr / mergefonts.py
Created March 20, 2012 20:52
fontforge merge
import fontforge
import sys
serif = "FreeSerif.ttf"
gubbi = "Gubbi.ttf"
navilu = "Navilu.ttf"
kedage = "Kedage.ttf"
s = fontforge.open(serif)
s.mergeFonts(kedage)
@vsr
vsr / notifyme.py
Created January 7, 2012 14:35
PyNotify
import os, sys
import datetime, time
import pynotify
# Notifies with a fortune cookie every X minutes.
# Usage: "python notifyme.py 10" to notify every 10 minutes
def notify(count):
fortune = os.popen('fortune -n 100 -s', 'r').read()
time = datetime.datetime.now().strftime("%H:%M:%S")
@vsr
vsr / resize.py
Created March 7, 2011 18:43
script for batch resizing images using imagemagick
source_path = "/media01/me/flickr/"
dest_path = "./converted"
import os
from pipes import quote
file_list = os.listdir(source_path)
for f in file_list:
source_file = os.path.join(source_path, f)
dest_file = os.path.join( dest_path, f )
#imagemagick resize & scaling options: http://www.imagemagick.org/Usage/resize/