Skip to content

Instantly share code, notes, and snippets.

Robert Wallis robert-wallis

Block or report user

Report or block robert-wallis

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@robert-wallis
robert-wallis / Loop.cpp
Created Aug 27, 2018
What's faster `i < list.size()` or `i < size` where size is precomputed?
View Loop.cpp
// My Results: VS 2017, Debug x86 Start-Without-Debugging, i7-4790K 4.0GHz 32.0GB RAM
//
// FunctionCondition 1 = 1783293664
// 369820712 ns
// VariableCondition 1 = 1783293664
// 229243798 ns
// FunctionCondition 2 = 1783293664
// 368293487 ns
// VariableCondition 2 = 1783293664
// 226769355 ns
@robert-wallis
robert-wallis / make_release.sh
Last active Apr 26, 2018
Publish git tag with build folder gzipped to github releases from the command line.
View make_release.sh
#!/bin/bash
# Copyright (C) 2018, Robert A. Wallis, All Rights Reserved
#
# make_release.sh expects a `git tag v1.2.3` style tag to have been created for the version `1.2.3` stored in buildnumber.txt
# It then creates a release out of the commit notes from the previous version's tag to the current version.
# And uploads the contents of the build/ folder as v1.2.3.tgz as an asset.
set -e
GITHUB_USER="robert-wallis"
GITHUB_REPO="yourRepoHere"
@robert-wallis
robert-wallis / NetUi.cs
Last active Dec 29, 2017
"Lower-Level" UNet example refactored into UI and Networking classes. https://docs.unity3d.com/Manual/UnityMultiplayerIntegratingLowLevel.html
View NetUi.cs
// Copyright (C) 2017 Robert A. Wallis, All Rights Reserved
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking.Match;
using UnityEngine.UI;
namespace Network {
public class NetUi : MonoBehaviour {
[SerializeField] public Button ButtonCreateRoom;
@robert-wallis
robert-wallis / 8to8.c
Last active Aug 29, 2015
8^8 matcher
View 8to8.c
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#define EIGHTTOEIGHT 0x00FFFFFF
int main(int argc, char** argv)
{
srand(time(NULL));
int match = rand() & EIGHTTOEIGHT;
@robert-wallis
robert-wallis / capture.cpp
Created Mar 1, 2013
Capture the raw screen pixels in OSX. Then saves to a file for debugging.
View capture.cpp
void captureScreen()
{
CGImageRef image_ref = CGDisplayCreateImage(CGMainDisplayID());
CGDataProviderRef provider = CGImageGetDataProvider(image_ref);
CFDataRef dataref = CGDataProviderCopyData(provider);
size_t width, height;
width = CGImageGetWidth(image_ref);
height = CGImageGetHeight(image_ref);
size_t bpp = CGImageGetBitsPerPixel(image_ref) / 8;
uint8 *pixels = malloc(width * height * bpp);
@robert-wallis
robert-wallis / Makefile
Created Jun 26, 2012
Static Jade Template Builder
View Makefile
JADE_C="../node/node_modules/jade/bin/jade"
template_OUT=../../static
template_JADE=*.jade */*.jade
template_HTML=$(foreach source_file, $(template_JADE), ${template_OUT}/${source_file:.jade=.html})
.PHONY: all
all: $(template_HTML)
$(template_OUT)/%.html: %.jade
@robert-wallis
robert-wallis / gist:1235148
Created Sep 22, 2011
Permutations in Python (from Python website)
View gist:1235148
// directly from http://docs.python.org/library/itertools.html
def permutations(iterable, r=None):
# permutations('ABCD', 2) --> AB AC AD BA BC BD CA CB CD DA DB DC
# permutations(range(3)) --> 012 021 102 120 201 210
pool = tuple(iterable)
n = len(pool)
r = n if r is None else r
if r > n:
return
indices = range(n)
View permutations.go
// By: Robert Wallis - SmilingRob@gmail.com
// Returns a channel of all the possible permutations of a string containing
// r length in characters.
// adopted from http://docs.python.org/library/itertools.html
func StringPermutationsSub(s string, r int) chan string {
out := make(chan string)
go func() {
defer close(out)
pool := []int(s) // get unicode
n := len(pool)
@robert-wallis
robert-wallis / debug.js
Created Sep 17, 2011
Display the contents of a JavaScript object in the #debug id on the page. Or alert it if there was no debug.
View debug.js
// debug() - Copyright (C) 2006-2008 Robert Wallis
function debug(obj, name)
{
var t = "";
if (name) {
t += ""+name+":";
}
for (var i in obj) {
t += i+"=\""+obj[i]+"\"\n";
@robert-wallis
robert-wallis / validateCard.js
Created Sep 17, 2011
Make sure they typed in the card correctly, before you send it to the server and the payment gateway. Using a cool algorithm built into every credit card.
View validateCard.js
// usage: valid = validateCard('4111111111111111');
function validateCard(cardno) {
if (cardno.length <= 0 || cardno.length < 13 || cardno.length > 20 ) {
return false;
}
var sum = 0 * 0;
var digits = cardno.split('');
digits.reverse();
for (var i = 0; i < digits.length; i++) {
var d = 1 * digits[i];
You can’t perform that action at this time.