https://github.com/fphilipe/psql2csv Run a query in psql and output the result as CSV
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 | |
/* Forked from https://gist.github.com/johanmeiring/2894568 */ | |
if (! function_exists('str_putcsv')) | |
{ | |
function str_putcsv($input, $delimiter = ',', $enclosure = '"') | |
{ | |
// Open a memory "file" for read/write | |
$memory = fopen('php://temp', 'r+'); | |
// Write the $input array to the "file" using fputcsv() | |
$length = fputcsv($memory, $input, $delimiter, $enclosure); |
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
{ | |
"AL": "Alabama", | |
"AK": "Alaska", | |
"AS": "American Samoa", | |
"AZ": "Arizona", | |
"AR": "Arkansas", | |
"CA": "California", | |
"CO": "Colorado", | |
"CT": "Connecticut", | |
"DE": "Delaware", |
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 | |
# http://jeffreysambells.com/2012/10/25/human-readable-filesize-php | |
function human_filesize($bytes, $decimals = 2) { | |
$size = array('B','kB','MB','GB','TB','PB','EB','ZB','YB'); | |
$factor = floor((strlen($bytes) - 1) / 3); | |
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$size[$factor]; | |
} | |
echo human_filesize(filesize('example.zip')); |
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
CREATE SEQUENCE next_id_seq; | |
CREATE OR REPLACE FUNCTION next_id(OUT id BIGINT) AS $$ | |
DECLARE | |
shard INT := 1; | |
epoch BIGINT := 1314220021721; | |
sequence BIGINT; | |
miliseconds BIGINT; | |
BEGIN | |
SELECT nextval('next_id_seq') % 1024 INTO sequence; |
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
After automatically updating Postgres to 10.0 via Homebrew, the pg_ctl start command didn't work. | |
The error was "The data directory was initialized by PostgreSQL version 9.6, which is not compatible with this version 10.0." | |
Database files have to be updated before starting the server, here are the steps that had to be followed: | |
# need to have both 9.6.x and latest 10.0 installed, and keep 10.0 as default | |
brew unlink postgresql | |
brew install postgresql@9.6 | |
brew unlink postgresql@9.6 | |
brew link postgresql |
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
# Mac OS X | |
csvcut -c 1 path/to/file.csv | uniq -c | grep -v '^ *1' | awk '{print $2}' | grep -f /dev/stdin path/to/file.csv |
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
# /etc/logrotate.d/app.example.com | |
/home/forge/app.example.com/storage/logs/*.log { | |
su forge forge | |
weekly | |
missingok | |
rotate 24 | |
compress | |
notifempty | |
copytruncate | |
create 755 forge forge |
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
1033edge.com | |
11mail.com | |
123.com | |
123box.net | |
123india.com | |
123mail.cl | |
123qwe.co.uk | |
150ml.com | |
15meg4free.com | |
163.com |
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
APP_DIR=/home/forge/sub.domain.com | |
RELEASE=$(date +%Y%m%d%H%M%S) | |
RELEASE_DIR=$APP_DIR/releases/$RELEASE | |
ARCHIVE=$RELEASE.tar.gz | |
PHP=php7.1 | |
[ -d $APP_DIR/releases ] || mkdir $APP_DIR/releases | |
cd $APP_DIR/releases | |
mkdir $RELEASE_DIR |
OlderNewer