Skip to content

Instantly share code, notes, and snippets.

View Cloudef's full-sized avatar

Jari Vetoniemi Cloudef

View GitHub Profile
@Cloudef
Cloudef / migrate_db.bash
Last active August 29, 2015 14:21
Darkstar db migration script
#!/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 October 22, 2016 14:42
Find shortest rotation without branches.
#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 November 23, 2022 10:00
Force glXSwapInterval* to whatever you want
/* 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 December 9, 2013 19:31
Speed metal song
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);}}
@Cloudef
Cloudef / gist:6460989
Last active December 22, 2015 10:48
pew pew
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main(int argc, char **argv) {
long int numbers[5];
long int highest = 0;
if (argc < 2 || strlen(argv[1]) < 5) {
fprintf(stderr, "5 digits minimum input string must be given\n");
/* gcc `pkg-config --cflags --libs libsystemd-login` systemd-active-user.c -o systemd-active-user
* get current active user id that has process in 'foreground' according to documentation */
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
uid_t *uids = NULL, uactiveid = 0;
int i, num = sd_get_uids(&uids);
@Cloudef
Cloudef / pandorahck.c
Last active December 18, 2015 13:18
Uh....
/* gcc -std=c99 -shared -Wl,-soname,libpandorahck.so pandorahck.c -o libpandorahck.so
*
* Hacks for Open Pandora that should not be normally needed
* Will be compiled with glhck if PANDORA option is specified when built with cmake
* You can then copy it to your project and launch with LD_PRELOAD=/path/to/libpandorahck.so ./project
*
* Hacks:
* 1. Report that pandora doesn't support libxi to avoid crash on any mouse event.
* 2. Grab all input to window to avoid popular Openbox PND keybind conflicts.
* (can be disabled with PANDORAHCK_NO_GRAB)
@Cloudef
Cloudef / gist:5735519
Created June 8, 2013 15:31
Spacerocks score decryptor/encryptor
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv)
{
FILE *f; char buf, buf2[255], read = 0, isScore = 0, *s;
if (argc < 1) return EXIT_FAILURE;
if (!(f = fopen(argv[1], "rb"))) return EXIT_FAILURE;
while (fread(&buf, 1, 1, f) == 1) {
@Cloudef
Cloudef / gist:4971329
Last active December 13, 2015 20:38
vsm glhck shader
Basic VSM shadow mapping shader
-- GLhck.DepthRender.Unpacking.Fragment
void main() {
float Depth = glhckUnpackHalf(texture2D(GlhckTexture0, GlhckFUV0).st);
GlhckFragColor = vec4(Depth, Depth, Depth, 1.0);
}
-- GLhck.Depth.Packing.Fragment
void main() {
@Cloudef
Cloudef / smscat.sh
Last active December 10, 2015 16:08
# sms through android
# $1 = phone number
# $@ = message
function sms() {
[[ -n "$1" ]] || { echo "no number given"; return; }
local num="$1"; shift 1;
[[ -n "$@" ]] || { echo "no message given"; return; }
ssh -q root@hack-ANDROID "am start -a android.intent.action.VIEW -d sms:$num --es sms_body \"$@\" --ez exit_on_sent true"
}