Skip to content

Instantly share code, notes, and snippets.

Avatar

Lars Wiegman namsral

View GitHub Profile
View mach_absolute_time.s
// Source from the xnu kernel used in macOS
// source https://opensource.apple.com/source/xnu/xnu-3248.60.10/libsyscall/wrappers/mach_absolute_time.s
.globl _mach_absolute_time
_mach_absolute_time:
pushq %rbp // set up a frame for backtraces
movq %rsp,%rbp
movq $(_COMM_PAGE_TIME_DATA_START),%rsi
1:
movl _NT_GENERATION(%rsi),%r8d // get generation
testl %r8d,%r8d // if 0, data is being changed...
View gist:c535fd258ddf94c272c4824244065986
Control group /:
-.slice
├─624 /sbin/cgmanager -m name=systemd
├─machine.slice
│ └─machine-rkt\x2d6ff19b11\x2d0075\x2d48c6\x2d95e1\x2dc632da796d4e.scope
│ ├─init.scope
│ │ └─13469 /usr/lib/systemd/systemd --default-standard-output=tty --log-target=null --show-status=0
│ └─system.slice
│ ├─nginx.service
│ │ ├─13490 nginx: master process /usr/sbin/nginx -g daemon off
@namsral
namsral / go.snippets
Created Oct 5, 2016
Go table-driven tests snippets for vim ultisnips
View go.snippets
snippet tt "table-driven tests"
func Test${1:Func}(t *testing.T) {
testCases := []struct {
${2:input} ${3:Type}
want ${4:Type}
}{
{$2: ${5:""}, want: ${6:""}},${0: // comment}
}
for _, tc := range testCases {
if got := $1(tc.$2); got != tc.want {
@namsral
namsral / person.go
Last active Sep 6, 2016
Example of a getter and setter in a single method
View person.go
package person_test
import (
"fmt"
"strings"
)
// Person is a modern human with a name.
type Person struct {
name string
@namsral
namsral / ziphttpd.go
Last active Oct 16, 2017
Deploy and serve assets from a zip archive
View ziphttpd.go
package main
import (
"archive/zip"
"flag"
"log"
"net/http"
"golang.org/x/tools/godoc/vfs/httpfs"
"golang.org/x/tools/godoc/vfs/zipfs"
@namsral
namsral / Random Password Generator
Created Mar 18, 2014
Random password generator with a default entropy of 84 bits.
View Random Password Generator
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os, string
def random_password(length=14):
"""
Random password generator.
Default generated password will have an entropy of 84 bits.
@namsral
namsral / gist:7673054
Last active Dec 29, 2015
Account Authentication Example
View gist:7673054
POST /api/authenticate
> Content-Type: application/x-www-form-urlencoded
>
user=lars,pass=secret
< 200 OK
<
{
"token": "897ca80f3443de1ad9c0ce8f9d7c4449c68606e0"
}
@namsral
namsral / Bindings.plist
Created Mar 8, 2012
TexMate icon bindings preference file
View Bindings.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>icon-template</key>
<array>
<string>tmpl</string>
</array>
<key>icon-xml</key>
<array>
@namsral
namsral / gist:1775417
Created Feb 8, 2012
Testing AngularJS
View gist:1775417
// service.js
angular.service('Address', function($resource, $cookies, $xhr, $log) {
// Add Header to comply with Django's CSRF implementation
token = $cookies['csrftoken'];
$xhr.defaults.headers['delete']['X-CSRFToken'] = token;
return $resource('/api/user/address/:addressId', {addressId:'@id'}, {});
});
@namsral
namsral / zippy.html
Created Feb 3, 2012
Zippy example from the Angular.js talk at HTML5 Dev Conf
View zippy.html
<!doctype html>
<html xmlns:ng="http://angularjs.org">
<meta charset="UTF-8" />
<script src="http://code.angularjs.org/angular-0.9.19.min.js" ng:autobind></script>
<body>
<zippy class="open">
<header>Greeting</header>
<pane>Hello World!</pane>
</zippy>