Skip to content

Instantly share code, notes, and snippets.

@Darfk
Darfk / main.go
Created September 25, 2018 23:50
channels that grow to avoid blocking on send
package main
import (
"sync"
)
func main() {
inChannel := make(chan int)
outChannel := make(chan int)

Keybase proof

I hereby claim:

  • I am darfk on github.
  • I am darfk (https://keybase.io/darfk) on keybase.
  • I have a public key whose fingerprint is 332E A6B9 2B5F BBED DA34 1CE3 21DD 6E12 BD7F 9E66

To claim this, I am signing this object:

@Darfk
Darfk / sigen.go
Created June 30, 2014 07:34
Signal Generator
package main
import (
"math"
"os/exec"
)
const (
tau float64 = math.Pi * 2
)
@Darfk
Darfk / lfsr.go
Created June 29, 2014 07:56
Linear Feedback Shift Register
package lfsr
import (
)
type LFSR struct {
buf int32
}
func NewLFSR() (r *LFSR) {
@Darfk
Darfk / scandir_recursive.php
Last active December 22, 2015 08:39
Returns a flat array of all the files in $d relative to $d.
<?php
// Returns a flat array of all the files in $d
function scandir_recursive ( $d, $b = '' )
{
$ls = scandir ( $d );
$a = array();
foreach ( $ls as $v )
{
if ( $v == '.' || $v == '..' ) continue;
@Darfk
Darfk / corrupt.py
Created August 3, 2013 08:55
Easily corrupt a file. A much better version of my previous corrupter. Tested on Python3 in Windows and Debian Linux
import argparse, subprocess
parser = argparse.ArgumentParser(description='Corrupts files.')
parser.add_argument('infile', type=str)
parser.add_argument('outfile', type=str)
parser.add_argument('-n', '--nth', metavar='N', type=int, help='corrupt every Nth byte', default=1000)
parser.add_argument('-i', '--increment', type=int, metavar='N', help='increment corrupted bytes by N', default=1)
parser.add_argument('-s', '--start', type=int, metavar='offset', help='start at corrupting at offset', default=0)
@Darfk
Darfk / framebuffer.c
Last active May 12, 2019 12:55
Mapping the Raspberry Pi's framebuffer to memory for direct access.
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <linux/kd.h>
int main (int argc, char* argv[])
@Darfk
Darfk / corrupt.py
Created September 21, 2012 14:33
Easily corrupt any file
import sys, random
if not len ( sys.argv ) > 2 :
print 'Usage: python ' + sys.argv[0] + ' seed,amount[,variant] infile [corrupted]'
exit ( 1 )
original = sys.argv[2]
# Parse the parameters
params = sys.argv[1].split ( ',' )
@Darfk
Darfk / init.el
Last active November 15, 2018 02:34
Tom's init.el
;; Tom's .emacs file or How to have a good time using emacs.
;; 2018 Edition
(require 'package)
(add-to-list 'package-archives
'("melpa-stable" . "https://stable.melpa.org/packages/"))
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/"))
(package-initialize)