Skip to content

Instantly share code, notes, and snippets.

crazy4groovy

Block or report user

Report or block crazy4groovy

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@crazy4groovy
crazy4groovy / checkReCaptcha.js
Last active Jul 3, 2019
Check Google reCaptcha response
View checkReCaptcha.js
const https = require('https')
async function checkReCaptcha(secret, response) {
const url = `https://www.google.com/recaptcha/api/siteverify?secret=${secret}&response=${response}`
return new Promise((resolve, reject) => {
https
.get(url, (res) => {
let rawData = ''
res.on('data', (data) => { rawData += data })
res.on('end', () => resolve(JSON.parse(rawData)))
@crazy4groovy
crazy4groovy / taiko1.js
Last active Jun 25, 2019
sample Taiko script for browser automation
View taiko1.js
const { emulateDevice, openBrowser, goto, write, click, closeBrowser } = require('taiko');
(async () => {
try {
// await openBrowser({headless: false, args:['--window-size=1440,900']})
await openBrowser();
// await emulateDevice('iPhone 6'); // note: breaks button label search below
await goto('google.com');
@crazy4groovy
crazy4groovy / getDataUrl.js
Created May 5, 2019
get a dataUrl for any img src on any domain.
View getDataUrl.js
async function getDataUrl(src) {
function run(resolve, reject) {
const tmpImage = new Image();
tmpImage.setAttribute('crossOrigin', 'Anonymous'); // NEEDED FOR CANVAS ANTI-TAINT
tmpImage.src = src;
tmpImage.onerror = reject; // no dataUrl
tmpImage.onload = () => {
const canvas = document.createElement('canvas');
canvas.width = tmpImage.naturalWidth; // or .width;
canvas.height = tmpImage.naturalHeight; // or .height;
@crazy4groovy
crazy4groovy / recurseByEventLoopTimer.js
Last active May 15, 2019
Example of how to "recursively" call an async function, using the event loop (setTimeout).
View recurseByEventLoopTimer.js
function delay(ms, data) {
return new Promise(res => setTimeout(res, ms, data));
}
function fn(arr) {
return async function work(recurse, resolve, reject) {
const num = Math.random();
const more = await delay(100, num > .5).catch(reject);
if (more) {
arr.push(num);
@crazy4groovy
crazy4groovy / index.html
Created Apr 29, 2019 — forked from obezuk/index.html
Cloudflare Worker - Link Shortener
View index.html
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
@crazy4groovy
crazy4groovy / docker_wordpress.md
Created Apr 29, 2019 — forked from bradtraversy/docker_wordpress.md
Docker Compose FIle For Wordpress, MySQL & phpmyadmin
View docker_wordpress.md

Wordpress & Docker

This file will setup Wordpress, MySQL & PHPMyAdmin with a single command. Add the code below to a file called "docker-compose.yaml" and run the command

$ docker-compose up -d

# To Tear Down
$ docker-compose down --volumes
@crazy4groovy
crazy4groovy / userdata.sh
Last active Apr 27, 2019
AWS EC2 user data setup script for darknet ML tool
View userdata.sh
#!/bin/bash
## Amazon Linux 2 AMI ##
# Note: many commands don't seem to work (??)
yum update -y
yum install -y git gcc gcc-c++ httpd
service httpd start
echo "<html><h1>Running httpd!</h1></html>" > /var/www/html/index.html
@crazy4groovy
crazy4groovy / scrollMessage.js
Created Apr 21, 2019
Scroll a message across the browser tab's Title and/or URL hash
View scrollMessage.js
function scrollMessage(message, timeoutMs, changeTitle, changeUrl) {
if (!message || !(changeTitle || changeUrl)) return function stopScroll() {}
if (changeTitle) document.title = message
if (changeUrl) document.location.hash = message
function init() {
var index = 0
function scrollerTick() {
index = (index + 1) % message.length
@crazy4groovy
crazy4groovy / async-patterns.js
Created Feb 22, 2019
How to throttle an array of promises until they've resolved
View async-patterns.js
const delay =
(ms) => // HOF, aka "constructor" providing state
() => // <<-- the thunk, executes a promise //
new Promise(
(resolve) => {
console.log('start work for >>', ms, 'ms')
setTimeout(resolve, ms, ms)
}
)
View Advent7-dependencies.js
var parseLine = /Step (\w) must be finished before step (\w) can begin./;
function groupBy(col, key, data) {
if (!col[key]) col[key] = [];
col[key].push(data);
}
function noKeyForVal(byAfter) {
const afterKeys = Object.keys(byAfter).sort();
const afterVals = afterKeys.reduce((col, k) => {
You can’t perform that action at this time.