Skip to content

Instantly share code, notes, and snippets.

@mia-0032
mia-0032 / Form1.cs
Created April 6, 2013 12:31
C#勉強会で作ったオセロゲーム。元々のソースは https://gist.github.com/7shi/5031182 です。少し自分でもいじってみました。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
@mia-0032
mia-0032 / image_resizer.php
Created March 20, 2013 16:16
画像の縦横比を保ったまま、必要に応じて黒帯をつけて表示するプログラム。
<?php
class ImageResizer {
public function resize($path, $width, $height) {
if (is_int($width) === FALSE || is_int($height) === FALSE) {
throw new Exception('$widthまたは$heightが不正');
}
if (is_string($path) && is_file($path)) {
$this->resizeImage($path, $width, $height);
@mia-0032
mia-0032 / simple_xml_loader.php
Created January 27, 2013 02:22
simple_xml_loadを使ったXMLパーサー
<?php
/**
* simple_xml_loadを使ったXMLパーサー
*/
class XmlLoader {
const DISPLAY_XML_ERROR_LIMIT = 3; //一箇所が不適切なXMLになっていると連鎖的にエラーが大量に出るので。
/**
@mia-0032
mia-0032 / inspectConsistentHasher.php
Last active December 10, 2015 16:18
ConsistentHashingで本当に分散できているのかを検証するためのプログラム
<?php
error_reporting(E_ALL);
require_once '../class/ConsistentHasher.php';
$start_time = microtime(TRUE);
$nodes = array('1', '2', '3', '4');
$another_nodes = array('1', '2', '3', '4', '5');
$ids = range(1, 10000);
@mia-0032
mia-0032 / ConsistentHasher.php
Last active December 10, 2015 16:18
PHPでConsistentHashingを実装してみた
<?php
/**
* ConsistentHashing法で分散してくれるクラス
*/
class ConsistentHasher {
protected $ring;
protected $keys;
@mia-0032
mia-0032 / blogger_social_button_body.html
Created January 5, 2013 05:43
Blogger用ソーシャルボタン設置タグ(body側)
<!-- ソーシャルボタン用JS -->
<script src='http://platform.twitter.com/widgets.js' type='text/javascript'/>
<script src='https://apis.google.com/js/plusone.js' type='text/javascript'>{lang: &#39;ja&#39;}</script>
<script src='http://static.evernote.com/noteit.js' type='text/javascript'/>
<script async='async' charset='utf-8' src='http://b.st-hatena.com/js/bookmark_button.js' type='text/javascript'/>
@mia-0032
mia-0032 / blogger_social_button.html
Created January 5, 2013 05:42
Blogger用ソーシャルボタン設置タグ(記事側)
<!-- ソーシャルボタンここから -->
<!-- twitterボタン data-viaのところだけ自分のアカウント名を入れる -->
<a class='twitter-share-button' data-count='horizontal' data-lang='ja' data-via='Twitterアカウント名' expr:data-text='data:post.title + &quot; - &quot;+ data:title' expr:data-url='data:post.url' href='http://twitter.com/share'>Tweet</a>
<!-- facebookいいねボタン -->
<iframe allowTransparency='true' expr:src='&quot;http://www.facebook.com/plugins/like.php?href=&quot; + data:post.url + &quot;&amp;layout=button_count&amp;show_faces=false&amp;width=100&amp;action=like&amp;colorscheme=light&amp;height=21&quot;' frameborder='0' scrolling='no' style='border:none; overflow:hidden; width:100px; height:21px;'/>
<!-- hatenaブックマークボタン -->
<a class='hatena-bookmark-button' data-hatena-bookmark-layout='standard' expr:data-hatena-bookmark-title='data:post.title + &quot; - &quot;+ data:title' expr:href='&quot;http://b.hatena.ne.jp/entry/&quot; + data:post.url' title='このエントリーをはてなブックマークに追加'><img alt='このエントリーをはてなブックマークに追加' height='20' src='http://b.st-hatena.com/images/en
@mia-0032
mia-0032 / pjaxLoader.coffee
Last active December 10, 2015 04:58
PJAX通信でDOMをロードするクラス(CoffeeScript)
##PJAX通信でHTMLを取得してDOMを書き換える
class PjaxLoader
previousUrl: null
$container: null
$loading: null
constructor: () ->
@previousUrl = location.href
@$container = $('#content_area') ##書き換える対象のDOM
@$loading = $('#loading_image') ##ローディング表示の画像とか
$(window).bind('popstate', @_doPopstate)
@mia-0032
mia-0032 / pjax.php
Last active December 19, 2015 06:46
PJAX通信の実装(PHP側)
<?php
/**
* pjax通信かどうか判定する関数。
* ヘッダーがあるかないかで判定。
*/
function isPjax() {
$headers = getallheaders();
//ブラウザごとに送られるヘッダーの大文字小文字が違うので吸収・・・だけどもっといい方法ありそう
if ((isset($headers['X-PJAX']) && $headers['X-PJAX'] === "true") ||
@mia-0032
mia-0032 / Iterator.php
Created December 26, 2012 04:05
Iteratorパターン
<?php
interface MyIterator {
public function hasNext();
public function next();
}
class MovieShelf {