Skip to content

Instantly share code, notes, and snippets.

@shilrobot
shilrobot / ssebug.cpp
Last active March 14, 2017 16:19
On Release x64 on VC++ 2015 update 3 this doesn't work, on Debug x64/x86 this works just fine... >:|
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "emmintrin.h"
struct Color4
{
uint8_t red;
uint8_t green;
Color4 Lerp(Color4 a, Color4 b, float t)
{
// nice branchless SIMD color lerp
__m128 one = _mm_set1_ps(1);
__m128 t4 = _mm_set1_ps(t);
t4 = _mm_max_ps(t4, _mm_setzero_ps());
t4 = _mm_min_ps(t4, one);
@shilrobot
shilrobot / HexDumper.cs
Created April 28, 2013 03:41
C# hex dumper
using System.Text;
namespace Whatever
{
public static class HexDumper
{
public static string HexDump(byte[] data)
{
var sb = new StringBuilder();
@shilrobot
shilrobot / NordicTest.ino
Created February 5, 2013 07:16
Nordic Wireless nRF24L01+ test project (with two wireless modules connected to one Arduino.)
#include <SPI.h>
#define CE_0 2
#define CE_1 3
#define CS_0 4
#define CS_1 5
#define IRQ_0 6
#define IRQ_1 7
#define PIN_SS 10
@shilrobot
shilrobot / lcdtest.ino
Last active December 10, 2015 19:08
Arduino -> Adafruit 20x4 LCD (product ID 198): Test code, including optimized 4-bit or 8-bit LCD refresh routine.
#include <LiquidCrystal.h>
// Notes:
// - LCD has an on-board current limiting resistor for the LED backlight (510 ohm I think.)
// So it can be connected directly to +5V and GND.
// LCD backlight LED draws 34 mA.
// - The whole LCD only draws about 35-36 mA, so the backlight is the majority of the power.
// - The included contrast trim pot is 10K.
// - Line 1 wraps to line 3 and line 2 wraps to line 4, although LiquidCrystal::setCursor() works(!)
// So LCDWrite may require some adjustment...
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using Microsoft.Xna.Framework.Content;
namespace Platformer
{
/// <summary>
LUA:
-- prints "nil"
print(undefined_var)
AS3:
// doesn't even compile, gives you "Access of undefined property" compiler error.
trace(undefined_var);
@shilrobot
shilrobot / hist.py
Created July 18, 2012 17:51
Display graphs of results from UDP packet loss tester
import matplotlib.pyplot as plt
from scipy import stats
import numpy as np
# parse CSV file
# format is <size>, <recv_time>, <send_time>
# recv_time and send_time may be on different clocks so we can only compare vs. mean
lines =[]
for l in open('client_data/0.csv'):
parts = [float(x) for x in l.strip().split(',')]
@shilrobot
shilrobot / ploss.py
Created July 17, 2012 22:50
simple UDP packet loss tester
"""
Usage:
(1) on host A:
python ploss.py recv <port>
(2) on host B:
python ploss.py send <A's hostname> <port from step 1>
(3) watch output on host B
"""
@shilrobot
shilrobot / package.sh
Created June 27, 2012 16:54
Making mkbundle work on Windows
#!/bin/bash
# If this doesn't work, ensure you have UNIX line endings in this file
# (\n, not \r\n.) You can use Notepad++ to switch them.
# Cygwin package requirements: gcc-mingw, pkg-config
# If you want to pass -z to mkbundle: mingw-zlib1, mingw-zlib-devel
# crash immediately if anything bad happens
set -o errexit
set -o nounset