Skip to content

Instantly share code, notes, and snippets.

View tim37021's full-sized avatar

Tim Hsu tim37021

View GitHub Profile
@tim37021
tim37021 / gs.glsl
Last active January 22, 2021 09:54
Geometry shader for switching between flat and smooth shading
#version 330
layout(triangles) in;
layout(triangle_strip, max_vertices=3) out
uniform int enableSmooth=1;
in vec3 vNorm[3];
in vec3 vWorldPos[3];
in vec2 vTexCoord[3];
@tim37021
tim37021 / gist:cdf47151d4064f572bc5
Created May 30, 2015 10:10
Light culling geometry shader
#version 330
layout(points) in;
layout(triangle_strip, max_vertices=6) out;
in vec3 vColor[1];
out vec3 lightPos;
out vec3 lightColor;
uniform mat4 view;
// e: near
// a: aspect: height/width;
uniform float e=0.1, a=1.0;
#include <stdio.h>
#define ROWS 9
#define COLS 9
#define SQ 3
#define MAX (SQ*SQ)
static void read_question(FILE *fp);
static int find_blank(int *, int *);
static int solve(int, int);
@tim37021
tim37021 / bmploader.cpp
Created July 11, 2016 13:09
Mini C BMP Loader
// mini bmp loader written by HSU YOU-LUN
unsigned char *load_bmp(const char *bmp, unsigned int *width, unsigned int *height, unsigned short int *bits)
{
unsigned char *result=nullptr;
FILE *fp = fopen(bmp, "rb");
if(!fp)
return nullptr;
char type[2];
unsigned int size, offset;
// check for magic signature
#include <stdio.h>
/* reference: http://misc.flogisoft.com/bash/tip_colors_and_formatting */
#define GRAY "\e[90m"
#define RED "\e[91m"
#define GREEN "\e[92m"
#define DEFAULT "\e[39m"
const int num_colors = 3;
const char *colors[] = {GRAY, RED, GREEN};
@tim37021
tim37021 / subscribe.py
Created April 5, 2019 16:01
Numpy subscribe
# arr = [1, 2, 3, 4, 5]
arr = np.arange(5)
# [1, 2, 3]
arr[[0, 1, 2]]
# [1, 3, 5]
arr[[True, False, True, False, True]]
# [4, 5]
arr[arr>3]
@tim37021
tim37021 / launch.json
Created January 15, 2020 07:47
BlackMagicProbe vscode launch.json example
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/binary.elf",
"args": [],
"stopAtEntry": false,
@tim37021
tim37021 / cmake.py
Created February 2, 2020 12:47
Dump include path of cmake cache
# license MIT
# Hsu Yu Lun
import subprocess
import json
import time
def start(executable_file):
return subprocess.Popen(
executable_file,
@tim37021
tim37021 / main.c
Last active March 1, 2020 16:53
USB DUAL CDC STM32F427 libopencm3
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2010 Gareth McMullin <[email protected]>
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
@tim37021
tim37021 / test.py
Last active April 5, 2020 13:04
PyQT5 recreate qml object that references the same python object
import sys
from PyQt5.QtQml import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
class ClassA(QObject):
bChanged = pyqtSignal()