Skip to content

Instantly share code, notes, and snippets.

View topliceanu's full-sized avatar
💭
🚀

Alexandru Topliceanu topliceanu

💭
🚀
View GitHub Profile
@topliceanu
topliceanu / alter-ajax-response.js
Created November 30, 2012 10:58
A centralized way to modify jquery ajax responses. Usefull in testing where you need semi-mocks
var alterResponse = function (opts) {
/**
* Function modifies $.ajax responses
* by allowing you to modify ajax response object before each bound success callback.
* Currently it supports only `success` callbacks, `error` and `complete` support to come.
* @param {RegExp} opts.urlMatch - use this to filter calls by url
* @param {String} opts.dataType - Optional - use this to filter calls by response type
* @param {Function} opts.successWrapper - function that gets called before each ajax callback
* - function (options:Object, originalOptions:Object, jqXHR:jQuery.XHR, originalSuccess: Function)
*/
@topliceanu
topliceanu / micro-mustache.js
Created December 30, 2011 04:22
John Resig's Micro Template with changed tags from <%=, %> into more mustache-esque {{= and }}
// Simple JavaScript Templating
// John Resig - http://ejohn.org/ - MIT Licensed
(function(){
var cache = {};
this.tmpl = function tmpl(str, data){
// Figure out if we're getting a template, or if we need to
// load the template - and be sure to cache the result.
var fn = !/\W/.test(str) ?
cache[str] = cache[str] ||
@topliceanu
topliceanu / tweet-parser.coffee
Created February 19, 2013 14:07
method to extract transform users and links in tweets into actual links
parseTweet = (tweet) ->
###
This method parses a plain tweet text and outputs html
containing links for all @usernames, #hashtags and links in it.
@param {String} tweet
@param {String} - html output
###
links = [
/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&~\?\/.=]+/g
(url) ->
@topliceanu
topliceanu / description.markdown
Created May 5, 2012 10:16
lists all user defined globals attached to [window]

This bookmarklet can be used to keep track of global variables attached to window.

It displays the user-defined global variables by comparing all properties attached on current window to all standard properties extracted from an empty iframe.

To install, create a new bookmark in your bookmark bar and copy-paste the contents of listGlobals.bookmarklet

@topliceanu
topliceanu / node-csv-parser-pipeable.js
Created April 19, 2012 13:16
script for adapting node-csv to allow .pipe()
var streams = require('stream');
var events = require('events');
var util = require('util');
var csv = require('csv');
var InputStream = function () {};
util.inherits(InputStream, streams.Stream);
var OutputStream = function () {};
util.inherits(OutputStream, events.EventEmitter);
@topliceanu
topliceanu / extend.es5.js
Created March 6, 2012 11:43
extends objects, similar in functionality to $.extend or _.extend
// jquery style `extend` work in ES5 compatible envs
var extend = function (obj) {
var args = Array.prototype.slice.call(arguments, 1);
args.forEach( function (source) {
for (var prop in source)
if (source.hasOwnProperty(prop)) obj[prop] = source[prop];
});
return obj;
};
@topliceanu
topliceanu / documentLocalStorage.js
Created March 3, 2012 11:05
store data in localstorage, api similar to document databases
// stores arrays binded to keys in localstorage
(function (win) {
var isStorage = function (obj) {
return (Object.prototype.toString.call(obj) === '[object Storage]');
};
var decode = function (str) {
try {
var arr = JSON.parse(str);
if (!Array.isArray(arr)) return false;
return arr;
@topliceanu
topliceanu / requestGzip.js
Created February 19, 2012 16:22
Stream downloader of web resources, based on mikeal's request, but processed first through zlib if necessary
var request = require('request');
var zlib = require('zlib');
// A two-way passthrough Stream, made by @felixge
// https://github.com/felixge/node-passthrough-stream/blob/master/lib/passthrough_stream.js
var PassthroughStream = function () {
this.writable = true;
this.readable = true;
}
util.inherits(PassthroughStream, streams.Stream);
@topliceanu
topliceanu / html.js
Created November 9, 2011 14:16
a simple html renderer for express.js, no need for ejs or jade
//register a *simple* html renderer
app.register( '.html', {
compile: function( str, options ){
return function( locals ){
return str;
}
}
});