Skip to content

Instantly share code, notes, and snippets.

View schwern's full-sized avatar

Michael G. Schwern schwern

View GitHub Profile
t = Process.clock_gettime(Process::CLOCK_MONOTONIC);
puts "%10.10f" % t.prev_float; # 391942.2739719209
puts "%10.10f" % t; # 391942.2739719210
puts "%10.10f" % t.next_float; # 391942.2739719211
#include <stdio.h>
typedef struct date_t {
int year; int month; int day;
} date_t;
#define EPOCH 1970
void date_convert(date_t* date, unsigned int days) {
int year = EPOCH, mo = 0, day = 1;
@schwern
schwern / gist:1a4482bfcd5feee0812c
Created March 4, 2016 09:37
nanosecond time on OS X
#include <time.h>
#include <stdio.h>
#include <unistd.h>
#ifdef __MACH__
#include <mach/mach_time.h>
#define CLOCK_REALTIME 0
#define CLOCK_MONOTONIC 0
int clock_gettime(int clk_id, struct timespec *t){
mach_timebase_info_data_t timebase;
@schwern
schwern / gist:39c100327f322caa9b5c
Created January 26, 2016 06:59
$RE{URI} from Regexp::Common
(?:(?:(?:https?)://(?:(?:(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a-zA-Z0-9]*[a-zA-Z0-9]|[a-zA-Z])[.]?)|(?:[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+)))(?::(?:(?:[0-9]*)))?(?:/(?:(?:(?:(?:(?:(?:[a-zA-Z0-9\-_.!~*'():@&=+$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\-_.!~*'():@&=+$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*)(?:/(?:(?:(?:[a-zA-Z0-9\-_.!~*'():@&=+$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\-_.!~*'():@&=+$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*))*))(?:[?](?:(?:(?:[;/?:@&=+$,a-zA-Z0-9\-_.!~*'()]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)))?))?)|(?:(?:file)://(?:(?:(?:(?:(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a-zA-Z0-9]*[a-zA-Z0-9]|[a-zA-Z]))|(?:[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+))|localhost)?)(?:/(?:(?:(?:(?:[-a-zA-Z0-9$_.+!*'(),:@&=]|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:/(?:(?:[-a-zA-Z0-9$_.+!*'(),:@&=]|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*)))))|(?:(?:nntp)://(?:(?:(?:(?:(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a-zA-Z0-9]*[a-zA-Z0-9]
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
static bool is_prime(const int candidate) {
if( candidate <= 1 )
return false;
if( candidate <= 3 )
#!/usr/bin/env perl
use strict;
use warnings;
use Date::Manip::Date;
my($command_date_string, @command) = @ARGV;
my $command_date = Date::Manip::Date->new;
#!/usr/bin/env perl
# Hand it something like EVO/Class-MakeMethods-1.01.tar.gz on STDIN
use perl5i::2;
use MetaCPAN::API;
my %Releases;
my @Missing;
@schwern
schwern / gist:3942210
Created October 23, 2012 22:39
Unblocking with cond_broadcast does not conflict
# Test that unblocking all threads at once using cond_broadcast won't
# cause them to collide with each other.
use strict;
use warnings;
use Config;
BEGIN {
if (! $Config{'useithreads'}) {
@schwern
schwern / gist:3239960
Created August 2, 2012 19:33
Benchmark Sub::Quote
#!/usr/bin/env perl
use strict;
use warnings;
use Sub::Quote;
use Benchmark qw(cmpthese);
my $qs = Sub::Quote::inlinify q{my $foo = 23; my $bar = 42; my $biff = 99}, '';
[color]
# Turn on colors as applicable
ui = auto
[alias]
# Shortcuts
st = status
br = branch
co = checkout