Skip to content

Instantly share code, notes, and snippets.

View justinbowes's full-sized avatar
💭
I may be slow to respond.

Justin Bowes justinbowes

💭
I may be slow to respond.
View GitHub Profile
@justinbowes
justinbowes / .block
Last active January 14, 2020 08:49
pictogram scratch
license: mit
@justinbowes
justinbowes / aes256.bookmarklet.html
Last active July 17, 2018 16:14
AES256 encrypt/decrypt bookmarklet
<!DOCTYPE html>
<html>
<body>
<h2>Drag link to bookmarks bar</h2>
<a href='javascript:(function(e){const t={split(e){const t=[];for(let r=0;r<e.length;){const n=e.charCodeAt(r);let o;n>=55296&&n<=56319?(o=(n-55296<<10)+(e.charCodeAt(r+1)-56320+65536),r+=2):(o=n,++r),t.push(String.fromCodePoint(o))}return t},encode(e){const t=5-e.length %25 5;let r="";e=String.fromCharCode(t)+"\0".repeat(t-1)+e;for(let t=0;t<e.length;t+=5){let o=e.substr(t,5).split("").map(n).reduce((e,t)=>256*e+t,0);for(let e=0;e<4;++e){const e=o %25 1024;o=Math.floor(o/1024),r+=this.map[e]}}return r},decode(e){const t=this.split(e);let r="";for(let e=0;t.length;++e){let n=[];for(;n.length<4;)n.unshift(this.map.indexOf(t.shift()));let o=n.reduce((e,t)=>1024*e+t,0),l="";for(let t=0;t<5;++t){let r=o %25 256;o=Math.floor(o/256),l=String.fromCharCode(r)+l,0==e&&4==t&&(l=l.substring(r))}r+=l}return r}};t.map=t.split("♈♉♊♋♌♍♎♏♐♑♒♓⚛⛓⛔🄰🄱🄲🄳🄴🄵🄶🄷🄸🄹🄺🄻🄼🄽🄾🄿🅀🅁🅂🅃🅄🅅🅆🅇🅈🅉🅐🅑🅒🅓🅔🅕🅖🅗🅘🅙🅚🅛🅜🅝🅞🅟🅠🅡🅢🅣🅤🅥🅦🅧🅨🅩🆎🆏🆑🆒🆓🆔🆕🆖🆗🆘🆙🆚🌀🌁🌂🌃🌄🌅🌆🌇🌈🌉🌊🌋🌌🌍🌎🌏🌐🌑🌒🌓🌔🌕🌖🌗🌘🌙🌚🌛🌜🌝🌞🌟🌠🌡🌤🌥🌦🌧🌨🌩🌪🌫🌬
@justinbowes
justinbowes / rui_test.h
Last active October 31, 2015 03:23
RUI test harness. C99, MSVC/GCC/Clang, standalone tests.
//
// rui_test.h
// Quanta
//
// Created by Justin Bowes on 2014-11-06.
// Copyright (c) 2014 Informi Software Inc. All rights reserved.
//
#ifndef rui_test__B2BD1D7_F65A_4026_B67F_437E3C640A18_h
#define rui_test__B2BD1D7_F65A_4026_B67F_437E3C640A18_h
/*
* An implementation of C11 stdatomic.h directly borrowed from FreeBSD
* (original copyright follows), with minor modifications for
* portability to other systems. Works for recent Clang (that
* implement the feature c_atomic) and GCC 4.7+; includes
* compatibility for GCC below 4.7 but I wouldn't recommend it.
*
* Caveats and limitations:
* - Only the ``_Atomic parentheses'' notation is implemented, while
* the ``_Atomic space'' one is not.
@justinbowes
justinbowes / blackbody_srgb.c
Created June 18, 2014 18:13
Blackbody to SRGB code based on piecewise blackbody curve reconstruction. Depends on XPL, but you can easily replace its vector-construction calls in blackbody_rgbi and blackbody_rgb with your own.
// science/blackbody_srgb.c. ©2014 Informi Software Inc. Use and modify this file for any purpose without attribution.
#include "science/blackbody_srgb.h"
#ifndef XPL_STATIC_INLINE
# define XPL_STATIC_INLINE static inline
#endif
XPL_STATIC_INLINE float r_0_6700(float k) {
return 1.0f;
@justinbowes
justinbowes / markov.c
Last active August 29, 2015 14:02
Markov chain random name generator. Takes a string of one name per line and generates new names. Has some dependencies on the rest of XPL, but it should be pretty straightforward to fix most of them (tips in the comments).
// xpl/res/markov.c. ©2014 Informi Software Inc. Use and modify this file for any purpose without attribution.
#include <ut/uthash.h> // get from https://github.com/troydhanson/uthash
#include <xpl/mem/memory.h> // you can use calloc(sizeof(type), 1) instead of xpl_calloc_type(type),
// strdup instead of xpl_strdup, free instead of xpl_free, etc.
#include "markov.h"
typedef struct link_entry {
@justinbowes
justinbowes / TemplateInfo.plist
Created April 28, 2014 20:03
UUID Guarded Header File.xctemplate
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AllowedTypes</key>
<array>
<string>public.c-header</string>
<string>public.c-plus-plus-header</string>
</array>
<key>BuildableType</key>
@justinbowes
justinbowes / udpnet.c
Last active December 21, 2015 05:39
Hacked-up version of Madgarden's udpnet that will build on Windows+MinGW32. Used successfully on Windows 7, OS X 10.8, iOS 6. win_inet_pton.c is required for Windows only and should not be compiled on other platforms.
#include <sys/unistd.h>
#include <sys/fcntl.h>
#include "net/udpnet.h"
#ifdef SOCK_WIN32
#include <ws2tcpip.h>
#include <ctype.h>
typedef int socklen_t;
@justinbowes
justinbowes / compile_time_hash.h
Last active January 2, 2019 13:02
Hash strings at compile time.
#ifndef compile_time_hash_h
#define compile_time_hash_h
// Posted by jbowes. Public domain.
// source: (dead link)
// http://lol.zoy.org/blog/2011/12/20/cpp-constant-string-hash
//
// At higher compiler optimization levels (-O1 and higher on clang/llvm),
// C_HASH("string") should be replaced by a hash of "string" at compile time.
@justinbowes
justinbowes / entity_system
Last active December 21, 2015 05:09
A complete entity system implemented in C. See entity_system.
C entity system. Justin Bowes, Informi Software Inc. Public domain. Go nuts.
The only external dependency is the wonderful UThash by Troy D. Hanson,
which I overuse.
http://troydhanson.github.io/uthash/
The system is intended to be used primarily through the macros. You
supply the component type you expect; the code hashes the type (as
a string) and casts the result (as pointer to the type you passed).