Skip to content

Instantly share code, notes, and snippets.

View xevix's full-sized avatar

Alejandro Wainzinger xevix

View GitHub Profile
fname = 'pwned-passwords-2.0.txt'
# Change me
# echo -n password | shasum -a 1 | awk '{print toupper($1)}'
password = '7C4A8D09CA3762AF61E59520943DC26494F8941B'
search = password
with open(fname) as f:
for line in f:
sha = line[:40]
if search == sha:

Keybase proof

I hereby claim:

  • I am xevix on github.
  • I am xevix (https://keybase.io/xevix) on keybase.
  • I have a public key ASDKzeeW4q_b8UXMKqF-posWghvBE63A41Msr3QCiHTrxwo

To claim this, I am signing this object:

@xevix
xevix / foldl1_ish.rs
Last active September 10, 2017 05:50
trait Folder {
type Item;
fn foldl1<F>(self, f: F) -> Option<Self::Item>
where
F: FnMut(Self::Item, &Self::Item) -> Self::Item;
}
impl<T: Clone> Folder for Vec<T> {
type Item = T;
fn foldl1<F>(self, mut f: F) -> Option<Self::Item>
@xevix
xevix / loop.rs
Last active September 10, 2017 02:53
pub fn combine_all_option<T>(xs: &Vec<T>) -> Option<T>
where
T: Semigroup + Clone,
{
match xs.first() {
Some(head) => {
// Dear lord this reads horribly
xs[1..].iter().fold(Some((*head).clone()), |acc, x| acc.combine(&Some((*x).clone())))
}
_ => None
@xevix
xevix / iterator_leak.py
Last active June 22, 2017 18:40
Iterator accessible after its scope ends
def main():
ary = ['I should never print']
for elem in ary:
pass
other_ary = ['other']
for other_elem in other_ary:
# "elem" hould not be defined here, but this works, because of Python's awful scoping rules
def foo(a, b={}):
if a == 1:
b["oops"] = "boom"
return b
for i in xrange(3):
print "foo: {}".format(foo(i))
# Output:
def foo(bob, **kwargs):
pass
kwargs = {'bob': 'first param is also bob, when splatted, they clash...'}
foo('bar', **kwargs) # KABOOM!
# Traceback (most recent call last):
# File "<stdin>", line 1, in <module>
# TypeError: foo() got multiple values for keyword argument 'bob'
@xevix
xevix / rust_lifetimes.rs
Created March 2, 2016 08:36
Rust Lifetimes
struct Foo {
x: i32,
}
struct Bar<'a> {
foo: &'a Foo,
// Uncomment to disallow drop()
x: ::std::cell::RefCell<() /* Option<&'a Bar<'a>>*/>,
}
import shapeless.syntax.std.tuple._
import shapeless._, syntax.singleton._
object ShapelessMain {
def main(args: Array[String]): Unit = {
val l = 23 :: "foo" :: true :: HNil
l(1)
val t = (23, "foo", true)
t(1)
@xevix
xevix / coproduct_scala_worksheet.scala
Created January 8, 2016 14:20
Coproduct Scala Worksheet Fail
// From Shapeless `coproduct.scala`
sealed trait Animal
case class Cat(name: String, livesLeft: Int) extends Animal
case class Dog(name: String, bonesBuried: Int) extends Animal
case class Koala(name: String, leavesEaten: Int) extends Animal