Skip to content

Instantly share code, notes, and snippets.

View mertenvg's full-sized avatar
🤖
when in doubt, just use Go

Merten van Gerven mertenvg

🤖
when in doubt, just use Go
View GitHub Profile
@mertenvg
mertenvg / example.go
Last active March 6, 2016 18:36
An example of handling errors using a task list
package main
import (
"errors"
"fmt"
)
// Task represents a callable task to be executed
type Task func() error
@mertenvg
mertenvg / work-example-two.go
Created March 6, 2016 15:08
An example of handling errors using a task list
package main
import (
"errors"
"fmt"
)
// Task represents a callable task to be executed
type Task func()
@mertenvg
mertenvg / start-ssh-agent.sh
Created February 2, 2016 10:36
Add to ~/.bash_profile to start ssh-agent when starting a terminal
SSH_ENV="$HOME/.ssh/environment"
function start_agent {
echo "Initialising new SSH agent..."
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
echo succeeded
chmod 600 "${SSH_ENV}"
. "${SSH_ENV}" > /dev/null
/usr/bin/ssh-add;
}
@mertenvg
mertenvg / main.go
Last active January 30, 2016 01:31
Method values and method expressions play
// http://play.golang.org/p/YbcN6-hLq-
//
package main
import "fmt"
type Methoder interface{
Method()
}
git ls-files --stage | grep 160000
@mertenvg
mertenvg / chain-callback-func-list.js
Created July 14, 2015 12:00
Chain the actions and callbacks so with the final callback is the final function called in the chain. fw -> f1 -> fw -> f2 -> fw -> f3 -> callback
var gtmActions = {
"a": function (callback) {
console.log("a");
window.setTimeout(callback, 500)
},
"b": function (callback) {
console.log("b");
window.setTimeout(callback, 500)
},
"c": function (callback) {
@mertenvg
mertenvg / current-tag.sh
Created December 29, 2014 12:17
Retrieve the current git tag from HEAD
git name-rev --tags --name-only $(git rev-parse HEAD)
@mertenvg
mertenvg / mkv2mp4.sh
Last active April 30, 2019 21:56
Convert *.mkv to *.mp4 with ffmpeg
ls *.mkv | sed -E -e 's/^(.+)[.][^.]+$/ffmpeg -i "&" -vcodec copy -acodec aac "\1.mp4"/g' | sh
@mertenvg
mertenvg / autoscroll-into-view
Created July 27, 2014 14:02
Scroll to anchor with same name as current page. Uses jQuery.
/*
* Scroll to page section if it exists, but delay for a bit first.
*/
var page = location.href.replace(/^.+?\/?([^\/]+)$/i, '$1')
, delay = 500
, offset = -50
, $anchor;
if (page && ($anchor = $('a[name="'+page+'"]')).length) {
$('html,body').delay(delay).animate({scrollTop: $anchor.offset().top + offset}, 'slow');
@mertenvg
mertenvg / polyfill.bind.js
Last active April 26, 2024 04:52
Function bind(obj[, arg1[, arg2[, ...]]]) polyfill
if (typeof Function.prototype.bind === 'undefined') {
/**
* Function bind(obj[, arg1[, arg2[, ...]]]) polyfill
*
* @param obj
*
* @returns {Function}
*/
Function.prototype.bind = function (obj) {
var fn = this,