Skip to content

Instantly share code, notes, and snippets.

View pmatseykanets's full-sized avatar
💻
Probably writing some Go code

Peter Matseykanets pmatseykanets

💻
Probably writing some Go code
View GitHub Profile
@pmatseykanets
pmatseykanets / str_putcsv.php
Last active August 29, 2015 14:22 — forked from johanmeiring/gist:2894568
Format line as CSV
<?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);
@pmatseykanets
pmatseykanets / postrges_tools.md
Created September 27, 2015 22:34
PostgreSQL tools
@pmatseykanets
pmatseykanets / states_hash.json
Created October 19, 2016 22:28 — forked from mshafrir/states_hash.json
US states in JSON form
{
"AL": "Alabama",
"AK": "Alaska",
"AS": "American Samoa",
"AZ": "Arizona",
"AR": "Arkansas",
"CA": "California",
"CO": "Colorado",
"CT": "Connecticut",
"DE": "Delaware",
@pmatseykanets
pmatseykanets / gist:c5c40eaf0db594f8a715691c3963ddbb
Created August 28, 2017 12:58 — forked from liunian/gist:9338301
Human Readable File Size with PHP
<?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'));
@pmatseykanets
pmatseykanets / next_id.sql
Last active August 30, 2017 22:31
Generate time based unique identifiers Instagram way
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;
@pmatseykanets
pmatseykanets / gist:3c1b373dd9f810779d228418aee69bf7
Created December 7, 2017 16:25 — forked from giannisp/gist:ebaca117ac9e44231421f04e7796d5ca
Upgrade PostgreSQL 9.6.5 to 10.0 using Homebrew (macOS)
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
@pmatseykanets
pmatseykanets / gist:ae6cc038750e45126fe64538d1132d35
Created December 7, 2017 20:11
Find duplicate values in csv file's column
# 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
@pmatseykanets
pmatseykanets / logrotate
Created January 29, 2018 02:15
Logrotate config for a Laravel application
# /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
@pmatseykanets
pmatseykanets / free_email_provider_domains.txt
Created February 22, 2018 16:52 — forked from tbrianjones/free_email_provider_domains.txt
A list of free email provider domains. Some of these are probably not around anymore. I've combined a dozen lists from around the web. Current "major providers" should all be in here as of the date this is created.
1033edge.com
11mail.com
123.com
123box.net
123india.com
123mail.cl
123qwe.co.uk
150ml.com
15meg4free.com
163.com
@pmatseykanets
pmatseykanets / forge_deploy.sh
Last active March 17, 2018 01:40
Forge Deploy script
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