Skip to content

Instantly share code, notes, and snippets.

Working on KnocKnock

Jack Zhang jackz314

Working on KnocKnock
View GitHub Profile
jackz314 /
Last active Jun 9, 2020
Get element index closest to target element in a list of tuples
# Modified from solution for numbers here:
# Tuple comparison solution from here:
def take_closest(self, list, element, idx=0):
Assumes myList is sorted. Returns closest value to element (tuple).
When comparing not all elements in tuple, set all other locations in tuple to nothing (e.g. (X,Y,)).
jackz314 /
Created Oct 2, 2019
Multi Prime RSA solver
# Solves multi prime rsa given n, e, and c. Need to factor n into primes first (recommend yafu)
# Reference
# From
# Params
e = 65537
c = 48761539940486768790697951968441053167086423529120379009399989923982917278530780108524481919294548305561552133247376067350664771674488982501980538923179804440135482761541868213581098181220801732284669971107195377327445661261746882474615837238429855596647745621191046720648860759474615170945636435027382702345930153884587334870109990234396501579
n = 81736943705459767985288486167314099164146317197040392194768161097750074479540025761100109449092862009195976097250151609584294118669228141027624354052423638509988705830737675936098155468596924772948252465412194715615408850250410310761063399013426728554729053139453019049285162533445627620506060381552244023004446417793032764776342793336374
jackz314 / disable.bat
Created Jul 12, 2019
Turn off Hyper-V on Windows completely (for VT-X to work)
View disable.bat
[in Windows UI]
Turn on/off Windows Features -> Untick Hyper-V
[in cmd or PowerShell]
bcdedit /set hypervisorlaunchtype off
[in PowerShell]
dism.exe /Online /Disable-Feature:Microsoft-Hyper-V
jackz314 /
Created Jun 29, 2019
Sort occurrence of words among a directory of files
cat *.txt | tr '[:space:]' '[\n*]' | grep -v "^\s*$" | sort | uniq -c | sort -bnr | head -n 100
#extension .txt, limit result to top 100. Change if needed
jackz314 /
Created Apr 20, 2019
Drag to select text with a mouse inside Android EditText like on computers
EditText mText = ....
final int[] beginOffset = {-1};
View.OnTouchListener otl = new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if(event.getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE){//only change behavior for mouse
int i = event.getAction();
if (i == MotionEvent.ACTION_DOWN) {
Layout layout = ((EditText) v).getLayout();
float x = event.getX() + mText.getScrollX();
jackz314 /
Last active Jun 9, 2020
A reflection method used to set EditText Cursor Color with support for Android P (API 28)
//StackOverflow solution by me here:
public static void setEditTextCursorColor(EditText editText, int color) {
try {
// Get the cursor resource id
Field field = TextView.class.getDeclaredField("mCursorDrawableRes");
int drawableResId = field.getInt(editText);
// Get the editor
jackz314 /
Last active Sep 29, 2018
Open a Preference in Android Setting (preference) Activity
private void openPreference(String key) {
PreferenceScreen preferenceScreen = getPreferenceScreen();
final ListAdapter listAdapter = preferenceScreen.getRootAdapter();
final int itemsCount = listAdapter.getCount();
int itemNumber;
for (itemNumber = 0; itemNumber < itemsCount; ++itemNumber) {
if (listAdapter.getItem(itemNumber).equals(findPreference(key))) {
preferenceScreen.onItemClick(null, null, itemNumber, 0);
jackz314 /
Last active Sep 29, 2018
Detect Past Times In a String
String[] pastTimeIndicators = new String[]{"last sec", "last min", "last hr", "last hour", "yesterday", "last week", "last month", "last year"};
if(isStringContainAnyOfTheseWords(group.getText().toLowerCase(), pastTimeIndicators)){
Calendar opCalendar = Calendar.getInstance();
long lastSecTime = opCalendar.getTimeInMillis();
long lastMinTime = opCalendar.getTimeI
You can’t perform that action at this time.