Skip to content

Instantly share code, notes, and snippets.

Avatar

tim37021

View GitHub Profile
@tim37021
tim37021 / test.py
Last active Apr 5, 2020
PyQT5 recreate qml object that references the same python object
View test.py
import sys
from PyQt5.QtQml import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
class ClassA(QObject):
bChanged = pyqtSignal()
@tim37021
tim37021 / main.c
Last active Mar 1, 2020
USB DUAL CDC STM32F427 libopencm3
View main.c
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2010 Gareth McMullin <gareth@blacksphere.co.nz>
*
* 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 / cmake.py
Created Feb 2, 2020
Dump include path of cmake cache
View cmake.py
# license MIT
# Hsu Yu Lun
import subprocess
import json
import time
def start(executable_file):
return subprocess.Popen(
executable_file,
@tim37021
tim37021 / launch.json
Created Jan 15, 2020
BlackMagicProbe vscode launch.json example
View launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/binary.elf",
"args": [],
"stopAtEntry": false,
View subscribe.py
# 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]
View color_test.c
#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 / bmploader.cpp
Created Jul 11, 2016
Mini C BMP Loader
View bmploader.cpp
// 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
View Sudoku.c
#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 / gist:cdf47151d4064f572bc5
Created May 30, 2015
Light culling geometry shader
View gist:cdf47151d4064f572bc5
#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;
@tim37021
tim37021 / gs.glsl
Last active Jan 22, 2021
Geometry shader for switching between flat and smooth shading
View gs.glsl
#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];