Skip to content

Instantly share code, notes, and snippets.

@tonykwok
tonykwok / GLCubeView.java
Created September 19, 2022 07:55 — forked from SebastianJay/GLCubeView.java
Android Sample GLSurfaceView Cube
package com.example.glcube;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
@tonykwok
tonykwok / yuvrgb.md
Created July 22, 2022 00:56 — forked from yohhoy/yuvrgb.md
RGB <=> YCbCr(YPbPr) color space conversion
Y  = a * R + b * G + c * B
Cb = (B - Y) / d
Cr = (R - Y) / e
BT.601 BT.709 BT.2020
a 0.299 0.2126 0.2627
b 0.587 0.7152 0.6780
@tonykwok
tonykwok / wget.sh
Created December 15, 2021 06:46 — forked from crittermike/wget.sh
Download an entire website with wget, along with assets.
# One liner
wget --recursive --page-requisites --adjust-extension --span-hosts --convert-links --restrict-file-names=windows --domains yoursite.com --no-parent yoursite.com
# Explained
wget \
--recursive \ # Download the whole site.
--page-requisites \ # Get all assets/elements (CSS/JS/images).
--adjust-extension \ # Save files with .html on the end.
--span-hosts \ # Include necessary assets from offsite as well.
--convert-links \ # Update links to still work in the static version.
@tonykwok
tonykwok / ServiceBindHelper.java
Created December 11, 2021 07:48 — forked from attacco/ServiceBindHelper.java
Android service bind helper class
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.support.annotation.Nullable;
/**
* This class based on official
* <a href="http://developer.android.com/guide/components/bound-services.html">documentation</a>
@tonykwok
tonykwok / update-git.sh
Created October 26, 2021 02:11 — forked from YuMS/update-git.sh
Update git to latest version on Ubuntu
#!/bin/bash
sudo add-apt-repository -y ppa:git-core/ppa
sudo apt-get update
sudo apt-get install git -y
@tonykwok
tonykwok / zip_and_hash.py
Created October 9, 2021 04:59 — forked from gtalarico/zip_and_hash.py
Zip a directory and get hash (useful for checking if contents have changed)
# http://stackoverflow.com/questions/1855095/how-to-create-a-zip-archive-of-a-directory
import os
import zipfile
import hashlib
import time
def zipdir(path, ziph):
for root, dirs, files in os.walk(path):
if '.git' not in root:
for file in files:
@tonykwok
tonykwok / BGRA2RGBA
Created October 9, 2021 03:22 — forked from micahpearlman/BGRA2RGBA
BGRA to RGBA
// Really awesome code taken from: http://apangborn.com/2011/05/pixel-processing-using-arm-assembly/
inline static void neon_rgba_to_bgra(unsigned char *src, unsigned char *dst, int numPixels)
{
#ifdef __ARM_NEON__
int simd_pixels = numPixels & ~7; // round down to nearest 8
int simd_iterations = simd_pixels >> 3;
int col;
if(simd_iterations) { // make sure at least 1 iteration
__asm__ __volatile__ ("1: \n\t"
// structured load of 8 pixels into d0-d3 (64-bit) NEON registers
@tonykwok
tonykwok / Install_gcc7_ubuntu_16.04.md
Created March 19, 2021 05:59 — forked from jlblancoc/Install_gcc7_ubuntu_16.04.md
Installing gcc-7 & g++-7 in Ubuntu 16.04LTS Xenial

Run the following in the terminal:

Install the gcc-7 packages:

sudo apt-get install -y software-properties-common
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt update
sudo apt install g++-7 -y

Set it up so the symbolic links gcc, g++ point to the newer version:

@tonykwok
tonykwok / gist:c4ef60d06c763286b3a2f9168f0d2967
Created February 22, 2021 07:31 — forked from getify/gist:3667624
escape all (not-already-escaped) double-quote chars in a string
// NOTE: only escapes a " if it's not already escaped
function escapeDoubleQuotes(str) {
return str.replace(/\\([\s\S])|(")/g,"\\$1$2"); // thanks @slevithan!
}
escapeDoubleQuotes(`ab`); // ab => ab (nothing escaped)
escapeDoubleQuotes(`a"b`); // a"b => a\"b
escapeDoubleQuotes(`a\\"b`); // a\"b => a\"b (nothing escaped)
escapeDoubleQuotes(`a\\\\"b`); // a\\"b => a\\\"b
escapeDoubleQuotes(`a\\\\\\"b`); // a\\\"b => a\\\"b (nothing escaped)
import io
import selectors
import subprocess
import sys
def capture_subprocess_output(subprocess_args):
# Start subprocess
# bufsize = 1 means output is line buffered
# universal_newlines = True is required for line buffering
process = subprocess.Popen(subprocess_args,