This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# source bash_init | |
SCRIPT_DIR=$(cd $(dirname $BASH_SOURCE); pwd) | |
export PATH="$PATH:$SCRIPT_DIR/node_modules/.bin" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* 半角スペース区切りの検索ワードを複数フィールドで検索する時にありがちなEloquent | |
**/ | |
$query = new QueryBuilder(); | |
$search_query = "foo bar"; | |
$search_fields = ['title', 'author']; | |
// WHERE (`title` LIKE '%foo%' or `authos` LIKE '%foo%') and (`title` LIKE '%bar%' or `authos` LIKE '%bar%') | |
foreach (array_map('trim', array_filter(explode(' ', $search_query))) as $word) { | |
$query->where(function ($query) use ($word, $search_fields) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// i番目の要素を1つ後ろにずらす(i>0) | |
a = ['aaa', 'bbb', 'ccc', 'ddd']; | |
i = 2; | |
a.splice(i-1, 2, a[i], a[i-1]); | |
console.log(a); // ['aaa', 'ccc', 'bbb', 'ddd']; | |
// i番目の要素を1つ前にずらす(i>0) | |
a = ['aaa', 'bbb', 'ccc', 'ddd']; | |
i = 2; | |
i--; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
OPTION="-rltgoDvz" | |
if [ $# -ne 1 ]; then | |
ARG="dry" | |
else | |
ARG=$1 | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fopen('php://output', 'a+') を使いましょう。 | |
<?php | |
$fields = [ | |
'p.name' => '名前', | |
'p.name_yomi' => 'よみがな', | |
'p.email' => 'メールアドレス', | |
'p.created_at' => '日時', | |
]; | |
ob_start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once '../../work/qr-code/vendor/autoload.php'; | |
use Endroid\QrCode\QrCode; | |
?> | |
<html> | |
<body> | |
<?php | |
$qr = new QrCode('Life is too short to be generating QR codes'); | |
$qr->setWriterByName('svg'); | |
$writer_options = [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function number_format_filesize($string) | |
{ | |
$size = intval($string); | |
$unit = "Byte"; | |
$units = array( | |
1 => "B", | |
1000 => "kB", | |
1000000 => "MB", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
LIVE_HOSTNAME='www.example.com' | |
NIC='ens3' | |
LIVE_IP=`nslookup $LIVE_HOSTNAME|grep "Address:"|grep -v "#53"` | |
LIVE_IP=`echo $LIVE_IP |sed -e "s/^Address: //"` | |
MYIP=`ip -f inet -o addr show $NIC|cut -d\ -f 7 | cut -d/ -f 1` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
MEMINFO=`free -m|grep "Mem:"` | |
MEM=(${MEMINFO// / }) | |
MEMSIZE=${MEM[1]} | |
SERVER_LIMIT=$((MEMSIZE/128)) | |
START_SERVERS=$((SERVER_LIMIT/7*5)) | |
sed -e "s/__START_SERVERS__/$START_SERVERS/g" /root/apache2_conf/mods-enabled/mpm_prefork.conf.placehold \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http'); | |
const url = require('url'); | |
const request = require('request'); | |
const cheerio = require('cheerio'); | |
const minimist = require("minimist"); | |
var LRU = require("lru-cache"); | |
var options = minimist(process.argv.slice(2), { | |
string: 'port', |
NewerOlder