Skip to content

Instantly share code, notes, and snippets.

@localdisk
localdisk / gist:5864130
Created June 26, 2013 01:47
Hello Laravel!
<?php
Route::get('/', function()
{
return 'Hello Laravel!';
});
@localdisk
localdisk / gist:6503902
Last active December 22, 2015 17:09
Confide のリソースファイルを日本語化しました。
<?php
return array(
// 'username' => 'Username',
'username' => 'ユーザー名',
// 'password' => 'Password',
'password' => 'パスワード',
// 'password_confirmation' => 'Confirm Password',
'password_confirmation' => 'パスワードの確認',
@localdisk
localdisk / html_macros.php
Last active December 31, 2015 02:39
Laravel4 HTML macros.
<?php
// env == local の場合 noindex, nofollow する
HTML::macro('follow', function() {
if (App::environment() === 'local') {
return PHP_EOL . '<meta name="robots" content="noindex,nofollow" />';
}
return '';
});
// 配列を分解して keywords にセット
HTML::macro('keywords', function($keywords) {
@localdisk
localdisk / routes.php
Last active January 1, 2016 16:09
Laravel Transaction Example
<?php
Route::post('save', function() {
$user = new User;
$user->username = 'foo';
$user->password = Hash::make('password');
$user->email = 'foo@bar.com';
DB::transaction(function() use ($user) {
$user->save();
});
@localdisk
localdisk / filters.php
Created January 10, 2014 03:07
Laravel 4 CSRF on all POST requests
<?php
App::before(function($request)
{
// POST / PUT / DELETE / PATCH also included You can use the $request-> getRealMethod()
if ($request->getMethod() === 'POST') {
Route::callRouteFilter('csrf', [], '', $request);
}
});
@localdisk
localdisk / Vagrantfile
Created January 19, 2014 03:24
basic vagrant file
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define :node do |node|
@localdisk
localdisk / play
Created January 21, 2014 07:27
playframework service
#!/bin/bash
# chkconfig: 345 20 80
# description: Play start/shutdown script
# processname: play
#
# Instalation:
# copy file to /etc/init.d
# chmod +x /etc/init.d/play
# chkconfig --add /etc/init.d/play
# chkconfig play on
@localdisk
localdisk / macros.php
Created January 27, 2014 04:07
Response::xml macro
<?php
Response::macro('xml', function(array $vars, $status = 200, array $header = [], $xml = null)
{
if (is_null($xml)) {
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><response/>');
}
foreach ($vars as $key => $value) {
if (is_array($value)) {
Response::xml($value, $status, $header, $xml->addChild($key));
@localdisk
localdisk / carbon.php
Created January 30, 2014 01:04
Carbon の使い方
<?php
// Carbon のインストール
// Composer 使います。使ってない人はそろそろ手を付けたほうがいいですよ
// composer.json にこう書いて…
// {
// "require": {
// "nesbot/Carbon": "*"
// }
// }
@localdisk
localdisk / typetalk.php
Created February 7, 2014 19:51
typetalk api php sample
<?php
$clientId = 'xxxxxxxxxxxxxxxxxxxx';
$clientSecret = 'xxxxxxxxxxxxxxxxxxxx';
$topicId = 'xxx';
$msg = 'Hello! typetalk! use PHP API!';
$tokenQuery = http_build_query([
'client_id' => $clientId,