Skip to content

Instantly share code, notes, and snippets.

View schwern's full-sized avatar

Michael G. Schwern schwern

View GitHub Profile
@schwern
schwern / .gitconfig
Created May 25, 2011 22:02
My git aliases
[alias]
st = status
ci = commit -v
cii = commit -v --interactive
cia = commit -v -a
addi = add --interactive
addchanged = add -u
br = branch
co = checkout
diffwords = diff --word-diff
#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
cmpthese shift || -3, {
"shift" => sub {
my $arg = shift;
@schwern
schwern / permutation.go
Last active August 31, 2021 14:18
A permutation library based on Paul Hankin's from https://stackoverflow.com/a/30230552/14660
package permutation
// Based on https://stackoverflow.com/a/30230552/14660 by Paul Hankin
// perm := NewPermutation( slice )
// for next := perm.Next(); next != nil; next = perm.Next() {
// ...
// }
//
// or
test=> select count(*) from orders;
count
---------
1003116
(1 row)
test=> select count(distinct articleid) from orders;
count
--------
999921
@schwern
schwern / gist:896004
Created March 31, 2011 08:03
Benchmarking simple accessors, Moose vs Mouse vs Moo vs hand written vs a hash
#!/usr/bin/env perl
use strict;
use warnings;
use Carp;
BEGIN {
# uncomment to test pure Perl Mouse
# $ENV{MOUSE_PUREPERL} = 1;
@schwern
schwern / foo.go
Created May 13, 2017 00:13
This is why whitespace should not be syntax. One is a syntax error, one is not. Can you guess?
for i, j := 0, len(r)-1;
i < len(r)/2;
i, j = i+1, j-1
{
r[i], r[j] = r[j], r[i]
}
for i, j := 0, len(r)-1;
i < len(r)/2;
i, j = i+1, j-1 {
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
char * strcat_ex( const char *s, ... )
{
if ( s == NULL ) {
return NULL;
}
@schwern
schwern / gist:f6dab96308a0322d2b22
Created December 28, 2014 05:28
% of Steam users with laptops
#! /usr/bin/perl
use v5.18;
use strict;
use warnings;
my $total = 0;
local $/ = "\n\n";
while(<DATA>) {
@schwern
schwern / test.c
Created December 11, 2016 00:16
fgets vs fgetc, strlen vs strcpsn for stripping newlines off input lines
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int read_line_fgetc(FILE *fp, char *line, int line_size){
int c;
int i = 0;
while( (c = fgetc(fp)) > 0) {
if( (char)c == '\n' ) {
break;
@schwern
schwern / gist:5d0d1ea3c1817fbba0d0d50c1d7b636b
Created April 29, 2016 22:35
Demonstrate it's safe to use a PRNG to seed more PRNGs with a GOOD PRNG.
/* See http://www.pcg-random.org/using-pcg-c-basic.html */
#include "pcg_basic.h"
#include <stdio.h>
void try_random(unsigned int seed, int initseq) {
pcg32_random_t rng;
pcg32_srandom_r(&rng, seed, initseq);
printf("Seed: %u\n", seed);