Skip to content

Instantly share code, notes, and snippets.

View Jim-Holmstroem's full-sized avatar
💭
Coding

Jim Holmström Jim-Holmstroem

💭
Coding
View GitHub Profile
@Jim-Holmstroem
Jim-Holmstroem / remove_if_on_string.cpp
Created January 2, 2012 00:40
Remove things (for example space) based on condition in std::string c++
//string.erase(std::remove_if(string.begin(),string.end(),&condition),string.end())
#include <algorithm>
#include <string>
bool condition(char c)
{
return c==' '; //simple example
}
@Jim-Holmstroem
Jim-Holmstroem / bash_eval_first
Created January 3, 2012 10:37
To evalute an expression in the arguments of a bash command
#example, will evalute and return the command inside the backticks `` to arguement
echo `pkg-config --cflags --libs gtk+-2.0`
#general
command `inner_command`
@Jim-Holmstroem
Jim-Holmstroem / numpy_array_hash.py
Created February 21, 2012 10:51
Hash numpy.array
from hashlib import sha1
import numpy
arr=numpy.zeros((256,256,4))
sha1(arr)
@Jim-Holmstroem
Jim-Holmstroem / sym_matrix.m
Created March 10, 2012 22:54
Symbolic matrices MATLAB
A=sym('[a b 0;c d 0;0 0 1]')
A*[1 0 0]'
@Jim-Holmstroem
Jim-Holmstroem / reinstallX
Created March 11, 2012 13:24
Reinstall X (Nvidia)
sudo apt-get purge nvidia*
#remove xorg.conf
sudo apt-get --reinstall xserver-xorg-core libgl1-mesa-glx:i386 libgl1-mesa-glx:amd64 libgl1-mesa-dri:i386 libgl1-mesa-dri:amd64
sudo dpkg-reconfigure xserver-xorg
sudo reboot
sudo apt-get install nvidia-current
#if this doesn't work
sudo apt-get install linux-headers-generic-pae
@Jim-Holmstroem
Jim-Holmstroem / vram_usage.sh
Created March 18, 2012 13:38
Get the amount of VRAM currently in use (nvidia/ubuntu)
nvidia-smi -a | grep Used
@Jim-Holmstroem
Jim-Holmstroem / vimhex
Created March 28, 2012 06:59
Hexeditor in VIM
:%!xxd #set
:%!xxd -r #unset
Stream vim’s buffer through the external program ‘xxd’
@Jim-Holmstroem
Jim-Holmstroem / int2bits.py
Created March 28, 2012 07:01
int to list of bits in Python
def int2bits(i,n,zero_element=0,one_element=1):
return list((zero_element,one_element)[i>>j & 1] for j in xrange(n-1,-1,-1))
for i in range(16):
print int2bits(i,4)
@Jim-Holmstroem
Jim-Holmstroem / maplist
Created March 28, 2012 07:02
Map indices tru list in Python
def maplist(a,indices):
return map(lambda i:operator.getitem(a,i),indices)
@Jim-Holmstroem
Jim-Holmstroem / finddivofzeroandgroupofunit.py
Created March 28, 2012 07:10
Pickout the div of zeroes / group of units for all elements in R in Python
dozsmatrix=dict(map(lambda a:(a,filter(lambda b:a*b==Zero,R)),R))
groupofunit=dict(map(lambda a:(a,filter(lambda b:a*b==e,Rstar)),Rstar))