Skip to content

Instantly share code, notes, and snippets.

View hisasann's full-sized avatar
🔖
I aspire to become a bookseller.

Yoshiyuki Hisamatsu hisasann

🔖
I aspire to become a bookseller.
View GitHub Profile
@hisasann
hisasann / jBenchMark.js
Created April 16, 2012 03:16
ベンチマーク用jQueryPluginです。
/*
* jBenchMark
*
* Date: 2008/09/04
* @author hisasann
* @version 0.1
*
* Tested
* On IE6.0, IE7.0, FF 3.0, Opera 9.5 and Safari 3.1 on Windows.
*
@hisasann
hisasann / bubble-sort.js
Created April 16, 2012 03:18
バブルソート
var arr = [
5, 10, 1, 2, 4, 3
];
console.log(arr);
function sort(data) {
for (i = 0; i < data.length - 1; i++) {
console.log(i);
for (j = 0; j < data.length - i - 1; j++) {
@hisasann
hisasann / Ctrl+Fで検索窓にfocus.html
Created April 16, 2012 03:20
よくあるCtrl+Fなどをアタッチするコード。GoogleDocsなどで使われている仕組み。
<!DOCTYPE HTML>
<html lang="ru-RU">
<head>
<meta charset="UTF-8">
<title></title>
<script src="lib/jquery.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
$(function() {
$(window).keydown(function(event) {
if ((event.ctrlKey || event.metaKey) && event.keyCode === 70) {
@hisasann
hisasann / fizzBuzz.rb
Created April 16, 2012 03:31
RubyでのfizzBuzz。もっと効率いいのあるかな?
def fizzBuzz()
(1..100).each { |i|
s = "";
i % 3 == 0 ? s += "Fizz" : "";
i % 5 == 0 ? s += "Buzz" : "";
p s == "" ? i : s;
}
end
@hisasann
hisasann / IEはFxに比べてscrollイベントの量多い?.html
Created April 16, 2012 03:41
onscrollの実験:Fx1回に対して、IEは30回も発生するみたい・・・すごい。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title></title>
<style type="text/css" media="screen">
#scroller {
height: 200px;
border: 1px solid;
@hisasann
hisasann / sleep.js
Created April 16, 2012 06:46
Packages.java.lang.Thread.sleepを使ったサンプル
console.log("start");
setTimeout(function() {
sleep(2000);
console.log(1);
}, 1000);
console.log("end");
function sleep(msec) {
try {
// FirefoxかOpera
@hisasann
hisasann / エラトステネスの篩.js
Created April 16, 2012 06:59
エラトステネスの篩
console.log(makePrime(100));
function makePrime(maxCount) {
var max = maxCount + 1,
primes = new Array(max),
ret = new Array();
// 一旦すべて素数とする
for (var i=1; i < max; ++i) { primes[i] = true; };
@hisasann
hisasann / singleton.m
Created July 30, 2012 04:08
Objective-Cでシングルトン
#import "Status.h"
@implementation Status
@synthesize customUrlAlbumId = _customUrlAlbumId;
@synthesize isTopReload = _isTopReload;
@synthesize isThumbnailReload = _isThumbnailReload;
@synthesize isInvitationReload = _isInvitationReload;
static Status *sharedHistory = nil;
@hisasann
hisasann / PaddingLabel.m
Created July 30, 2012 04:11
UILabelにPadding入れる
#import "PaddingLabel.h"
@implementation PaddingLabel
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
@hisasann
hisasann / ImageUtil.m
Created July 30, 2012 04:31
Objective-Cで画像のリサイズ系
#import "ImageUtil.h"
@implementation ImageUtil
// 幅を元に、リサイズ画像の幅・高さを算出する
+ (CGSize)resizeFromWidth:(CGFloat)width imageSize:(CGSize)imageSize {
CGFloat s_x = imageSize.width / width;
CGFloat s_y = imageSize.height / (imageSize.height / s_x);
CGFloat scale = MAX(s_x, s_y);