Skip to content

Instantly share code, notes, and snippets.

View koriym's full-sized avatar

Akihito Koriyama koriym

View GitHub Profile
@koriym
koriym / gist:3616424
Created September 4, 2012 04:06
isAssoc($array)
/**
* Determines if an array is associative
*
* @param array $array Array to check
*
* @return bool
*/
private function isAssoc(array $array)
{
return (bool) count(array_filter(array_keys($array), 'is_string'));
@koriym
koriym / gist:3766081
Created September 22, 2012 12:45
[eclipse][juno] Enable to toggle comment with shortcut key [cmd + /]
drop this file onto dropins folder.
http://www.eclipse.org/downloads/download.php?file=/tools/pdt/updates/2.2/milestones/plugins/org.eclipse.php.ui_2.2.1.v20101001-2300.jar
restart eclipse option with -clean
that's it.
@koriym
koriym / gist:3909776
Created October 18, 2012 03:51
Could not load package zendframework/zendframework
When using this composer.json file the following error message appears:
[RuntimeException]
Could not load package zendframework/zendframework in http://packages.zendframework.com: [UnexpectedValueException] Could not parse version constraint develop
[UnexpectedValueException]
Could not parse version constraint develop
{
"repositories": [
{
@koriym
koriym / ApcFacebook.txt
Created October 18, 2012 11:16
ApcFacebook
; http://ja.scribd.com/doc/88689/ApcFacebook
; Slam Defenses & TTL
apc.slam_defense=0
apc.write_lock=0
apc.file_update_protection=2
apc.ttl=0
apc.user_ttl=0
apc.gc_ttl=3600
; Filters
apc.max_file_size=1M
@koriym
koriym / rm-r
Created January 30, 2013 12:48
recursively remove a directory by PHP closure
$rm = function ($dir) use (&$rm) {
foreach(glob($dir . '/*') as $file) {
is_dir($file) ? $rm($file) : unlink($file);
rmdir($file);
}
};
// delete
$rm('./tmp');
@koriym
koriym / gist:4715085
Created February 5, 2013 15:20
macports maintenance
sudo port sync
sudo port selfupdate
sudo port clean –dist outdated
sudo port upgrade outdated
sudo port -u uninstall
@koriym
koriym / gist:4721099
Created February 6, 2013 08:06
PHP5.4でのpecl/imagickインストール ※PHP5.4ではimagick-betaでないとコンパイルできない問題 https://bugs.php.net/bug.php?id=61501&edit=3
sudo port install ImageMagick
pecl download imagick-beta
tar xvzf imagick-3.1.0RC2.tgz
cd imagick-3.1.0RC2
phpize
./configure --with-imagick=/opt/local
make
sudo make install
@koriym
koriym / gist:4743773
Created February 9, 2013 04:00
短いハッシュ base64_encodeを使ってハッシュを圧縮
<?php
$shortHash = function ($data, $algo = 'CRC32') {
return strtr(rtrim(base64_encode(pack('H*', $algo($data))), '='), '+/', '-_');
};
$a = 'hello';
echo $a;
echo md5($a) . PHP_EOL; // hello5d41402abc4b2a76b9719d911017c592
echo CRC32($a) . PHP_EOL; // 907060870
@koriym
koriym / gist:5549847
Created May 9, 2013 19:23
vhosts.conf for osx: /private/etc/apache2/extra/httpd-vhosts.conf
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
@koriym
koriym / gist:5574222
Last active December 17, 2015 07:39
Fatal error: Method BEAR\Resource\Request::__toString()
<?php
class A
{
public function __toString()
{
try {
resource();
} catch (Exception $e) {
return '';
}