Skip to content

Instantly share code, notes, and snippets.

View samuelmaddock's full-sized avatar

Sam Maddock samuelmaddock

View GitHub Profile
@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 / 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 / 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 / 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 / .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 / 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 / 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 / unicode_fix.js
Last active August 29, 2015 14:15
Renames files using `#U[\w\d]{4}` names to their actual unicode character.
var fs = require('fs');
var files = fs.readdirSync('.');
var UNICODE_PATTERN = /#U([\d\w]{4})/gi;
for (var i = 0; i < files.length; i++) {
var filename = files[i];
if (!UNICODE_PATTERN.test(filename)) { continue; }
var fixedFilename = filename.replace(UNICODE_PATTERN, function (match, grp) {
@samuelmaddock
samuelmaddock / gm_sublime_glass.lua
Last active May 14, 2016 05:59
Glass effect for Garry's Mod; save in lua/autorun.
---
-- Sublime Glass - Garry's Mod
--
-- Use with the 'Sublime Text Trans' package.
-- https://github.com/vhanla/SublimeTextTrans
--
if SERVER then
AddCSLuaFile()
return
@samuelmaddock
samuelmaddock / loading.lua
Last active February 6, 2017 00:25
Garry's Mod Loading Screen - Disable Audio; overwrite "garrysmod\lua\menu\loading.lua", set to read-only
--=============================================================================--
--
-- This file has been modified to remove any audio that plays on loading screens.
-- https://gist.github.com/samuelmaddock/bb2f643ac95dcc6a56e9
--
--=============================================================================--
g_ServerName = ""
g_MapName = ""
g_ServerURL = ""