Skip to content

Instantly share code, notes, and snippets.

View cy20lin's full-sized avatar
🙂

Chien-Yu Lin cy20lin

🙂
View GitHub Profile

Working around offsetof limitations in C++:

There is sometimes a situation in which one needs to get the relative offset of a structure field, common examples of this include serialization frameworks which aid to serialize objects, vertex attributes for rendering (D3D, GL.), etc.

The most common technique for getting this information is through the offsetof macro defined in stddef.h. Unfortunately using the macro in C++ comes with a new set of restrictions that prevent some (subjectively valid) uses of it.

@cy20lin
cy20lin / moveptr.c
Created October 11, 2021 14:23 — forked from kulp/moveptr.c
Moves the mouse pointer between screens on an X11 display
/**
* @file
* @brief Moves the mouse pointer between screens on an X11 display.
*
* This program might be useful to you if you wish to switch between two X11
* screens without moving your hands from the keyboard. I configure bbkeys to
* map the otherwise-unused windows keys and right-click key to move to the left
* screen, move to the right screen, and toggle between screens, respectively.
*
* Run with zero to three arguments (additional arguments are ignored). The
@cy20lin
cy20lin / xreadkeys.c
Created October 11, 2021 12:53 — forked from javiercantero/xreadkeys.c
A X11/Xlib program that reads the KeyPress and KeyRelease events from the window and prints them to the standard output. Used to debug the keyboard within X.
#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
Display *display;
Window window;
XEvent event;
int s;
@cy20lin
cy20lin / gist:fcaeb1dadc4fd5eb147e726df6b5e701
Created October 10, 2021 16:40 — forked from kui/gist:2622504
get the active window on X window system.
// -*- coding:utf-8-unix; mode:c; -*-
//
// get the active window on X window system
//
#include <stdlib.h>
#include <stdio.h>
#include <locale.h>
#include <X11/Xlib.h> // `apt-get install libx11-dev`
@cy20lin
cy20lin / x11_screen_grab.cpp
Created October 9, 2021 14:36 — forked from richard-to/x11_screen_grab.cpp
X11 Example code for grabbing screenshots of window and sending key events
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <X11/Xlib.h>
@cy20lin
cy20lin / usb_hid_keys.h
Created October 8, 2021 16:50 — forked from MightyPork/usb_hid_keys.h
USB HID Keyboard scan codes
/**
* USB HID Keyboard scan codes as per USB spec 1.11
* plus some additional codes
*
* Created by MightyPork, 2016
* Public domain
*
* Adapted from:
* https://source.android.com/devices/input/keyboard-devices.html
*/
@cy20lin
cy20lin / ProGit-zh-translation.md
Created September 26, 2020 05:06 — forked from fntsrlike/ProGit-zh-translation.md
《Pro Git》第二版中文文件翻譯對照表與規範

《Pro Git》第二版中文文件翻譯對照表與規範

由於原本 Pro Git zh-tw 翻譯社群共筆的服務 hackpad 已經停止運作,並被移植到 Dropbox Paper。為了有利於本份資料在社群共享、傳播,故將其從 Dropbox Paper 輸出,並存在 Gist 備存。

相關議題可以參照 progit/progit2-zh-tw#38#39

前言

很慶幸的,有各位熱心的夥伴參與翻譯,其實就算是單人翻譯的狀況,常常會發生有些專有名詞或者是格式上前後不一的狀況。所以開了一個 pad 專門記錄這些規範以及參考的翻譯對照表。有些是我個人的一些想法,如果夥伴們有其他的意見跟想法歡迎提出來討論。 關於專有名詞翻譯的部分,我能理解部分夥伴會覺得就保留英文即可,但我會希望文件也類似於中文翻譯書般,第一次出現時我們可以以 專有名詞中文翻譯 (英文原文)的呈現方式來表示,讓讀者可以產生中英關聯,之後同份文件再次出現將只會出現中文翻譯。這樣做是因為對於初學者來說不會因為滿滿的英文專有名詞而產生抗拒。當然前提是在於中文的翻譯是否能夠達意,這部分建議參考對岸的一些翻譯,有時候比我們Pro Git的還直觀。但對於像 Laravel, Composer 等是名字、指令等就不強求要中文對照,這類不會有統一翻法更不容易從翻譯中知道用意的,就保留英文即可。如果不清楚該怎麼翻才好也可以留著與大家討論。

@cy20lin
cy20lin / configure_isolate_workspace.bash
Last active March 20, 2020 14:40
Ubuntu Isolate Workspace
gsettings set org.gnome.shell.app-switcher current-workspace-only true
gsettings set org.gnome.shell.extensions.dash-to-dock isolate-workspaces true
gsettings set org.gnome.shell.extensions.dash-to-panel isolate-workspaces true
#!/usr/bin/env xdg-open
# git clone https://github.com/1j01/jspaint/ ~/Downloads/jspaint
# mkdir -p ~/.icons
# cp ~/Downloads/jspaint/images/icons/16.png ~/.local/share/icons/hicolor/16x16/apps/jspaint.png
# cp ~/Downloads/jspaint/images/icons/32.png ~/.local/share/icons/hicolor/32x32/apps/jspaint.png
# cp ~/Downloads/jspaint/images/icons/48.png ~/.local/share/icons/hicolor/48x48/apps/jspaint.png
# cp ~/Downloads/jspaint/images/icons/128.png ~/.local/share/icons/hicolor/128x128/apps/jspaint.png
# #/usr/share/icons/hicolor/<resolution>/<type>/<name>.png
# touch ~/.local/share/applications/jspaint.desktop
[Desktop Entry]