Skip to content

Instantly share code, notes, and snippets.

@visnup
visnup / selection.js
Created August 24, 2012 22:05 — forked from Munawwar/test.html
IE8 equivalent of HTML5/W3C Range object's startContainer,startOffset,endContainer and endOffset properties
(function selectionPolyfill(window, document) {
if (window.getSelection || !document.selection) return;
// convert an IE TextRange to a W3C one
function convert(range, startOrEnd) {
var point = range.duplicate()
, result = {};
// point is either the start or end of the range
point.collapse(startOrEnd);
@Yaffle
Yaffle / gist:3051734
Last active October 6, 2015 20:57
matchesSelector
/*jslint vars: true, indent: 2 */
/*global Utils*/
(function (exports) {
"use strict";
function matchesCompoundSelector(element, compoundSelector) {
// only tagName + ('.' + className) *
var tagName = compoundSelector[0];
if (tagName !== null && !tagName.test(element.nodeName)) {
@darobin
darobin / gist:2935734
Created June 15, 2012 10:10
Async testing
// testharness.js
var t = async_test("Timeout times out");
setTimeout(t.step_func(function () {
assert_true(true);
t.done();
}), 100);
// Jasmine
describe("Timeout", function () {
@JeffJacobson
JeffJacobson / tocsv.js
Last active July 21, 2023 13:53
JavaScript object to CSV
/**
* Converts a value to a string appropriate for entry into a CSV table. E.g., a string value will be surrounded by quotes.
* @param {string|number|object} theValue
* @param {string} sDelimiter The string delimiter. Defaults to a double quote (") if omitted.
*/
function toCsvValue(theValue, sDelimiter) {
var t = typeof (theValue), output;
if (typeof (sDelimiter) === "undefined" || sDelimiter === null) {
sDelimiter = '"';
@siritori
siritori / aatree.c
Created May 21, 2012 03:40
AA tree by C
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <stdbool.h>
#include "aatree.h"
static aanode* new_aanode(const int key, void *val, aanode *nullnode) {
aanode *n = (aanode*)malloc(sizeof(aanode));
if(n == NULL) return NULL;
n->key = key;
@tylergaw
tylergaw / dabblet.css
Created April 19, 2012 04:17
Centered Vertical line with CSS Gradient
/**
* Centered Vertical line with CSS Gradient
*/
div {
background: #fff;
background: linear-gradient(180deg, transparent, #353535, transparent);
background-position: 50%;
background-repeat: repeat-y;
background-size: 1px auto;
}
@eligrey
eligrey / html-domparser.js
Last active March 9, 2025 03:34
DOMParser HTML extension - Now a polyfill since HTML parsing was added to the DOMParser specification
/*
* DOMParser HTML extension
* 2019-11-13
*
* By Eli Grey, http://eligrey.com
* Public domain.
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
*/
/*! @source https://gist.github.com/1129031 */
@sebastien-p
sebastien-p / LICENSE.txt
Created June 14, 2011 09:10
Tweet-sized JavaScript implementation of the Lempel–Ziv–Welch universal lossless data compression algorithm.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Sebastien P. https://twitter.com/#!/_sebastienp
Special thanks to @subzey (you rock) and @kbjr !
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
@bradwright
bradwright / websockets-server.js
Created June 11, 2011 23:29
Pure Node.js WebSockets server
/*
* node-ws - pure Javascript WebSockets server
* Copyright Bradley Wright <[email protected]>
*/
// Use strict compilation rules - we're not animals
'use strict';
var net = require('net'),
crypto = require('crypto');
@joubertnel
joubertnel / gist:870190
Last active July 8, 2023 12:52
HTML5 Canvas - Rendering of Text on high-DPI screens
<html>
<head>
<script src='http://code.jquery.com/jquery-1.5.1.min.js'></script>
</head>
<body>
<h2>Naive canvas</h2>
<canvas id="naive" width="400" height="50"></canvas>
<h2>High-def Canvas</h2>