This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
outfile="/tmp/runst-$$" | |
rustc -o "$outfile" "$1" && "$outfile" | |
rm -f "$outfile" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
# -*- encoding: utf-8 -*- | |
import re | |
import os | |
import sys | |
import json | |
import argparse | |
import yaml | |
from logging import getLogger |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "'\''") }' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Python Template Markup Language | |
# Simple Python DSL for HTML and (a little) CSS templating. | |
# | |
# Example: | |
# | |
# from ptml import * | |
# | |
# with html5 as out: | |
# with head: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__all__ = [] | |
def export(value): | |
__all__.append(value.__name__) | |
return value | |
import sys | |
module = sys.modules[__name__] | |
class Context(object): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |