Skip to content

Instantly share code, notes, and snippets.

View AndersDJohnson's full-sized avatar

Anders D. Johnson AndersDJohnson

View GitHub Profile
@AndersDJohnson
AndersDJohnson / file-size.sh
Last active June 5, 2022 15:24
shell get download content-length
#! /bin/bash
# get download file size
URL=$1
curl -sI "${URL}" | grep "Content-Length" | cut -d ' ' -f 2
@AndersDJohnson
AndersDJohnson / add-event-listener.js
Last active November 23, 2019 11:28
javascript cross-browser add event listener
function bindEvent(el, eventName, eventHandler) {
if (el.addEventListener){
el.addEventListener(eventName, eventHandler, false);
} else if (el.attachEvent){
el.attachEvent('on'+eventName, eventHandler);
}
}
// ...
bindEvent(document.getElementById('myElement'), 'click', function () {
alert('element clicked');
@AndersDJohnson
AndersDJohnson / wget-download-website.sh
Last active June 5, 2019 13:33
wget download websites for off-line viewing
wget --recursive --domains gnupg.org --no-parent --page-requisites --html-extension --convert-links --restrict-file-names=windows --no-clobber
@AndersDJohnson
AndersDJohnson / generate-ssl-cert.sh
Last active June 5, 2019 13:33
SSL certificate
# See: http://www.houseofding.com/2008/11/generate-a-self-signed-ssl-certificate-for-local-development-on-a-mac/
# Gen­er­ate a host key
ssh-keygen -f host.key
# Gen­er­ate a cer­tifi­cate request file
openssl req -new -key host.key -out request.csr
# Cre­ate a self-signed SSL cer­tifi­cate using the request file.
openssl x509 -req -days 365 -in request.csr -signkey host.key -out server.crt
@AndersDJohnson
AndersDJohnson / text.txt
Last active June 5, 2019 13:33
gist for INET 3102
Here are some contents.
@AndersDJohnson
AndersDJohnson / text.txt
Last active June 5, 2019 13:33
gist for INET 3102
Here are some contents.
@AndersDJohnson
AndersDJohnson / text.txt
Last active June 5, 2019 13:33
gist for INET 3102
Here are some contents.
@AndersDJohnson
AndersDJohnson / Set.coffee
Last active June 5, 2019 13:33
Sets in JS
_ = require 'underscore'
class Set
constructor: (opts = {}) ->
@items = {}
@fromArray = (arr) ->
set = new Set()
for item in arr
set.add(item)
#!/usr/bin/env coffee
argv = require('optimist')
.alias('s', 'selector')
.default('s', ':root')
.argv
JSONSelect = require('JSONSelect')
# eyes = require('eyes')
# inspect = -> eyes.inspect.apply(eyes, arguments)
@AndersDJohnson
AndersDJohnson / clone.js
Last active June 5, 2019 13:33
js cloning
// inspired by https://github.com/bestiejs/lodash/blob/master/lodash.js
// but supports cloning custom constructor instances
// still need to implement Date, RegExp
//If Object.create isn't already defined, we just do the simple shim, without the second argument,
//since that's all we need here
var Object_create = Object.create;
if (typeof Object_create !== 'function') {
Object_create = function(o) {
function F() {}