Skip to content

Instantly share code, notes, and snippets.

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,
@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)
@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 / AppDataDirGuesser.java
Created August 11, 2021 03:35
Uses heuristics to guess the application's private data directory.
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@see https://android.googlesource.com/platform/frameworks/base/+/ccbf84f44c9e6a5ed3c08673614826bb237afc54
Some system apps are more system than others
"signatureOrSystem" permissions are no longer available to all apps
residing en the /system partition. Instead, there is a new /system/priv-app
directory, and only apps whose APKs are in that directory are allowed
to use signatureOrSystem permissions without sharing the platform cert.
This will reduce the surface area for possible exploits of system-
bundled applications to try to gain access to permission-guarded
@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 / 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 / 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 / gralloc_handle_t.c
Last active October 28, 2021 10:46
gralloc_handle_t
127 + // copied from the link bebow:
128 + // https://es.osdn.net/projects/android-x86/scm/git/external-mesa/commits/5a595cd3af15b99d266d3fd5cba41da33f1888ac
129 +
130 + bool ubwc = false;
131 +
132 + const uint32_t *handle_fds = (uint32_t *)gralloc_info->handle->data;
133 + const uint32_t *handle_data = &handle_fds[gralloc_info->handle->numFds];
134 + int dma_buf;
135 +
136 + if (gralloc_info->handle->numFds == 1) {
@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>