Skip to content

Instantly share code, notes, and snippets.

View samuelmaddock's full-sized avatar
:electron:

Sam Maddock samuelmaddock

:electron:
View GitHub Profile
@samuelmaddock
samuelmaddock / whitespace.js
Last active August 5, 2017 17:45
JavaScript Whitespace Encode/Decode
var source = 'hello world';
function whitespaceEncode(str) {
var j, result = '';
for (var i = 0; i < str.length; i++) {
var charCode = str.charCodeAt(i);
var binStr = charCode.toString(2);
var padLen = 7 - (binStr.length % 7);
@samuelmaddock
samuelmaddock / ExampleEvent.php
Last active August 29, 2015 14:22
ZF2 Eventing Skeleton
<?php
namespace Example;
use Zend\EventManager\Event;
class ExampleEvent extends Event
{
const EVENT_FOOBAR = 'foobar';
protected $value;
@samuelmaddock
samuelmaddock / .editorconfig
Created January 13, 2016 03:55
UE4 EditorConfig file
# EditorConfig is awesome: http://EditorConfig.org
# top-most EditorConfig file
root = true
# Windows newlines with a newline ending every file
[*]
end_of_line = crlf
insert_final_newline = true
@samuelmaddock
samuelmaddock / example.lua
Last active January 17, 2016 05:00
MediaPlayer grab fft
local mp = MediaPlayer.Create( "global" )
-- only allow media which supports FFTs (remove this if you don't want it)
mp.ServiceWhitelist = { 'af', 'sc' }
if CLIENT then
local function audioPostDraw( media )
local fft = media.fft
if not fft then return end
@samuelmaddock
samuelmaddock / CEF3.build.cs
Last active February 22, 2016 05:32
Unreal Engine 4.10.1 CEF3 binaries missing from shipping build fix; overwrite this file in `\Engine\Source\ThirdParty\CEF3`
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
using UnrealBuildTool;
using System.IO;
public class CEF3 : ModuleRules
{
public CEF3(TargetInfo Target)
{
/** Mark the current version of the library */
@samuelmaddock
samuelmaddock / poll.js
Created August 17, 2016 16:35
Scroll polling example
var element = $('.element-with-scrolling');
// don't do this
element.attachEventListener('scroll');
// do this instead
window.requestAnimationFrame(poll);
var pollScrollPos = function () {
var scrollPos = element.scrollLeft;
@samuelmaddock
samuelmaddock / bind-all-keys.cpp
Created November 18, 2016 01:33
Unreal Engine 4 UE4 Hack to bind a delegate to all key presses. This allows for multiple keys to be pressed down at once without blocking events.
// example.h
DECLARE_DYNAMIC_DELEGATE_TwoParams(FBindAllKeysDelegate, const FKey&, Key, bool, bKeyPressed);
// example.cpp
void UExampleStatics::BindAllKeyInputActions(AActor *Actor, const FBindAllKeysDelegate& Delegate)
{
// Get input component from actor
UInputComponent *InputComponent = Actor->InputComponent;
if (InputComponent == nullptr) return;
@samuelmaddock
samuelmaddock / rgba2url.ts
Last active September 23, 2017 19:18
Converts RGBA data to a URL using an HTML canvas element
export const rgba2url = async (
rgba: Uint8Array,
width: number,
height: number
): Promise<string | void> => {
let canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
let ctx = canvas.getContext('2d');
@samuelmaddock
samuelmaddock / proposal.md
Last active November 4, 2017 18:09
Application user networking using Dat protocol

Application user networking using Dat protocol

This document outlines a structure to connect application users using Dat protocol. Users can identify themselves with a dat archive and publish session metadata to coordinate WebRTC connections.

Forewarning: I have no idea what I'm talking about.

Social peer dat archive

A user's identity resides in a dat archive which can be shared to create a connection.

@samuelmaddock
samuelmaddock / dat-libsodium-seal.js
Last active November 16, 2017 02:49
Dat crypto
const sodium = require('sodium-universal')
function keyPair(seed) {
var publicKey = new Buffer(sodium.crypto_sign_PUBLICKEYBYTES)
var secretKey = new Buffer(sodium.crypto_sign_SECRETKEYBYTES)
sodium.crypto_sign_keypair(publicKey, secretKey)
return {
publicKey: publicKey,