Skip to content

Instantly share code, notes, and snippets.

View jesboat's full-sized avatar

Jade Sailor jesboat

  • Boston, MA
View GitHub Profile
Jan 1 of a year with $y mod 400 = 0$,
Jan 2 of a year with $y mod 400 = 0$,
...
Feb 28 of a year with $y mod 400 = 0$,
Feb 29 of a year with $y mod 400 = 0$,
Mar 1 of a year with $y mod 400 = 0$,
...
Dec 31 of a year with $y mod 400 = 0$,
Jan 1 of a year with $y mod 400 = 1$,
#!/usr/bin/env python
months = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" ")
days_normal = map(int, "31 28 31 30 31 30 31 31 30 31 30 31".split(" "))
days_leap = map(int, "31 29 31 30 31 30 31 31 30 31 30 31".split(" "))
assert len(months) == 12
assert len(days_normal) == 12
assert len(days_normal) == 12
assert sum(days_normal) == 365
@jesboat
jesboat / confirm-lock.c
Created December 26, 2015 21:14
Check whether there are outstanding POSIX fcntl or flock locks on files. Written after a stray lock broke my mbox, to see if there were any others hiding around. Does not check for dotlocks (just use ls).
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
/* Compile with any c99 compiler:
@jesboat
jesboat / pass-by-ref.cpp
Created April 7, 2015 04:20
demo of pass-by-value vs pass-by-reference in C++
#include <iostream>
#include <string>
using std::string;
void passByVal(string passBy) {
passBy = "reference";
}
void passByRef(string &passBy) {
@jesboat
jesboat / delete-old-branches
Created January 16, 2015 03:09
deletes branches in a git repo not accessed in the last month
#!/usr/bin/perl
use strict;
use warnings;
use autodie;
use Time::Piece;
use Time::Seconds;
use Getopt::Long;
#!/usr/bin/perl
use strict;
use warnings;
use 5.010;
use autodie;
use File::Temp qw(tempdir);
use File::Spec;
use File::Slurp qw(read_dir);
@jesboat
jesboat / gist:4e628ed93537b9e9ab72
Created August 30, 2014 10:40
Fix a spurious ssh error/warning message
diff -ru OpenSSH-186 2/openssh/ssh.c OpenSSH-186/openssh/ssh.c
--- OpenSSH-186 2/openssh/ssh.c 2013-07-02 16:09:16.000000000 -0700
+++ OpenSSH-186/openssh/ssh.c 2014-08-30 03:32:29.000000000 -0700
@@ -1505,6 +1505,7 @@
u_int n_ids;
char *identity_files[SSH_MAX_IDENTITY_FILES];
Key *identity_keys[SSH_MAX_IDENTITY_FILES];
+ int identity_file_userprovided[SSH_MAX_IDENTITY_FILES];
#ifdef ENABLE_PKCS11
Key **keys;
@jesboat
jesboat / parse-mr-counters.pl
Created August 19, 2014 03:01
Quick script to scrape the counters from a Hadoop jobdetails.jsp page
#!/usr/bin/env perl
use strict;
use warnings;
use XML::XPath;
@ARGV == 1 or die "Usage: $0 infile.xml\n";
my ($infile) = @ARGV;
my $xp;
@jesboat
jesboat / big.html
Created August 18, 2014 19:12
You probably don't want to open this
<!DOCTYPE html
PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<title>Blah</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<body>
<script type="text/javascript">
x = "blah";
for (i=0; i<28; i++) {
@jesboat
jesboat / enhanced-cd.sh
Created August 14, 2014 20:09
Better version of the enhanced `cd` described in the `iselect(1)` man page
#!bash
# database scan for enhanced cd command
cds() {
(
set -o pipefail
# XXX: handle directories with newlines in their names?
find "$HOME" -type d -print \
| sort -u > "$HOME/.cdpaths"
exit $?