Skip to content

Instantly share code, notes, and snippets.

@walf443
walf443 / gist:4481036
Created January 8, 2013 03:57
変更があったphpファイルのsyntaxをチェック
# guard start -i
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
guard :shell, :all_on_start => false do
watch %r{((app|tests|lib/(src|tests))/.*\.php$)} do |m|
puts "######################## start syntax check #{m[0]} ##############################"
system("php /home/yoshimin/project/PHP-Parser/syntax_check.php #{m[0]}")
end
@walf443
walf443 / gist:4248281
Created December 10, 2012 03:46
phpおそろしい子!!
<?php
function echoCount($val)
{
var_dump($val);
echo "=> ";
echo count($val);
echo "\n";
}
@walf443
walf443 / gist:4152313
Created November 27, 2012 04:11
重複されるキーは無視される
<?php
$options = array('foo' => 'bar', 'baz' => 'boo');
$default = array('foo' => 'aaa');
$options += $default;
var_dump($options);
@walf443
walf443 / null.t
Created July 19, 2012 04:16
nullでも警告なしにすっぽ抜けるのね...
#!/usr/bin/env php<?php
require_once('lib/TestTap.php');
$t = new TestTap();
$t->subtest("nullのケース", function($t) {
$a = null;
$t->is($a, null, "null ok");
$t->is($a['xxxxx'], null, "null ok");
});
diff --git a/lib/CloudForecast/Data/Mysqlcachehit.pm b/lib/CloudForecast/Data/Mysqlcachehit.pm
index 4ef3ae6..238dca8 100644
--- a/lib/CloudForecast/Data/Mysqlcachehit.pm
+++ b/lib/CloudForecast/Data/Mysqlcachehit.pm
@@ -93,13 +93,13 @@ fetcher {
(1.0 - $status{'key_reads'} / $status{'key_read_requests'} ) * 100;
my $query_cache = sprintf '%.2f',
- ($status{'qcache_hits'} / ($status{'qcache_inserts'} + $status{'qcache_hits'} + $status{'qcache_not_cached'})
+ ($status{'qcache_hits'} / ( ($status{'qcache_inserts'} + $status{'qcache_hits'} + $status{'qcache_not_cached'
./test_rankd [ ~/project/cpp/rankd git[master] ]
# Testing: top_same_value
ok 1 - top ok
ok 2 - get_rank ok
ok 3 - top ok
# Testing: top_test2
ok 4 - 82 should be rank 0
# top 82
ok 5 - top ok
ok 6 - 82 should be rank 1
#!/usr/bin/perl
use strict;
use warnings;
use opts;
use Net::SSH;
use Parallel::ForkManager;
use IO::Socket;
use IO::File;
use IO::Select;
@walf443
walf443 / gist:1866537
Created February 19, 2012 23:44
get_memory_usage
void get_memory_usage(char *memsiz){
pid_t pid = getpid();
FILE *fh = popen("ps aux", "r");
char buffer[BUFSIZ];
char colbuf[BUFSIZ];
if ( fh == NULL ) {
perror("popen");
exit(1);
} else {
while ( fgets(buffer, BUFSIZ, fh) != NULL ) {
use strict;
use warnings;
use List::Util;
use String::Random;
List::Util::shuffle(1, 2, 3);
my @pids;
for my $counter ( 1..3 ) {
my $pid = fork();
@walf443
walf443 / gist:1663101
Created January 23, 2012 13:23
何々した順にならべるデータ構造
module Orderd
class Ranking
def initialize
@first = @last = Node.new
@item_id_of = {}
@marker_of = {}
@size = 0
end
def top item_id