Skip to content

Instantly share code, notes, and snippets.

@bytespider
bytespider / copy javascript array.js
Created January 25, 2010 14:12
Copy javascript array to new array
var array_a = [1,2,3];
var copy_of_array_a = array_a.slice(0);
function ANSI_X923_pad(hex_str, blocksize) {
blocksize = blocksize || 512; // in bits
var bit_str_len = hex_str.length * 4; // in bits
var bit_str_len_hex = bit_str_len.toString(16);
// how many nibbles are left over?
var pad_nibbles = (((bit_str_len / blocksize) < 1) ? (blocksize - (bit_str_len_hex.length * 4)) - bit_str_len : (blocksize - (bit_str_len_hex.length * 4)) - (bit_str_len - blocksize)) / 4;
return hex_str + new Array(1 + pad_nibbles).join(0) + bit_str_len_hex;
}
// bookmarklet to introspect the source of current page
javascript:(function(d,h){h=d.documentElement.innerHTML;d.open();d.write('<pre>'+('<!DOCTYPE html><html>'+h+'</html>').replace(/[<>]/g,function(m){return{'<':'&lt;','>':'&gt;'}[m]})+'</pre>')})(document);
window.addEventListener('load', function (event) {
var stylesheets = window.document.styleSheets;
for(var i = 0; i < stylesheets.length; i++) {
parseStylesheet(stylesheets[i]);
}
function parseStylesheet(stylesheet) {
if(stylesheet.imports) {
for (var i = 0; i < stylesheet.imports.length; i++) {
function openURL(url) {
var a = d.createElement('a'), d = document;
a.href = url;
a.dispatchEvent(d.createEvent('MouseEvents').initMouseEvent('click'));
}
<html>
<head>
<title>Overflow test</title>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
<style>
body {
padding: 0;
}
#scroller {
overflow-y: scroll;
@bytespider
bytespider / gist:785158
Created January 18, 2011 21:11
Appcelerator Titanium window drag
/*
Bullet Proof window drag
This is the most performant window dragging code
I could come up with. All the example on
developer.appcelerator.com we laggy
Version 2: More contained version
*/
@bytespider
bytespider / demand.js
Created March 27, 2011 20:10
Require functions in external scripts on demand
/**
* demand.js
* @author: Rob Griffiths
* On demand javascript
*
* Usage:
* demand('alerter', 'alerter.js');
* ...
* alerter('OMG!'); // script is only inserted now and executed
*
@bytespider
bytespider / JPGE Image dimensions
Created April 7, 2011 08:43
Loads a JPEG image into memory, storing the width and height as properties of a JPEG object using Node.JS
var fs = require('fs');
function JPEG(filename) {
var image = this;
image.blob = null;
if (filename) {
image = JPEG.loadFromFile(filename);
}
@bytespider
bytespider / LICENSE.txt
Created May 24, 2011 10:08 — forked from 140bytes/LICENSE.txt
Base64 Encode
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Rob Griffiths http://bytespider.eu
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.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE