Skip to content

Instantly share code, notes, and snippets.

View kewitz's full-sized avatar
💾

Leo Kewitz kewitz

💾
View GitHub Profile
@kewitz
kewitz / cuda
Created February 3, 2015 12:34
CUDA On/Off switcher for Ubuntu
#!/bin/bash
if [ "$#" != "1" ]; then
echo -e "Usage: cuda [on|off]"
exit 1
fi
if [ "$1" == "on" -o "$1" == "ON" ]; then
sudo tee /proc/acpi/bbswitch <<<ON
sleep 1
@kewitz
kewitz / snippets.cuh
Created October 14, 2014 15:58
CUDA Snippets.
// Calculate the thread global position, taken it's thread position within the block.
__device__ __inline__ uint3 __getGlobalPosition (uint3 blockIdx, dim3 blockDim, uint3 threadIdx) {
return make_uint3(blockIdx.x * blockDim.x + threadIdx.x, blockIdx.y * blockDim.y + threadIdx.y, blockIdx.z * blockDim.z + threadIdx.z);
};
// Device function to return the index of a given thread within a block.
__device__ __inline__ unsigned int __tIndex(uint3 b, dim3 bd, uint3 t) {
return t.x + t.y*bd.x + t.z*bd.x*bd.z;
};
@kewitz
kewitz / base.tex
Last active August 29, 2015 14:01
Base TeX template for class notes.
\documentclass[12pt,utf8,twocolumn,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[brazilian]{babel}
\usepackage{mathtools}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[margin=2cm]{geometry}
\newcommand{\sidenote}[1]{\marginpar{\footnotesize{#1}}}
\newcommand{\drawspace}[2]{\setlength{\unitlength}{#1}\begin{picture}(1,1)\end{picture}\\{\footnotesize #2}}
@kewitz
kewitz / snippet.h
Created March 13, 2014 22:37
Humanizing bytesize in C/C++
string hByte(unsigned int bytes){
string r;
if (bytes <= 0) r = "0 Bytes";
else if (bytes >= 1073741824) r = to_string(bytes/1073741824) + " GBytes";
else if (bytes >= 1048576) r = to_string(bytes/1048576) + " MBytes";
else if (bytes >= 1024) r = to_string(bytes/1024) + " KBytes";
return r;
};
@kewitz
kewitz / gist:9263836
Created February 28, 2014 02:10
my prism.js stuff.
/**
* Prism: Lightweight, robust, elegant syntax highlighting
* MIT license http://www.opensource.org/licenses/mit-license.php/
* @author Lea Verou http://lea.verou.me
*/(function(){var e=/\blang(?:uage)?-(?!\*)(\w+)\b/i,t=self.Prism={util:{type:function(e){return Object.prototype.toString.call(e).match(/\[object (\w+)\]/)[1]},clone:function(e){var n=t.util.type(e);switch(n){case"Object":var r={};for(var i in e)e.hasOwnProperty(i)&&(r[i]=t.util.clone(e[i]));return r;case"Array":return e.slice()}return e}},languages:{extend:function(e,n){var r=t.util.clone(t.languages[e]);for(var i in n)r[i]=n[i];return r},insertBefore:function(e,n,r,i){i=i||t.languages;var s=i[e],o={};for(var u in s)if(s.hasOwnProperty(u)){if(u==n)for(var a in r)r.hasOwnProperty(a)&&(o[a]=r[a]);o[u]=s[u]}return i[e]=o},DFS:function(e,n){for(var r in e){n.call(e,r,e[r]);t.util.type(e)==="Object"&&t.languages.DFS(e[r],n)}}},highlightAll:function(e,n){var r=document.querySelectorAll('code[class*="language-"], [class*="language-"] code, code[