Skip to content

Instantly share code, notes, and snippets.

@benhylau
benhylau / root-ro
Created February 2, 2018 23:30 — forked from kidapu/root-ro
Read-only Root-FS with overlayfs for Raspian
#!/bin/sh
#
# Read-only Root-FS for Raspian
#
# Modified 2016 by Stefan Bonfert to make it compatible with Raspbian
# Jessie (vanilla).
#
# Modified 2015 by Pascal Rosin to work on raspian-ua-netinst with
# overlayfs integrated in Linux Kernel >= 3.18.
#
@benhylau
benhylau / systemd-prblm.service
Created July 25, 2017 18:53 — forked from nickjacob/systemd-prblm.service
execute arbitrary bash code/variable substitution in systemd units
[Unit]
Description=Demonstrate Bash
[Service]
ExecStartPre=/usr/bin/bash -c "/usr/bin/systemctl set-environment MYVAR=$(( 2 + 2 ))"
ExecStart=/usr/bin/ech "2 + 2 = ${MYVAR}"
@benhylau
benhylau / gist:595ee89fa70bbeabab7a9eea63c2097b
Last active May 13, 2017 03:03
cjdns Public Peer serving wikipedia-on-ipfs.org
# ipfs Gateways
internet -> http://178.62.223.245/ipfs/
cjdns -> http://[fc44:ff51:390e:f401:3045:c8d5:47af:a745]/ipfs/
# ipfs Pinned Snapshots
tr.wikipedia-on-ipfs.org -> /ipfs/QmT5NvUtoM5nWFfrQdVrFtvGfKFmG7AHE8P34isapyhCxX
# cjdns Public Peerings
@benhylau
benhylau / Command.md
Created March 14, 2017 21:25 — forked from RickyCook/Command.md
Using socat to forward new ports via STDIO in a running Docker container

What?... Why?

Imagine you're messing around in a container, and you install some stuff, add some config, and now it's time to load up your client and check it out! Oh wait, you forgot to forward ports when you created the container! Fear not, all is not lost, for in the world of pipes, and streams, there is always a way to do something disgusting.

The Dockerfile

Example Dockerfile included will install Nginx, and socat in a container, and make Nginx run in foreground mode. To build, and run:

@benhylau
benhylau / rPi3-ap-setup.sh
Last active January 2, 2021 19:41 — forked from Lewiscowles1986/rPi3-ap-setup.sh
Raspberry Pi 3 access-point-setup
#!/bin/bash
#
# This version uses September 2016 rpi jessie image, please use this image
#
if [ "$EUID" -ne 0 ]
then echo "Must be root"
exit
fi
@benhylau
benhylau / gist:a7d21c8806df9c73da7d
Created April 19, 2015 07:19
AnimationDrawableCallback
/**
* Provides a callback when a non-looping {@link AnimationDrawable} completes its animation sequence. More precisely,
* {@link #onAnimationCompleted()} is triggered when {@link View#invalidateDrawable(Drawable)} has been called on the
* last frame.
*
* @author Benedict Lau
*/
public abstract class AnimationDrawableCallback implements Callback {
/**

Keybase proof

I hereby claim:

  • I am benhylau on github.
  • I am benhylau (https://keybase.io/benhylau) on keybase.
  • I have a public key whose fingerprint is 3748 E7C4 4ED7 18C9 51F9 27AC 9D9F 2856 67B7 9B2E

To claim this, I am signing this object:

@benhylau
benhylau / gist:46264dd7aed089074c0c
Created April 8, 2015 19:07
Browse Android app database
$ adb backup -f data.ab APPLICATION_PACKAGE
$ dd if=data.ab bs=1 skip=24 | python -c "import zlib, sys; sys.stdout.write(zlib.decompress(sys.stdin.read()))" | tar -xvf - -C .
$ sqlite3 DATABASE_FILE
$ SELECT name FROM sqlite_master WHERE type='table';
/**
* Gets the size of content fitted inside a container while maintaining its aspect ratio.
*
* @param containerWidth width of the container.
* @param containerHeight height of the container.
* @param contentWidth width of the content.
* @param contentHeight height of the content.
* @return a {@link Point} where the (x, y) corresponds to the (width, height) of the content fitted inside the
* container.
*/