Skip to content

Instantly share code, notes, and snippets.

Avatar

Hugo Wetterberg hugowetterberg

View GitHub Profile
View check_iptc_encoding
#!/bin/bash
set -e
exec 3>&1 # make stdout available as fd 3 for the result
exec 1>&2 # redirect all output to stderr for logging
image=$1
debug='n'
# Check if the first parameter was '-v' then we check for the image in
View keybase.md

Keybase proof

I hereby claim:

  • I am hugowetterberg on github.
  • I am hugo_wetterberg (https://keybase.io/hugo_wetterberg) on keybase.
  • I have a public key ASD3IFtKQe-HrHLTQv01rHzYdxTr_3H7P07qSHdyu_Jyggo

To claim this, I am signing this object:

@hugowetterberg
hugowetterberg / listdiff.js
Created Jan 15, 2016
Brute force diff & patch lists
View listdiff.js
function fixup(a, b) {
console.log(a, '=>', b);
var add = [];
var remove = [];
for (var i = 0; i < a.length; i++) {
if (b.indexOf(a[i]) == -1) {
remove.push(a[i]);
}
}
for (var i = 0; i < b.length; i++) {
@hugowetterberg
hugowetterberg / utf8buffer.js
Created Nov 30, 2015
A test of utf8-encoding in javascript
View utf8buffer.js
// https://github.com/beatgammit/base64-js
var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
;(function (exports) {
'use strict'
var Arr = (typeof Uint8Array !== 'undefined')
? Uint8Array
: Array
View callback_scoping.js
function test() {
for (var i=0;i < 5;i++) {
console.log('orig: '+ i);
doStuff(i);
}
function doStuff(i) {
setTimeout(function debugLogging() {
console.log('cb: '+ i);
}, 100);
@hugowetterberg
hugowetterberg / uuid4.js
Last active Aug 16, 2018
Simple "spec-driven" v4 UUID implementation
View uuid4.js
// Version 4 UUIDs have the form xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx where
// x is any hexadecimal digit and y is one of 8, 9, A, or B (e.g.,
// f47ac10b-58cc-4372-a567-0e02b2c3d479).
// See: http://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_.28random.29
function uuid() {
var reservedBitValues = ['8','9','a','b'];
return Array.prototype.map.call("xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx", function mapUUID(c) {
if (c == "x") {
return Math.round(Math.random()*16-0.5).toString(16);
}
View t.js
var hasLanguage = true;
var lang = {
greeting: 'Hello __name__, welcome to __placeHTML__!'
};
var langReplace = /__([^\s]+)__/g;
var entityReplace = /[<>&]/g;
var entities = {
'<': '&lt;',
'>': '&gt;',
@hugowetterberg
hugowetterberg / JsonStream.php
Created Nov 29, 2012
Streaming JSON serializer
View JsonStream.php
<?php
define('JSON_STREAM_ERROR_OOO', 1);
class JsonStreamException extends Exception {
private $json_state;
public function __construct($message = "", $code = 0, $state = NULL, $previous = NULL) {
parent::__construct($message, $code, $previous);
$this->json_state = $state;
}
@hugowetterberg
hugowetterberg / geo-distance.coffee
Created Nov 3, 2011
Converts the distance between the WGS 84 coordinates pointA and pointB to meters.
View geo-distance.coffee
###
Converts the distance between the WGS 84 coordinates pointA and pointB to meters.
Ported from http://groups.google.com/group/sci.geo.satellite-nav/msg/0bfca0bf8a986395
with the suggested radii-calculation optimization.
###
module.exports.WGS84DegreesToMeters = (pointA, pointB)->
radFactor = Math.PI/180
[lat1, lon1] = [pointA[0]*radFactor, pointA[1]*radFactor]
[lat2, lon2] = [pointB[0]*radFactor, pointB[1]*radFactor]
@hugowetterberg
hugowetterberg / gist:796784
Created Jan 26, 2011
Reading the reference from HEAD in a git repo at path
View gist:796784
-(NSString*)currentBranch {
const char *refAnfang = "ref: ";
NSString *branch;
const char *filename = [[path stringByAppendingPathComponent:@"HEAD"] cStringUsingEncoding:NSUTF8StringEncoding];
FILE *file = fopen (filename, "r");
if (file != NULL) {
char line [256];
if (fgets(line, sizeof line, file) != NULL) {
line[strlen(line)-1] = 0;
You can’t perform that action at this time.