Skip to content

Instantly share code, notes, and snippets.

@jonleighton
jonleighton / base64ArrayBuffer.js
Last active November 2, 2024 06:08
Encode an ArrayBuffer as a base64 string
// Converts an ArrayBuffer directly to base64, without any intermediate 'convert to string then
// use window.btoa' step. According to my tests, this appears to be a faster approach:
// http://jsperf.com/encoding-xhr-image-data/5
/*
MIT LICENSE
Copyright 2011 Jon Leighton
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
@lelandbatey
lelandbatey / whiteboardCleaner.md
Last active November 11, 2024 22:46
Whiteboard Picture Cleaner - Shell one-liner/script to clean up and beautify photos of whiteboards!

Description

This simple script will take a picture of a whiteboard and use parts of the ImageMagick library with sane defaults to clean it up tremendously.

The script is here:

#!/bin/bash
convert "$1" -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 "$2"

Results

@mikelehen
mikelehen / generate-pushid.js
Created February 11, 2015 17:34
JavaScript code for generating Firebase Push IDs
/**
* Fancy ID generator that creates 20-character string identifiers with the following properties:
*
* 1. They're based on timestamp so that they sort *after* any existing ids.
* 2. They contain 72-bits of random data after the timestamp so that IDs won't collide with other clients' IDs.
* 3. They sort *lexicographically* (so the timestamp is converted to characters that will sort properly).
* 4. They're monotonically increasing. Even if you generate more than one in the same timestamp, the
* latter ones will sort after the former ones. We do this by using the previous random bits
* but "incrementing" them by 1 (only in the case of a timestamp collision).
*/
@JosePedroDias
JosePedroDias / rndBase32.js
Created March 9, 2015 10:50
random base32 string of length len. works well up to 6 characters. chars are in the range [0-9][a-t]
function rndBase32(len) {
return ( ~~(Math.random() * Math.pow(32, len)) ).toString(32);
}
@justinribeiro
justinribeiro / instructions.md
Last active October 8, 2018 01:57
The Web Platform Podcast: Pipelines for publishing

Justin's Guide to faster episodes

The follwing is my working document as I create a pipeline for faster YouTube > LibSyn / iTunes distribution. This is not complete, but really cuts down on some time.

Prerequisites

I'm a commandline guy, I like UNIX tooling philosophy. Hence, my prereqs.

  1. youtube-dl
  2. ffmpeg
  3. mutagen
@alinz
alinz / gundb-stresstest.js
Created December 5, 2017 17:03
Gundb Stress Test
const stream = require('stream')
const Gun = require('gun')
const randomString = length => {
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
let text = ''
for (var i = 0; i < length; i++) {
text += possible[Math.floor(Math.random() * possible.length)]
}
return text
@zrrrzzt
zrrrzzt / gun.restrict.put.server.js
Last active November 24, 2022 16:41
Example code for restricting put on GUN
/* You'll need this on your client
Gun.on('opt', function (ctx) {
if (ctx.once) {
return
}
ctx.on('out', function (msg) {
var to = this.to
// Adds headers for put
msg.headers = {
token: 'thisIsTheTokenForReals'
@d3x0r
d3x0r / gun_dev_null.js
Created April 18, 2018 23:47
A no-op storage driver for gun, in case gun has no other storage; at least one ack from a storage device is required for the engine to work....
Gun.on('opt', function(ctx){
const ACK_ = '@';
const SEQ_ = '#';
var gun = ctx.gun;
this.to.next(ctx);
ctx.on('put', function(at) {
this.to.next(at);
ctx.on('in', {[ACK_]: at[SEQ_], gun:gun, ok: 1});
@jpstrikesback
jpstrikesback / Component.jsx
Last active April 20, 2019 03:15
RAD AsyncStorage Adapter
import * as React from 'react';
import {
View,
Text,
} from 'react-native';
import Gun from 'gun/gun';
import 'gun/lib/open';
import '../extensions/sea';
@pseudosavant
pseudosavant / jSugar.js
Last active May 24, 2024 01:07
Utility function that adds in some jQuery-like syntactic sugar
// jQuery-like syntactic sugar. Only queries for one element. Does not loop over multiple like jQuery
export function $(query) {
if (typeof query === 'undefined') throw 'No query provided to $';
var el;
if (typeof query.nodeType === 'string') {
el = query;
} else if (typeof query === 'string' && query[0] === '<') {
const container = document.createElement('div');
container.innerHTML = query;