Skip to content

Instantly share code, notes, and snippets.

View vikynandha-zz's full-sized avatar

Vignesh Nandha Kumar vikynandha-zz

View GitHub Profile
@vikynandha-zz
vikynandha-zz / svgexport.sh
Last active September 17, 2015 10:51
Shell script to export SVG files in bulk to PNG
### TODO: Support command-line options (width, bg color, etc)
if [ $# -eq 0 ]; then
echo 'No arguments passed.'
echo "Usage: svgexport <SVG files to export>"
echo "Say \"svgexport .\" to export all SVGs in current directory"
exit 1
else
pattern=$*
fi
<script type="text/javascript">
(function () {
"use strict";
// once cached, the css file is stored on the client forever unless
// the URL below is changed. Any change will invalidate the cache
var css_href = '/static/media/fonts/proxima-nova/font-compiled.css';
// a simple event handler wrapper
function on(el, ev, callback) {
if (el.addEventListener) {
el.addEventListener(ev, callback, false);
@vikynandha-zz
vikynandha-zz / form.css
Created October 17, 2014 05:45
Polyfill for placeholder atttribute in input elements
input.placeholder {
color: #999;
}
@vikynandha-zz
vikynandha-zz / old-IE-cross-domain-requests.js
Created October 16, 2014 14:23
jQuery patch for cross-domain requests in IE <= 9
if ( window.XDomainRequest ) {
jQuery.ajaxTransport(function( s ) {
if ( s.crossDomain && s.async ) {
if ( s.timeout ) {
s.xdrTimeout = s.timeout;
delete s.timeout;
}
var xdr;
return {
send: function( _, complete ) {
@vikynandha-zz
vikynandha-zz / underscore-to-jade.js
Created May 30, 2014 11:28
Grunt task to convert underscore templates to jade
'use strict';
module.exports = function(grunt) {
var cheerio = require("cheerio"),
_ = require("underscore"),
jadeWrapIndent = function(renderedContent, indentLevel) {
var indentation=[];
for(var i=0;i<indentLevel;i++){
indentation.push(' ');
}
@vikynandha-zz
vikynandha-zz / loc_js.sh
Last active December 25, 2015 16:19
Count lines of js code in the given (or current) directory, excluding blank lines
if [ $# -eq 0 ]
then wd=.
else wd=$1
fi
find $wd -name "*.js" -not -path "*/tests/*" | xargs grep -v '^[ ]*$' | wc -l
@vikynandha-zz
vikynandha-zz / format-file-size.js
Last active December 25, 2015 00:28
Format file size in bytes to human-readable string
function fileSizeFormat( num_bytes ) {
if ( ! num_bytes ) return '0 bytes';
typeof num_bytes == 'number' || ( num_bytes = parseFloat( num_bytes ) );
if ( isNaN( num_bytes ) ) return '';
var i = -1;
var byteUnits = [ 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
do {
num_bytes = num_bytes / 1000;
i++;
@vikynandha-zz
vikynandha-zz / sample-marionette-itemview.js
Last active December 23, 2015 04:09
Backbone Marionette sample model-view
var MyModelView = Backbone.Marionette.ItemView.extend({
template: '#jst-some-template',
modelEvents: {
'change': 'render'
'destroy': 'remove'
}
});
@vikynandha-zz
vikynandha-zz / backbone-duplicate-data.js
Created September 16, 2013 08:04
Backbone leading to duplicate copies of data
var Post = Backbone.Model.extend({
parse: function( resp ) {
return _( resp ).extend({
created_by: new User( resp.created_by )
});
}
});
@vikynandha-zz
vikynandha-zz / boilerplate-collection-view.js
Last active December 23, 2015 03:59
Example to demonstrate too much boilerplate code while in Backbone.
var AnyCollectionView = Backbone.View.extend({
initialize: function() {
this.collection.on( 'add', this.appendItem, this );
},
render: function() {
this.$el.empty();
this.collection.each( this.appendItem, this );
return this;