Skip to content

Instantly share code, notes, and snippets.

View dmalikov's full-sized avatar
🥞
!

Dmitry Malikov dmalikov

🥞
!
View GitHub Profile
@dmalikov
dmalikov / blewotah.sh
Created August 12, 2013 20:17
unsorted stream intersection with grep, -xF magician
What is going on here is creating 2 streams with numbers from 1 to 100000 sorting randomly and finding with grep all lines that each of them contains. All of them, actually. -c flag is a shortcut for `| wc -l`, nothng more.
$> n=100000; time grep -f <(seq 1 $n | sort -R) <(seq 1 $n | sort -R) -c
100000
grep -f <(seq 1 $n | sort -R) <(seq 1 $n | sort -R) -c 148.65s user 0.28s system 98% cpu 2:31.89 total
$> n=100000; time grep -xF -f <(seq 1 $n | sort -R) <(seq 1 $n | sort -R) -c
100000
grep -xF -f <(seq 1 $n | sort -R) <(seq 1 $n | sort -R) -c 0.34s user 0.01s system 26% cpu 1.315 total
@dmalikov
dmalikov / wut.fs
Created September 24, 2013 21:03
nice constructor syntax
open System
open System.Net
type Stock(symbol : string) = class
let url =
"http://download.finance.yahoo.com/d/quotes.csv?s=" + symbol + "&f=sl1d1t1c1ohgv&e=.csv"
let mutable _symbol = String.Empty
let mutable _current = 0.0
let mutable _open = 0.0
@dmalikov
dmalikov / git-contributors.sh
Created January 28, 2014 20:52
analogue of github contributors stats
#!/bin/bash
# wow so bash such fast very O(n^2*log(n)^2)
for author in `git log --format='%ae' | sort -u`; do
changes=`git log --author=$author --pretty=tformat: --numstat | awk '{ add += $1 ; subs += $2 } END { printf "%s ++ / %s --\n",add,subs }'`
commits=`git log --author=$author --oneline | wc -l`
echo "$author: $commits commits / $changes"
done | sort -rn -k2
@dmalikov
dmalikov / wut.ps1
Created February 27, 2014 10:30
powershell wut
PS > "m" -contains "m"
True
PS > "a b m" -contains "m"
False
#!/usr/bin/perl
$_='
$q ="\ 47"; wh
ile ($ ;=
$z += .5 ){
%c= $r=0;$/ ="";whi le(2
0+ $z>($;+=.05)){$c{int$ _+ 2
6+ 2*($ r+= .0 2) *
s in$ ;}{1 -$_
+1 0+ int $r*c o s
@dmalikov
dmalikov / !.ps1
Last active August 29, 2015 13:57
.GetNewClosure()
PS C:\> { param($x) { param($y) $x + $y } }.Invoke(10).Invoke(20)
20
PS C:\> { param($x) { param($y) $x + $y }.GetNewClosure() }.Invoke(10).Invoke(20)
30
PS C:\> ({ param($x) { param($y) $y * $x } }.Invoke(10).Invoke(20)) -eq 0
True
PS C:\> ({ param($x) { param($y) $x * $y } }.Invoke(10).Invoke(20)) -eq $null
True
@dmalikov
dmalikov / such expected.ps1
Last active August 29, 2015 13:57
powershell wow so pure very functional
$ cat function.ps1
function f() {
{ param($x) "expected output" }.Invoke()
}
function g() {
{ param($x) "unexpected" }.Invoke()
return "output"
}
@dmalikov
dmalikov / wow
Created April 14, 2014 14:09
Wow so null very static such empty
$ powershell ./wut.ps1
String is null
String is null
String is empty
@dmalikov
dmalikov / Eu.hs
Last active August 29, 2015 14:01
Groupping strings by multiple fileds in various languages (All Hail Powershell)
module Eu where
import Control.Applicative ((<$>))
import Data.Function (on)
import Data.List (groupBy, intercalate)
import Data.List.Split (splitOn)
import qualified Data.Map as M
import Data.Maybe (mapMaybe)
main :: IO ()
@dmalikov
dmalikov / README.markdown
Last active May 31, 2019 06:31
Nix / NixOS links

Various blog posts related to Nix and NixOS


General