Skip to content

Instantly share code, notes, and snippets.

@jcward
jcward / _readme.txt
Created April 6, 2018 16:43
A Perl-regex based copy script, derived from the rename script
I really like the regex syntax of the rename perl script, e.g.:
rename "s/OldFile/NewFile/" OldFile*
I simply wanted the same thing with a copy command:
copy "s/OldFile/NewFile/" OldFile*
So here it is!
@jcward
jcward / gist:30f084bb72b033569b2708010318f709
Created November 16, 2017 16:14
Getting Started with Haxe, OpenFL, or Kha
try.haxe.org lets you play with Haxe code examples.
Here's a plain Haxe->JS example: https://try.haxe.org/#94aC4
OpenFL:
OpenFL has good docs, community, samples, and tutorials:
http://www.openfl.org/learn/docs/getting-started/
http://www.openfl.org/learn/tutorials/
Kha:
@jcward
jcward / Main.hx
Last active January 6, 2022 00:45
Haxe example SQLLite usage
typedef ArtistsBackupRecord = {
artistid:Int,
name:String
}
class Main
{
public static function main()
{
var conn = sys.db.Sqlite.open("test.db");
@jcward
jcward / gist:26895ebbe7ffcc0e8d4d0659e5d133df
Created April 14, 2017 15:49
Generating AS3 from Haxe, and post-processing it to work in an AS3 project
#!/usr/bin/ruby
require "open3"
require 'json'
require 'pathname'
require 'yaml'
# no trace TextField on the stage, please
defines = "-D native_trace"
@jcward
jcward / Readme.txt
Created April 14, 2017 15:08
Generating iOS P12 / certs without Mac OSX Keychain (on linux, windows, etc)
1) Generate a private key and certificate signing request:
openssl genrsa -out ios_distribution.key 2048
openssl req -new -key ios_distribution.key -out ios_distribution.csr -subj '/[email protected], CN=Example, C=US'
2) Upload CSR to apple at: https://developer.apple.com/account/ios/certificate/create
- choose Production -> App Store and Ad Hoc
3) Download the resulting ios_distribution.cer, and convert it to .pem format:
@jcward
jcward / JSONProxy.php
Last active March 12, 2018 19:35
A PHP JSONP proxy script
<?php header('content-type: application/json; charset=utf-8');
# Curl / proxy parts of this script from:
# https://webster.cs.washington.edu/course-website/16au/lectures/slides/proxy.phps
$url = $_GET['src'];
$data = array();
# Open the cURL session
$curlSession = curl_init();
@jcward
jcward / random.js
Last active July 22, 2018 16:50
Quick Math.random() wrapper with support for window.crypto.getRandomValues
// Math.random() wrapper with support for window.crypto.getRandomValues
// return a random number, 0 <= rand() < 1
function rand() {
if (window.crypto && window.crypto.getRandomValues && (typeof Uint8Array=='function')) {
var buf = new Uint8Array(4);
window.crypto.getRandomValues(buf);
// buf = [0,0,0,0]; // 0
// buf = [255,255,255,255]; // closest to 1
// buf = [0,0,0,128]; // < 0.5
// buf = [1,0,0,128]; // > 0.5
@jcward
jcward / webp_detect.js
Created March 7, 2017 16:31
Quick webp support detection
// Based on Modernizr webp basic test:
// https://github.com/Modernizr/Modernizr/blob/5eea7e2a213edc9e83a47b6414d0250468d83471/feature-detects/img/webp.js
//
// - Adds webp / no-webp classes to <body>, allowing loading of background images, e.g. scss:
//
// body.no-webp .hero-space { background-image: url(".../hero-space.jpg"); }
// body.webp .hero-space { background-image: url(".../hero-space.webp"); }
//
// - TODO: <img> lazyloading support
@jcward
jcward / create_self_extracting_script.sh
Last active August 25, 2022 06:34
Quick bash script to create self-extracting .sh files /w Base64 encoded contents (e.g. binary, zip, etc)
#!/bin/bash
#
# create_self_extracting_script.sh <INPUT_FILE> [<OUTPUT_SCRIPT>]
#
# Creates a self-extracting shell script containing INPUT_FILE as Base64-encoded
# bytes. When executed, the script writes INPUT_FILE and restores its permissions.
#
# (c) Jeff Ward, 2017
# MIT License
@jcward
jcward / _readme.txt
Created February 6, 2017 18:32
Dump of LZW rendering engine for TIC by Deck.
Dump of LZW rendering engine for TIC by Deck.
References:
https://twitter.com/tic_computer/status/828312767677530112
https://itch.io/t/60446/lzw-image-render
It always makes me nervous when I see code snippets in dropbox --
the link can disappear anytime. So I encoded the dropbox ZIP into a
self-extracting bash script.