Skip to content

Instantly share code, notes, and snippets.

@kaeluka
kaeluka / horr.erl
Last active July 2, 2019 06:03
Global mutable state in erlang.
-module(horr).
-export([malloc/0, free/1, read/1, write/2, test/0]).
% You can use `malloc` to get a globally sharable, mutable cell of memory.
% A difference to C's `malloc` is that such a cell doesn't have a certain size (you can't overflow)
% Memory is initialised with the atom `null`.
malloc() ->
spawn(fun() -> mem(null) end).
% As processes are not garbage collected, you have to call `free` when you're done with your memory:
@sznurek
sznurek / coroutine.py
Created February 19, 2014 22:37
Python asynchronous server featuring generator (coroutines).
#!/usr/bin/env python3
import sys
import socket
import select
def command(name, args=None):
return {'name': name, 'args': args}
def readcmd():
@danasilver
danasilver / README.md
Last active November 6, 2017 12:48
Jekyll Pygments/Redcarpet Global Configs

Jekyll Pygments/Redcarpet Global Configs

A Jekyll plugin that enables global configuration options for Pygments.

  • Add pygments_global_config.rb to my-jekyll-project/_plugins/.

  • Add Pygments options to _config.yml

markdown: redcarpet
###
# Scheme code is translated to YARV byte code, then evaluated in the
# Ruby Virtual Machine
require 'rbconfig'
require 'dl'
require 'fiddle'
require 'strscan'
class RubyVM
@jayankandathil
jayankandathil / cq_maintenance.sh
Last active September 27, 2016 14:31
Bash shell script to run Adobe CQ (Experience Manager) maintenance operations on Red Hat Enterprise Linux. Tested on RHEL 6.3 and 6.4
#!/bin/bash
# Bash script to run CQ daily maintenance operations, excluding TarPM Optimization and Tar Index Merge
# Author : Jayan Kandathil
# Version : 0.4
# Last updated : May 24, 2013
# Instructions : Copy to CQ's /bin folder, make necessary changes, enable the execute bit and run
@jaseg
jaseg / gist:5296519
Last active March 23, 2016 10:08
zsh unicode table using only zsnexpn(1) in <140 characters

The following line produces a unicode table (decimal value and unicode characters) using only zsh * expansion, * substitution and the print-builtin.

setopt extendedglob histsubstpattern multibyte
print -ac ${${(A)=u::={5126..5743}}:s/#%(#b)(*)/'${(r:6:m)match[1]}${(#mr:4:)match[1]}'/}

Output:

//Provide details around the bootdelgation state
println "Bootdelgation property value :- "+bundleContext.getProperty("org.osgi.framework.bootdelegation")
println "Felix bootdelgation entries"
bundleContext.bundle.framework.bootPackages.each {
println it
}
@megakorre
megakorre / rust-poly.md
Created August 8, 2012 21:47
blog: rust pollymorpism

EDIT! full code can be found here gist

So I played around with rust a bit now. And I thought I might share some random stuff.

So say you wanted to represent a expression tree with plus and minus nodes and a node for values. One way to do this would be to use rust's enum's.

In rust enums are like haskell's union types so you can specify the different values to be constructors carrying data.

@leegao
leegao / Swap.c
Created January 19, 2011 22:45
C is fucking crazy.
#include <stdio.h>
void(*swap)() = (void(*)()) "\x8b\x44\x24\x04\x8b\x5c\x24\x08\x8b\x00\x8b\x1b\x31\xc3\x31\xd8\x31\xc3\x8b\x4c\x24\x04\x89\x01\x8b\x4c\x24\x08\x89\x19\xc3"
"Oh, there you are Mr. Insanity...";
int main(){ // works on GCC 3+4
int a = 37, b = 13;
swap(&a, &b);
printf("%d%d",a,b);
}
The Challenge
-------------
Given the following riddle, write a regular expression describing all possible answers,
assuming you never make a move which simply undoes the last one you made.
The Riddle
----------
You are on your way somewhere, taking with you your cabbage, goat, and wolf, as always.
You come upon a river and are compelled to cross it, but you can only carry one of the
three companions at a time. None of them can swim because this isn't THAT kind of riddle.