Skip to content

Instantly share code, notes, and snippets.

View icodejs's full-sized avatar

Tahir Joseph icodejs

View GitHub Profile
@icodejs
icodejs / webWorkers.js
Created March 11, 2012 00:23
Web Workers
// Consider, for example, parsing a large JSON string. Suppose that the data is large
// enough that parsing takes at least 500 milliseconds. That is clearly too long to allow
// JavaScript to run on the client, as it will interfere with the user experience. This particular
// task is difficult to break into small chunks with timers, so a worker is the ideal solution. The
// following code illustrates usage from a web page:
var worker = new Worker("jsonparser.js");
//when the data is available, this event handler is called
worker.onmessage = function(event){
@icodejs
icodejs / lineNumbers.css
Created March 11, 2012 00:34
CSS: Add line numbers to embedded Gist code
.gist-highlight {
border-left: 3ex solid #eee;
position: relative;
}
.gist-highlight pre {
counter-reset: linenumbers;
}
.gist-highlight pre div:before {
@icodejs
icodejs / sort.js
Created April 3, 2012 15:42
Messing around with sorting arrays
// ---------- Messing around with sorting --------------
(function stableSort(v) {
var dv = [];
for (var i=0; i<v.length; i++) {
dv[i] = [v[i], i];
}
dv.sort();
@icodejs
icodejs / jQueryPluginTemplate.js
Created April 4, 2012 21:02
Global functions and plugin methods
jQuery.extend({
myFunction: function (){
// jqglobal => Tab
// this will add a global function that that can be accessed via the dollar sign does not work on elements
// e.g. jquery.myFunction()
}
});
jQuery.fn.extend({
myFunction: function () {
@icodejs
icodejs / timedProcessArray.js
Created April 8, 2012 08:46
Timed Process Array
// timedProcessArray
// Since each new Date object is initialized with the current system time, you can time
// code by creating new Date objects periodically and comparing their values. The plus
// operator (+) converts the Date object into a numeric representation so that any further
// arithmetic doesn’t involve conversions. This same basic technique can be used to op-
// timize the previous timer patterns.
function timedProcessArray(items, process, callback){
var todo = items.concat(); //create a clone of the original
// Beacons
// This technique is very similar to dynamic script tag insertion. JavaScript is used to create
// a new Image object, with the src set to the URL of a script on your server. This URL
// contains the data we want to send back in the GET format of key-value pairs. Note that
// no img element has to be created or inserted into the DOM.
var url = '/status_tracker.php';
var params = [
'step=2',
'time=1248027314'
@icodejs
icodejs / ApacheAnt.xml
Created April 12, 2012 21:18
ApacheAnt
<!--
Apache Ant provides the ability to combine several files via the concat task. It is im-
portant, however, to remember that JavaScript files usually need to be concatenated in
a specific order to respect dependencies. Once these dependencies have been estab-
lished, using a filelist or a combination of fileset elements allows the order of the
files to be preserved. Here is what the Ant target looks like:
-->
<target name="js.concatenate">
<concat destfile="${build.dir}/concatenated.js">
@icodejs
icodejs / getPostBackControl.vb
Created April 16, 2012 10:28
what page control caused postback?
public function getPostBackControl(page as Page) as string ' what control caused postback?
dim control as control = nothing
dim ctrlname as string = page.request.Params("__EVENTTARGET")
if ctrlname isNot nothing andAlso ctrlname <> string.empty then
control = page.findControl(ctrlname)
else
for each ctl as string in page.request.form
dim c as control = page.findControl(ctl)
@icodejs
icodejs / object_create.js
Created April 16, 2012 10:40
Create JS object
/*
Similarly to the classical Holy Grail, you would use an empty temporary
constructor function F(). You then set the prototype of F() to be the parent
object. Finally, you return a new instance of the temporary constructor:
*/
function object(o) {
function F() {}
@icodejs
icodejs / launch_sublime_from_terminal.markdown
Created April 19, 2012 17:29 — forked from artero/launch_sublime_from_terminal.markdown
Launch Sublime Text 2 from the Mac OS X Terminal

Launch Sublime Text 2 from the Mac OS X Terminal

Sublime Text 2 ships with a CLI called subl (why not "sublime", go figure). This utility is hidden in the following folder (assuming you installed Sublime in /Applications like normal folk. If this following line opens Sublime Text for you, then bingo, you're ready.

open /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl

You can find more (official) details about subl here: http://www.sublimetext.com/docs/2/osx_command_line.html

Installation