Skip to content

Instantly share code, notes, and snippets.

View icodeforlove's full-sized avatar
:octocat:
Indefinitely In Bangkok

Chad icodeforlove

:octocat:
Indefinitely In Bangkok
View GitHub Profile
@icodeforlove
icodeforlove / mp4-chunk-test.js
Created September 18, 2012 22:57
Simple file server test for video
/*jshint node:true*/
var fs = require('fs'),
http = require('http'),
path = require('path'),
port = 1338,
dir = '.';
http.createServer(function (request, response) {
var filePath = path.join(dir, path.basename(request.url));
if (path.extname(request.url) !== '.mp4' || !fs.existsSync(filePath)) return throw404();
@icodeforlove
icodeforlove / Float32Array.concat.js
Last active March 7, 2022 23:09
Float32Array concatenation uses buffers
Float32Array.prototype.concat = function() {
var bytesPerIndex = 4,
buffers = Array.prototype.slice.call(arguments);
// add self
buffers.unshift(this);
buffers = buffers.map(function (item) {
if (item instanceof Float32Array) {
return item.buffer;
@icodeforlove
icodeforlove / cdn.js
Created January 2, 2014 19:19
cdn url generator
function CDN ($config) {
this.protocol = $config.protocol;
this.domain = $config.domain;
this.alias = $config.alias;
this.total = $config.total;
}
CDN.prototype = {
getURL: function (path) {
return this.protocol + '://' + this.alias + (this._stringToNumber(path) % this.total) + '.' + this.domain + path;
},
@icodeforlove
icodeforlove / .webpack-dev-server-delay.js
Created February 22, 2016 21:08
webpack-dev-server-delay
// add a delay to webpack-dev-server
(function () {
var Server = require('webpack-dev-server/lib/Server'),
sendStats = Server.prototype._sendStats,
delay = 75;
Server.prototype._sendStats = function () {
var args = arguments,
self = this;
@icodeforlove
icodeforlove / JSONP.js
Created December 4, 2011 23:17
simple JSONP support
/**
* simple JSONP support
*
* JSONP.get('https://api.github.com/gists/1431613', function (data) { console.log(data); });
* JSONP.get('https://api.github.com/gists/1431613', {}, function (data) { console.log(data); });
*
* gist: https://gist.github.com/gists/1431613
*/
var JSONP = (function (document) {
var requests = 0,
@icodeforlove
icodeforlove / ResizeHandle.js
Created April 15, 2019 12:23
Custom window resize handle for nw.js
import React, { useState, useEffect } from 'react';
const {
resizeWindowTo
} = nw.global;
function ResizeHandle () {
let timeout,
startW,
startH,
@icodeforlove
icodeforlove / worker.js
Last active May 31, 2018 00:02
GDPR Block All European Countries (Cloudflare Worker)
const BLOCKED_COUNTRIES = [
'AL', 'AD', 'AM', 'AT', 'BY', 'BE', 'BA', 'BG', 'CH', 'CY', 'CZ', 'DE',
'DK', 'EE', 'ES', 'FO', 'FI', 'FR', 'GB', 'GE', 'GI', 'GR', 'HU', 'HR',
'IE', 'IS', 'IT', 'LT', 'LU', 'LV', 'MC', 'MK', 'MT', 'NO', 'NL', 'PL',
'PT', 'RO', 'RU', 'SE', 'SI', 'SK', 'SM', 'TR', 'UA', 'VA'
];
addEventListener('fetch', event => {
event.respondWith((async request => {
let country = request.headers.get('CF-IpCountry'),
@icodeforlove
icodeforlove / bandcamp.js
Last active December 23, 2017 15:38
download mp3's from bandcamp
var commands = [];
commands.push('mkdir "' + TralbumData.current.title + '"');
commands.push('cd "' + TralbumData.current.title + '"');
TralbumData.trackinfo.forEach(function (track, index) {
if (track.file) {
commands.push('curl -o "' + track.title + '.mp3" -L "' + track.file['mp3-128'] + '"');
}
@icodeforlove
icodeforlove / react-js-harmony-fiddle-integration.js
Created July 14, 2014 18:59
react-js-harmony-fiddle-integration.js
(function() {
var tag = document.querySelector(
'script[type="application/javascript;version=1.7"]'
);
if (!tag || tag.textContent.indexOf('window.onload=function(){') !== -1) {
alert('Bad JSFiddle configuration, please fork the original React JSFiddle');
}
tag.setAttribute('type', 'text/jsx;harmony=true');
tag.textContent = tag.textContent.replace(/^\/\/<!\[CDATA\[/, '');
})();