Skip to content

Instantly share code, notes, and snippets.

View kstep's full-sized avatar
🗺️

Konstantin Stepanov kstep

🗺️
View GitHub Profile
@kstep
kstep / lostfilm.py
Last active January 26, 2017 18:55
lostfilm download script
#!/usr/bin/env python2
# -*- encoding: utf-8 -*-
import re
import os
import sys
import json
import argparse
import yaml
from logging import getLogger
#!/bin/sh
outfile="/tmp/runst-$$"
rustc -o "$outfile" "$1" && "$outfile"
rm -f "$outfile"
function fish_prompt --description 'Write out the prompt'
set -l last_status $status
set -l prompt_status
if test $last_status -ne 0
if not set -q __fish_prompt_status
set -g __fish_prompt_status (set_color $fish_color_status)
end
set prompt_status "$__fish_prompt_status [$last_status]$__fish_prompt_normal"
end
"""A simple addition to Python's optparse module supporting subcommands
like those found in the svn or hg CLIs.
To use it, instantiate the Subcommand class for every subcommand you
want to support. Each subcommand has a name, aliases, a help message,
and a separate OptionParser instance. Then pass a list of Subcommands
to the constructor of SubcommandsOptionParser to make a subcommand-
aware parser. Calling parse_args on that parser gives you the
subcommand invoked, the subcommand's arguments and options, and the
global options all in one fell swoop. See the smoke test at the bottom
use std::io::net;
fn get_my_external_ip() -> Option<net::ip::IpAddr> {
net::tcp::TcpStream::connect("8.8.8.8", 53).and_then(|ref mut s| s.socket_name()).map(|a| a.ip).ok()
}
fn main() {
println!("My external IP: {}", get_my_external_ip());
}
#![feature(plugin)]
#![plugin(regex_macros)]
extern crate regex;
use std::ops::Index;
use regex::Regex;
pub struct Re(Regex);
@kstep
kstep / cargo-build
Created June 4, 2015 16:33
Build binaries from Crates.io
#!/bin/sh
REPO_URL="https://crates.io"
API_URL="$REPO_URL/api/v1"
die() {
echo "$@" >&2
exit 1
}
@kstep
kstep / rustrun
Last active August 29, 2015 14:23
run rust as script
#!/bin/sh
SELF="$1"
MD5=$(md5sum "${SELF}" | cut -f1 -d" ")
OUT="${SELF}.${MD5}.out"
if [ ! -f "${OUT}" ]; then
rustc -C debuginfo=0 -C prefer-dynamic "${SELF}" -o "${OUT}" || exit 1
fi
shift
exec "${OUT}" "$@"
KEYMAP=us
FONT=ter-v18b
@kstep
kstep / linus-git-merges.txt
Created October 20, 2015 13:36
Linus on Git merge
I want clean history, but that really means (a) clean and (b) history.
People can (and probably should) rebase their _private_ trees (their own
work). That's a _cleanup_. But never other peoples code. That's a "destroy
history"
So the history part is fairly easy. There's only one major rule, and one
minor clarification:
- You must never EVER destroy other peoples history. You must not rebase