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 / 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 );
}
@ivan-krukov
ivan-krukov / Imports.pm
Created October 19, 2014 08:44
Imports - default modules I want to use everywhere in perl
package Imports;
strict->import();
warnings->import(qw(FATAL));
5.010_000->import();
utf8->import();
1;
@ivan-krukov
ivan-krukov / pointer_madness.xs
Created November 3, 2014 02:55
Get a structure pointer from perl's SV containing T_PTRREF
typedef struct datum {
int number;
} datum;
typedef datum * table;
TYPEMAP: <<END
table T_PTRREF
END
@ivan-krukov
ivan-krukov / median.c
Last active August 29, 2015 14:10
Memory-efficient median calculation
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
/**
* Median calculation
* This program takes an input file with one number per line and calculates mean and median.