Skip to content

Instantly share code, notes, and snippets.

@kmcallister
kmcallister / gist:7206061
Created October 28, 2013 22:38
switching to RGB pixmaps
diff --git a/platform/linux/surface.rs b/platform/linux/surface.rs
index e2249d7..13b56ce 100644
--- a/platform/linux/surface.rs
+++ b/platform/linux/surface.rs
@@ -13,9 +13,9 @@ use platform::surface::NativeSurfaceMethods;
use texturegl::Texture;
use geom::size::Size2D;
-use opengles::glx::{GLXFBConfig, GLXDrawable, GLXPixmap, GLX_BIND_TO_TEXTURE_RGBA_EXT};
+use opengles::glx::{GLXFBConfig, GLXDrawable, GLXPixmap, GLX_BIND_TO_TEXTURE_RGB_EXT};
@kmcallister
kmcallister / gist:7272676
Created November 1, 2013 22:02
nvidia crash wtf
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff574748a in glReadPixels () from /usr/lib/x86_64-linux-gnu/libGL.so.1
(gdb) x/10xi glReadPixels
0x7ffff5747480 <glReadPixels>: add %cl,-0x75(%rax)
0x7ffff5747483 <glReadPixels+3>: add $0x25,%al
0x7ffff5747485 <glReadPixels+5>: pushq $0xffffffffffffffff
=> 0x7ffff574748a <glReadPixels+10>: movabs 0xcccccccc00000688,%al
0x7ffff5747493 <glReadPixels+19>: int3
0x7ffff5747494 <glReadPixels+20>: int3
0x7ffff5747495 <glReadPixels+21>: int3
@kmcallister
kmcallister / gist:7312179
Created November 5, 2013 01:09
chmod macro
macro_rules! perm (
(N) => (0); (X) => (1); (W) => (2); (WX) => (3);
(R) => (4); (RX) => (5); (RW) => (6); (RWX) => (7);
)
macro_rules! chmod (
($path:expr, $u:ident, $g:ident, $o:ident) => (
println!("chmod({:s}, {:d})",
$path, (perm!($u) << 6) | (perm!($g) << 3) | (perm!($o)))
)
@kmcallister
kmcallister / ledd.c
Created November 30, 2013 06:02
UDP server for LED lights on RPi Use at your own risk!
#include <time.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <netinet/in.h>
#include <sys/select.h>
def foo(func=None, x=3):
def wrap(oldfunc):
def newfunc(*args, **kwargs):
print 'calling function, x =', x
oldfunc(*args, **kwargs)
return newfunc
if func is None:
# Decorator was used as @foo(x=...)
return wrap
@kmcallister
kmcallister / gist:8128275
Last active January 1, 2016 09:59
xview is very polite
$ strings $(which xview) | grep -i sorry
%s: %d: Buffer overflow (token too long, sorry).
%s: I can read this image type but cannot write it (sorry).
jpegDump: sorry, arithmetic coding not supported
jpegDump: sorry, multiple-scan support was not compiled
Memory has been exhausted; operation cannot continue (sorry).
information about the error is available, sorry.
%s is no longer supported (sorry)
Cannot create background (not enough resources, sorry)
Loading image onto root would change default colormap (sorry)
@kmcallister
kmcallister / gist:8178050
Last active January 1, 2016 17:38
top level asm
#include <stdio.h>
asm("foo:");
void bar() { puts("Hello, world!"); }
int main() {
void foo();
foo();
return 0;
}
@kmcallister
kmcallister / monitor-battery.py
Created January 4, 2014 22:08
thinkpad battery monitor
#!/usr/bin/env python
import os
import time
import traceback
def get(var):
with open('/sys/class/power_supply/BAT0/' + var, 'r') as f:
return float(f.read().strip())
def check():
@kmcallister
kmcallister / gist:8679155
Created January 29, 2014 00:04
can't convert ~Trait to &Trait using 'as'
// rustc 0.9 (d3b3c66 2014-01-12 19:44:26 -0700)
// host: x86_64-unknown-linux-gnu
trait T {}
struct S;
impl T for S {}
fn main() {
@kmcallister
kmcallister / void.rs
Created February 18, 2014 19:57
Void type in Rust
enum Void {}
impl Void {
fn unreachable(self) -> ! {
match self { }
}
unsafe fn make() -> Void {
std::unstable::intrinsics::uninit()
}