Skip to content

Instantly share code, notes, and snippets.

View netshade's full-sized avatar
🧛

Chris Zelenak netshade

🧛
View GitHub Profile
@netshade
netshade / gist:3a237588e51124c6fc52
Created July 21, 2014 14:20
Thoughts About Data At Rest

So this thing has been happening a lot lately as I observe game developers talk about data. They have multiple phases to how data is dealt with, namely:

  • Data when it must be written to (designed)
  • Data when it is being read (played)

And they treat the data in very different ways. During the design phase, data is expressly flexible and transformable. Store it in XML? Dynamically allocate all the things? Objects whose properties can be discovered at runtime? All acceptable ideas, because efficiency isn't the /point/ during this phase.

But in the transition from design phase to play phase will traditionally have a baking step, wherein the data as designed is turned into a very efficient (and mechanically simple) representation. What was once a 2MB XML file is now a 200kb packed binary representation that can be mmap'd and read directly from structs.

The efficiency in this case isn't the thing I'm interested in, however. It's the guarantee of representation and the understanding that data as it enters

# Ruby 2.1, Macbook Pro 2.6 i7, 16GB RAM
# Only 1 iter, I know i know i know
irb(main):001:0> require 'benchmark'
=> true
irb(main):002:0> h = {}
=> {}
irb(main):003:0> 1000_000.times.map { |i| h[i] = i }; nil
=> nil
irb(main):004:0> Benchmark.realtime { h.dup }
@netshade
netshade / gist:91ec260233bcd4029e07
Created June 13, 2014 19:42
64 bit / 32 bit twitter response

So I tried to find an authoritative source for you on this, but I believe it depends on the vendor.

When it comes to Linux (and iOS, it seems) you can assume that long == machine word size. A machine word is how your architecture addresses memory - on a 32bit machine Linux or iOS system, a long is 32 bits wide. On a 64 bit system iOS or Linux system, it's 64 bits wide. You'll note I hedge strongly here on referring to Linux or iOS. Windows has different behavior, and I've seen enough anecdote to imply that there are in fact many different interpretations of what int and long should be. This wikipedia article is instructive.

In the case of your SO example, on a 32 bit machine it just so happened that UInt32 and unsigned long took up the same number of bits. Hooray! On a 64 bit machine, unsigned long happened to take 64 bits, whilst UInt32, as you might assume, took 32 bits.

Now, where it gets a bit weird is that the unsigned long _(a 64 bit value on y

#!/bin/bash
if [ -z "$1" ]; then
echo "Usage: sudo $0 /dev/sdh1"
exit 1;
fi
dd if=$1 of=/dev/null & pid=$!
while true; do
ps -p$pid --no-heading || break;
echo "-- $(date) ------------------";
@netshade
netshade / main.c
Created January 23, 2014 18:10
level0
#include "bloom.h"
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#ifndef DEBUG
#include "filter.h"
#include "filter_bytes.h"
#endif
#define BUFFER_SIZE 8192
@netshade
netshade / gist:7830721
Created December 6, 2013 19:28
NSOperationQueue Usage
// to initialize the nsoperationqueue
NSOperationQueue * queue = [[NSOperationQueue alloc] init];
[queue setMaxConcurrentOperationCount:4];
// to add an operation to the context
NSOperation * op = [NSBlockOperation blockOperationWithBlock:^{
int i = 0;
dispatch_async(dispatch_get_main_queue(), ^{
// update ui
});
@netshade
netshade / PCSingletonExample.h
Last active December 30, 2015 12:39
Objective C double locking singleton example
//
// PCSingletonExample.h
// Lab11
//
// Created by Chris Zelenak on 12/6/13.
// Copyright (c) 2013 Bootstrapping iOS. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
@netshade
netshade / coordinates.json
Last active December 30, 2015 08:59
Random 20 points around Indianapolis
[
[39.76086989, -86.09757829],
[39.7863158, -86.18213742],
[39.79117821, -86.14879769],
[39.81917532, -86.10297819],
[39.79636724, -86.08487503],
[39.77425791, -86.14833736],
[39.72851886, -86.1906329],
[39.80005767, -86.0743134],
[39.76392219, -86.11534466],
@netshade
netshade / Gemfile
Created November 21, 2013 20:54
Test scripts for observing failover data consistency
source :rubygems
gem 'pg'
@netshade
netshade / cmd-instrumental.sh
Created June 3, 2013 20:59
Collect a bunch of command outputs in a shell script and send to Instrumental, no dependencies
#!/bin/sh
if [ -z "$1" ]
then
echo "You have to pass your Instrumental API token as an argument to this script."
exit -1
fi
instrumental_token=$1
# List of keys and commands to run for them
declare -a measurements=(