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 / makefile
Last active Aug 29, 2015
Float array returns with python ctypes
View makefile numbers.c
gcc --std=c99 -fPIC -c numbers.c
gcc -shared numbers.o -o
rm -f numbers.o
ivan-krukov /
Created Feb 28, 2014
Get a table of floats out of a string
[map(float,a.split(" ")) for a in data.split("\n")]
ivan-krukov /
Created Jun 3, 2014
Armadillo 4.300.8 Arch Linux AUR PKGBIULD
# Maintainer: Lucas Hermann Negri <>
# Contributor: shacristo
pkgdesc="C++ linear algebra library"
arch=('i686' 'x86_64')
license=('MPL 2.0')
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 / 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 /
Last active Aug 29, 2015
A dumb line filter
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 /
Created Oct 19, 2014
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 /
Created Oct 19, 2014
Imports - default modules I want to use everywhere in perl
package Imports;
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;
table T_PTRREF
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.