Skip to content

Instantly share code, notes, and snippets.

View kewitz's full-sized avatar
💾

Leo Kewitz kewitz

💾
View GitHub Profile
@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[
@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 / 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 / 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 / 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 / cpf
Created January 30, 2016 20:06
intel_pstate max cpu-frequency bash script.
#!/bin/bash
# Copyleft 2015 - Leonardo Kewitz github.com/kewitz
# intel_pstate max cpu-frequency script.
PMAX=/sys/devices/system/cpu/intel_pstate/max_perf_pct
CPUINFO=/proc/cpuinfo
if [ "$#" != "1" ]
then
echo -e "Usage: cpf 30-100"
@kewitz
kewitz / gist:484010da959767314ccf
Last active March 16, 2016 18:17
MatplotLib configuration for LaTeX articles.
mpl.rc('font', weight = 'light', size = 8, **{'family':'serif','serif':['Times New Roman']})
mpl.rc('text', usetex=True)
mpl.rc('legend', borderaxespad = 0.3, fontsize = 6, handlelength = 2, markerscale = 1, labelspacing = 0.3, numpoints = 1)
figsize = (3.3,1.8)
@kewitz
kewitz / plot.py
Created March 30, 2016 21:40
IEEE oriented plotting for spyder
figsize = (3.5, 3.5)
#plt.style.use('grayscale')
plt.rc('font', size = 10, **{'family':'serif','serif':['Times New Roman']})
plt.rc('text', usetex=True)
plt.rc('legend', fancybox=True)
colors = plt.rcParams['axes.color_cycle']
def lines(x, ys, labels, filename):
series = len(ys)
xlabels = x;
@kewitz
kewitz / esnextbin.md
Created December 14, 2016 23:21
esnextbin sketch
@kewitz
kewitz / VimiumTheme.css
Created January 13, 2017 16:34
Vimium Black Monospace theme.
/*
Installation:
1. Right Click on the Vimium icon
2. Select "Options"
3. On the footer, click on "Show Advanced Options"
4. Paste this inside "CSS for link hints" textbox
5. On the footer, click on "Save Changes"
*/
div > .vimiumHintMarker {
background: #000;