Skip to content

Instantly share code, notes, and snippets.

#!/bin/zsh
set -e
set -x
## Begin group of moves that could be done in parallel
# Largest temp size 234901, desire 3422
# Moving swapA-1 (3422) (Final goal)
pvmove --alloc anywhere /dev/md2:0-3421 /dev/md1:0-3421
# Largest temp size 89514, desire 103031
# Not enough contiguous temporary room for a multipart pvmove
# Moving spaceA-5 (14163) (Final goal)
@eatnumber1
eatnumber1 / gist:2179092
Created March 24, 2012 06:37
Photohunt API
Semi-formally, the JSON communicated will follow the following EBNF
(https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_form) grammar (note
that this is only roughly EBNF):
(* Valid error codes *)
ERR_SUCCESS = 0 (* No error occurred *)
ERR_UNSPEC = 1 (* Unspecified error. Message contains additional information *)
ERR_NOTAUTH = 2 (* Authorization token invalid *)
ERR_GAMEOVER = 3 (* Photohunt competition is over. No judged submissions allowed *)
(* Additional error codes will be added during development *)
Mysql2::Error - MySQL server has gone away:
/var/www/pub/photohunt/.bundle/ruby/1.9.1/gems/sequel-3.33.0/lib/sequel/database/logging.rb:53:in `query'
/var/www/pub/photohunt/.bundle/ruby/1.9.1/gems/sequel-3.33.0/lib/sequel/database/logging.rb:53:in `block in log_connection_execute'
/var/www/pub/photohunt/.bundle/ruby/1.9.1/gems/sequel-3.33.0/lib/sequel/database/logging.rb:28:in `log_yield'
/var/www/pub/photohunt/.bundle/ruby/1.9.1/gems/sequel-3.33.0/lib/sequel/database/logging.rb:53:in `log_connection_execute'
/var/www/pub/photohunt/.bundle/ruby/1.9.1/gems/sequel-3.33.0/lib/sequel/database/query.rb:509:in `rollback_transaction'
/var/www/pub/photohunt/.bundle/ruby/1.9.1/gems/sequel-3.33.0/lib/sequel/adapters/shared/mysql.rb:318:in `rollback_transaction'
/var/www/pub/photohunt/.bundle/ruby/1.9.1/gems/sequel-3.33.0/lib/sequel/database/query.rb:271:in `rescue in _transaction'
/var/www/pub/photohunt/.bundle/ruby/1.9.1/gems/sequel-3.33.0/lib/sequel/data
@eatnumber1
eatnumber1 / sls.c
Created January 14, 2013 18:49
A awesome^H^H^H^H^H^H^Hdisgusting use of the stack in C.
#include <stdio.h>
#include <setjmp.h>
#include <stddef.h>
#include <string.h>
#define NORETURN __attribute__((noreturn))
typedef void (*AllocCont)( void * );
void NORETURN longjmp_on_return( AllocCont f, jmp_buf env, void *mem ) {
@eatnumber1
eatnumber1 / gist:5764292
Created June 12, 2013 10:35
The script I used to migrate from LastPass to 1Password. Your mileage may vary.
#!/bin/zsh
emulate -L zsh
setopt err_exit warn_create_global no_unset
#setopt xtrace
function parse_elem {
local obj cur="$1" in_recovery="$2"
if [[ -z "$cur" ]]; then
read -r cur || return 1
ret_delim=$'\n'
@eatnumber1
eatnumber1 / ignoresig.rb
Created June 28, 2013 01:21
Ignore signals without modifying your program.
#!/usr/bin/env ruby
require 'getoptlong'
include Process
include Signal
$ignored_signals = ["CLD"]
def usage(strm)
strm.puts <<-EOF
@eatnumber1
eatnumber1 / implicit_conv.cpp
Last active December 19, 2015 08:09
An example of user-defined implicit type conversion.
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
class string {
public:
string( const char *str ) : m_str(strdup(str)) {}
string( int i ) {
asprintf(&m_str, "%d", i);
@eatnumber1
eatnumber1 / langf-hand-scanner.sml
Created August 4, 2013 07:18
SML Implementation of Regular Expressions
(* langfc-src/scanner-parser/langf-hand-scanner.sml
*
* COPYRIGHT (c) 2011-2013 Matthew Fluet (http://www.cs.rit.edu/~mtf)
* All rights reserved.
*
* Rochester Institute of Technology
* 4005-711
* Q20112,Q20122
*
* COPYRIGHT (c) 2009 Matthew Fluet (http://tti-c.org/fluet)
#include <stdint.h>
#include <stdio.h>
#include <string.h>
int main() {
unsigned char foo_arr[9];
memset(foo_arr, 0, 9);
unsigned char *foo = foo_arr;
uint8_t a = 0xDE;
uint64_t b = 0xDEEFBEADDEEFBEADLL;
#include <stdint.h>
#include <stdio.h>
#include <string.h>
int main() {
unsigned char foo_arr[9];
memset(foo_arr, 0, 9);
unsigned char *foo = foo_arr;
uint8_t a = 0xDE;
uint64_t b = 0xDEEFBEADDEEFBEADLL;