Skip to content

Instantly share code, notes, and snippets.

View anacrolix's full-sized avatar
🚀
Factorio

Matt Joiner anacrolix

🚀
Factorio
View GitHub Profile
bytesRange :: Wai.Request -> FileLength -> (Integer, Integer)
bytesRange r l = fromMaybe (0,l) $
(\case
ByteRangeFrom f -> (f, l-f)
ByteRangeFromTo f t -> (f, t-f+1)
ByteRangeSuffix s -> (l-s,s)
) <$> (requestHeaderRange r >>= parseByteRanges >>= listToMaybe)
@anacrolix
anacrolix / cthulu.hs
Created March 11, 2018 10:18
what have i made
data Transcode = Transcode
{ inputUrl :: ByteString
, ffmpegOpts :: [ByteString]
, format :: ByteString
}
getOutputName :: ByteString -> [ByteString] -> ByteString -> ByteString
getOutputName i opts f =
(C.pack . List.map toLower . C.unpack . hex $ hashStrings (i : opts)) <> "." <>
f
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
-- {-# LANGUAGE TDNR #-}
module Main where
import Control.Concurrent.STM
import Control.Exception
import Control.Monad
import Crypto.Hash.MD5 as MD5
@anacrolix
anacrolix / conditions.go
Created January 9, 2018 03:20
condition style
// which would you do? comment below
// distinct ifs
if n == 1 {
single()
}
if n > 1 {
multi()
}
import time, datetime, re
def parse_go(logger, line):
event = {
'msg_text': line,
'priority': 'low',
}
try:
date = datetime.datetime.strptime(line[:19], "%Y/%m/%d %H:%M:%S")
except ValueError:
type Msg
= ApiAvailability Cast.ApiAvailability
| CastContext Cast.JsContext
| RequestSession
| UrlChange Navigation.Location
| Navigate String
| NavbarMsg Navbar.State
| LoadMedia
| ProposedMediaInput (Cast.Media -> String -> Cast.Media) String
class g:
def __init__(self):
self.s = "f"
def __call__(self, c=None):
if c is None:
self.s += "o"
return self
else:
return self.s+c
def f(c=None):
class g:
def __init__(self):
self.s = "f"
def __call__(self, c=None):
if c is None:
self.s += "o"
return self
else:
return self.s+c
def f(c=None):
usage = chunk(redis_cli('hgetall', key+':'+date), 2)
usage = map(lambda x: x[:1]+(int(x[1]),)+x[2:], usage)
usage = sorted(usage, key=lambda x: x[1], reverse=True)
module StaleUpdater exposing (..)
type alias StaleUpdater =
{ stale : Bool
, updating : Bool
}
new : StaleUpdater