Skip to content

Instantly share code, notes, and snippets.

<?php
$link = mysql_connect('localhost', 'root');
function mysql_results($result) {
$foos = array();
while ($row = mysql_fetch_row($result)) {
$foo = $row[0];
array_push($foos, $foo);
}
#include "buffer.h"
/* statically allocate tests */
#define TEST_MAX (2 << 8)
struct test {
struct test *next;
char *desc;
int pass;
} tests[TEST_MAX];
@acdimalev
acdimalev / gem-depcheck
Created August 4, 2011 10:51
Check for uninstalled gem dependencies.
#!/usr/bin/ruby
require 'rubygems'
installed_gems = Gem::Dependency.new '', Gem::Requirement.default
missing = []
# mind the short-hand, looping over installed gem specs
specs = Gem.source_index.search installed_gems
specs.each do |spec|
gem = Gem::Dependency.new spec.name, spec.version
# looping over gem dependencies
specs = Gem.source_index.search gem
#include <sys/ioctl.h>
#include <unistd.h>
#include "unicode_ascii_translation_table.c"
#define CSI "\x1B["
int is_ascii_printable(char c) {
return (c > 0x1F) & (c != 0x7F);
}
from math import *
# settings
n = 4
radii = [1/2.0 * sqrt((2.0 ** i - 1) / (2.0 ** n - 1)) for i in range(1, n + 1)]
# calculate bezier
@rygorous
rygorous / vr_urgh.txt
Last active September 6, 2022 21:35
What I mean when I say "I think VR is bad news".
This just got linked to by the Y combinator news account, without proper context,
so a brief introduction: A month ago (end of May / early June 2014) I had a
Twitter conversation with a bunch of acquaintances. One tweet in the middle
of that thread, with obligatory hyperbole, was me saying that I think VR is
bad news.
Well, that part of the thread (but not the rest that provides context) recently
got retweeted, and then someone asked me if I could explain what I mean by that,
and because Twitter is a great platform for delivering 140 character slogans and
not so great for lengthy explanations, I wrote this. So, obligatory disclaimer:
21:27:39.987070 IP 127.0.0.1.1234 > 224.0.0.1.1234: UDP, length 60
0x0000: 4500 0058 4699 4000 0111 d3f9 7f00 0001
0x0010: e000 0001 04d2 04d2 0044 5f58 ffff ffff
0x0020: ffff 5254 0012 3457 0806 0001 0800 0604
0x0030: 0001 5254 0012 3457 0a00 0802 0000 0000
0x0040: 0000 0a00 0803 0000 0000 0000 0000 0000
0x0050: 0000 0000 0000 0000
// Retro Arch has a bunch of options and fiddly bits
// this is a starting point with just enough wired up to hack on some demos
// build with `gcc -shared -fPIC -o retroarch-scratch.so retroarch-scratch.c`
// run with `retroarch -L retroarch-scratch.so`
// docs are good
// https://github.com/libretro/libretro.github.com/blob/master/documents/libretro.pdf
// https://github.com/libretro/RetroArch/blob/master/libretro-common/include/libretro.h
@rygorous
rygorous / divide.py
Created August 23, 2018 12:29
Restoring and nonrestoring binary division
#!/usr/bin/python3
# Per's code
def sw_binary_divide2(n, d, num_bits):
q = 0
r = n
d2 = d << (num_bits - 1)
for i in range(num_bits):
q <<= 1
if r >= d2:
[jamin@dependent 2018-06-06-bindump]$ perf stat -e task-clock,cycles,instructions,cache-references,cache-misses
./say hello > /dev/null
Performance counter stats for './say hello':
0.197061 task-clock:u (msec) # 0.363 CPUs utilized
133682 cycles:u # 0.678 GHz
115712 instructions:u # 0.87 insn per cycle
1486 cache-references:u # 7.541 M/sec
937 cache-misses:u # 63.055 % of all cache refs