Skip to content

Instantly share code, notes, and snippets.

View carlos-jenkins's full-sized avatar

Carlos Jenkins carlos-jenkins

View GitHub Profile
@carlos-jenkins
carlos-jenkins / genetic_code.c
Last active August 29, 2015 14:07
Genetic code conversion routine implemented in constant time using a lookup table. It supports both DNA and mRNA sequences.
/*
* Copyright (C) 2014 Carlos Jenkins <carlos@jenkins.co.cr>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
from gi.repository import Gtk
from os.path import abspath, dirname, join
class MyApp(object):
def __init__(self):
"""
Build GUI
"""
@carlos-jenkins
carlos-jenkins / fibonacci.py
Last active August 29, 2015 14:14
Different approaches to program the Fibonacci sequence algorithm.
# -*- coding:utf-8 -*-
# Different approaches to program the Fibonacci sequence algorithm.
#
# - Bottom-up stack recursion.
# - Top-down tail recursion.
# - Bottom-up iterative.
# - Bottom-up dynamic programming.
# - Top-down dynamic programming.
#
# For more information see:
@carlos-jenkins
carlos-jenkins / debug.py
Last active August 29, 2015 14:15
Python debug breakpoint
# -*- coding:utf-8 -*-
#
# When executed, this file shows to following behavior:
#
# $ python debug.py
# * Break: debug.py ::: Line 72
# * Continue with Ctrl+D...
# >>> a
# 10
# >>>
@carlos-jenkins
carlos-jenkins / Makefile
Created March 26, 2015 18:47
Create a hierarchy of nodes using Graphviz and HTML
# Document variables
ENTRY = domains.html
PAGE_TPL = page.tpl
BUILDDIR = build
INPUTS = $(wildcard *.dot)
IMGS = $(INPUTS:%.dot=%.png)
BUILD_IMGS = $(addprefix $(BUILDDIR)/, $(IMGS))
HTML = $(INPUTS:%.dot=%.html)
BUILD_HTML = $(addprefix $(BUILDDIR)/, $(HTML))
@carlos-jenkins
carlos-jenkins / bytes.c
Created May 5, 2015 20:08
Bytes structure in C
// Bytes structure to handle the data pointer and size tuple together
// and using a single heap allocation
// gcc bytes.c -o bytes
// ./bytes
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
typedef struct
@carlos-jenkins
carlos-jenkins / register.c
Last active August 29, 2015 14:20
Example of a register structure that can be memory mapped
// Example of a memory mapped register structure:
//
// gcc register.c -o register
// ./register
//
// This assumes register size is 8bits.
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
@carlos-jenkins
carlos-jenkins / custom_elf_section.c
Created May 22, 2015 00:31
C magic to put, and then iterate, some symbols in an ELF custom section.
#include <stdio.h>
//
// Define a thing to store in sections
//
struct mything {
const char* name;
int num;
};
@carlos-jenkins
carlos-jenkins / hexdump.py
Created June 4, 2015 00:06
Hexdump implementation in Python 2.7 and 3.
# -*- coding:utf-8 -*-
#
# Copyright (C) 2015 Carlos Jenkins <carlos@jenkins.co.cr>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
@carlos-jenkins
carlos-jenkins / add_digits.py
Last active September 15, 2015 10:52
Using timeit
def add_digits_optimized(num):
"""
Recursively sum al digits of a number until result is one digit.
Optimized version using simple integer logic.
:param int num: Number to sum all it's digits.
:rtype: int
:return: The recusive sum of all digits.
"""
result = 0