This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/dmd -run | |
import std.stdio, std.file, std.path, std.string, std.conv, std.math, std.container, std.algorithm, std.parallelism, std.range; | |
string filesize(double size){ | |
string units = "KMGT"; | |
double left = cast(double)size.abs(); | |
int unit = -1; | |
while(left > 1100 && unit < 3){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//template<typename T> | |
//bool Foo(T a, T b) { | |
// T c = a + b; | |
// return a == c; | |
//} | |
// | |
//Expands to: | |
//------------- begin ------------- | |
#include <iostream> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Cut from bigint.rs | |
pub struct MontyReducer<'a> { | |
p: &'a BigUint, | |
n: Vec<u32>, | |
n0inv: u64 | |
} | |
fn inv_mod_u32(num: u32) -> u64 { | |
assert!( num % 2 != 0 ); | |
let mut x = 0; | |
let mut y = 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct applyRange(T, ElemType) { | |
import core.thread; | |
private { | |
class rangeFiber : Fiber { | |
ElemType *tmp = null; | |
T r; | |
this(T r) { | |
this.r = r; | |
super(&work); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Fun { | |
// Gadget used for return type based deduction | |
// operator T() is probably the only place in C++ | |
// where the template parameter can be deduced from | |
// what the function should return | |
template<typename T> | |
operator T() { | |
return T(sizeof(T)); | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |