Skip to content

Instantly share code, notes, and snippets.

@cflems
cflems / hook.js
Last active August 16, 2017 17:13
// npm install githubhook
const githubhook = require('githubhook');
const exec = require('child_process').exec;
let config = {
ip: '0.0.0.0',
port: 1234,
url: '/push',
secret: 'whatever',
branch: 'master',
@cflems
cflems / aggressive_scrape.js
Created August 11, 2017 18:59
Obtain a local copy of any static website. Background images and some references may not work properly.
const http = require('http');
const https = require('https');
const fs = require('fs');
const path = require('path');
const url = require('url');
const exec = require('child_process').execSync;
const jq = require('jquery');
const jsdom = require('jsdom');
const SAVE_DIR = path.dirname(__filename)+'/scrape';
@cflems
cflems / hook.php
Created August 17, 2017 04:33
PHP Github Webhook Template
<?php
function sh ($cmd, $cwd) {
$descriptorspec = array(
1 => array('pipe', 'w'), // stdout is a pipe that the child will write to
2 => array('pipe', 'w') // stderr
);
$resource = proc_open($cmd, $descriptorspec, $pipes, $cwd);
if (is_resource($resource)) {
$output = stream_get_contents($pipes[2]);
$output .= PHP_EOL;
@cflems
cflems / linestyle.js
Created October 24, 2017 18:33
Comb for lines that create difficulty reading code.
const readline = require('readline');
const colors = require('colors');
const rl = readline.createInterface({
input: process.stdin,
});
let line = 1, warn = 0;
rl.on('line', (ln) => {
if (ln.length > 80) console.warn(('#'+(++warn)+' ').red.bold
@cflems
cflems / fwgc.pro
Last active December 13, 2021 14:41
Solution to the farmer/wolf/goat/cabbage problem in Prolog.
cross(w, e).
cross(e, w).
execmove([F, W, G, C], 0, [NF, NW, NG, NC]) :- F = W,
cross(F, NF),
cross(W, NW),
NG = G,
NC = C.
execmove([F, W, G, C], 1, [NF, NW, NG, NC]) :- F = G,
cross(F, NF),
@cflems
cflems / boost.rb
Created July 10, 2019 18:11
Boost 1.69.0 brew formula
class Boost < Formula
desc "Collection of portable C++ source libraries"
homepage "https://www.boost.org/"
url "https://dl.bintray.com/boostorg/release/1.69.0/source/boost_1_69_0.tar.bz2"
sha256 "8f32d4617390d1c2d16f26a27ab60d97807b35440d45891fa340fc2648b04406"
head "https://github.com/boostorg/boost.git"
bottle do
cellar :any
end
@cflems
cflems / getopt.c
Created October 20, 2020 01:06
How to use getopt_long to parse a standard argument list in C.
#include <unistd.h>
#include <getopt.h>
#include <stdio.h>
const struct option longopts[] = {
{"chdir", no_argument, NULL, 'd'},
{"noclose", no_argument, NULL, 'n'},
{"log-stdout", required_argument, NULL, '1'},
{"log-stderr", required_argument, NULL, '2'},
{0, 0, 0, 0}
@cflems
cflems / base32_decode.js
Created July 15, 2022 06:11
Portable and compact JavaScript base32 encoding/decoding functions that I found on the internet
function decode(s) {
const len = s.length;
const apad = 'abcdefghijklmnopqrstuvwxy1234567z';
let v,x,r=0,bits=0,c,o='';
s = s.toUpperCase();
for(i=0;i<len;i+=1) {
v = apad.indexOf(s.charAt(i));
if (v>=0 && v<32) {
@cflems
cflems / obfuscator.js
Last active December 12, 2022 10:01
Obfuscate JavaScript code into having zero readable characters; I want to improve this not to use eval at all but I'll have to write a JS tokenizer for that.
const zero = '+[]'; // 1
const one = '+!![]'; // 1
const two = '('+ one + one +')'; // 2
const three = '('+ one + one + one +')'; // 3
const four = '('+ one + one + '<<' + one +')'; // 3
const five = '('+ four + one +')'; // 4
const six = '('+ one + one + one + '<<' + one +')'; // 4
const seven = '('+ six + one +')';
const eight = '('+ one + one + '<<' + one + one +')'; // 4
const int_lits = {0: zero, 1: one, 2: two, 3: three, 4: four, 5: five, 6: six, 7: seven, 8: eight};
@cflems
cflems / eml.js
Created December 28, 2022 12:56
Simple-JS email protection scheme to prevent harvesting (when not running Cloudflare, which has this built in already.)
const key = 0x90;
function protect_email(email) {
bytes = []
for (char of email) {
bytes.push(String.fromCharCode(char.charCodeAt(0) ^ key));
}
return btoa(bytes.join(''));
}