Skip to content

Instantly share code, notes, and snippets.

@danlei
danlei / forvo-trim
Last active February 19, 2024 20:57
#!/usr/bin/env python3.10
# trim noise from forvo audio files
# experiment with treshold (in db) as needed
import sys
from pydub import AudioSegment
from pydub.silence import split_on_silence
@danlei
danlei / Dockerfile
Created August 9, 2020 15:34
Camunda with root redirect
FROM camunda/camunda-bpm-platform:latest
RUN echo '<% response.sendRedirect("/camunda"); %>' > /camunda/webapps/ROOT/index.jsp
// ==UserScript==
// @name Enlarge Arabic
// @namespace danlei
// @author danlei
// @version 1.1.5
// @updateURL https://gist.githubusercontent.com/danlei/17478a08b53ba9367e83111104bfa002/raw
// @installURL https://gist.githubusercontent.com/danlei/17478a08b53ba9367e83111104bfa002/raw
// @include /^https?://.*$/
// @exclude https://twitter.com*
// @description Increase Arabic font size relatively (adapted from Arminius99's script)
@danlei
danlei / motif-offsets.lisp
Created August 1, 2012 07:25
Syntactic motif offsets (Lisp baseline)
(defun indices (input-file output-file)
(with-open-file (in input-file :direction :input)
(with-open-file (out output-file :direction :output
:if-exists :supersede
:if-does-not-exist :create)
(loop with previous-field = nil
for index from 0
for field = (read in nil nil)
while field
if (not previous-field)
@danlei
danlei / LogicTemplates.hs
Created September 12, 2011 13:56
Templates for n-ary logic functions
{-# LANGUAGE TemplateHaskell #-}
module LogicTemplates (true,
false,
eq,
taut,
cont)
where
import Language.Haskell.TH
@danlei
danlei / raw-reader.lisp
Created June 27, 2011 13:59
Simple raw string reader macro
;; Beware: #" is actually not reserved for the user. See:
;; http://www.lispworks.com/documentation/HyperSpec/Body/02_dh.htm
(defun read-raw-string (stream subchar arg)
(declare (ignore subchar arg))
(with-output-to-string (out)
(loop for char = (read-char stream nil nil)
while (and char (char/= char #\"))
do (write-char char out))))
@danlei
danlei / Soundex.hs
Created May 25, 2011 04:05
Simple Haskell implementation of the soundex algorithm. difference :: String -> String -> Int yields "phonetic distance" between words as an integer in range [0..4].
module Soundex
where
import Data.Maybe (catMaybes)
import GHC.Exts (the)
import Data.List (group)
import Data.Function (on)
classes = [("bfpv",'1'),
("cgjkqsxzß",'2'),
@danlei
danlei / img-alt-table.el
Created March 23, 2011 19:34
Show src/alt comparison table of a site's images.
(require 'xml)
(require 'html-lite)
(defun xml-get-nodes (node node-name)
(let ((nodes (list)))
(labels ((match (node) (eq (xml-node-name node) node-name))
(rec (node)
(when (listp node)
(if (match node)
(push node nodes)
@danlei
danlei / htmltoy.el
Created March 20, 2011 02:36
toy html generation
(defun transform-args (args)
(if (null args)
""
(destructuring-bind (name value . rest) args
(when (not (keywordp name))
(signal 'wrong-type-argument (list name)))
(concat " " (substring (symbol-name name) 1)
"=\"" (format "%s" value) "\""
(transform-args rest)))))
@danlei
danlei / DSParser.hs
Created February 17, 2011 02:25
Simple dependence parser
module DSParser
where
import Prelude hiding (lex)
type Word = String
type Pos = Integer
data Token = Token { pos :: Pos, lex :: Word }