Skip to content

Instantly share code, notes, and snippets.

const puppeteer = require('puppeteer-core');
(async () => {
// connect to the dockerised chrome
const browser = await puppeteer.connect({
browserURL: 'http://docker.for.mac.localhost:9222'
});
const page = await browser.newPage();
await page.goto('https://github.com/puppeteer/puppeteer', { waitUntil: 'networkidle2' });
await page.screenshot({ path: 'screenshots/example.png' });
@Juddling
Juddling / StripShortcode.php
Created July 12, 2019 00:24
Regex for removing a BB-style shortcode from content
<?php
class StripTag implements Replacement {
private $tagName;
public function __construct( string $tagName ) {
$this->tagName = $tagName;
}
public function replace( string $html ) : string {
@Juddling
Juddling / archiver.py
Created December 19, 2018 11:49
Create an archive for each directory in a given directory
import os.path
import shutil
directory = '.'
backup_directory = '_archives'
to_skip = []
def should_be_archived(file):
if not os.path.isdir(file):
return False
quicksort [] = []
quicksort (pivot:tail) = sorted_less ++ [pivot] ++ sorted_greater
where
sorted_less = quicksort [x | x <- tail, x <= pivot]
sorted_greater = quicksort [x | x <- tail, x > pivot]
main = do
putStrLn "quicksort:"
print $ quicksort [10,9..0]
from math import log, pow, factorial
def nCr(n,r):
f = factorial
return f(n) / f(r) / f(n-r)
def H(x):
# Shannon entropy / information content
sum = 0.0
task body Periodic is
Next_Release : Time;
Next_Deadline : Time;
Period : Time_Span := Milliseconds(500);
Deadline : Time_Span := Milliseconds(10);
begin
loop
select
delay until Next_Dealine;
-- deadline miss recovery code here
@Juddling
Juddling / lempel.py
Created March 30, 2016 20:33
LZ78 encoder, no decoding
import math
class Node():
def __init__(self, position, bit_string, bit):
self.position = position
self.bit_string = bit_string
self.bit = bit
self.one = None
self.zero = None
self.pointer = None
def combine(x, y):
return x + y
print(combine(2, 4))
Array
(
[0] => PhpParser\Node\Stmt\Function_ Object
(
[byRef] =>
[name] => combine
[params] => Array
(
[0] => PhpParser\Node\Param Object
(
<?php
// snippet one
function combine($x, $y) {
return $x + $y;
}
echo combine(2, 4);