Skip to content

Instantly share code, notes, and snippets.

Avatar
🐼

Guy Smoilovsky guysmoilov

🐼
View GitHub Profile
View no-proxy.bat
set http-proxy=
set https-proxy=
set http_proxy=
set https_proxy=
start cmd
View kill-android-process.py
import subprocess
import sys
pslist = subprocess.check_output("adb shell ps " + sys.argv[1]).decode("utf-8").split()
if len(pslist) > 8:
pid = pslist[9]
print("killing " + pid)
subprocess.check_call("adb shell kill " + pid)
@guysmoilov
guysmoilov / reinstall-apk.py
Created Jun 13, 2016
Python script to reinstall an apk
View reinstall-apk.py
import subprocess
import sys
import re
apkpath = sys.argv[1]
print('checking packagename')
head = subprocess.check_output('aapt d badging "' + apkpath + '"').decode("utf-8").split("\n")[0]
packagename = re.match(r'^package: name=\'([A-Za-z0-9\.]+)\'', head).group(1)
print('uninstalling ' + packagename)
subprocess.check_call("adb uninstall " + packagename)
@guysmoilov
guysmoilov / clojure-exponent.clj
Created Feb 6, 2016
Effficient exponent function in Clojure
View clojure-exponent.clj
(defn exp
"exponent of x^n (int n only), with tail recursion and O(logn)"
[x n]
(if (< n 0)
(/ 1 (exp x (- n)))
(loop [acc 1
base x
pow n]
(if (= pow 0)
acc
View infinite-recursive-eval.js
var recursive = "var iterationNum=ITERATION_NUM; console.log('iteration number %s', iterationNum); var recursive = \"REPLACE\"; eval(recursive.replace('REPLACE', recursive.replace(/\\\\/g, '\\\\\\\\').replace(/\"/g, '\\\\\"').replace(/'/g, '\\\\\\'')).replace('ITERATION_NUM', iterationNum + 1))";
eval(recursive.replace('REPLACE', recursive.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/'/g, '\\\'')).replace('ITERATION_NUM', 0));
@guysmoilov
guysmoilov / dex.py
Last active Aug 29, 2015
Get number of methods in a dex file contained in an apk.
View dex.py
import zipfile
import sys
def methods_in_dex(dex_bytes):
return int.from_bytes(dex_bytes[88:92], byteorder='little', signed=False)
def methods_in_apk(apkfile, dexfile='classes.dex'):
with zipfile.ZipFile(apkfile, 'r') as apkzip:
dex_bytes = apkzip.read(dexfile)
return methods_in_dex(dex_bytes)
@guysmoilov
guysmoilov / browser-policy.coffee
Last active Aug 29, 2015
Meteor browser policy supporting tests
View browser-policy.coffee
laxBrowserPolicy = ->
BrowserPolicy.content.allowOriginForAll "localhost:*"
BrowserPolicy.content.allowConnectOrigin "ws://localhost:*"
BrowserPolicy.content.allowConnectOrigin "http://localhost:*"
Meteor.startup ->
BrowserPolicy.content.disallowInlineScripts()
BrowserPolicy.content.disallowInlineStyles()
BrowserPolicy.content.disallowEval()
@guysmoilov
guysmoilov / _mutation_observer_helper.js
Created Mar 25, 2015
Can be used inside client integration tests to wait for elements to change
View _mutation_observer_helper.js
observeMutationsHelper = function(targetSelector, done, callback) {
var target = document.querySelector(targetSelector);
var observer = new MutationObserver(function(mutations) {
callback(mutations);
observer.disconnect();
done();
});
var config = {
attributes: true,
childList: true,
@guysmoilov
guysmoilov / documentSpreader.html
Created Mar 11, 2015
Meteor template that can recursively display any document's structure.
View documentSpreader.html
<template name="fieldSpreader">
{{#if isArray}}
{{> arraySpreader}}
{{else}}
{{#if isObject}}
{{> objectSpreader}}
{{else}}
{{!-- This is just a value type --}}
{{ this}}
{{/if}}
You can’t perform that action at this time.