Skip to content

Instantly share code, notes, and snippets.

View pcapriotti's full-sized avatar

Paolo Capriotti pcapriotti

View GitHub Profile
@pcapriotti
pcapriotti / exists.c
Created June 7, 2012 15:35
CreateFile example
#include <windows.h>
#include <stdio.h>
int main()
{
HANDLE h = CreateFile(
"bar.txt",
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
@pcapriotti
pcapriotti / reactor.py
Created July 16, 2011 08:54
Reactor Framework
"""The reactor framework.
This module introduces the *reactor framework*, a collection of utilities to be
used in conjunction with the greelet library to solve the problem of inversion
of control in event-driven code.
Traditionally, writing event-driven code typically consists of "connecting"
signals to handlers (i.e. callbacks), which are to be invoked by the framework
in use when a certain "event" occurs.
@pcapriotti
pcapriotti / gist:1761136
Created February 7, 2012 18:30
Composition of free monads
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies #-}
import Control.Monad
import Control.Monad.Free
class (Functor f, Functor g, Functor h) => Compose f g h | f g -> h where
compose :: f x -> g y -> Free h (Free f x, Free g y)
compose f g = return (liftF f, liftF g)
composeF :: Compose f g h => Free f x -> Free g x -> Free h x
@pcapriotti
pcapriotti / pagination_link
Last active April 8, 2019 19:29
Extract next link from HTTP header
@pcapriotti
pcapriotti / allrepos
Last active May 14, 2018 15:22
List all personal repositories from git hosting services
#!/bin/bash
set -e
usage() {
echo "Usage: $0 USERNAME" 2>&1
exit 1
}
username="$1"
[ -z "$username" ] && usage
@pcapriotti
pcapriotti / i3-exit
Created March 28, 2017 12:46
lock/logout script
#!/bin/bash -e
WALLPAPER_DIR="$HOME/backup/content/pictures/wallpapers"
function lock() {
local wp="$(scaled_wallpaper)"
local cmdline=""
[ -z "$wp" ] || cmdline="-i $wp"
function revert() {
@pcapriotti
pcapriotti / newgist
Last active December 7, 2016 21:28
Script to create a new gist
#!/bin/bash
set -e
usage() {
echo "Usage: $0 [-f FILE] [-n NAME] [-l LANGUAGE] [-p] [-d] DESCRIPTION" 2>&1
exit 1
}
public=true
dryrun=false
@pcapriotti
pcapriotti / arxiv.sh
Created December 7, 2016 18:20
ArXiv submission script
#!/bin/bash
# prepare submission tarball for arXiv.org
set -e
usage() {
echo "Usage: $0 DEST SOURCE..."
exit 1
}
on_exit() {

Keybase proof

I hereby claim:

  • I am pcapriotti on github.
  • I am pcapriotti (https://keybase.io/pcapriotti) on keybase.
  • I have a public key whose fingerprint is 2461 C117 39FE 5784 858C 9F18 DF96 7258 59FA 1C1F

To claim this, I am signing this object:

@pcapriotti
pcapriotti / git-branch-status.sh
Created July 31, 2012 14:54
summary of branches
#!/bin/bash
# based on https://gist.github.com/1288596
RED="\033[0;31m"
YELLOW="\033[0;33m"
GREEN="\033[0;32m"
NOCOLOR="\033[00m"
BOLD="\033[1;37m"
git for-each-ref --format="%(refname:short) %(upstream:short)" refs/heads | \
while read local remote