Skip to content

Instantly share code, notes, and snippets.

@pgp
pgp / InfiniteIterable.java
Created April 10, 2019 14:02
Infinite dummy iterable
import java.util.Iterator;
public class InfiniteIterable<T> implements Iterable {
private final T marker;
public InfiniteIterable(T marker) {
this.marker = marker;
}
@pgp
pgp / BuildRustAppForAndroid.sh
Created April 11, 2019 08:36
Cross compile RUST application for Android (uses standalone toolchains, NDK >= 19 required)
# arm
export PATH=$PATH:$HOME/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin
export CC=armv7a-linux-androideabi19-clang
export CXX=armv7a-linux-androideabi19-clang++
~/.cargo/bin/cargo build --target armv7-linux-androideabi
# aarch64
export PATH=$PATH:$HOME/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin
export CC=aarch64-linux-android21-clang
export CXX=aarch64-linux-android21-clang++
@pgp
pgp / build.gradle
Created April 11, 2019 11:07
launch ndk-build from build-gradle in Android project
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "28.0.0"
defaultConfig {
applicationId "com.example.ndkbuildexample"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdint>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <ifaddrs.h>
#include <netinet/in.h>
get_cmake_property(_variableNames VARIABLES)
list (SORT _variableNames)
foreach (_variableName ${_variableNames})
message(STATUS "${_variableName}=${${_variableName}}")
endforeach()
@pgp
pgp / sudo_from_python.py
Created January 8, 2020 12:04
Programmatically use sudo from python
import subprocess
sudoPassword = b'mySudoPassword\n'
cmd = 'sudo -S touch /dev/shm/1.txt'.split(' ')
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
p.communicate(sudoPassword)
#ifndef __RH_PROGRESS_HOOK__
#define __RH_PROGRESS_HOOK__
#include "unifiedlogging.h"
#ifdef _WIN32
#include <shobjidl.h>
#endif
class ProgressHook {
public:
@pgp
pgp / hybrid_batch_bash.bat
Created January 30, 2020 12:36
Hybrid batch/bash script
:<<BATCH
@echo off
rem Web source: https://stackoverflow.com/questions/17510688/single-script-to-run-in-both-windows-batch-and-linux-bash
echo %PATH%
exit /b
BATCH
#!/bin/bash # CAUTION: SHEBANG WON'T WORK HERE (NOT FIRST LINE)
echo $PATH
@pgp
pgp / qsortExample.cpp
Created February 4, 2020 09:15
qsort example
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cstdint>
#include <cstring>
/**
* g++ -O3 qsortExample.cpp
*
* # MinGW
@pgp
pgp / logcat_to_colored_stdout.py
Last active March 9, 2020 12:04
Colorize logcat file and print to console
import sys
import re
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'