This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def dictcmp(a, b, stacka=None, stackb=None): | |
if a is b: | |
return True | |
if type(a) is not type(b): | |
return False | |
stacka = stacka or [] | |
stackb = stackb or [] | |
stacka.append(id(a)) | |
stackb.append(id(b)) | |
res = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://nolandc.com/sandbox/fractals/?x=25&y=1&l=8&d=6&sa=80&a=-45&s=F++F++F++F++&r=F,F+D---F++F,D,+F+D---F+D | |
// space-filling fractal, a modification of Sierpinski curve | |
function d2xy(d, s) { | |
var r = {x: 0, y: 0}, p = {x: 0, y: 0}; | |
for (s = s-1; s >= 0; s--) { | |
p.x *= 2; | |
p.y *= 2; | |
var pow = 1 << (s*2); | |
rot(r, (d & pow*3) >> s*2); | |
if(s==1){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- algorithm is following: find all swaps for current step, apply them, | |
-- repeat recursively for nested set of ranges | |
import Data.Array | |
quickSortI :: (Num i, Ix i, Show i, Ord a, Show a) => | |
Array i a -> [(i, i)] -> Array i a | |
quickSortI array ranges = | |
let (swaps, ranges') = findSwaps array ranges | |
array' = array // swaps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Wolfram Mathematica JSON form - convert expression to JSON representation | |
SetAttributes[JSONForm, HoldAll]; | |
SetAttributes[JSONForm`lispyI, SequenceHold]; | |
SetAttributes[JSONForm`lispy, HoldAll]; | |
JSONForm`lispyI[List, xs_] := Prepend[Map[JSONForm`lispy, xs], "List"]; | |
JSONForm`lispyI[Symbol, xs_] := SymbolName[xs]; | |
JSONForm`lispyI[String, xs_] := {"String", xs}; | |
JSONForm`lispyI[Integer | Real, xs_] := xs; | |
JSONForm`lispyI[h_, t_] := Prepend[Map[JSONForm`lispy, Level[t, 1]], JSONForm`lispy[h]]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import io, re, requests | |
import hashlib | |
import lxml.etree as etree | |
session = requests.session() | |
parser = etree.HTMLParser() | |
template = 'template.fb2' | |
output = 'book-partial.fb2' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// xml parser | |
var xmlp=function(e){ | |
return new DOMParser().parseFromString(e, "text/xml"); | |
} | |
// xml serializer | |
var xmls=function(e){ | |
return new XMLSerializer().serializeToString(e); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* little endian parser */ | |
function lit2int(str){ | |
var ret=0; | |
for(var i=str.length-1;i>=0;i--){ | |
ret=ret*256+(str.charCodeAt(i)&0xff); | |
} | |
return ret; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function cross3(o, p1, p2) { | |
return (p1.x - o.x) * (p2.y - o.y) - (p1.y - o.y) * (p2.x - o.x); | |
} | |
function findEdges(point, path) { | |
var min = path[0], | |
max = path[0]; | |
for (var i = 1; i < path.length; i++) { | |
if (cross3(point, min, path[i]) < 0) { | |
min = path[i]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- http://elm-lang.org/try | |
import Regex (..) | |
import Maybe (..) | |
import Graphics.Input as Input | |
import Graphics.Input.Field as Field | |
maybeMatch : String -> String -> Maybe Match | |
maybeMatch reg str = | |
case find (AtMost 1) (regex reg) str of | |
[] -> Nothing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System.Environment | |
isPrime :: Int -> Bool | |
isPrime a = | |
let isOddBy x = a `mod` x /= 0 | |
gtSqr x = x * x <= a | |
in all isOddBy $ takeWhile gtSqr primes | |
primes :: [Int] | |
primes = 2 : filter isPrime [3..] |
OlderNewer