Skip to content

Instantly share code, notes, and snippets.

View kstep's full-sized avatar
🗺️

Konstantin Stepanov kstep

🗺️
View GitHub Profile
#!/usr/bin/python
# encoding: utf-8
import sys, os, itertools as it
try:
root = sys.argv[1]
except IndexError:
root = os.getcwd()
@chadselph
chadselph / patternmatching.py
Last active February 15, 2024 14:45
Functional language style pattern matching in python with a decorator
from collections import defaultdict
class BadMatch(NameError):
"""Exception when your args don't match a pattern"""
pass
class Any(object):
"""
>>> 'wutup' == Any()
True
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());
}