Skip to content

Instantly share code, notes, and snippets.

@dev0x10
dev0x10 / crazytouch.txt
Created February 19, 2017 00:57
Monkey Runner Touch For Loop
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
device = MonkeyRunner.waitForConnection()
for i in range(1, 1000000):
MonkeyRunner.sleep(0.1)
device.touch(692, 1129, 'DOWN_AND_UP')
@dev0x10
dev0x10 / hapijs-options-header.js
Last active September 7, 2016 03:27
HapiJS CORS Handler For 'DELETE'
if (request.method === 'options') {
let response = request.response.isBoom ? request.response.output : request.response;
response.statusCode = 200;
response.headers['access-control-expose-headers'] = 'content-type, content-length, etag';
response.headers['access-control-max-age'] = 60 * 10; // might be not needed
// dynamically set allowed headers & method (this is the important part)
if (request.headers['access-control-request-headers']) {
response.headers['access-control-allow-headers'] = request.headers['access-control-request-headers']
}
@dev0x10
dev0x10 / nginx.conf
Created June 18, 2016 06:18 — forked from plentz/nginx.conf
Best nginx configuration for improved security(and performance). Complete blog post here http://tautt.com/best-nginx-configuration-for-security/
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
@dev0x10
dev0x10 / storagePolyfill.js
Created April 23, 2016 13:21 — forked from jarrodirwin/storagePolyfill.js
LocalStorage/SessionStorage Polyfill with Safari Private Browsing support.
// Refer to https://gist.github.com/remy/350433
try {
// Test webstorage existence.
if (!window.localStorage || !window.sessionStorage) throw "exception";
// Test webstorage accessibility - Needed for Safari private browsing.
localStorage.setItem('storage_test', 1);
localStorage.removeItem('storage_test');
} catch(e) {
(function () {
var Storage = function (type) {
@dev0x10
dev0x10 / localstorage_safari_private_shim.js
Created April 23, 2016 13:09 — forked from philfreo/localstorage_safari_private_shim.js
Don't let localStorage/sessionStorage setItem throw errors in Safari Private Browsing Mode
// Safari, in Private Browsing Mode, looks like it supports localStorage but all calls to setItem
// throw QuotaExceededError. We're going to detect this and just silently drop any calls to setItem
// to avoid the entire page breaking, without having to do a check at each usage of Storage.
if (typeof localStorage === 'object') {
try {
localStorage.setItem('localStorage', 1);
localStorage.removeItem('localStorage');
} catch (e) {
Storage.prototype._setItem = Storage.prototype.setItem;
Storage.prototype.setItem = function() {};
@dev0x10
dev0x10 / 1) Install
Last active March 13, 2016 05:43 — forked from nghuuphuoc/1) Install
Install Redis on Centos 6
// --- Compiling ---
$ wget http://download.redis.io/releases/redis-3.0.7.tar.gz
$ tar xzvf redis-3.0.7.tar.gz
$ cd redis-3.0.7
$ make
$ make install
// --- or using yum ---
$ rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
$ rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
@dev0x10
dev0x10 / README.md
Created December 9, 2015 05:59 — forked from denji/README.md
Remove WebStorm; PhpStorm; PyCharm; RubyMine; AppCode; CLion, IntelliJ; 0xDBE10 settings and cli-links from Mac OSX

Quick uninstall JetBrains settings:

curl -sL https://gist.github.com/denji/9731967/raw/jetbrains-uninstall.sh | bash -s
@dev0x10
dev0x10 / cmd.sh
Created November 3, 2015 09:06 — forked from kelvinn/cmd.sh
Example of using Apache Bench (ab) to POST JSON to an API
# post_loc.txt contains the json you want to post
# -p means to POST it
# -H adds an Auth header (could be Basic or Token)
# -T sets the Content-Type
# -c is concurrent clients
# -n is the number of requests to run in the test
ab -p post_loc.txt -T application/json -H 'Authorization: Token abcd1234' -c 10 -n 2000 http://example.com/api/v1/locations/
@dev0x10
dev0x10 / gist:12e9dc6ff0a4a0c13a2f
Last active September 14, 2015 09:35
Simple node.js code style tips to improve code quality

Whether you use 2 spaces or 4 spaces, there are a few simple things that can make your node.js code easier to read. We've been using them in all the hapi modules for over 4 years now to great results. This list is by no means complete but it highlights the most useful elements that will give you immediate value in reducing bugs.

Required modules

JavaScript makes it harder than most languages to know where variables are coming from. Variables assigned required modules are particularly important because they represent a singleton object shared with the entire application. There are also globals and module globals, along with function variables and arguments.

Traditionally, variables starting with an uppercase letter represent a class that must be instantiated using new. This was an important semantic in the early days of JavaScript but at this point, if you don't know Date requires new Date() you are probably very new. We have adopted Upper Camel Case variable names for all module global variables

@dev0x10
dev0x10 / rebalance.sh
Last active August 29, 2015 14:25 — forked from gjcourt/rebalance.sh
#!/bin/sh
# This will allow you to rebalance the Cassandra ring
# Accepts hosts from stdin and automatically rebalances
# tokens in your ring.
#
# $ echo "one two three" | ./rebalance.sh
RING_SIZE=$(echo "2^127" | bc)