Skip to content

Instantly share code, notes, and snippets.

Avatar
🦉
Someone here is possessed by an owl. Who?

Oleg Grenrus phadej

🦉
Someone here is possessed by an owl. Who?
View GitHub Profile
View gist:1149737
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.
View maybe.cc
// 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 Sep 25, 2012
Viikkotehtävä 1
View viikko1.hs
{-
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 Sep 27, 2012
Testit vs Proof
View Take.md

Hehkutettu Haskellin QuickCheck

import Prelude hiding (take)

import Test.QuickCheck

take :: Int -> [a] -> [a]
take _ []     = []
take 0 _      = []
@phadej
phadej / Vikko1.v
Created Sep 28, 2012
Viikkotehtävän neliöhuijauksen todistus!
View Vikko1.v
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 Oct 8, 2012
lrevl l <-> pal l
View gist:3853458
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 Oct 30, 2012
Docopt.hs - parsing command line options <=> matching a regexp
View Docopt.hs
module Docopt where
import System.Environment (getArgs)
import Regexp
data DocoptResult = DocoptCommand Bool
| DocoptPositionalArg (Maybe String)
| DocoptRepatableArg [String]
| DocoptFlag Bool
View gist:3994045
% cat test2.py
"""
Usage:
  test2.py [options] <file>...

  Options:
View gist:3994121
% cat tar.py
"""
Usage:
tar [-c] [options] <files>...
tar [-r | -u] -f ARCHIEVE [options] <files>...
tar [-t | -x] [options] [<patterns>...]
@phadej
phadej / getExample.js
Last active Dec 12, 2015
How to do transactions with indexedDb using promises?
View getExample.js
// 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;
});