Skip to content

Instantly share code, notes, and snippets.

@NSBum
NSBum / rpi-bcm2835-lib-install.sh
Created March 3, 2018 21:15
Version-agnostic installation of Raspberry Pi BCM2835 library for C
sudo apt-get install html-xml-utils
mkdir -p bcm2835 && (wget -qO - `curl -sL http://www.airspayce.com/mikem/bcm2835 | hxnormalize -x -e | hxselect -s '\n' -c "div.textblock>p:nth-child(4)>a:nth-child(1)"` | tar xz --strip-components=1 -C bcm2835 )
cd bcm2835
./configure
make
sudo make install
@NSBum
NSBum / mcp3008.c
Created March 3, 2018 23:39
Reading MCP3008 using C on the Raspberry Pi
// Using C to read the MCP3008 10-bit
// ADC via SPI
#include <stdio.h>
#include <bcm2835.h>
uint8_t start = 0x01;
uint8_t end = 0x00;
uint8_t chan = 0x00;
@NSBum
NSBum / si7021.c
Last active April 27, 2018 09:00
Example of reading from Si7021 with Raspberry Pi
#include <stdio.h>
#include <stdlib.h>
#include <bcm2835.h>
#include <string.h>
/*+---------------------------------------------------------+
| |
| si7021.c - Read Si7021 temperature and humidity |
| over I2C bus using Raspberry Pi |
@NSBum
NSBum / RF24_Button_Relay_test.cpp
Created March 29, 2018 21:40
Trigger relay remotely using nRF24L01+ modules
#include <SPI.h>
#include "RF24.h"
#include <EEPROM.h>
/* Hardware connections from Arduino Nano to nRF24L01
* CE -> D9
* CSN -> D10
* SCK -> D13
* MOSI -> D11
* MISO -> D12
@NSBum
NSBum / 4bit7segment.ino
Created April 16, 2018 19:18
4 bits 7 segment with shift registers
unsigned char LED_0F[] =
{// 0 1 2 3 4 5 6 7 8 9 A b C d E F -
0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x8C,0xBF,0xC6,0xA1,0x86,0xFF,0xbf
};
unsigned char LED[4]; //用于LED的4位显示缓存
int SCLK = 2;
int RCLK = 1;
int DIO = 0; //这里定义了那三个脚
void setup ()
{
@NSBum
NSBum / foldergallery.html
Last active January 18, 2020 11:20
Adaptation of this fancybox-based folder gallery: https://greekdeveloper.com/2018/folder-based-gallery-for-hugo/
<!-- /layouts/shortcodes/foldergallery.html -->
<style>
div.gallery {
display: flex;
flex-wrap: wrap;
}
div.gallery a {
flex-grow: 1;
@NSBum
NSBum / df
Created March 11, 2020 17:59
External note editor error log
Syncing failed:
Traceback (most recent call last):
File "aqt/sync.py", line 376, in _sync
File "aqt/sync.py", line 356, in _abortingSync
File "anki/sync.py", line 44, in sync
File "anki/sync.py", line 592, in meta
File "anki/sync.py", line 556, in req
File "anki/sync.py", line 441, in post
File "requests/sessions.py", line 572, in post
File "requests/sessions.py", line 510, in request
@NSBum
NSBum / CompressAndTruncate.txt
Created July 13, 2020 14:31
Audacity macro to trim silence and compress dynamic range
SelectAll:
TruncateSilence:Action="Truncate Detected Silence" Compress="50" Independent="0" Minimum="0.5" Threshold="-20" Truncate="0.5"
Compressor:AttackTime="0.2" NoiseFloor="-40" Normalize="1" Ratio="2" ReleaseTime="1" Threshold="-12" UsePeak="0"
@NSBum
NSBum / KjellinSentences.txt
Created July 13, 2020 14:43
Generate six iterations of the track content + 650 ms silence
SelEnd:
Select:End="-0.65" Mode="Set" RelativeTo="SelectionEnd" Start="0"
Silence:Use_Preset="User Preset:650ms"
SelectAll:
CursSelEnd:
Repeat:Count="5"
@NSBum
NSBum / check_mlhu_vaccine.py
Last active April 7, 2021 10:38
MHLU vaccine notifier
#!/usr/bin/env python3
try:
# Python 2
from urllib2 import urlopen
except ImportError:
from urllib.request import urlopen, Request
from lxml import etree
import re
from py_imessage import imessage