Skip to content

Instantly share code, notes, and snippets.

@cflems
cflems / fwgc.pro
Last active Jan 17, 2018
Solution to the farmer/wolf/goat/cabbage problem in Prolog.
View fwgc.pro
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 / linestyle.js
Created Oct 24, 2017
Comb for lines that create difficulty reading code.
View linestyle.js
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 / hook.php
Created Aug 17, 2017
PHP Github Webhook Template
View hook.php
<?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 / aggressive_scrape.js
Created Aug 11, 2017
Obtain a local copy of any static website. Background images and some references may not work properly.
View aggressive_scrape.js
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';
View hook.js
// 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',
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.