Skip to content

Instantly share code, notes, and snippets.

View andsve's full-sized avatar
🍎
Coding

Sven Andersson andsve

🍎
Coding
View GitHub Profile
@andsve
andsve / app_delegate.c
Created January 17, 2019 13:36
A simple implementation of a NSApplicationDelegate and two methods (openFile:, openFiles:) in pure C.
/*
app_delegate.c
1. Compile and link with:
$ clang -g -o AppInC app_delegate.c -lobjc -framework Foundation -framework AppKit -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
2. Create a Info.plist with:
[[
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
@andsve
andsve / bot.lua
Created August 16, 2010 21:58
Auto updating IRC Bot written in Lua (using luasockets)
local socket = require("socket")
function create_bot(nick, channels)
local bot = {nick = nick, -- nickname of bot
firstresponse = false, -- got any data?
connection_ok = false,
channels = channels
}
function bot:connect(serv, port)
@andsve
andsve / thrustmasters_t150_pro_USB_report_data.txt
Last active March 27, 2021 14:19
Thrustmasters T150 Pro USB, Mac data report
Investigating values in the report data for Thrustmasters T150 Pro (including and connected pedals) when connected to a MacBook Pro.
The wheel is set in the PS4 mode, NOT the "recommended" PC mode "PS3".
The values were snooped up using Wireshark, listening to the USB.
Vendor: 0x44F (1103)
Product: 0xB66D (46701)
(Note: The values were recorded while the "switch clutch and acc" mode was enabled, sadly... But hopefully it should only be those two "axis" being swapped.)
Example of report data (in idle):
@andsve
andsve / neeze.h
Created January 16, 2021 14:32
snippets for reading nes controller 1 input (using minifb)
// ...
enum GAMEPAD_ID
{
GAMEPAD_1 = 0,
GAMEPAD_2 = 1,
GAMEPAD_MAX = GAMEPAD_2,
};
enum GAMEPAD_BUTTON
g++ -MMD -MP -MP -DDEBUG -DSOKOL_GLCORE33 -I"/usr/include/gtk-3.0" -I"/usr/include/cairo" -I"/usr/include/pango-1.0" -I"/usr/include/harfbuzz" -I"/usr/include/atk-1.0" -I"/usr/include/gdk-pixbuf-2.0" -I"/usr/include/glib-2.0" -I"/usr/lib/x86_64-linux-gnu/glib-2.0/include" -g -m64 -fno-exceptions -fno-rtti -Wall -Werror -Wno-deprecated-declarations -m64 -lstdc++ -Wl,--no-as-needed -ldl -lXi -lXrandr -lXxf86vm -lXinerama -lXcursor -lrt -rdynamic -lpthread -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lGL -lX11 -lm sokol_gtk.cpp -o "sokol_gtk.out"
g++ -MMD -MP -MP -DDEBUG -DSOKOL_GLCORE33 -I"/usr/include/gtk-3.0" -I"/usr/include/cairo" -I"/usr/include/pango-1.0" -I"/usr/include/harfbuzz" -I"/usr/include/atk-1.0" -I"/usr/include/gdk-pixbuf-2.0" -I"/usr/include/glib-2.0" -I"/usr/lib/x86_64-linux-gnu/glib-2.0/include" -g -m64 -fno-exceptions -fno-rtti -Wall -Werror -Wno-deprecated-declarations -m64 -lstdc++ -Wl,--no-as
@andsve
andsve / JSON.lua
Created March 10, 2012 14:59
BigBrother Sweden Tweet-Getter
-- -*- coding: utf-8 -*-
--
-- Copyright 2010-2011 Jeffrey Friedl
-- http://regex.info/blog/
--
local VERSION = 20111207.5 -- version history at end of file
local OBJDEF = { VERSION = VERSION }
--
-- Simple JSON encoding and decoding in pure Lua.
@andsve
andsve / Unblock SOPA
Created January 18, 2012 14:13
Copy and paste into URL bar while visiting Wikipedia, press enter and you should be able to see the article again. PROTIP: Make it a bookmark for easy access!
javascript:e=["mw-page-base","mw-head-base","content","mw-head","mw-panel","footer"];for(var l in e){document.getElementById(e[l]).style.display="block";};document.getElementById("mw-sopaOverlay").style.display="none";void(0);
module("modules/imgcache2/imgcache2")
function parse_message(bot, msg)
local i,j,chan,s = string.find(msg, ":.-!.- PRIVMSG (.-) :(.+)")
if not (i == nil) then
function db_connect()
local luasql = require("luasql.sqlite3")
local env = luasql.sqlite3()
local conn = env:connect("imgcache2.sqlite")
module("modules/imgcache/imgcache")
function get_image(url)
local socket = require("socket")
-- get host and path
local socketurl = require("socket.url")
local parsedurl = socketurl.parse(url)
local host = parsedurl.host
{
["components"] = {
["Block_render_5"] = {
["output_type"] = "texture",
["type"] = "geometry",
["connections_in"] = {
[1] = {
["input"] = 1,
["block"] = "Block_aux_1",
["type"] = "vec3constant",