Skip to content

Instantly share code, notes, and snippets.

@m1el
m1el / quicksort.hs
Last active August 29, 2015 13:57
trying to implement quicksort in haskell
-- 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
@m1el
m1el / JsonForm.m
Last active August 29, 2015 13:57
Wolfram Mathematica JSON form - convert expression to JSON representation.
// 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]];
@m1el
m1el / download-book.py
Last active August 29, 2015 14:01
downloading book as fb2 from wordpress blag
#!/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'
@m1el
m1el / invoker-2.md
Last active November 28, 2022 13:45
Old Invoker skills

Quas

Builds Kael's skill in the arcane magics. These spells, when invoked, deal with the power of the mind, wind, and water. As a reagent, increases damage by 2% per level, per reagent cast. increases Intelligence by 1 each time skill is learned.

card:
dates:
- 28.06.1996
id: 254к/96-вр
issuers:
- name: Верховна Рада України
numbers:
- 254к/96-ВР
state:
- Чинний

Lifetimes of cryptographic hash functions

I've written some cautionary articles on using cryptographic hashes to create content-based addresses (compare-by-hash). This page brings together everything I've written and keeps an updated table of the status of popular cryptographic hash functions. Quick summary of my recommendations on compare-by-hash: If you are using compare-by-hash to generate addresses for data that can be supplied by malicious users, you should have a plan to migrate to a new hash every few years. For example, BitTorrent falls into this category, but rsync doesn't. Keep in mind that new, more secure hashes are likely to have larger outputs (e.g., 256 bits for SHA-2 vs. 160 bits for SHA-1) and be more computationally expensive.

An Analysis of Compare-by-hash appeared in Hot Topics in Operating Systems 2003 The original paper casting doubt on compare-by-hash as the answer to all of life's problems.

@m1el
m1el / xslt.js
Last active August 29, 2015 14:03
xslt transformation
// xml parser
var xmlp=function(e){
return new DOMParser().parseFromString(e, "text/xml");
}
// xml serializer
var xmls=function(e){
return new XMLSerializer().serializeToString(e);
}
@m1el
m1el / binstr.js
Created June 26, 2014 08:29
functions for binary strings
/* 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;
}
@m1el
m1el / polygon-edges.js
Created June 27, 2014 20:47
determine polygon edges as seen from certain origin point
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];
@m1el
m1el / maybe-match.elm
Last active August 29, 2015 14:03
playing with maybes in elm
-- 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