Skip to content

Instantly share code, notes, and snippets.

@rodrigoalviani
rodrigoalviani / webspider.hs
Created January 5, 2016 10:04 — forked from shangaslammi/webspider.hs
Haskell Web Spider example
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
@rodrigoalviani
rodrigoalviani / Sense.file
Created August 10, 2016 13:57
ElasticSearch Aggregation test
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 / watermarkImage().js
Created June 12, 2017 16:56 — 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.
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');
// 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 / plate-snitch.js
Created August 29, 2017 13:45 — forked from taitems/plate-snitch.js
(Extract) Check the status of a vehicle registration and scrape results.
// 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) {
@rodrigoalviani
rodrigoalviani / newid.js
Created September 11, 2023 19:11
Generate alphanumeric ID
function newid() {
const base = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; // base58
const size = 11;
let id = new Uint8Array(size);
crypto.getRandomValues(id);
let result = "";
for (let i = 0; i < size; i++) {