Skip to content

Instantly share code, notes, and snippets.

@asciimo
asciimo / getNexus.js
Created November 27, 2012 23:46
Fill your GooglePlay cart with Nexuses and drop this script in your Chrome console.
function simulateClick(element) {
var oEvent;
oEvent = document.createEvent("MouseEvents");
oEvent.initMouseEvent("click", true, true, document.defaultView);
element.dispatchEvent(oEvent);
return element;
}
var myButton = document.getElementsByClassName("buy-button-price")[1];
var myInterval = setInterval(function(){simulateClick(myButton)}, 2000);
@asciimo
asciimo / gist:7576426
Created November 21, 2013 05:16
Filtering a list of strings against a list of compiled regular expressions, in Python.
import re
patterns = [re.compile('one'), re.compile('two'), re.compile('three')]
strings = ['one', 'fudge', 'two', 'twenty', 'three', 'something']
# To collect the matches
[s for s in strings if any(p.match(s) for p in patterns)]
#Output: ['one', 'two', 'three']
# To colelct the non-matches
[s for s in strings if not any(p.match(s) for p in patterns)]
@asciimo
asciimo / gist:8929680
Last active August 29, 2015 13:56
Shell Goodies
# Tunneling MySQL over SSH
ssh -fNg -L 3307:127.0.0.1:3306 myuser@remotehost.com
mysql -h 127.0.0.1 -P 3307 -u dbuser -p db

Keybase proof

I hereby claim:

  • I am asciimo on github.
  • I am asciimo (https://keybase.io/asciimo) on keybase.
  • I have a public key whose fingerprint is FBE8 BB07 9E6F 6107 04BF 7C9D 1249 F99B DCD2 A5BC

To claim this, I am signing this object:

@asciimo
asciimo / total_deaths.js
Created October 18, 2015 21:18
Here's an example of how to sum the numeric values in a Wikipedia HTML table column.
// Written for this Wikipedia page on 2015-10-18:
// https://en.wikipedia.org/wiki/List_of_motor_vehicle_deaths_in_U.S._by_year
var deaths = 0;
$("table.wikitable").first().find("tr").each(
function() {
var deathsCell = $(this).find("td").first().text();
var pattern = new RegExp("([\d,,]+)[^\d,,]?")
deathsNum = parseInt(deathsCell.replace(/,/g, ""), 10);
if(!isNaN(deathsNum)) {
deaths += deathsNum;
@asciimo
asciimo / disco_duck.js
Created December 5, 2015 17:41
Example of a JS object with public/private methods
// Utility for ducking Discovery under fixed agent navigation bars and ads
var discoDuck = (function() {
var _discoveryContainer = $("#discoveryContainer");
var _proNavBarHeight = $("#navbarAgent").outerHeight();
var _proCatcherHeight = $("#pro_catcher").outerHeight();
var _adjustMarginTop = function(pixels, addOrRemove) {
if(_discoveryContainer.length < 1) {
return;
}
@asciimo
asciimo / selenium_ffde.py
Last active July 25, 2016 02:17
Configure custom Firefox Developer Edition path for python3 selenium, on a Mac
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary("/Applications/FirefoxDeveloperEdition.app/Contents/MacOS/firefox")
browser = webdriver.Firefox(firefox_binary=binary)
# Or, in your terminal session: PATH=$PATH:/Applications/FirefoxDeveloperEdition.app/Contents/MacOS/firefox
@asciimo
asciimo / template.html
Created August 9, 2016 18:26
Simple html5 document template
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title><!-- change me --></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<!-- change me -->
@asciimo
asciimo / array_intersect.js
Last active December 15, 2017 09:51
ES6 equivalent to PHP's array_intersect()
const intersect = (leftArray, rightArray) => leftArray.filter(value => rightArray.indexOf(value) > -1);
@asciimo
asciimo / lazyload.js
Created August 26, 2016 19:50
"Unobtrusive lazy load pattern" from [friendlybit.com](https://friendlybit.com/js/lazy-loading-asyncronous-javascript/).
(function() {
function async_load(){
var s = document.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = 'http://yourdomain.com/script.js';
var x = document.getElementsByTagName('script')[0];
x.parentNode.insertBefore(s, x);
}
if (window.attachEvent)