Skip to content

Instantly share code, notes, and snippets.

View prattmic's full-sized avatar

Michael Pratt prattmic

View GitHub Profile
@prattmic
prattmic / go.mod
Created December 6, 2023 21:05
Weighted profile merge
module example.com/weighted-merge
go 1.21
require (
github.com/chzyer/readline v1.5.1 // indirect
github.com/google/pprof v0.0.0-20231205033806-a5a03c77bf08 // indirect
github.com/ianlancetaylor/demangle v0.0.0-20230524184225-eabc099b10ab // indirect
golang.org/x/sys v0.6.0 // indirect
)
@prattmic
prattmic / main.S
Last active March 10, 2018 18:08
Standalone binary
/* x86-64 Linux only! */
#define __NR_exit_group 231
.text
.global foobar
foobar:
movq $__NR_exit_group, %rax
movq $42, %rdi
@prattmic
prattmic / BUILD
Created February 25, 2016 05:01
Bazel external Skylark error
load("@nanopb//:nanopb.bzl", "nanopb_cpp_library")
nanopb_cpp_library(
name = "test",
proto = "test.proto",
)
@prattmic
prattmic / .gitignore
Last active January 30, 2016 23:55
Sphinx bug
venv/
_build/
@prattmic
prattmic / camel_case.py
Last active August 29, 2015 14:25
camelCase to snake_case
#!/usr/bin/env python2
import argparse
import re
import fileinput
# Match a camelCaseName in a context it might be expected:
# ' ' -> 'def camelCaseName'
# '.' -> 'self.camelCaseName'
# '_' -> 'test_camelCaseName'
main: file format elf32-littlearm
Disassembly of section .text:
08000000 <main>:
8000000: f240 0068 movw r0, #104 ; 0x68
8000004: f6c0 0000 movt r0, #2048 ; 0x800
8000008: f890 1021 ldrb.w r1, [r0, #33] ; 0x21
@prattmic
prattmic / gist:d36a1fd233299e0b5e29
Created October 10, 2014 01:01
Reading bytes from file
use std::io::BufferedReader;
use std::io::File;
use std::os;
fn main() {
let args = os::args();
if args.len() < 2 {
println!("Provide a file to read!");
return;
@prattmic
prattmic / iter.rs
Created September 15, 2014 00:16
Iterate over strings
// Based on https://github.com/kmcallister/rust/blob/8ccbf4f2d4c6d0755b6460d0b0809e442af2bd6d/src/test/run-pass/format-no-std.rs
#![feature(phase)]
#![no_std]
#[phase(plugin, link)]
extern crate core;
#[phase(plugin, link)]
extern crate collections;
@prattmic
prattmic / code.txt
Created September 8, 2014 01:08
Inner scope initialization
int main(int argc, char **argv) {
400506: 55 push %rbp
400507: 48 89 e5 mov %rsp,%rbp
40050a: 48 83 ec 20 sub $0x20,%rsp
40050e: 89 7d ec mov %edi,-0x14(%rbp)
400511: 48 89 75 e0 mov %rsi,-0x20(%rbp)
int x = 1;
400515: c7 45 fc 01 00 00 00 movl $0x1,-0x4(%rbp)
if (x) {
@prattmic
prattmic / Makefile
Created September 8, 2014 00:50
container_of() macro bug
all: unoptimized optimized
unoptimized:
gcc -o $@ fun.c
optimized:
gcc -O2 -o $@ fun.c