Skip to content

Instantly share code, notes, and snippets.

@satooshi
satooshi / DateTime_createFromFormat.php
Last active August 29, 2015 13:56
! in time format.
<?php
$time = '03/2014';
$dt1 = \DateTime::createFromFormat('m/Y', $time); // "2014-03-19 17:14:38"
$dt2 = \DateTime::createFromFormat('!m/Y', $time); // "2014-03-01 00:00:00"
$dt3 = \DateTime::createFromFormat('m/Y!', $time); // "1970-01-01 00:00:00"
$dt4 = \DateTime::createFromFormat('m!/Y', $time); // "2014-01-01 00:00:00"
var_dump($dt1, $dt2, $dt3, $dt4);
/*
# Start the old vagrant
$ vagrant init centos-6.3
$ vagrant up
# You should see a message like:
# [default] The guest additions on this VM do not match the install version of
# VirtualBox! This may cause things such as forwarded ports, shared
# folders, and more to not work properly. If any of those things fail on
# this machine, please update the guest additions and repackage the
# box.
@satooshi
satooshi / hello.swift
Created June 5, 2014 17:19
hello Swift
protocol Greeter {
func greet() -> String
}
protocol エンジニャー {
func meo()
}
class Person: Greeter {
var name: String = "kitamura"
@satooshi
satooshi / gist:07101df80354db75c6b8
Created October 10, 2014 08:02
php 5.5.9 ubuntu 14.04 segmentation fault
(gdb) continue
Continuing.
Program received signal SIGSEGV, Segmentation fault.
0x000000000070ff48 in zend_std_object_get_class (object=0x35cfb78) at /build/buildd/php5-5.5.9+dfsg/Zend/zend_object_handlers.c:1499
1499 /build/buildd/php5-5.5.9+dfsg/Zend/zend_object_handlers.c: No such file or directory.
@satooshi
satooshi / notify.rb
Created October 27, 2014 09:02
Send a message to Mac OSX notification center.
def changed(file_path)
notify File.open(file_path, "rb").read
end
def notify(result)
messages = result.split("\n")
title = messages.shift
group = messages.shift
info = messages.join("\n")
@satooshi
satooshi / gist:b310ca78f1f26d24cae1
Last active October 30, 2015 15:27
tcp通信する場合のnginxの設定
upstream backend {
server 127.0.0.1:3001;
}
# http://henteco-labs.com/labs/2014/04/14/rails-nginx/
server {
location / {
try_files $uri @proxy;
}
@satooshi
satooshi / gist:608fd70c19cff35f4981
Last active October 30, 2015 15:28
unix socketを使う場合のnginxの設定
upstream backend {
server unix:/home/vagrant/prj/blog/tmp/sockets/puma.sock;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
root /home/vagrant/prj/blog/public;
index index.html;
@satooshi
satooshi / parseLineLtsv.php
Last active December 12, 2015 08:59
LTSV line parser for php.
#!/usr/bin/env php
<?php
while (false !== $line = fgets(STDIN)) {
print_r(parse($line));
}
// 68 sec
function parse($line)
{
@satooshi
satooshi / ColorCLI.php
Last active December 12, 2015 09:19 — forked from donatj/ColorCLI.php
<?php
/**
* PHP CLI Colors – PHP Class Command Line Colors (bash)
*
* $str = "This is an example ";
*
* foreach (ColorCLI::$foregroundColors as $fg => $fgCode) {
* echo ColorCLI::$fg($str);
*
@satooshi
satooshi / blog-sample.php
Last active December 13, 2015 20:38
PHP code for blog sample.
<?php
namespace Satooshi;
/**
* Short description.
*
* Long description.
*/
class Test
{