Skip to content

Instantly share code, notes, and snippets.

Avatar

Jari Vetoniemi Cloudef

View GitHub Profile
@Cloudef
Cloudef / git-archive-all
Created Jun 15, 2017
wlc release scripts
View git-archive-all
#!/bin/bash
# Archive git project including all submodules
# Usage: git archive-all <name> <ref>
set -eEuo pipefail
current="$(git rev-parse --abbrev-ref HEAD)"
toplevel="$(git rev-parse --show-toplevel)"
toplevel="${toplevel##*/}"
name="${1:-$toplevel}"
@Cloudef
Cloudef / packet.h
Last active Jul 2, 2018
poc uinputd and vita client, TL;DR it sucks
View packet.h
#pragma once
enum packet_type {
PACKET_IOCTL,
PACKET_WRITE,
};
enum ioctl_dir {
IOCTL_NONE,
IOCTL_IOR,
@Cloudef
Cloudef / fakepkg.bash
Created Sep 6, 2016
Fake makepkg enough to build and install android-protobuf from PKGBUILD
View fakepkg.bash
#!/bin/bash
# Fake makepkg enough to build and install android-protobuf PKGBUILD
# Go into sanity mode
set -eEuo pipefail
# Heuristics, do your job if not true.
PROTOC="$(which protoc)"
MAKEFLAGS="$@"
@Cloudef
Cloudef / xic.c
Last active Mar 4, 2017
FFXI message compression/decompression
View xic.c
/**
* tcc -std=c99 xic.c -o xic
*
* Tool to compress/decompress FFXI server messages.
*
* I'm not sure what the algorithm is, but it seems to work on separate encoding and
* decoding tables. (It seems to be some sort of cumulative substitution coder)
*
* At most encoding outputs 8 times bigger buffer than original for decoding.
* However this buffer is mostly zeros and needs to be only expanded during decoding,
View fizz-enterprise-w-numbers.c
#include <stdio.h>
#include <stdint.h>
void main(void)
{
char num[4];
const char *lut[] = { num, "Fizz\n", "Buff\n", "FizzBuff\n" };
for (uint32_t i = 1; i <= 100; ++i) {
const uint8_t n = !(i % 3) + (2 * !(i % 5));
snprintf(num, sizeof(num), "%d\n", i);
@Cloudef
Cloudef / bitrot.c
Last active Aug 29, 2015
Bitwise rotation with mask
View bitrot.c
#include <stdint.h>
#include <stdio.h>
#include <limits.h>
#include <assert.h>
static void
print_bits(uint32_t v)
{
for (uint32_t i = 0; i < sizeof(v) * CHAR_BIT; ++i)
printf("%u", !!(v & (1<<i)));
@Cloudef
Cloudef / migrate_db.bash
Last active Aug 29, 2015
Darkstar db migration script
View migrate_db.bash
#!/bin/bash
# Migrate database automatically.
#
# Automatically migrates between schema changes.
# Where fields were either added or removed.
#
# However does not understand, if field names were renamed.
# You stil have to manually migrate those (eg. linkshellid1 -> linkshellid)
# These fields should show up as "old fields" and "new fields" in stdout.
#
@Cloudef
Cloudef / bams.c
Last active Oct 22, 2016
Find shortest rotation without branches.
View bams.c
#include <stdint.h>
// you can use any precision you want
typedef uint32_t ubams;
typedef int32_t bams;
static const uint32_t erro = (sizeof(ubams) < sizeof(uint32_t));
static const uint32_t most = (ubams)~0;
static inline ubams
@Cloudef
Cloudef / glvsync.c
Last active Jun 24, 2020
Force glXSwapInterval* to whatever you want
View glvsync.c
/* gcc -std=c99 -fPIC -shared -Wl,-soname,glvsync.so glvsync.c -o glvsync.so
* gcc -m32 -std=c99 -fPIC -shared -Wl,-soname,glvsync.so glvsync.c -o glvsync.so (for 32bit)
*
* Force VSYNC interval on OpenGL applications
* Alternatively can also try FPS locking a OpenGL program
* Usage: LD_PRELOAD="/path/to/glvsync.so" ./program
*/
#define _GNU_SOURCE
#include <dlfcn.h>
@Cloudef
Cloudef / speedmetal.c
Created Dec 9, 2013
Speed metal song
View speedmetal.c
char *ns = "小 さ い む ね by. Cloudef a b a b a B E B E Z U Z U D A D A dooo daaat →";
main(i){int t=8;for(char *n=ns;*n;++n){int s=16e3/(220+*n);unsigned char v[s];read(0,v,s);for(i=0;i<s*(t+(ns[n-ns]!=0?0:100));)putchar(v[i%s]=(v[i%s]+v[++i%s])/2);}}