Skip to content

Instantly share code, notes, and snippets.

View phadej's full-sized avatar
🦉
Someone here is possessed by an owl. Who?

Oleg Grenrus phadej

🦉
Someone here is possessed by an owl. Who?
View GitHub Profile
We actually need more words, as entropy of the words is less than characters.
Suppose there is about 50000 words (There is 301 000 main entries in OED).
Than
50000^x > 94^13 => x => 5.5
So i would say that
"balloons are very nice" < "@$XsBv2JMc473"
Also entropy of word like "are" is almost zero, so predictable.
@phadej
phadej / maybe.cc
Created August 9, 2012 18:57
Keulii
// works with clang++ bundled with xcode 4.4
// clang++ -std=c++11 -stdlib=libc++ maybe.cc -o maybe
#include <iostream>
#include <utility>
// didn't realize how to make this a class to hide members
template <typename T>
struct maybe {
// private:
@phadej
phadej / viikko1.hs
Created September 25, 2012 09:23
Viikkotehtävä 1
{-
110 viikkovisa #1
---------------------------
Piirretään ruutupaperille numeroita myötäpäivään "ympyrään" alkaen vasemmasta yläkulmasta:
1
...
1 2
...
@phadej
phadej / Take.md
Created September 27, 2012 18:57
Testit vs Proof

Hehkutettu Haskellin QuickCheck

import Prelude hiding (take)

import Test.QuickCheck

take :: Int -> [a] -> [a]
take _ []     = []
take 0 _      = []
@phadej
phadej / Vikko1.v
Created September 28, 2012 08:37
Viikkotehtävän neliöhuijauksen todistus!
Theorem plus_comm : forall (n m : nat),
n + m = m + n.
Proof.
intros n. induction n as [| n'].
(* case n = 0 *)
intros m. rewrite <- plus_n_O. rewrite -> plus_O_n. trivial.
(* case n = S n' *)
intros m. rewrite <- plus_n_Sm. rewrite -> plus_Sn_m.
apply eq_S. apply IHn'. Qed.
@phadej
phadej / gist:3853458
Created October 8, 2012 16:33
lrevl l <-> pal l
Require Export Poly.
Inductive pal {X:Type} : list X -> Prop :=
| pal_nil : pal nil
| pal_singleton : forall x:X, pal [x]
| pal_cons_snoc : forall (x:X) (l : list X), pal l -> pal (x :: snoc l x).
Inductive lrevl {X:Type} : list X -> Prop :=
| pal_lrevl : forall (l : list X), l = rev l -> lrevl l.
@phadej
phadej / Docopt.hs
Created October 30, 2012 18:40
Docopt.hs - parsing command line options <=> matching a regexp
module Docopt where
import System.Environment (getArgs)
import Regexp
data DocoptResult = DocoptCommand Bool
| DocoptPositionalArg (Maybe String)
| DocoptRepatableArg [String]
| DocoptFlag Bool
% cat test2.py
"""
Usage:
  test2.py [options] <file>...

 Options:
% cat tar.py
"""
Usage:
tar [-c] [options] <files>...
tar [-r | -u] -f ARCHIEVE [options] <files>...
tar [-t | -x] [options] [...]
@phadej
phadej / getExample.js
Last active December 12, 2015 04:28
How to do transactions with indexedDb using promises?
// Using moreUsable.js style
indexedDB.open(DBNAME, DBVERSION, DBSCHEMA)
.then(function(connection) {
return connection.transaction(["table1"]) // undefined -> readonly, state undefined also
.then(function(obj) {
return obj.transaction.get(obj.state, "table1", "foo");
})
.then(function(obj) {
return obj.state;
});