Skip to content

Instantly share code, notes, and snippets.

Ivan Krukov ivan-krukov

  • Canada
Block or report user

Report or block ivan-krukov

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ivan-krukov
ivan-krukov / makefile
Last active Aug 29, 2015
Float array returns with python ctypes
View makefile
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 Feb 28, 2014
Get a table of floats out of a string
View munge.py
[map(float,a.split(" ")) for a in data.split("\n")]
@ivan-krukov
ivan-krukov / Armadillo-Arch-PKGBUILD.sh
Created Jun 3, 2014
Armadillo 4.300.8 Arch Linux AUR PKGBIULD
View Armadillo-Arch-PKGBUILD.sh
# 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 Aug 29, 2015
Using sds with clib/list
View example.c
//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 Oct 1, 2014
Some queue-like lists
View list.c
#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 Aug 29, 2015
A dumb line filter
View vcf-filter.pl
#/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 Oct 19, 2014
Calculate codon number
View codon_number.pl
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 Oct 19, 2014
Imports - default modules I want to use everywhere in perl
View Imports.pm
package Imports;
strict->import();
warnings->import(qw(FATAL));
5.010_000->import();
utf8->import();
1;
@ivan-krukov
ivan-krukov / pointer_madness.xs
Created Nov 3, 2014
Get a structure pointer from perl's SV containing T_PTRREF
View pointer_madness.xs
typedef struct datum {
int number;
} datum;
typedef datum * table;
TYPEMAP: <<END
table T_PTRREF
END
@ivan-krukov
ivan-krukov / median.c
Last active Aug 29, 2015
Memory-efficient median calculation
View median.c
#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.
You can’t perform that action at this time.