Skip to content

Instantly share code, notes, and snippets.

@tell
tell / add_asm_main.c
Created August 26, 2011 23:47
Practice Inline ASM on GCC
#include <assert.h>
#include <stdio.h>
void in_emu_add(int *z, const int x, const int y)
{
*z = x + y;
}
void in_asm_add(int *z, const int x, const int y)
{
@tell
tell / code.sage
Last active September 27, 2015 15:28
Symbolic calculation on Sage 4.7.1 using Napier's constant
## Problem: Do not use symbol 'e'.
## see http://homepage1.nifty.com/herumi/diary/1110.html#14
var('x t a b c d g') # we can not use symbol 'e' instead of 'g'.
assume(t > 0)
f = ((exp(x) - (a + b*x + c*x^2 + d*x^3 + g*x^4))^2).integral(x,0,t)
ans = solve([f.diff(a), f.diff(b), f.diff(c), f.diff(d), f.diff(g)], [a,b,c,d,g])
## work around
@tell
tell / matrix_mul.c
Created November 3, 2011 02:31
Matrix multiplication in C language
/*
* The author and original source code are from:
* 機械学習序曲(仮) > 数値計算の実行速度 - Python, C, Rの比較
* http://hawaii.naist.jp/~kohei-h/my/python-numeric-comp.html
*
* It is modified version in above Web page.
*
* This program needs data files to construct matrix.
* A generating data files program is published in
* original author's Web page.
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
struct Stack {
uint32_t used;
int *array;
};
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
struct Stack {
uint32_t used;
int *array;
};
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <stdio.h>
#include <setjmp.h>
sigjmp_buf return_point;
/* 適切で無いハンドラ */
# -*- coding: utf-8 -*-
import datetime
from threading import Thread
from Queue import Queue as queue
import SocketServer
import logging
import logging.handlers
class UTC(datetime.tzinfo):
@tell
tell / gmp.java
Created May 20, 2012 10:14
GMP Wrapper by JNA, but this code is broken
package com.github.tell.gmp;
import java.util.logging.ConsoleHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.github.tell.gmp.JNAGMP.GMPLib.mpz_struct;
import com.sun.jna.Library;
import com.sun.jna.Native;
@tell
tell / EventCall.java
Created September 28, 2012 23:50
Forwarding Events
package com.github.gist._3802655;
public interface EventCall <LISTENER> {
public void addListener(LISTENER listener);
public void removeListener(LISTENER listener);
}
@tell
tell / sage
Last active December 19, 2015 12:29
#!/bin/sh
if [ -n "$PYTHONPATH" ]; then
echo WARNING: unset PYTHONPATH 1>&2
unset PYTHONPATH
fi
SAGE_ROOT=/path/to/directory/of/sage
$SAGE_ROOT/sage "$@"