Skip to content

Instantly share code, notes, and snippets.

View developit's full-sized avatar
🦊
write, the codes

Jason Miller developit

🦊
write, the codes
View GitHub Profile
@Raynos
Raynos / partial.js
Created January 24, 2012 19:44
Partial non-enumerable implementation
/* partial non-enumerable property implementation
Adds a flag to a weakmap saying on obj foo property bar is not enumerable.
Then checks that flag in Object.keys emulation.
*/
// pd.Name :- https://github.com/Raynos/pd#pd.Name
var enumerables = pd.Name();
@nickcoutsos
nickcoutsos / bookmarklet.js
Created February 19, 2012 03:17
Timestamp parser bookmarklet. Highlight a timestamp (or any number) and use the bookmarklet to display it parsed as a date and time, in your locale using your browser's timezone and UTC.
javascript:(function(){findSelectionDocument=function(w){if(w.document.getSelection().toString().length>0){return w.document;}for(var i=0;i<w.frames.length;i++){var doc=findSelectionDocument(w.frames[i]);if(doc){return doc;}}return null;};doc=findSelectionDocument(window)||document;timestamp=doc.getSelection().toString().trim();c=doc.getElementById("_canvas");if(c)return;c=doc.createElement("div");c.id="_canvas";c.setAttribute("style","position:fixed;z-index:100;background-color:rgba(25,25,25,.90);top:0px;left:0px;height:100%;width:100%;text-align:center;font-family:monospace, sans-serif;font-size:12px;");c.onclick=function(){this.parentNode.removeChild(this);};w=doc.createElement("div");w.setAttribute("style","background-color:white;padding:20px;margin:100px auto 0;display:inline-block;border-radius:10px;text-align:left;box-shadow:5px 8px 24px -10px black;");w.onclick=function(){event.stopPropagation();};t=doc.createElement("table");t.setAttribute("style","border-collapse:separate;border-spacing:20px 4px;");
@dbainbridge
dbainbridge / app.js
Created April 19, 2012 20:48
How to use socket.io with Express 3
/**
* Module dependencies.
*/
var express = require('express')
, routes = require('./routes')
, http = require('http');
var app = express();
var server = app.listen(3000);
@jlong
jlong / uri.js
Created April 20, 2012 13:29
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@michaelcox
michaelcox / xdr.js
Created May 10, 2012 18:56
Adds XDomainRequest IE CORS support to jQuery
// Based on https://github.com/jaubourg/ajaxHooks/blob/master/src/ajax/xdr.js
(function( jQuery ) {
if ( window.XDomainRequest && !jQuery.support.cors ) {
jQuery.ajaxTransport(function( s ) {
if ( s.crossDomain && s.async ) {
if ( s.timeout ) {
s.xdrTimeout = s.timeout;
delete s.timeout;
@domenic
domenic / q-nexttick-times.md
Created May 27, 2012 06:30
Q test suite nextTick results

Comparing Different Implementations of process.nextTick using the Q test suite.

Used: q-spec.js@a1a416.

Implementations compared:

Based on MessageChannel

This is currently in Q:

@piatra
piatra / app.js
Created June 27, 2012 12:14
xhr2 + nodejs + filereader = resumable uploads
var http = require('http')
, formidable = require('formidable')
, fs = require('fs')
, qs = require('querystring')
, util = require('util')
, uploads = {};
http.createServer(function(req, res){
if(req.method == 'GET') {
if(req.url != '/favicon.ico') {
@rwaldron
rwaldron / index.js
Created July 27, 2012 07:01
Correct implementation of Array.from and Array.of as they are currently spec'ed. Includes "isConstructor"
(function( global ) {
"use strict";
function isConstructor( C ) {
try {
new C();
return true;
} catch ( e ) {
return false;
}
@edwardhotchkiss
edwardhotchkiss / graphics_magick_center_image_on_canvas.js
Created October 31, 2012 03:32
Use GM Module (Graphics Magick) for Node.js to center an image on a white background canvas
var gm = require('gm');
var canvasWidth = 248;
var canvasHeight = 389;
gm(__dirname + '/original.jpg').size(function(error, size) {
if (error) {
console.error(error);
@CatTail
CatTail / htmlentity.js
Created November 30, 2012 08:27
Javascript: encode(decode) html text into html entity
// encode(decode) html text into html entity
var decodeHtmlEntity = function(str) {
return str.replace(/&#(\d+);/g, function(match, dec) {
return String.fromCharCode(dec);
});
};
var encodeHtmlEntity = function(str) {
var buf = [];
for (var i=str.length-1;i>=0;i--) {