Skip to content

Instantly share code, notes, and snippets.

View reqshark's full-sized avatar
🪂
ridge soaring

Bent Cardan reqshark

🪂
ridge soaring
View GitHub Profile
@reqshark
reqshark / ip.js
Last active May 6, 2017 10:37
get your ips
const ip_regex = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/
const digits = /^\d\d\.|^\d\d\d\./g
const local = /^127\.|^10\.|^172\.1[6-9]\.|^172\.2[0-9]\.|^172\.3[0-1]\.|^192\.168\./g
const RTCPeerConnection = window.RTCPeerConnection
|| window.mozRTCPeerConnection || window.webkitRTCPeerConnection
ipaddr(function(addr1){
console.log(addr1)
setTimeout(function(){
@reqshark
reqshark / cal.js
Last active March 8, 2017 10:20
the calendar
const days = [ 's', 'm', 't', 'w', 't', 'f', 's' ]
const today = new Date(Date.now())
// calsz, for conducting hypertext markup language measurements
const calsz = [ 0 ]
// generate a calendar year
const calendar = yr ( today.getFullYear() )
@reqshark
reqshark / git.sh
Created February 17, 2017 10:05
damn it! committed to the wrong branch again...
# FIX TRIGGER HAPPY COMMIT TO WRONG BRANCH:
# ----------
git reset --soft HEAD^
git checkout branch
git commit
# DELETE TAG
# ----------
git tag -d 12345
git push origin :refs/tags/12345
@reqshark
reqshark / dsock_http.c
Created February 16, 2017 13:14
first try dsock http
//cc main.c $CFLAGS $LDFLAGS -ldill $opt/lib/libdsock.a -o server && ./server
#include <libdill.h>
#include <dsock.h>
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@reqshark
reqshark / parseURL.js
Created January 27, 2017 19:46
parse url
function parseURL (url) {
var div = document.createElement('div');
div.innerHTML = '<a></a>';
div.firstChild.href = url; // Ensure href is properly escaped
div.innerHTML = div.innerHTML; // Run current innerHTML back through parser
return div.firstChild.origin || '//' + div.firstChild.hostname; // or case is for IE
}
@reqshark
reqshark / from.args.js
Created January 21, 2017 06:01
`$ ls -la` to list files on unix. for success, call process.exit with zero
const n = [ 'error', 'stdout', 'stderr' ]
require('child_process').exec('ls -la', function output () {
return []
.slice
.call ( arguments ) // or do [].from(arguments)
.reduce ( ( p, c, i ) => {
if ( c )
console.log(`\n\n${n[i]}:\n\n${c}`)
return p
}, process.exit ) ( 0 )
@reqshark
reqshark / bld.js
Created January 21, 2017 04:49
my javascript build system: more front-end shenanigans
// $ npm i nanomsg browserify es6ify stylus
// $ node bld
const createWriteStream = require('fs').createWriteStream
const readFileSync = require('fs').readFileSync
const writeFile = require('fs').writeFile
const resolve = require('path').resolve
const browserify = require('browserify')
const join = require('path').join
const watch = require('fs').watch
@reqshark
reqshark / killthatthing.js
Created October 13, 2016 19:42
stream talk
/**
* Readable Stream
*/
require('util').inherits( _rs, require('stream').Readable );
function _rs ( fn ) {
this._read = function(){};
require('stream').Readable.call( this, { objectMode: true } );
}
function rs ( fn ) {
@reqshark
reqshark / when.js
Created September 30, 2016 09:45
when was that?
/**
* `_ (27).daysago`
* returns date notation n days ago
*/
exports._ = n => { // 86400000 == 24 hrs
return { daysago : new Date( Date.now() - (n * 86400000) )};
}
@reqshark
reqshark / suuid.js
Last active September 29, 2016 02:05
small identifier derived from a single UUID 8 character hex component
console.log( suuid() ); // somethiing like 'e1bdadd6'
function suuid() {
var sm = [], i = 256;
while (i--)
sm[ i ] = ( i < 16 ? '0' : '' ) + ( i ).toString( 16 );
var uu = Math.random() * 0xffffffff | 0;
return sm[ uu & 0xff ] +
sm[ uu >> 8 & 0xff ] +
sm[ uu >> 16 & 0xff ] +