Skip to content

Instantly share code, notes, and snippets.

@tmiz
tmiz / fib.py
Created October 18, 2011 07:21
blog sample
def fib(n):
if n==0:return 0
if n==1:return 1
return fib(n-1)+fib(n-2)
@tmiz
tmiz / cached_fib.py
Created October 18, 2011 07:23
cached fib
cache_fib={}
def c_fib(n):
if cache_fib.has_key(n):
return cache_fib[n]
if n==0:
cache_fib[0]=0
elif n==1:
cache_fib[1]=1
else:
cache_fib[n] = c_fib(n-1)+c_fib(n-2)
@tmiz
tmiz / fib.py
Created October 18, 2011 07:28
fib using generator
def fib_gen_():
temp1,temp2 = 0,1
while 1:
yield temp1 + temp2
temp2,temp1 = temp1,temp2+temp1
def alt_fib(n):
if n==0:return 0
elif n==1:return 1
a = fib_gen_()
@tmiz
tmiz / fib.output
Created October 18, 2011 07:33
fib output
>>> import fib
>>> fib.alt_fib(10)
55
>>> fib.alt_fib(100)
354224848179261915075L
>>> fib.alt_fib(1000)
43466557686937456435688527675040625802564660517371780402481729089536555417949051890403879840079255169295922593080322634775209689623239873322471161642996440906533187938298969649928516003704476137795166849228875L
>>> fib.alt_fib(10000)
33644764876431783266621612005107543310302148460680063906564769974680081442166662368155595513633734025582065332680836159373734790483865268263040892463056431887354544369559827491606602099884183933864652731300088830269235673613135117579297437854413752130520504347701602264758318906527890855154366159582987279682987510631200575428783453215515103870818298969791613127856265033195487140214287532698187962046936097879900350962302291026368131493195275630227837628441540360584402572114334961180023091208287046088923962328835461505776583271252546093591128203925285393434620904245248929403901706233888991085841065183173360437470737908552631764325733993712871937587746897479926305837065742830161637
@tmiz
tmiz / SystemSerial.cpp
Created October 18, 2011 09:00
Get System Serial Number for Mac / TN1103
//
// USAGE:
// $ clang++ main.cpp -framework CoreFoundation -framework IOKit -o SystemSerial
// $ ./SystemSerial
// Serial Number(System): XXXXXXXXXXX
//
// Reference.
// http://developer.apple.com/library/mac/#technotes/tn1103/_index.html
//
// tmiz moo@tmiz.net
@tmiz
tmiz / CoreLocationTest.m
Created December 1, 2011 12:08
Using CoreLocation on Mac OS X with command-line
//
// Using CoreLocation on Mac OS X with command-line
// $ clang CoreLocationTest.m -framework cocoa -framework CoreLocation
// $ ./a.out
// location service enabled
// 2011-12-01 21:03:01.839 a.out[10214:903] latitude,logitude : 35.606647, 140.695538
// 2011-12-01 21:03:01.842 a.out[10214:903] timestamp : 2011-12-01 21:01:36 +0900
// tmiz moo@tmiz.net
//
#import <cocoa/cocoa.h>
@tmiz
tmiz / build_openssl_dylib.sh
Last active November 1, 2023 13:18
Build latest OpenSSL Universal Binary on OSX
#!/bin/bash
OPENSSL_VERSION="1.0.1g"
curl -O http://www.openssl.org/source/openssl-$OPENSSL_VERSION.tar.gz
tar -xvzf openssl-$OPENSSL_VERSION.tar.gz
mv openssl-$OPENSSL_VERSION openssl_i386
tar -xvzf openssl-$OPENSSL_VERSION.tar.gz
mv openssl-$OPENSSL_VERSION openssl_x86_64
cd openssl_i386
@tmiz
tmiz / main.c
Created December 8, 2011 12:28
a sample which using openssl
#include <stdio.h>
#include <string.h>
#include "openssl/opensslv.h"
#include "openssl/sha.h"
void printBufferOfSha256(const unsigned char *output)
{
int i = 0;
for(; i < SHA256_DIGEST_LENGTH; i++) {
@tmiz
tmiz / monotest.py
Created December 13, 2011 04:40
IronPython Sample
#!/usr/bin/env ipy
import clr
clr.AddReference("System.Windows.Forms")
clr.AddReference('System.Drawing')
import System.Windows.Forms
import System.Drawing
myForm = System.Windows.Forms.Form()
myForm.Text = "2011 Mac Dev JP Advent Calendar"
myForm.Show()
@tmiz
tmiz / MainWindowController.cs
Created December 14, 2011 06:13
Example MonoMac 0001
using System;
using System.Collections.Generic;
using System.Linq;
using MonoMac.Foundation;
using MonoMac.AppKit;
namespace MonoDemoProject
{
public partial class MainWindowController : MonoMac.AppKit.NSWindowController
{