Skip to content

Instantly share code, notes, and snippets.

View perillo's full-sized avatar

Manlio Perillo perillo

  • Avellino, Italy
View GitHub Profile
@perillo
perillo / unkill
Last active August 29, 2015 14:11
/*
* Create an input/output character device that will put in an
* uninterruptible sleep state the user process that opens it.
*
* Copyright 2014 Manlio Perillo. All rights reserved.
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
@perillo
perillo / last-line.go
Last active August 29, 2015 14:11
last-line
// Read each line from a reader, and report the number of lines until EOF,
// as a negative integer, for the last N lines.
//
// Copyright Manlio Perillo (manlio.perillo@gmail.com)
package main
import (
"bufio"
"bytes"
"fmt"
@perillo
perillo / string-ref.go
Created December 31, 2014 15:21
string-ref.go
// Check generate assembler with
// go tool 6g -S src/string-ref.go
package main
import (
"fmt"
"unsafe"
)
func do(b []byte) {
@perillo
perillo / syncc.py
Created March 8, 2015 19:10
Synchronous call an asynchronous, callback based, function
#!/usr/bin/env python3
import threading
import time
def syncc(f, *args, **kwargs):
"""syncc calls the asynchronous function f with supplied
parameters, waiting until the function callback is called, and returning
the received parameters.
"""
@perillo
perillo / unix-perms.go
Last active October 10, 2015 10:36
Parsing Unix permissions string
// https://gist.github.com/perillo/4bda8e2f57bc3bd16dbc
package main
import (
"fmt"
"log"
"os"
)
@perillo
perillo / atexit.go
Last active November 17, 2015 09:17
// Copyright 2015 Manlio Perillo. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
// Package atexit implements support for running deferred functions in case of
// abnormal exit (in contrast to a normal exit when the program returns from
// the main function).
//
// Since calling os.Exit, e.g. during a signal handler, does not call deferred
// functions, a complementary mechanism is required when the program acquires
@perillo
perillo / errors.go
Last active November 23, 2015 14:45
Go errors with source file and line number
package errors
import (
"errors"
"fmt"
"runtime"
)
type errorDebug struct {
error
package main
import (
"fmt"
"time"
)
func producer(ch chan<- int) {
ch <- 0
}
package main
import (
"fmt"
"time"
"unsafe"
)
func producer(ch chan<- int) {
ch <- 777