Skip to content

Instantly share code, notes, and snippets.

View sassy's full-sized avatar
😀
happy hacking!

Satoshi Watanabe sassy

😀
happy hacking!
View GitHub Profile
@sassy
sassy / gist:1743591
Created February 5, 2012 06:52
rustでfizzbuzz
use std;
fn is_fizzbuzz(x:int) -> bool { x % 15 == 0}
fn is_fizz(x:int) -> bool { x % 3 == 0}
fn is_buzz(x:int) -> bool { x % 5 == 0}
fn fizzbuzz(n:int) -> str {
ret
if is_fizzbuzz(n) { "fizzbuzz"}
else if is_fizz(n) { "fizz" }
@sassy
sassy / gist:1745591
Created February 5, 2012 13:28
rustでクイックソート
use std;
fn sort(v: [int]) -> [int] {
let len = vec::len(v) as int;
if len < 2 { ret v; }
let i = 0;
let pivot = v[(len-1)/2];
let lv = [], rv = [];
while i < len {
@sassy
sassy / gist:1745669
Created February 5, 2012 13:48
rustでpascal's triangle
use std;
fn factorial(n: int) -> int {
if n == 0 {ret 1; }
else {ret n * factorial(n - 1); }
}
fn bt(n: int, k: int) -> int {
ret factorial(n) / (factorial(n -k) * factorial(k));
}
@sassy
sassy / gist:1807060
Created February 12, 2012 07:29
RustでGenericsを使ってみる
use std;
fn iter<T>(seq: [T], f: block(T)) {
for elt: T in seq {
f(elt);
}
}
fn main() {
let array :[str] = ["test", "test2", "test3"];
@sassy
sassy / gist:1839862
Created February 15, 2012 23:03
ActionBar(Android4.0) sample
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.ActionBar.TabListener;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
@sassy
sassy / gist:1858560
Created February 18, 2012 10:02
CでBoolean
typedef enum boolean_ {
false = 0,
true = 1
} boolean;
@sassy
sassy / gist:1861762
Created February 19, 2012 03:07
Cでn-queen
#include <stdio.h>
#include <stdlib.h>
#define N 8
typedef enum boolean_ {
false = 0,
true = 1
} boolean;
@sassy
sassy / gist:2267195
Created March 31, 2012 18:03
二分探索木
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
typedef struct sNode Node;
struct sNode {
int value;
Node *left;
Node *right;
};
javascript:(function(){
var f = document.createElement('iframe');
f.src='http://share.gree.jp/share?url=' + encodeURIComponent(location.href) + '&type=0&height=20';
f.width=100;
f.height=100;
f.frameBorder=0;
f.marginWidth=0;
f.marginHeight=0;
f.setAttribute('scrolling','no');
f.setAttribute('allowTransparency','true');
@sassy
sassy / gist:5945678
Created July 8, 2013 01:40
DailyMotionから動画を取得して、再生する。
<html>
<head>
<script src="http://api.dmcdn.net/all.js"></script>
<script type="text/javascript">
var videoArray = new Array();
var j = 0;
window.dmAsyncInit = function() {
DM.api('/videos', {search: "momoclo"}, function(response) {
console.log(response.list[0]);