Skip to content

Instantly share code, notes, and snippets.

@ericlagergren
ericlagergren / index.gohtml
Last active December 22, 2023 17:51
Hot-reloading / hot-swapping live template files in Go
My name is {{.Name}} and I'm {{.Age}} years old!!
@ericlagergren
ericlagergren / gist:231c84b9de31373ffa8d
Created January 30, 2015 01:08
gregorian to julian and back in go
package main
import (
"fmt"
"time"
)
func main() {
today := time.Now()
julian := GregorianToJulian(today.Year(), int(today.Month()), today.Day())
" Name: No Frils Dark Colorscheme
" Author: robertmeta (on Github)
" URL: https://github.com/robertmeta/nofrils
" (see this url for latest release & screenshots)
" License: OSI approved MIT license
hi clear
if exists("syntax_on")
syntax reset
endif
package main
import (
"crypto/hmac"
"crypto/sha256"
"fmt"
"hash"
"io"
"golang.org/x/crypto/hkdf"
@ericlagergren
ericlagergren / poly.c
Created February 5, 2022 19:23
POLYVAL x86_64
#include <immintrin.h>
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
// hi lo
// Vd, Vn, Vm, #imm
#define vext8(x, y) ({ \
uint64_t xhi = _mm_extract_epi64((x), 1); \
uint64_t ylo = _mm_extract_epi64((y), 0); \
@ericlagergren
ericlagergren / poly.c
Created January 31, 2022 23:54
POLYVAL ARMv8
#include <arm_neon.h>
#include <stdint.h>
typedef uint8x16_t u128;
#define pmullq_u8(a, b) ({ \
u128 r; \
__asm__ __volatile__("pmull %0.1q, %1.1d, %2.1d \n\t" \
: "=w"(r) \
: "w"((a)), "w"((b))); \
@ericlagergren
ericlagergren / gist:ebed1dcf846db354bdb5
Created March 28, 2015 07:30
simple ioctl FIONREAD example.
package main
import (
"fmt"
"os"
"syscall"
"unsafe"
)
var (
@ericlagergren
ericlagergren / spectre.c
Created January 4, 2018 03:57 — forked from ErikAugust/spectre.c
Spectre example code
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#ifdef _MSC_VER
#include <intrin.h> /* for rdtscp and clflush */
#pragma optimize("gt",on)
#else
#include <x86intrin.h> /* for rdtscp and clflush */
#endif
/*-------, .-------*
| +----------------------+ |
*----| THE REALTIME GUILD |----*
`*--------------------*/
#ifndef ListH
#define ListH
#include <stdlib.h>
#include <string.h>
#define LIST_DECLARE_EX(n,t,r) \
typedef struct list_##n { t* v; unsigned c, a; } list_##n; \
void list_init_##n (list_##n * list); \
void list_clear_##n (list_##n * list); \