Skip to content

Instantly share code, notes, and snippets.

Clack clack click clack

Gergely Nagy algernon

Clack clack click clack
Block or report user

Report or block algernon

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
algernon / Makefile
Created Jul 7, 2011
JSON to BSON conversion in C
View Makefile
all: json2bson
rm -f json2bson
json2bson: json2bson.c
${CC} $(shell pkg-config --cflags json libmongo-client glib-2.0) -Wall -O0 -ggdb3 -std=c99 ${CFLAGS} \
$(shell pkg-config --libs json libmongo-client glib-2.0) -o $@ $^
check: all
./json2bson <test.json >test.bson
algernon / trim-at-boundary.clj
Created Aug 7, 2011
Trim strings at word boundary, with a maximum length
View trim-at-boundary.clj
(ns algernon.util
(:require [clojure.contrib.str-util2 :as s]))
(defn trim-at-boundary [string max-len]
(if (< (.length string) max-len)
(str (s/take
(reduce #(if (< (+ (.length %1) (.length %2) 1) (- max-len 3))
(str %1 " " %2) %1)
(s/split string #"\s"))
algernon / utf8wtf.rb
Created Nov 17, 2011
Fun stuff with UTF-8
View utf8wtf.rb
#! ruby -KUTF-8
hello world = "Goodbye world!"
  = "For real?!?"
 1 = 2
puts 1 + 1
puts hello world
algernon /
Created Nov 25, 2011
The Journal => JSON exporter, via systemd-journalctl
#! /usr/bin/python
## Usage: systemd-journalctl |
import json
import sys
class JournalCtlParser:
fp = None
def __init__(self, fp):
algernon /
Created Aug 24, 2012
Obfuscated uniq -c in Perl
#!perl -n
BEGIN{$;=open(STDOUT,"|sort -nr")&&0;}$"=$_ if !$;++;next if $_ eq $";print $;-1 ."|".$";($;,$")=(1,$_);END{print "$;|".$";}
algernon /
Created Oct 9, 2012
AMQP consumer in python, for testing
#! /usr/bin/python
import sys
import pika
# Import all adapters for easier experimentation
from pika.adapters import *
pika.log.setup(pika.log.INFO, color=True)
algernon / dance.bas
Created Nov 25, 2012
My very first program, ever
View dance.bas
10 PRINT CHR$(27);"N"
20 PRINT "\o/"
30 PRINT " | "
40 PRINT "/ \"
50 FOR I=1 TO 1000: NEXT
60 PRINT CHR$(27);"N"
70 PRINT " o "
80 PRINT "/|\"
90 PRINT "/ \"
100 FOR I=1 TO 1000: NEXT
algernon / python-lisp-hybrid
Created Feb 4, 2013
A python "dialect" with significant parens. The point is, any whitespace at the beginning of line that is used for indentation must be replaced by opening parens, and to end a block, you must close all relevant parens.
View python-lisp-hybrid
def foobar(blah):
((for i in range(1, 10):
((((print "blah: %s" % blah))))))
algernon / fizzbuzz-seq.clj
Created Feb 10, 2013
A fizzbuzz implementation that produces a lazy list of results.
View fizzbuzz-seq.clj
(defn fizzbuzz-seq
(letfn [(nil-prefix [n s]
(concat (take n (cycle [nil])) [s]))]
(map #(let [s (or %4 %2 %3 (inc %1))] s)
(cycle (nil-prefix 2 "Fizz"))
(cycle (nil-prefix 4 "Buzz"))
(cycle (nil-prefix 14 "FizzBuzz")))))
algernon / fizzbuzz-logic.clj
Last active Dec 12, 2015
My feeble attempt at implementing FizzBuzz using core.logic, one which can be run back and forth aswell. Requires core.logic 0.8.0-rc3-SNAPSHOT or later.
View fizzbuzz-logic.clj
(refer 'clojure.core :exclude [==])
(use '[clojure.core.logic])
(require '[clojure.core.logic.fd :as fd])
(require '[clojure.test :as t])
(defn multo
"Ensure that `n` is a multiplicate of `div`."
[n div]
(fresh [x]
You can’t perform that action at this time.