Skip to content

Instantly share code, notes, and snippets.

@remram44
remram44 / yaml_filter.py
Last active April 7, 2020 15:15
Filtering YAML loader
import json
import sys
import yaml
import yaml.events
import yaml.nodes
class FilterLoader(yaml.SafeLoader):
def __init__(self, stream):
super(FilterLoader, self).__init__(stream)
@remram44
remram44 / crosstab_to_html.py
Created September 17, 2017 00:57
Pretty HTML formatting for cross tabulation pandas DataFrame, similar to Qualtrics
from pandas.core.indexes.multi import MultiIndex
def _read_index(idx):
if isinstance(idx, MultiIndex):
return list(idx), idx.names, lambda t: t
else:
return [(e,) for e in idx], [idx.name], lambda t: t[0]
@remram44
remram44 / fizzbuzz.cpp
Last active August 29, 2017 18:33
FizzBuzz with std::nexttoward()
#include <cmath>
#include <iostream>
int main() {
// Bounds: from 1 to 100 (here we are assuming inclusive)
float current = 1.0, to = 100.0;
// The next integer to test
int next = 2;
@domenic
domenic / redirecting-github-pages.md
Created February 10, 2017 19:28
Redirecting GitHub pages after a repository move

Redirecting GitHub Pages after a repository move

The problem

You have a repository, call it alice/repo. You would like to transfer it to the user bob, so it will become bob/repo.

However, you make heavy use of the GitHub Pages feature, so that people are often accessing https://alice.github.io/repo/. GitHub will helpfully redirect all of your repository stuff hosted on github.com after the move, but will not redirect the GitHub Pages hosted on github.io.

The solution

@izabera
izabera / asciinema-to-scriptreplay
Last active March 23, 2023 12:32
convert between asciinema and scriptreplay
#!/bin/bash
exec {times}> times {typescript}> typescript < "${1-/dev/stdin}"
while read -r; do [[ $REPLY = ' "stdout": [' ]] && break; done # skip to this line
LANG=C
printf "Script started on %(%c)T\n" -1 >&"$typescript" # dummy
while read -r open; [[ $open = '[' ]]; do
read -r elapsed; read -r string; read -r close
eval printf %b%n "$string" characters >&"$typescript" # put count in $characters
printf "%s %s\n" "${elapsed%,}" "$characters" >&"$times"
done
@remram44
remram44 / Vagrantfile
Last active August 29, 2015 14:08
Torque on Vagrant
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define "master", primary: true do |m|
m.vm.box = "remram/debian-7-amd64"
m.vm.network "private_network", ip: "10.4.8.11"
m.vm.provider "virtualbox" do |v|
@remram44
remram44 / ipython-script.py
Created July 22, 2014 22:00
ipython-script.py
#!C:\Python2.7\python.exe
# EASY-INSTALL-ENTRY-SCRIPT: 'ipython==2.1.0','console_scripts','ipython'
__requires__ = 'ipython==2.1.0'
import sys
from pkg_resources import load_entry_point
if __name__ == '__main__':
sys.exit(
load_entry_point('ipython==2.1.0', 'console_scripts', 'ipython')()
)
@olasd
olasd / stream_to_youtube.sh
Created March 28, 2014 19:58
Stream video to youtube via ffmpeg
#! /bin/bash
#
# Diffusion youtube avec ffmpeg
# Configurer youtube avec une résolution 720p. La vidéo n'est pas scalée.
VBR="2500k" # Bitrate de la vidéo en sortie
FPS="30" # FPS de la vidéo en sortie
QUAL="medium" # Preset de qualité FFMPEG
YOUTUBE_URL="rtmp://a.rtmp.youtube.com/live2" # URL de base RTMP youtube
@remram44
remram44 / logstack.py
Created September 13, 2013 20:43
Adds context to your stack traces
import contextlib
import linecache
import logging
import sys
import traceback
try:
import cStringIO as StringIO
except ImportError:
import StringIO
@remram44
remram44 / http_directory.py
Last active September 16, 2022 00:14
Recursively download a directory with Python
from HTMLParser import HTMLParser
import urllib2
import os
import re
re_url = re.compile(r'^(([a-zA-Z_-]+)://([^/]+))(/.*)?$')
def resolve_link(link, url):
m = re_url.match(link)