Skip to content
{{ message }}

Instantly share code, notes, and snippets.

📞
Working on KnocKnock

# Jack Zhangjackz314

📞
Working on KnocKnock
Last active Jun 9, 2020
Get element index closest to target element in a list of tuples
View closest.py
 # Modified from solution for numbers here: https://stackoverflow.com/a/12141511/8170714 # Tuple comparison solution from here: https://stackoverflow.com/a/31779268/8170714 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,)).
Created Oct 2, 2019
Multi Prime RSA solver
View multi_prime_rsa.py
 # Solves multi prime rsa given n, e, and c. Need to factor n into primes first (recommend yafu) # Reference https://crypto.stackexchange.com/questions/31109/rsa-enc-decryption-with-multiple-prime-modulus-using-crt # From https://github.com/diogoaj/ctf-writeups/tree/master/2018/Timisoara/crypto/NotYourAverageRSA # Params e = 65537 c = 48761539940486768790697951968441053167086423529120379009399989923982917278530780108524481919294548305561552133247376067350664771674488982501980538923179804440135482761541868213581098181220801732284669971107195377327445661261746882474615837238429855596647745621191046720648860759474615170945636435027382702345930153884587334870109990234396501579 n = 81736943705459767985288486167314099164146317197040392194768161097750074479540025761100109449092862009195976097250151609584294118669228141027624354052423638509988705830737675936098155468596924772948252465412194715615408850250410310761063399013426728554729053139453019049285162533445627620506060381552244023004446417793032764776342793336374
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
Created Jun 29, 2019
Sort occurrence of words among a directory of files
View occur.sh
 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
Created Apr 20, 2019
Drag to select text with a mouse inside Android EditText like on computers
View DragEditText.java
 EditText mText = .... final int[] beginOffset = {-1}; View.OnTouchListener otl = new View.OnTouchListener() { @Override 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();
Last active Jun 9, 2020
A reflection method used to set EditText Cursor Color with support for Android P (API 28)
View SetEditTextCursorColor.java
 //StackOverflow solution by me here: https://stackoverflow.com/a/52564925/8170714 public static void setEditTextCursorColor(EditText editText, int color) { try { // Get the cursor resource id Field field = TextView.class.getDeclaredField("mCursorDrawableRes"); field.setAccessible(true); int drawableResId = field.getInt(editText); // Get the editor
Last active Sep 29, 2018
Open a Preference in Android Setting (preference) Activity
View openPreference.java
 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); break;
Last active Sep 29, 2018
Detect Past Times In a String
View DetectPastTime.java
 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)){ Toast.makeText(getContext(),getString(R.string.past_time_warning),Toast.LENGTH_LONG).show(); Calendar opCalendar = Calendar.getInstance(); opCalendar.setTime(currentTime); opCalendar.add(Calendar.SECOND,-1); long lastSecTime = opCalendar.getTimeInMillis(); opCalendar.setTime(currentTime); opCalendar.add(Calendar.MINUTE,-1); long lastMinTime = opCalendar.getTimeI
You can’t perform that action at this time.