Skip to content

Instantly share code, notes, and snippets.

View SomeHats's full-sized avatar

alex SomeHats

View GitHub Profile
@SomeHats
SomeHats / runDevBrowser.mjs
Last active May 21, 2024 08:29
A hacky local version of cloudflare's browser rendering API. To use this, copy either runDevBrowser.ts or runDevBrowser.mjs and install the puppeteer and ws packages from npm. Run the dev server alongside wranger with `node runDevServer.mjs` or `tsx runDevServer.ts`
/* eslint-disable no-console */
/***
* This is a little server that emulates the protocol used by cloudflare's browser rendering API. In
* local development, you can run this server, and connect to it instead of cloudflare's (strictly
* limited) API. e.g. in your worker you might use a function like this:
*
* ```ts
* import { Browser, launch as launchPuppeteer } from '@cloudflare/puppeteer'
* function launchBrowser(env: Environment) {
* if (env.LOCAL_BROWSER_ORIGIN) {
const fs = require('fs');
const json = JSON.stringify(process.env, null, 2);
const file = "module.exports = " + json + ';';
fs.writeFileSync('./index.js', file, 'utf-8');
@SomeHats
SomeHats / index.js
Created August 10, 2018 11:07
did - track stuff wat u did
#!/usr/bin/env node
const fs = require("fs");
const path = require("path");
const os = require("os");
const Airtable = require("airtable");
const apiKeyFile = path.join(os.homedir(), ".done-airtable-api-key");
const apiKey = fs.readFileSync(apiKeyFile, "utf-8").trim();
@SomeHats
SomeHats / utils.js
Created January 11, 2018 14:04
Utilities
// @flow
/// MATHSY STUFF ///
// constrain a value between min and max
export const constrain = (min: number, max: number, n: number): number =>
Math.max(min, Math.min(max, n));
// covert degrees into radians
export const degreesToRadians = (degrees: number): number =>
degrees => degrees / (180 / Math.PI);
@SomeHats
SomeHats / PointableCover.js
Last active January 11, 2018 13:13
Cover element for tracking drag-type interactions without interferance. To ignore full-screen mode, replace `getFullScreenElement()` with `document.body`
import getFullscreenElement from './getFullscreenElement';
const coverStyle = {
position: 'fixed',
top: 0,
left: 0,
width: '100%',
height: '100%',
zIndex: 10000,
touchAction: 'none',

Keybase proof

I hereby claim:

  • I am somehats on github.
  • I am somehats (https://keybase.io/somehats) on keybase.
  • I have a public key whose fingerprint is 6088 C3EA D987 982D 2927 DEC2 B252 709B D1C5 FAD1

To claim this, I am signing this object:

with x as (
select clock_timestamp() as t,
gen_random_bytes(3) as r,
1503576000 as offset
),
id as (
select
(((extract(epoch from t) - offset) * 1000)::int8 << 24) |
(get_byte(r, 0) | (get_byte(r, 1) << 8) | (get_byte(r, 2) << 16)) as id
from x
@SomeHats
SomeHats / convert-compress.rb
Created January 20, 2013 14:09
A drop in plugin for converting from various preprocessors (Stylus, Sass, LESS & CoffeeScript), as well as minify-ing the whole lot, using YUICompressor for CSS and Google's Closure Compiler for Javascript. It also automatically optimises images using optipng and jpegtran. Drop convert-compress.rb into your _plugins directory, and install the de…
require 'rubygems'
require 'yuicompressor'
require 'stylus'
require 'less'
require 'sass'
require 'closure-compiler'
require 'coffee-script'
require 'optipng'
require 'jpegtran'
@SomeHats
SomeHats / dabblet.css
Created June 5, 2012 17:21
Rubik's thingy
/**
* Rubik's thingy
*/
* {
padding:0;
margin:0;
transition: all 1s ease;
}