Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Jookia
Jookia / brainfu.c
Created January 3, 2011 02:25
BRAINFU
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Some defines useful for tweaking the interpreter.
#define DATA char
#define CELL unsigned char
#define CELL_COUNT 30000
#define LOOP_STACK_SIZE 32
@Jookia
Jookia / brainfu.c
Created January 3, 2011 11:08
BRAINFU 2
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
// Some defines useful for tweaking the interpreter.
#define CELL uint8_t
#define CELL_COUNT (30000)
#define LOOP_STACK_SIZE (256)
#include <iostream>
#include <cassert>
#include "endian.hpp"
int main(void)
{
assert(flipEndian(long(0x123456789ABCDEF)) == long(0xEFCDAB8967452301));
assert(flipEndian(int(0x12345678)) == int(0x78563412));
assert(flipEndian(short(0x1234)) == short(0x3412));
assert(flipEndian(char(0x12)) == char(0x12));
@Jookia
Jookia / SQLite Test.cpp
Created April 18, 2011 11:24
SQLite Test
int stepStatus;
do
{
stepStatus = sqlite3_step(statement);
@Jookia
Jookia / cat.cpp
Created June 13, 2011 06:07
Inheritence to avoid duplicating business code.
#include <ctime>
#include <cstdlib>
#include <iostream>
using namespace std;
class feline
{
public:
feline(void)
@Jookia
Jookia / palindrome.c
Created January 30, 2012 06:00
palindrome.c
#include <stdio.h>
#include <string.h>
int is_palindrome(const char* text)
{
/* Set the forward and backward iterators to outside
the string as they move in the first iteration. */
const char* forward = &text[0] - 1;
const char* backward = &text[strlen(text)];
@Jookia
Jookia / brokework.diff
Created April 30, 2012 18:22
brokework.diff
15,17c15,17
< --- {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=8135, si_status=0, si_utime=0, si_stime=0} (Child exited) ---
< --- {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=8134, si_status=0, si_utime=0, si_stime=0} (Child exited) ---
< --- {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=8133, si_status=0, si_utime=0, si_stime=0} (Child exited) ---
---
> --- {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=8165, si_status=0, si_utime=0, si_stime=0} (Child exited) ---
> --- {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=8164, si_status=0, si_utime=0, si_stime=0} (Child exited) ---
> --- {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=8163, si_status=0, si_utime=0, si_stime=0} (Child exited) ---
299c299
< open("", O_RDONLY) = -1 ENOENT (No such file or directory)
@Jookia
Jookia / functionToPtr.hpp
Created October 30, 2013 02:17
A hack to convert C++'s std::function to C callbacks. A little bit like currying.
/*
Copyright (C) 2013 Jookia
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: The above copyright
notice and this permission notice shall be included in all copies or
# Originally written on 2017-04-26 19:03.
# Welcome to my fancy Shift JIS explanation and simple implementation in Python.
#
# If you haven't heard of Shift JIS, it's a single or double-byte encoding for
# the JIS X 0201 and JIS X 0208 character sets, a bit like UTF-8 is for Unicode.
#
# The key feature of Shift JIS is being able to use both character sets at once,
# retaining legacy half-width ASCII and Katakana characters from JIS X 0201.
#