Skip to content

Instantly share code, notes, and snippets.

View hiroshi-maybe's full-sized avatar

Hiroshi Kori hiroshi-maybe

  • San Jose, CA, United States
View GitHub Profile
@hiroshi-maybe
hiroshi-maybe / js-sandbox.html
Created January 8, 2012 06:39
instantly check javascript whether it can be compiled to not.
<html>
<head>
<script type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script>//<![CDATA[
$(document).ready(function(){
var p = function(val){
$("#result").append(val+"<br/>");
};
@hiroshi-maybe
hiroshi-maybe / google-employment-exam.html
Created February 14, 2012 16:52
Google Employment Exam
<!DOCTYPE HTML5>
<meta charset=\"UTF-8\"/>
<html>
<title>Google Employment Exam</title>
<body>
1<br/>
11<br/>
21<br/>
1211<br/>
111221<br/>
@hiroshi-maybe
hiroshi-maybe / fizzbuzz.rb
Created February 26, 2012 01:41
fizzbuzz
(1..1000000) .each {|i|
result=(i%FIZZ_NUM==0 ? "Fizz":"")+(i%BUZZ_NUM==0 ? "Buzz":"")
p result.empty? ? i.to_s : result
}
@hiroshi-maybe
hiroshi-maybe / extract_csv_from_dml.rb
Created August 2, 2012 10:00
Extract csv from DML in a specific format
#!/usr/bin/ruby
##################################################
#
# author: Hiroshi Kori
# Extract csv from DML in a specific format:
# INSERT INTO `table_name` (`column1`, `column2`, ..) VALUES
# (value1, value2, ..),
# (value1, value2, ..),
# (value1, value2, ..);
#
@hiroshi-maybe
hiroshi-maybe / todo.hs
Created December 29, 2012 11:07
Refined todo.hs in Chap 9 of "Learn You a Haskell for Great Good!": http://learnyouahaskell.com/
import System.Environment
import System.Directory
import System.IO
import Data.List
import Control.Exception
dispatch :: String -> [String] -> IO ()
dispatch "add" = add
dispatch "view" = view
dispatch "remove" = remove
@hiroshi-maybe
hiroshi-maybe / sleepSort.js
Created January 26, 2013 11:09
Sleep sort implemented with Javascript.
var sleepSort = function(array){
for (var i=0, length=array.length; i<length; i+=1) {
setTimeout((function(n){
return function(){
console.log(n);
};
})(array[i]), array[i]*100);
}
};
@hiroshi-maybe
hiroshi-maybe / bubbleSort.js
Created January 26, 2013 11:57
Bubble sort implemented with Javascript.
var bubbleSort = function(array) {
for (var i=0, length=array.length; i<length; i+=1) {
for (var j=0; j<array.length-i-1; j+=1) {
if (array[j]>array[j+1]) {
var smallNum = array[j+1];
array[j+1]=array[j];
array[j]=smallNum;
}
}
}
@hiroshi-maybe
hiroshi-maybe / combSort.js
Created February 3, 2013 09:13
Comb sort implemented with Javascript.
var combSort = function (array) {
var interval = Math.floor(array.length/1.3);
while (interval > 0) {
for(var i=0; i+interval<array.length; i+=1) {
if (array[i] > array[i+interval]) {
var small = array[i+interval];
array[i+interval] = array[i];
array[i] = small;
}
}
@hiroshi-maybe
hiroshi-maybe / selectionSort.js
Created February 3, 2013 09:25
Selection sort implemented with Javascript.
var selectionSort = function(array) {
for(var i=0, length=array.length; i<length; i+=1) {
var min_i = i;
for(var j=i+1; j<length; j+=1) {
if (array[j] < array[min_i]) {
min_i = j;
}
}
var small = array[min_i];
array[min_i] = array[i];
@hiroshi-maybe
hiroshi-maybe / insertionSort.js
Created February 3, 2013 09:57
Insertion sort implemented with Javascript.
var insertionSort = function(array) {
for(var i=1, length=array.length; i<length; i+=1) {
var insertion = array[i], j=i;
if (insertion < array[i-1]) {
do {
array[j] = array[j-1];
j-=1;
} while (array[j] > insertion && j > 0)
array[j] = insertion;
}