Skip to content

Instantly share code, notes, and snippets.

View ivan-krukov's full-sized avatar
🗃️
Getting there

Ivan Krukov ivan-krukov

🗃️
Getting there
View GitHub Profile
@ivan-krukov
ivan-krukov / linearSolver.cpp
Created November 29, 2013 03:18
Simple example for linear system solver in LAPACK
#include "mkl.h"
#include <math.h>
#include <float.h>
#include <stdio.h>
/* Auxiliary routine: printing a matrix */
void print_matrix(float * matrix, int nrow, int ncol) {
for (int i = 0; i < nrow; i++) {
for (int j = 0; j < ncol; j++) {
printf("%.*e\t",FLT_DIG, matrix[i * ncol + j]);
@ivan-krukov
ivan-krukov / scd.cpp
Created December 3, 2013 21:50
Singular value decomposition to solve the null space problem
#include "mkl.h"
#include <math.h>
#include <float.h>
#include <ctime>
#include <stdio.h>
/* Auxiliary routine: printing a matrix */
void print_matrix(double * matrix, int nrow, int ncol) {
for (int i = 0; i < nrow; i++) {
for (int j = 0; j < ncol; j++) {
@ivan-krukov
ivan-krukov / matplot.R
Created December 9, 2013 20:00
Matrix plotting in R
#this is a simple way to plot a matrix from a txt file
mat_data_frame=read.table("data.txt",header=F)
#rev is there to start plotting M(0,0) in the upper left corner
#col=rainbow(10) uses the rainbow color palette. You can find other ones here:
#http://stat.ethz.ch/R-manual/R-devel/library/grDevices/html/palettes.html
image(as.matrix(rev(mat_data_frame)),col=rainbow(10))
@ivan-krukov
ivan-krukov / makefile
Last active August 29, 2015 13:55
Float array returns with python ctypes
numbers.so: numbers.c
gcc --std=c99 -fPIC -c numbers.c
gcc -shared numbers.o -o numbers.so
clean:
rm -f numbers.o numbers.so
@ivan-krukov
ivan-krukov / munge.py
Created February 28, 2014 20:30
Get a table of floats out of a string
[map(float,a.split(" ")) for a in data.split("\n")]
@ivan-krukov
ivan-krukov / Armadillo-Arch-PKGBUILD.sh
Created June 3, 2014 04:00
Armadillo 4.300.8 Arch Linux AUR PKGBIULD
# Maintainer: Lucas Hermann Negri <lucashnegri@gmail.com>
# Contributor: shacristo
pkgname=armadillo
pkgver=4.300.8
pkgrel=1
pkgdesc="C++ linear algebra library"
arch=('i686' 'x86_64')
url="http://arma.sourceforge.net/"
license=('MPL 2.0')
@ivan-krukov
ivan-krukov / example.c
Last active August 29, 2015 14:06
Using sds with clib/list
//A little function to allocate a length-1 sds from a char
//This is a little nasty, since we would need a lot of tiny mallocs if we do this often
sds sdsnewchar(char c) {
//Do some dirty allocations to save the char
char *ch = (char*)malloc(2*sizeof(char)); //culprit of small size allocation - could pre-allocate if we do this often
ch[0] = c;
ch[1] = '\0'; //zero-termination
sds str = sdsnew(ch); //new sds item, copied
free(ch); //sdsnew copies the content, so we can free
return str;
@ivan-krukov
ivan-krukov / list.c
Created October 1, 2014 04:37
Some queue-like lists
#include "list.h"
list* list_init() {
list* ls = (list*)malloc(sizeof(list));
ls->head = (list_node*)malloc(sizeof(list_node));
ls->cursor = ls->head;
ls->head->data = NULL;
ls->dealloc = NULL;
ls->copy = NULL;
return ls;
@ivan-krukov
ivan-krukov / vcf-filter.pl
Last active August 29, 2015 14:07
A dumb line filter
#/usr/bin/perl
use strict;
use warnings;
#The names of the input files are provided on the command line
if (@ARGV == 2) {
# Read input files
my $ids_file = $ARGV[0];
@ivan-krukov
ivan-krukov / codon_number.pl
Created October 19, 2014 04:08
Calculate codon number
sub codon_sequence {
my ($self, $n) = @_;
my ( $r, @s );
for my $i ( 0 .. 2 ) {
$r = $n % 4;
$n = $n >> 2;
unshift( @s, $nucleotides[$r] );
}
return join( '', @s );
}