Skip to content

Instantly share code, notes, and snippets.

View euank's full-sized avatar

Euan Kemp euank

View GitHub Profile
@euank
euank / testSortByIdAndLine.html
Created April 24, 2013 08:41
Open as html in firefox and chrome to see that the old sort function behaves incorrectly in firefox while the new one behaves correctly in both.
Old output:
<div id="oldoutput">
</div>
<br /><br />
New output:
<div id="newoutput">
</div>
@euank
euank / fizzbuzz.c
Last active December 26, 2015 20:09
fizzbuzz
#include <stdio.h>
#include <string.h>
struct node {
struct node *next;
char *str;
};
int main (void) {
struct node nodes[0xF];
int i;
for (i=0;i<0xF;++i) {
@euank
euank / gist:7414238
Created November 11, 2013 14:48
Code found in the wild (all in the same project)
if (stopped) {
// don't proceed
} else {
// proceed
/* code */
}
/* Note, there are a ton of these. if(CONDITION) { /* don't do anything */ } else { /* code */} ... I suspect the programmer did not know you could do if(!CONDITION)
@euank
euank / README.md
Last active July 11, 2021 02:54
Fix chrome's console.log 'TypeError: Illegal invocation'

Chrome exhibits behavior different from firefox (and other javascript environments) in that console.log requires "this" to be console. This issue is discussed here.

Simple failing code is

var helloWorld = function(callback) { 
  callback("Hello World"); 
}; 
helloWorld(console.log);

The included snippet makes failing code function correctly without any other changes required. It just has to be run before any console.logs. Similar code can be written for console.info and so on.

@euank
euank / quote
Created November 26, 2013 04:45
Stable computer codes use Qs
"Stable computer codes use as many Qs as possible" - Introduction to Linear Algebra, Fourth Edition
He of course refers to the Q in QR factorization.
However, a simple way to make your C program more stable, as he shows, is to add "#define i Q" to the top of it.
@euank
euank / gist:7799958
Created December 5, 2013 04:12
Bank of America Password box
<input class="TL_NPI_Pass tl-private" name="newPassCode" id="tlpvt-new-passcode" maxlength="20" value="" oncopy="return false" onpaste="return false" type="password">
There are two problems here:
1. maxlength="20". That's pretty darn short for a password for my *bank*
2. onpaste="false". Using a password manager (like keepass) is MORE secure than having short and memorable passwords. This discourages people from using secure techniques like that. I doubt most BoA users are technical enough to get around that, but even for those that are it's inconvenient.
I plan to switch from BoA at my earliest convenience.
@euank
euank / Windows compile.md
Last active November 4, 2021 22:03
Build instructions for ponscripter-fork on windows. Possibly outdated (see project's instructions instead)

Install MinGW. Within it select the following items:

  • mingw32-libz (dev/dll)
  • mingw32-autoconf
  • mingw32-automake
  • mingw32-gcc
  • mingw32-gcc-g++
  • msys-core

Afterwards, run the pi.bat (postinstall) script that should be at C:\MinGW\msys\1.0\postinstall\pi.sh

@euank
euank / Steam-runtime build.md
Last active August 29, 2015 13:57
ponscripter steam runtime build

ponscripter-fork build for steam.

The machine I used was running 32-bit ubuntu server, 12.04. I think it needs to be 32 bit to easily do these steps or else there's some issues with the configure script.

sudo apt-get install git build-essential automake

wget http://media.steampowered.com/client/runtime/steam-runtime-sdk_latest.tar.xz
tar xvf steam-runtime-sdk_latest.tar.xz
cd steam-runtime-sdk*
@euank
euank / gist:cae2773776741ff46049
Last active August 29, 2015 13:57
Just demonstrating c behavior that allows a non-returning function to still accidentally return the right value.
#include <stdlib.h>
#include <stdio.h>
int *getOne() {
register int eax asm("eax");
printf("eax is %x before malloc\n", eax);
int *one = malloc(sizeof(int));
@euank
euank / sleepsort.js
Created April 16, 2014 19:41
sleepsort joke in javascript eventloop. yes-it's-a-joke
function sort(arr) {arr.forEach(function(n){var s=['console.log('+n+');'];for(var i=0;i<n;i++) {s.unshift('process.nextTick(function(){');s.push('});');}eval(s.join(''));});}