Skip to content

Instantly share code, notes, and snippets.


Guy Smoilovsky guysmoilov

View GitHub Profile
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}}
{{#if isObject}}
{{> objectSpreader}}
{{!-- This is just a value type --}}
{{ this}}
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) {
var config = {
attributes: true,
childList: true,
guysmoilov /
Last active Aug 29, 2015
Meteor browser policy supporting tests
laxBrowserPolicy = ->
BrowserPolicy.content.allowOriginForAll "localhost:*"
BrowserPolicy.content.allowConnectOrigin "ws://localhost:*"
BrowserPolicy.content.allowConnectOrigin "http://localhost:*"
Meteor.startup ->
guysmoilov /
Last active Aug 29, 2015
Get number of methods in a dex file contained in an apk.
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 =
return methods_in_dex(dex_bytes)
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 / 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)
guysmoilov /
Created Jun 13, 2016
Python script to reinstall an apk
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)
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)
View no-proxy.bat
set http-proxy=
set https-proxy=
set http_proxy=
set https_proxy=
start cmd
# Usage: arg 1 is number of random lines to generate, arg 2 is length of each line
# Stolen from:
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w $2 | head -n $1
You can’t perform that action at this time.