Skip to content

Instantly share code, notes, and snippets.

View JamesDunne's full-sized avatar

jsd1982 JamesDunne

View GitHub Profile
int init()
{
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) != 0) {
app.window = SDL_CreateWindow(GAME_TITLE, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, (int)SCREEN_WIDTH, (int)SCREEN_HEIGHT, 0);
if (app.window != NULL) {
app.renderer = SDL_CreateRenderer(app.window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
// app.renderer = SDL_CreateRenderer(app.window, -1, SDL_RENDERER_ACCELERATED);
if (app.renderer != NULL) {
@JamesDunne
JamesDunne / fsw.c
Created February 20, 2017 16:35
C library for polling 16 active-low button states via SX1509 over I2C bus from Raspberry Pi Model B
typedef unsigned char u8;
typedef u8 byte;
#include "sx1509_registers.h"
// https://learn.sparkfun.com/tutorials/sx1509-io-expander-breakout-hookup-guide#sx1509-breakout-board-overview
// SX1509 breakout board exposes ADD1 and ADD0 jumpers for configuring I2C address.
// ADD1 = 0, ADD0 = 0
#define i2c_sx1509_btn_addr 0x3E
@JamesDunne
JamesDunne / midi.c
Created February 20, 2017 16:29
C library for MIDI output on Raspberry Pi Model B using UART0 and breakout board with opto-isolators
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <asm/termios.h>
#include <unistd.h>
typedef unsigned char u8;
@JamesDunne
JamesDunne / i2c.c
Last active April 11, 2024 10:54
C library for reading/writing I2C slave device registers from Raspberry Pi 1 Model B
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <linux/i2c-dev.h>
// Terrible portability hack between arm-linux-gnueabihf-gcc on Mac OS X and native gcc on raspbian.
#ifndef I2C_M_RD
#include <linux/i2c.h>
#endif
@JamesDunne
JamesDunne / detect_flash.js
Created July 9, 2014 12:29
Flash plugin detection javascript code; works on IE8 and Chrome
// Returns true or false if flash installed or not. Tested with IE8 on Windows 7 and Chrome on Win7 and Mac.
(function() { var ie_flash; try { ie_flash = (window.ActiveXObject && (new ActiveXObject("ShockwaveFlash.ShockwaveFlash")) !== false) } catch(err) { ie_flash = false; } var _flash_installed = ((typeof navigator.plugins != "undefined" && typeof navigator.plugins["Shockwave Flash"] == "object") || ie_flash); return _flash_installed; })()
@JamesDunne
JamesDunne / private.xml
Last active August 29, 2015 14:02
KeyRemap4MacBook good settings for Windows keyboards
<?xml version="1.0"?>
<root>
<appdef>
<appname>Google Chrome</appname>
<equal>com.google.Chrome</equal>
</appdef>
<item>
<name>Refresh with F5 in Chrome</name>
<identifier>private.Chrome.Refresh</identifier>
<only>Google Chrome</only>
@JamesDunne
JamesDunne / makegif-sociopath.cmd
Last active August 29, 2015 14:02
Make animated GIF from Sherlock S03E02 scene: High-functioning sociopath
@echo off
rem Final result: http://i.bittwiddlers.org/b/KH8
rem goto annotate
:capture
ffmpeg -i Sherlock.3x02.the_sign_of_three.mkv -ss 10:37 -t 10 fr%d.png
:annotate
del /f /q v*.txt 2>NUL
rem Bloody psychopath!
@JamesDunne
JamesDunne / makegif-itoldyouso.cmd
Last active August 29, 2015 14:01
Creating animated GIFs from videos using ffmpeg and imagemagick
@echo off
rem http://i.bittwiddlers.org/b/KHh
rem goto extract
goto annotate
rem goto combine
:extract
rem Extract frames:
rem del /f /q glass.avi
@JamesDunne
JamesDunne / divide-benchmark.cpp
Created October 2, 2013 19:41
A small benchmark in C++ to demonstrate integer vs. floating point division operations on various platforms.
#include <stdlib.h>
#include <stdio.h>
#ifdef _WIN32
#include <sys/timeb.h>
#else
#include <sys/time.h>
#endif
#include <time.h>
double
@JamesDunne
JamesDunne / bigbenircbot.cs
Created November 14, 2012 16:33
Big Ben C# IRC bot
using System;
using System.Linq;
using System.Threading.Tasks;
namespace IrcBots {
public class BigBenIrcBot : PircBot {
const string IRC_CHANNEL = "#bitswebteam";
public BigBenIrcBot() { setName("isu_big_ben"); }
static void Main() {
var bot = new BigBenIrcBot();