Skip to content

Instantly share code, notes, and snippets.

View alchem0x2A's full-sized avatar
👨‍🍼

T.Tian alchem0x2A

👨‍🍼
View GitHub Profile
@alchem0x2A
alchem0x2A / mt19937.cpp
Created April 17, 2018 16:23
[C++] mt19937 snippet
#include <random>
#include <iostream>
int main()
{
std::random_device device;
/* Or use any number replace the device() */
std::mt19937 generator(device());
std::uniform_int_distribution<int> distribution(1,6);
@alchem0x2A
alchem0x2A / rand_array_generate.cpp
Created April 17, 2018 16:37
[c++] Fill an array with lambda function
#include <algorithm>
#include <iostream>
#include <random>
int main() {
std::mt19937_64 gen(42);
std::uniform_real_distribution<double> uni(-10.0, 10.0);
double *numbers = new double[20];
/*use std::generate to fill the array pointer with lambda function*/
std::generate(numbers, &numbers[20],
@alchem0x2A
alchem0x2A / array_point_func.cpp
Created April 20, 2018 14:59
Right Handle of Array Point with function
#include <iostream>
// Return vector y = x * x
void manipulate(double *y, double *x, size_t n){
/* x and y must be initialized! */
std::cout << "Inside the function" << std::endl;
std::cout << "Size of x?: " <<
sizeof(x) << " "
<< "Size of y?: "
<<sizeof(y)
@alchem0x2A
alchem0x2A / memcpy_simple.cpp
Created April 20, 2018 16:07
Memory copy of pointers in c++
#include <iostream>
#include <cstring> //memcpy implemented here
// Copy pointer y from x
void copy_pointer(double *y, const double *x, size_t n){
// The size in memcpy is byte length!
std::memcpy(y, x, n * sizeof(double));
}
int main() {
@alchem0x2A
alchem0x2A / sub_job_comsol_lsf.sh
Last active May 26, 2018 10:32
Template submission script for comsol in lsf
#Generic script for submitting comsol job
#usage: sub_job.sh [COMSOL_IN_NAME] [optional:MEM]
INFILE=$1
OUTFILE=$(echo $INFILE | cut -f 1 -d ".")
OUTFILE+="_out.mph"
#Memory alloc
MEM=4096
if [ $# -ge 2 ]; then
MEM=$2
@alchem0x2A
alchem0x2A / gpaw_config_euler.md
Last active September 23, 2019 14:20
Configure GPAW on euler cluster

Preparation

  • Compiler: python/3.1.1 (shipped) gcc-6.3.0, open_mpi/3.0.0, libxc/4.3.0, fftw/3.3.3, openblas/0.2.13_seq, scalapack
  • tar for numpy scipy matplotlib

Working on virtualenv

python -m venv gpaw
source ~/.virtualenv/gpaw/bin/activate

Alternatively, if you want to use the shipped =numpy= and =scipy= versions,

@alchem0x2A
alchem0x2A / uninstall.sh
Created July 5, 2018 13:00 — forked from myusuf3/uninstall.sh
how to cleanly uninstall python packages installed with python setup.py
# Next time you need to install something with python setup.py -- which should be never but things happen.
python setup.py install --record files.txt
# This will cause all the installed files to be printed to that directory.
# Then when you want to uninstall it simply run; be careful with the 'sudo'
cat files.txt | xargs sudo rm -rf
@alchem0x2A
alchem0x2A / gpaw_config_euler_intel.md
Last active July 6, 2018 09:56
Install GPAW with intel on Euler

Preparation

  • Compiler: intel/15.0, open_mpi/1.10.0, libxc/3.0.0, fftw/3.3.4, scalapack
  • tar for numpy scipy matplotlib

Compile python with intel

Download the python tarball, untar and cd into the root directory.

./configure --prefix="abs/path/to/build" --with-icc CC=icc CXX=icpc
@alchem0x2A
alchem0x2A / convert.py
Last active December 10, 2018 11:15
Convert all video files under current folder to mp4
import os, os.path
import subprocess
def convert(in_name, out_name, delete=True):
prog = "ffmpeg"
params = ["-i", "{}".format(in_name),
"-pix_fmt", "yuv420p",
"-vcodec", "libx264",
"{}".format(out_name)]
res = subprocess.call([prog, *params])
@alchem0x2A
alchem0x2A / wrapper.sh
Last active August 18, 2019 16:19
[Emacs] Wrapping up emacsclient to automatically start server
#!/bin/sh
# Provide a wrapper of emacsclient that automatically opens up Emacs or server
function ec_wrapper {
GREEN='\033[0;32m'
NC='\033[0m'
buffers=$@
cmd="emacsclient -nqc"
# Excecute command