Skip to content

Instantly share code, notes, and snippets.

View auxiliary's full-sized avatar

Mohammad (Moa) Raji auxiliary

View GitHub Profile
@auxiliary
auxiliary / spawn.cpp
Created September 6, 2017 23:25 — forked from konstantint/spawn.cpp
Example of communication with a subprocess via stdin/stdout
//
// Example of communication with a subprocess via stdin/stdout
// Author: Konstantin Tretyakov
// License: MIT
//
#include <ext/stdio_filebuf.h> // NB: Specific to libstdc++
#include <sys/wait.h>
#include <unistd.h>
#include <iostream>
@auxiliary
auxiliary / git_change_commit_alias
Created August 28, 2017 14:05
Git change commit alias
[alias]
change-commits = "!f() { VAR1=$1; VAR='$'$1; OLD=$2; NEW=$3; echo \"Are you sure for replace $VAR $OLD => $NEW ?(Y/N)\";read OK;if [ \"$OK\" = 'Y' ] ; then shift 3; git filter-branch --env-filter \"if [ \\\"${VAR}\\\" = '$OLD' ]; then export $VAR1='$NEW';echo 'to $NEW'; fi\" $@; fi;}; f "
# Usage:
# git change-commits GIT_AUTHOR_EMAIL "OLD EMAIL" "NEW EMAIL"
# git push --force --tags origin 'refs/heads/*'
@auxiliary
auxiliary / vim_layouts.vim
Created May 2, 2017 18:32
Automatic Vim Layouts
" Vim Layouts (pure Vim version)
argdelete *
bufdo argadd %:p
let args = split(expand("##"))
let counter = 0
for i in args
if counter % 4 == 0
if counter == 0
silent exe "edit" i
else
@auxiliary
auxiliary / filter_spark_logs.sh
Created April 30, 2017 02:11
Redirections needed to run a spark job without the annoying INFO logs
((<file submit command> 1>&3) 2>&1 | awk '/Error/') 3>&1
@auxiliary
auxiliary / python_in_cpp.cpp
Created April 13, 2017 01:34
Sample code to call a python function in cpp
#include <python2.7/Python.h>
#include <iostream>
int main(int argc, char *argv[])
{
PyObject *pModule, *pModuleName, *pDict, *pFunc, *pValue, *pArgs;
Py_Initialize();
pModuleName = PyString_FromString("pie");
pModule = PyImport_Import(pModuleName);
// An OLN namespace
namespace = {
foo: function(){ alert('namespace.foo'); },
bar: function(){ alert('namespace.bar'); },
};
// A namespace
(function(projecto){
projecto.flag = true;
projecto.foo = function()
@auxiliary
auxiliary / volume_rendering.py
Created October 9, 2016 03:57 — forked from kevin-keraudren/volume_rendering.py
Volume rendering in Python using VTK-SimpleITK
#!/usr/bin/python
import SimpleITK as sitk
import vtk
import numpy as np
import sys
from vtk.util.vtkConstants import *
filename = sys.argv[1]
#!/usr/bin/env python
import numpy as np
def getDegree(ref_id, grid_list):
results = np.zeros(grid_list[0].shape)
for i, grid in enumerate(grid_list):
results += (grid_list[ref_id] == grid)
return results / float(len(grid_list)) * 100
#!/usr/bin/python
import numpy as np
import sys
sys.path.append('/home/mohammad/Downloads/visit2_10_0.linux-x86_64/2.10.0/linux-x86_64/lib/site-packages')
import vtk
from vtk.util.vtkConstants import *
# In case you need byte arrays
import numpy as np
a = np.uint64(7640891576956014592) #64 bits
b = a.tostring() # '\x00\xd0\xbc\xf3g\xe6\tj' in bytes
b = bytearray(b) # bytearray(b'\x00\xd0\xbc\xf3g\xe6\tj') Byte array object
# Padding
a = [1, 1, 1, 1, 1]
a + [0] * (16 - len(a)) # [1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]