Skip to content

Instantly share code, notes, and snippets.

multi-pitch climbing transitions
general notes
-------------
always reply to commands
this let's the other climber know you heard him
e.g. climber calls "on belay" but belayer isn't ready yet, can't call "belay is on"
instead of waiting silently and climber calling out "on belay" again and again
say "thanks" as acknowledgment
#!/bin/sh
# https://blog.svpino.com/2015/05/07/five-programming-problems-every-software-engineer-should-be-able-to-solve-in-less-than-1-hour
# problem 5
# usage: ./p5_adding beg end goal
# e.g. : ./p5_adding 1 10 100
awk -v "beg=$1" -v "end=$2" -v "goal=$3" '
function f(cur, last, out, sum, op) {
if (cur > end) {
if (sum == goal)
printf("%s\n", out)
@deepcube
deepcube / bsolve
Last active August 29, 2015 14:20
#!/usr/bin/env bash
# solve Rubik's cube using the Tperm blindfold method. input: http://tomas.rokicki.com/cubecontest/
# idea from Stefan Pochmann's second entry: http://tomas.rokicki.com/cubecontest/winners.html
n=0 tperm="R2 U' R2 D B2 L2 U L2 D' B2 U "
cube=("$@") solved=(UF UR UB UL DF DR DB DL FR FL BR BL UFR URB UBL ULF DRF DFL DLB DBR)
declare -A inverse=([\']=\ [2]=2 [\ ]=\') setups=(
[UF]="R2 U R2 " [UR]="" [UB]="R2 U' R2 " [UL]=""
[DF]="D' L2 " [DR]="D2 L2 " [DB]="D L2 " [DL]="L2 "
[FR]="U2 R U2 " [FL]="L' " [BR]="U2 R' U2 " [BL]="L "
[FU]="R F' L' R' " [RU]="" [BU]="R' B L R " [LU]="L F' D' F L2 "
/*
* base64
* with no arguments read from stdin and write base64 encoded output to stdout
* with argument -d read base64 encoded input from stdin and write decoded output to stdout
* exit status 1 on any error
* ignores newlines in encoded input
* any illegal character in encoded input causes error
* no newlines in encoded output
* does not require padding (=) but if padding is present it must be correct
* after padding more encoded input may follow
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#define x(s,d,...)if(s){o=errno;fputs(*v,stderr);fprintf(stderr,": "__VA_ARGS__\
);errno=o;perror(0);d;}
#define l while
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct Node Node;
struct Node {
Node *next; /* next Node in the chain */
Node *first; /* Node we started the chain on */
int pos; /* position in chain */
};
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
uintmax_t calls;
void print(int *chain, int len)
{
for (int i = 0; i < len; i++)
#!/bin/sh
#
# Simulate add/remove events by writing directly
# into the uevent files.
if [ "$#" -ne 1 ] || [ "$1" != add ] && [ "$1" != remove ]; then
# warning: can't trust $0, better off just hard coding the name
# echo "usage: simevent add|remove" 1>&2
printf "usage: %s add|remove\n" "${0##*/}" 1>&2
exit 1
@deepcube
deepcube / broker.c
Created May 24, 2013 16:49
zeromq broker. Frontend client prepends messages with the ID of the final destination. Broker receives message through a ZMQ_ROUTER so message now has initial source ID prepended. Broker swaps first two frames and sends message out backend ZMQ_ROUTER, which routes message to final destination. Clients used as destinations must identify to broker…
#include <czmq.h>
#include <stdlib.h>
#include <zmq.h>
#include "zerr.h"
/*
* read message, switch first two frames (from and to), send it back out
* arg is the socket to which the message should be sent. For the front_end arg
* is back_end, and vice versa.
@deepcube
deepcube / zerr.h
Created May 24, 2013 16:43
zeromq macros I use, see comments for descriptions. gcc specific due to branching macros. _GNU_SOURCE specific due to program_invocation_name.
#ifndef ZERR_H
#define ZERR_H
#ifndef _GNU_SOURCE
#define _GNU_SOURCE // for program_invocation_name
#endif
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>