Skip to content

Instantly share code, notes, and snippets.

@snoj
snoj / DOM3D.js
Created March 27, 2024 17:39 — forked from OrionReed/dom3d.js
3D DOM viewer, copy-paste this into your console to visualise the DOM topographically.
// 3D Dom viewer, copy-paste this into your console to visualise the DOM as a stack of solid blocks.
// You can also minify and save it as a bookmarklet (https://www.freecodecamp.org/news/what-are-bookmarklets/)
(() => {
const SHOW_SIDES = false; // color sides of DOM nodes?
const COLOR_SURFACE = true; // color tops of DOM nodes?
const COLOR_RANDOM = false; // randomise color?
const COLOR_HUE = 190; // hue in HSL (https://hslpicker.com)
const MAX_ROTATION = 180; // set to 360 to rotate all the way round
const THICKNESS = 20; // thickness of layers
const DISTANCE = 10000; // ¯\\_(ツ)_/¯
@snoj
snoj / index.js
Created May 24, 2023 23:48
IPFS livestreaming
import bodyParser from 'body-parser';
import express from 'express'
import * as _ from 'lodash';
import * as IPFS from 'ipfs-client';
import Queue from 'promise-queue';
import xmlp from 'fast-xml-parser';
import { readFileSync } from 'fs';
const app = express()
const port = 3000
@snoj
snoj / extractpfx.php
Created February 12, 2016 15:24
Extract certificates and key from PFX.
<?php
//Requires php with the openssl module.
//This is useful for instances where installing openssl isn't an option
// but PHP is available, like on Windows servers using WAMP.
//use php extractpfx.php /path/tocert.pfx "pass phrase"
//http://php.net/manual/en/function.openssl-pkcs12-read.php
if(file_exists($argv[1])) {
$rawpfx = file_get_contents($argv[1]);
@snoj
snoj / example1.js
Created September 15, 2019 01:34
multiple asc/desc sort
function comp(a, b, n) {
let p1,p2,ret;
ret = 0;
ret += a < b;
ret -= a > b;
ret = convert(ret ? ret : 0, n);
return ret
p1 = ((a<b)/2);
@snoj
snoj / archive.to.sh
Created May 16, 2019 21:33
archiving tweets shell scripts
#!/bin/bash
turl="$1"; #`php -r "echo urlencode(\$argv[1]);" "$1"`;
enurl=`php -r "echo urlencode('$turl');"`;
#php -r "echo urlencode(\$argv[1]);" "$1" ; # $turl;
aurl="https://archive.is/?run=1&url=$enurl";
$video = "path/to/source/file.mp4";
$video_extension = "mp4"; ##This must match what the source file has. eg. if it's flv, use that.
$output_directory = "output/directory/video"; ##destination folder for 2 hour chunks
$ffmpegEXE = "path/to/ffmpeg.exe";
for($i = 0; $i -lt 13; $i++) {
& $ffmpegEXE -i $video -ss ("{0}:00:00" -f (($i)*2)) -t "2:0:0" -c copy ("{0}_{1}.{2}" -f $output_directory, ($i+1), $video_extension);
}
#!/bin/bash
tuser="TWITTERUSERNAME";
searchurl="https://twitter.com/search?f=tweets&vertical=default&q=from%3A$tuser&src=typd"
curl -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36" -s "$searchurl" | pup "a[href*=$tuser/status] attr{href}" 2>/dev/null | xargs -I {} archive.to "https://twitter.com{}"
@snoj
snoj / function.bindMap.js
Created November 4, 2017 21:08
For when you're stuck in the middle
Function.prototype.bindMap = function(context) {
function nullfilter(v) { return v != null; }
function isnotfalse(v) { return v !== false; }
function getUndefinedIndex(v, i, a) { return typeof a[i] == 'undefined' ? i : false; }
var self = this;
var args = Array.prototype.slice.call(arguments, 1);
var unargs = args.map(getUndefinedIndex).filter(isnotfalse);
return function() {
@snoj
snoj / promise-series.js
Created November 4, 2017 19:04
Promise.series
//Run an array of values in series.
//Non-functions are wrapped in Promise.resolve().
//Functions are passed to the Promise constructor. (eg new Promise(myFunction);)
//Series order starts from 0.
Promise.series = function PromiseSeries(promises) {
function assignTo(o, k) {
return function(v) {
o[k] = v;
return v;
};
@snoj
snoj / index.js
Last active March 30, 2017 05:28
hamstrings
function FromRight(str1, str2) {
var longest, tmpshortest, shortest;
if(str1.length != str2.length) {
if(str1.length > str2.length) {
longest = str1;
tmpshortest = str2;
} else {
longest = str2;
tmpshortest = str1;
}