Skip to content

Instantly share code, notes, and snippets.

@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) { }
@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 / 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")
package main
import (
"fmt"
"sync"
"time"
)
type RWMutex struct {
qr chan struct{} // queue of readers
#!/bin/sh
#
# Given a package's import path, this script will list the Go sources (not in $GOROOT)
# used to build that pacakge.
go list -f '{{ join .Deps "\n" }}' "$@" |
xargs -r -d '\n' \
go list -f '{{ if not .Goroot }}{{ .ImportPath }}{{ end }}' 2> /dev/null |
xargs -r -d '\n' \
go list \
-- http://sylnsr.blogspot.com/2015/08/generate-golang-struct-model-from.html
WITH models AS (
WITH data AS (
SELECT
replace(initcap(table_name::text), '_', '') table_name,
replace(initcap(column_name::text), '_', '') column_name,
CASE data_type
WHEN 'timestamp without time zone' THEN 'time.Time'
WHEN 'timestamp with time zone' THEN 'time.Time'
WHEN 'boolean' THEN 'bool'
@mem
mem / go
Created July 13, 2016 19:09
go wrapper to automatically set GOPATH
#!/bin/sh
get_inode() {
stat -c '%i' "$1"
}
find_go() {
self=`get_inode $(readlink -m "$1")`
local IFS=:
### Keybase proof
I hereby claim:
* I am mem on github.
* I am mem (https://keybase.io/mem) on keybase.
* I have a public key ASC7tQYyimGItv9HXARDm-zuEZx7HZwV_Px4hRcsZbOxkgo
To claim this, I am signing this object:
@mem
mem / generic_mount_flow.plantuml
Created May 30, 2019 17:57
Description of generic mount flow
@startuml
autonumber
hide footbox
participant "wrapper\n(stage 2)" as wrapper
participant "stage 1" as stage_1
participant master
participant "rpc server" as rpc_server
@startuml
autonumber
hide footbox
participant "wrapper\n(stage 2)" as wrapper
participant "stage 1" as stage_1
participant master
participant "rpc server" as rpc_server