Skip to content

Instantly share code, notes, and snippets.

View glennklockwood's full-sized avatar

Glenn K. Lockwood glennklockwood

View GitHub Profile
@glennklockwood
glennklockwood / dmidecode.txt
Last active December 17, 2019 11:23
iMac 2017 Hardware
ubuntu@ubuntu:~$ sudo dmidecode
# dmidecode 3.0
Getting SMBIOS data from sysfs.
SMBIOS 3.0.0 present.
Table at 0x8AF1D000.
Handle 0x0000, DMI type 16, 23 bytes
Physical Memory Array
Location: System Board Or Motherboard
Use: System Memory
@glennklockwood
glennklockwood / omp_binding.c
Created January 4, 2017 06:12
Test to display how OpenMP threads are bound
#include <stdio.h>
#include <sched.h>
int main( int argc, char**argv )
{
#pragma omp parallel
{
printf( "Hello world from thread %d of %d running on cpu %2d!\n",
omp_get_thread_num()+1,
omp_get_num_threads(),
@glennklockwood
glennklockwood / simple_transistor_exp.py
Last active October 30, 2016 01:05
MCP3008 and MCP41010 Transistor Experimentation
#!/usr/bin/env python
"""Vary resistance on a digital potentiometer and measure the effect using
an analog-digital converter"""
import spi # from https://github.com/glennklockwood/raspberrypi
import time
### use two independent SPI buses, but daisy chaining then is also valid
adc = spi.SPI(clk=18, cs=25, mosi=24, miso=23, verbose=False)
digipot = spi.SPI(clk=19, cs=13, mosi=26, miso=None, verbose=False)
@glennklockwood
glennklockwood / terrible.md
Last active May 29, 2020 13:13
Why Python is terrible
@glennklockwood
glennklockwood / max7219-column2.py
Last active October 15, 2016 21:44
Turn on/off individual LEDs on a 8x8 matrix driven by MAX7219
#!/usr/bin/env python
import spi
### Initialize an SPI connection using BCM-mode pins 21, 20, and 16
max7219 = spi.SPI(clk=21, cs=20, mosi=16, miso=None, verbose=True)
### Zero out all registers
for cmd in range(16):
packet = cmd << 8
@glennklockwood
glennklockwood / basic_cd4017be.py
Created October 9, 2016 22:23
Basic CD4017BE implementation for Raspberry Pi
#!/usr/bin/env python
import RPi.GPIO as GPIO
input_pin = 14
output_pins = [22, 17, 5, 6, 13, 12, 25, 24, 27, 23]
GPIO.setmode(GPIO.BCM)
GPIO.setup(input_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
for pin in output_pins:
GPIO.setup(pin, GPIO.OUT)
i = 0
@glennklockwood
glennklockwood / drop_file_from_page_cache.c
Created July 22, 2016 03:28
Drop a file from page cache
#define _XOPEN_SOURCE 600
#include <unistd.h>
#include <fcntl.h>
int main(int argc, char *argv[]) {
int fd;
fd = open(argv[1], O_RDONLY);
fdatasync(fd);
posix_fadvise(fd, 0,0,POSIX_FADV_DONTNEED);
close(fd);
return 0;
@glennklockwood
glennklockwood / diff.sql
Last active April 18, 2021 00:46
Subtracting each row from the one before it in MySQL
SELECT
b.ts,
b.ost_name,
b.bytes_written - a.bytes_written,
b.bytes_read - a.bytes_read
FROM
(
SELECT
OST_DATA.TS_ID AS tsid,
TIMESTAMP_INFO.`TIMESTAMP` AS ts,
@glennklockwood
glennklockwood / ior.in
Created February 17, 2016 23:43
IOR Input to test DataWarp DVS client-side counters
################################################################################
#
# Run the IOR benchmark with the POSIX I/O API and one file per task
#
################################################################################
IOR START
### You MUST change the following parameters (see README.APEX)
numTasks=32 # number of MPI processes to use. You may choose to use one or more MPI processes per node.
segmentCount=81920 # must be > fileSize / ( blockSize * numTasks ) where fileSize must be greater than 1.5 times the aggregate DRAM available for use by
@glennklockwood
glennklockwood / .bashrc
Created July 23, 2015 01:59
Sensible .bashrc on Solaris 10
### bashrc/bash_profile for SunOS 5.10
# Solaris 10 lacks support for xterm-color (although it is provided in OpenCSW)
if [ "$TERM" == "xterm-color" ]; then
export TERM=xterm
fi
alias ssh='ssh -X'
alias ls='ls -p'
alias md5='digest -a md5 -v'