Skip to content

Instantly share code, notes, and snippets.

View kstep's full-sized avatar
🗺️

Konstantin Stepanov kstep

🗺️
View GitHub Profile
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());
}
"""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
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
#!/bin/sh
outfile="/tmp/runst-$$"
rustc -o "$outfile" "$1" && "$outfile"
rm -f "$outfile"
@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
ACTION=="add", SUBSYSTEM=="block", ENV{ID_FS_USAGE}=="filesystem", DRIVERS=="usb-storage", GOTO="automount_go"
ACTION=="remove", SUBSYSTEM=="block", ENV{ID_FS_USAGE}=="filesystem", DRIVERS=="usb-storage", RUN{program}+="/bin/rmdir /media/%E{AUTOMOUNT_NAME}"
GOTO="automount_end"
LABEL="automount_go"
PROGRAM="/usr/local/bin/automount-helper.py $number", GROUP="disk", TAG+="systemd", ENV{AUTOMOUNT_NAME}="$result{1}", ENV{SYSTEMD_WANTS}="usb-mount@$result{2}.service"
LABEL="automount_end"
@kstep
kstep / gist:8599679
Created January 24, 2014 15:39
Simple player with "mplayer" and current song notifications.
mplayer -vo null -playlist playlist.m3u -loop 0 -shuffle | awk -F ': ' '/^ title: / { title=$2; gsub(/'\''/, "&\\\\&&", title) } /^ artist: / { artist=$2; gsub(/'\''/, "&\\\\&&", artist) } /^Starting playback/ { system("notify-send -i /usr/share/icons/oxygen/22x22/actions/media-playback-start.png Playing '\''" artist " — " title "'\''") }'
@kstep
kstep / ptml.py
Created August 29, 2012 18:03
Simple Python HTML template DSL (improved Python 3 version)
#
# Python Template Markup Language
# Simple Python DSL for HTML and (a little) CSS templating.
#
# Example:
#
# from ptml import *
#
# with html5 as out:
# with head:
@kstep
kstep / html.py
Created August 15, 2012 13:12
Simple Python HTML template DSL
__all__ = []
def export(value):
__all__.append(value.__name__)
return value
import sys
module = sys.modules[__name__]
class Context(object):
@kstep
kstep / xrandrconf.sh
Created March 9, 2012 18:44
autoconfigure displays layout with xrandr
#!/bin/sh
case "$1" in
left-of|right-of|above|below|same-as) D=$1 ;;
*) D=left-of ;;
esac
xrandr | awk -v dir=$D 'out { gsub("[^0-9.]", "", $2); print "--output " out " --mode " $1 " --rate " $2 pout; pout=" --" dir " " out; out=0 } / connected/ { out=$1 }' | xargs xrandr