Skip to content

Instantly share code, notes, and snippets.

View yshui's full-sized avatar
🪲

Yuxuan Shui yshui

🪲
View GitHub Profile
@yshui
yshui / 0001.patch
Last active December 23, 2015 16:09
From b5ab6d1ad67e38a11d5296d41a4c3b82145c4185 Mon Sep 17 00:00:00 2001
From: Yuxuan Shui <yshuiv7@gmail.com>
Date: Sun, 22 Sep 2013 01:17:57 +0800
Subject: [PATCH 1/2] core: Add a User= to scopes.
---
src/core/dbus-scope.c | 17 +++++++++++++++++
src/core/load-fragment-gperf.gperf.m4 | 1 +
src/core/scope.c | 27 +++++++++++++++++++++++++++
src/core/scope.h | 2 ++
@yshui
yshui / boom.cpp
Last active December 17, 2016 03:17
Symbol name goes BOOM!
template<typename First, typename ...Rest>
struct Int{
using Next = Int<Int<First, Rest...>, First, Rest...>;
using Prev = First;
};
struct Zero{
using Next = Int<Zero, Int<Zero>>;
};
template<typename A, typename B>
struct Plus{
@yshui
yshui / t.d
Created January 26, 2017 22:30
opDispatch
struct R(T...) {
T data;
auto opDispatch(string str)() {
import std.conv;
return data[to!int(str[1..$])];
}
}
int main() {
import std.stdio;
auto tmp = R!(int, float)(1,2.0);
@yshui
yshui / rangeapply.d
Created May 9, 2017 17:20
Turn struct with opApply into ranages
struct applyRange(T, ElemType) {
import core.thread;
private {
class rangeFiber : Fiber {
ElemType *tmp = null;
T r;
this(T r) {
this.r = r;
super(&work);
}
@yshui
yshui / kb.lua
Last active July 16, 2017 02:29
Key bindings with deai
xc = di.xorg.connect()
o = get_output("eDP1")
xc.key.new(nil, "xf86monbrightnessup", false).on("pressed", function()
o.backlight = math.min(math.ceil(o.backlight+o.max_backlight/10),o.max_backlight)
print("up", o.backlight)
end)
xc.key.new(nil, "xf86monbrightnessdown", false).on("pressed", function()
o.backlight = math.max(math.floor(o.backlight-o.max_backlight/10),0)
print("down",o.backlight)
end)
//fun(T)(ref immutable T a){
// //If T is a struct, and I only use immutable fields of T
// //then it should be ok to call fun with a partially mutable type
//}
void f(T: class)(immutable T a) {
return a.x+1;
}
@yshui
yshui / glx.c
Created February 3, 2019 14:41
madness
// gcc glx.c -lX11 -lGL
#include <GL/glx.h>
#include <X11/Xlib.h>
#include <stdio.h>
int main() {
Display *dpy = XOpenDisplay(NULL);
int scr = DefaultScreen(dpy);
int ncfg;
GLXFBConfig *fbs = glXGetFBConfigs(dpy, scr, &ncfg);
@yshui
yshui / meson.build
Last active July 8, 2019 13:51
meson cmake bug
project('test', 'cpp')
prometheus_cpp = dependency('prometheus-cpp', method: 'cmake', modules: ['prometheus-cpp::core'], static: false)
#include <GL/glx.h>
#include <X11/X.h>
#include <X11/Xlib-xcb.h>
#include <stddef.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <xcb/xcb.h>
#include <xcb/xfixes.h>
#define auto __auto_type
@yshui
yshui / number_parser.rs
Last active November 1, 2020 15:39
GitCafe格调秀第二周第一题,Proof-of-concept。需要rust-peg
#![feature(plugin)]
#![feature(collections)]
#![feature(str_char)]
#![feature(convert)]
#![plugin(peg_syntax_ext)]
use std::io;
peg! pynum(r#"
digit -> i64
= digit_nozero
/ "ling" {0i64}