Skip to content

Instantly share code, notes, and snippets.

@rodrigoalviani
rodrigoalviani / plate-snitch.js
Created Aug 29, 2017 — forked from taitems/plate-snitch.js
(Extract) Check the status of a vehicle registration and scrape results.
View plate-snitch.js
// Open form and submit enquire for `rego`
function getInfo(rego) {
horseman
.userAgent('Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0')
.open(url)
.type('#registration-number-ctrl input[type=text]', rego)
.click('.btn-holder input')
.waitForSelector('.ctrl-holder.ctrl-readonly')
.html()
.then(function(body) {
View gist:d9267df0974fcd393b1615aeece6ec2e
// SCRIPT
#!/bin/bash
dd if=/dev/urandom bs=1M count=1 of=somerandom
for i in $(seq 1 1000)
do
thisblock=$(shuf -i 0-63999 -n 1)
sudo dd if=somerandom of=/dev/mmcblk0 bs=1M seek=$thisblock
sudo sync
sudo dd if=/dev/mmcblk0 skip=$thisblock bs=1M count=1 | diff - somerandom
@rodrigoalviani
rodrigoalviani / watermarkImage().js
Created Jun 12, 2017 — forked from westc/watermarkImage().js
Add a watermark text to the bottom right of any image element on the page that is on the same domain.
View watermarkImage().js
function watermarkImage(elemImage, text) {
// Create test image to get proper dimensions of the image.
var testImage = new Image();
testImage.onload = function() {
var h = testImage.height, w = testImage.width, img = new Image();
// Once the image with the SVG of the watermark is loaded...
img.onload = function() {
// Make canvas with image and watermark
var canvas = Object.assign(document.createElement('canvas'), {width: w, height: h});
var ctx = canvas.getContext('2d');
@rodrigoalviani
rodrigoalviani / Sense.file
Created Aug 10, 2016
ElasticSearch Aggregation test
View Sense.file
DELETE test
PUT test/test/1
{"make":{"id":12,"name":"fiat"},"model":{"id":121,"name":"strada"}}
PUT test/test/2
{"make":{"id":12,"name":"fiat"},"model":{"id":122,"name":"palio"}}
PUT test/test/3
{"make":{"id":12,"name":"fiat"},"model":{"id":123,"name":"ka"}}
PUT test/test/4
{"make":{"id":12,"name":"fiat"},"model":{"id":124,"name":"uno"}}
@rodrigoalviani
rodrigoalviani / webspider.hs
Created Jan 5, 2016 — forked from shangaslammi/webspider.hs
Haskell Web Spider example
View webspider.hs
import Control.Exception
import Control.Monad
import Control.Monad.IO.Class
import Data.ByteString.Lazy (ByteString)
import Data.ByteString.Lazy.UTF8 (toString)
import Data.Function
import Data.Enumerator
import Data.List
import Data.Maybe
View crawler haskell
-- | URL Doc : http://hackage.haskell.org/package/url-2.1.3/docs/Network-URL.html
module Page where
import Network.URL
import Network.Curl
import Text.XML.HXT.Core
import Text.HandsomeSoup
data Page = Page {
title :: String,
View accent_replace.php
<?
preg_replace("/&([a-z])[a-z]+;/i", "$1", htmlentities($valor));
@rodrigoalviani
rodrigoalviani / tor_curl.php
Created Nov 17, 2015 — forked from zachflower/tor_curl.php
How To Anonymize PHP cURL Requests Using Tor
View tor_curl.php
<?php
$ip = '127.0.0.1';
$port = '9051';
$auth = 'PASSWORD';
$command = 'signal NEWNYM';
$fp = fsockopen($ip,$port,$error_number,$err_string,10);
if(!$fp) { echo "ERROR: $error_number : $err_string";
return false;
@rodrigoalviani
rodrigoalviani / colorContrast.js
Created Sep 15, 2015
Get best contrast to a given color
View colorContrast.js
// rgb is a array [r, g, b]
function colorContrast (rgb) {
var r = rgb.r * 255,
g = rgb.g * 255,
b = rgb.b * 255;
var factor = (r * 299 + g * 587 + b * 114) / 1000;
return (factor >= 128) ? 'dark' : 'light';
}
View fuzzysearch.js
'use strict';
function fuzzySearch (subject, pattern) {
var i = 0, n = -1, l;
subject = subject.toLowerCase();
pattern = pattern.toLowerCase();
for (; l = pattern[i++];)
if (!~(n = subject.indexOf(l, n + 1)))
You can’t perform that action at this time.