Skip to content

Instantly share code, notes, and snippets.

package main
import (
"fmt"
"sync"
"time"
)
type RWMutex struct {
qr chan struct{} // queue of readers
@mem
mem / next-wrapper
Created November 17, 2015 01:37
Next command wrapper
#!/bin/sh
get_next() {
IFS=:
id=$(stat -c '%D:%i' "$1")
prg=
name=$(basename "$0")
for p in $PATH ; do
n="$p/$name"
if test -e "$n" ; then
nid=$(stat -c '%D:%i' "$n")
@mem
mem / gist:7e989639e6204e687987
Created February 3, 2015 19:44
Look for process pid by command line without forking
needle=/usr/lib/chromium/chromium
cd /proc
for pid in * ; do
if test -e "$pid/cmdline" ; then
read cmd rest < $pid/cmdline
if test "$cmd" = "$needle" ; then
echo $pid
fi
esac
done
@mem
mem / endo.cc
Created August 25, 2014 17:34
NeedsObject needs an instance of Object. In order to manage the scope of the Object instance, a class is derived from NeedsObject and it's put in charge of the Object instance lifetime. This allows the creation of another class for testing purposes.
class Object {
public:
Object() { }
virtual ~Object() { }
};
class NeedsObject {
protected:
NeedsObject(Object *object) : object(object) { }