Skip to content

Instantly share code, notes, and snippets.

@patflick
patflick / gcc_segfault.cpp
Created April 25, 2017 20:49
GCC Segfault
/*
* This little code snipped will segfault for gcc <= 4.8:
*
* g++ --std=c++11 gcc_segfault.cpp
*/
#include <tuple>
#include <utility>
#include <iostream>
#include <typeinfo>
@patflick
patflick / blog_part1.md
Last active March 27, 2025 17:00
Generative Adversarial Networks Explained

Generative Adversarial Networks - Part 1

By Patrick Flick

Intro and Basics

GAN stands for Generative Adversarial Networks. In this two part blog series, I will introduce the idea behind GANs, and explain how they work, talk about their history and some applications of GANs. In part two, we will create a little toy example with GANs using python and keras and train them to generate digits.

This blog assumes that you are already familiar with neural networks and convolutional neural networks (CNNs).

@patflick
patflick / cputimer.hpp
Last active August 29, 2015 14:05
timing C++ code on Linux
/**
* @file cputimer.h
* @author Patrick Flick <patrick.flick@gmail.com>
* @brief Provides a timing stop watch for benchmarking code.
*
* Timing C++ code
* Copyright 2014 Patrick Flick
*
* Licensed under the "THE BEER-WARE LICENSE" (Revision 42):
* Patrick Flick wrote this file. As long as you retain this notice you
@patflick
patflick / sped3.c
Created February 22, 2013 14:31
Rendering text on the SPED using dcpu-cc
#include "sped3.h"
int sped3_hw_num = -1;
void init_sped3()
{
int hwn;
int hw_id_b, hw_id_a;
int i;
__asm {
@patflick
patflick / gist:4981049
Last active November 18, 2021 09:10
handling interrupts (in this example keyboard interrupts) with C (DCPUToolchain)
#include <stdio.h>
#include <ext/screen.h>
#define KEYBOARD_INTERRUPT_MSG 0xdead
#define KEYBOARD_HW_ID_B 0x30cf
#define KEYBOARD_HW_ID_A 0x7406
int kb_hw_num = -1;
int* screen_pos = (int*) 0x8000;
# Makefile only for compiling single c files
DT_PATH=$(HOME)/dev/dcpu16/DCPUToolChain/build
KERNEL_PATH=$(DT_PATH)/kernel
KERNEL_SRC_PATH=$(DT_PATH)/../src/kernel/stubsys
CC=$(DT_PATH)/dtcc/dtcc
ASM=$(DT_PATH)/dtasm/dtasm
@patflick
patflick / gist:4963845
Last active December 13, 2015 19:38
dump a binary to DAT of 8 columns per row
#!/bin/bash
xxd -ps $1 | sed -r 's/(....)/\1 /g' | sed -r 's/^([0-9a-f])(.*)/DAT \1\2/g' | sed -r 's/([0-9a-f]{4})/0x\1,/g' | sed -r 's/(.*), $/\1/g'
@patflick
patflick / gist:4955402
Created February 14, 2013 19:09
how to use general iterators (not depending on the container), but force a certain base type
#include <iterator>
#include <vector>
#include <deque>
#include <list>
#include <iostream>
#include <cstdint>
#include <algorithm>
template<class I, class=
typename std::enable_if<std::is_same<typename std::iterator_traits<I>::value_type, uint16_t>::value>::type>
@patflick
patflick / gist:4943856
Created February 13, 2013 10:59
using the sped3 with C
#include <stdio.h>
#include <ext/screen.h>
#define SPED3_HW_ID_A 0xbf3c
#define SPED3_HW_ID_B 0x42ba
#define SPED3_COLOR_BLACK 0
#define SPED3_COLOR_RED 1
#define SPED3_COLOR_GREEN 2
#define SPED3_COLOR_BLUE 3
@patflick
patflick / input.c
Created February 5, 2013 17:40
An example for extern, static and default variables and functions in dtcc2
int someglobal = 32;
static int static_global = 13;
extern int extern_global;
typedef int typedef_global;
extern void extern_function(int foo);
void function1(int blah)
{
someglobal = blah;