Skip to content

Instantly share code, notes, and snippets.

@commenthol
commenthol / cron.sh
Created October 18, 2015 19:14
a cron job for non root
#!/bin/bash
# add the times you'd like to schedule fcmd
times=(8:00 13:00 23:00)
# your commands
fcmd() {
# add your commands here
echo "execute your commands here"
}
@commenthol
commenthol / cwd.sh
Last active January 23, 2016 07:52
get current working dir of running bash script
CWD=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
echo $CWD
echo ${CWD##*/}
@commenthol
commenthol / json.js
Created November 22, 2016 20:59
print selected JSON data on console
#!/usr/bin/env node
/**
* print selected JSON data on console
*
* using files
*
* curl https://registry.npmjs.com/mergee > /tmp/j
* json /tmp/j versions 0.2.3 name
*
@commenthol
commenthol / promisify.js
Last active February 26, 2020 13:36
promisify
const promisify = (fn) => (
(...args) => (
new Promise((resolve, reject) => {
fn(...args, (err, ...res) => {
if (err) reject(err)
else resolve(...res)
})
})
)
)
@commenthol
commenthol / small-flux-demo.js
Last active June 20, 2017 21:01
small flux demo
const EventEmitter = require('events');
const random = () => ('' + Math.random()).substr(2)
class Dispatcher extends EventEmitter {
constructor () {
super()
this.token = `dispatch_${random()}`
this.dispatch = this.dispatch.bind(this)
}
@commenthol
commenthol / findrequire.sh
Created June 24, 2017 11:30
find all required packages in a directory
#!/bin/bash
# find all required packages in a directory
# usage
# findrequire src
# findrequire src | xargs npm i -S
# findrequire test | xargs npm i -D
find $1 -iname "*.js" |\
xargs egrep -h "require\(['][^.]" |\
sed "s/.*require('\([^'']*\)').*/\1/g" |\
egrep -v "^(assert|child|cluster|events|dgram|dns|domain|fs|http|https|inspector|net|os|path|punnycode|querystring|readline|stream|string_decoder|tls|tty|udp4|url|util|v8|vm|zlib)$" |\
@commenthol
commenthol / test-ciphers.sh
Created July 13, 2017 16:47
Test Cipher Suites, find TLS Protocols
#!/usr/bin/env bash
#
# From https://superuser.com/questions/109213/how-do-i-list-the-ssl-tls-cipher-suites-a-particular-website-offers
#
# Find cipher suites a website offers
#
# Usage
#
#!/bin/bash
# rotate scanned pdf pages by 180°
# name all pages
help=$(cat <<EOS
Usage: rotate-pdf.sh IN.pdf OUT.pdf [PAGES]
Read from IN.pdf, rotate PAGES by 180° and write out to OUT.pdf
@commenthol
commenthol / geany.sh
Created June 24, 2018 11:26
start exe files from cygwin
#!/bin/bash
exe=$(cygpath -u "C:\Program Files (x86)\Geany\bin\geany.exe")
args=""
while (( "$#" )); do
arg=$1
if [[ $arg == /* ]] ; then
arg=\"$(cygpath -a -w "$arg")\"
fi
@commenthol
commenthol / server.js
Last active September 19, 2018 16:00
legacy server with logger, body-parser middlewares and connect runner
const http = require('http')
const logger = (req, res, next) => {
const time = Date.now()
res.on('finish', () => {
const {method, url, headers, body} = req
const {statusCode} = res
console.log('%s %s %s %s %j %s', method, url, statusCode, Date.now() - time, headers, JSON.stringify(body))
})
next()