Skip to content

Instantly share code, notes, and snippets.

View andreipetcu's full-sized avatar
💯

Andrei Petcu andreipetcu

💯
View GitHub Profile
@andreipetcu
andreipetcu / composer.json
Last active April 16, 2018 13:54
Git pre commit hook
{
"scripts": {
"phpcs": [
"./vendor/bin/phpcs --standard=PSR2 app/"
],
"phpmd": [
"./vendor/bin/phpmd app/ text phpmd.xml"
],
"security": [
"php ./common/security-checker.phar security:check composer.lock --timeout=5 --no-ansi"
@andreipetcu
andreipetcu / prepare-commit-msg.sh
Last active February 19, 2017 19:27 — forked from bartoszmajsak/prepare-commit-msg.sh
How to automatically prepend git commit with a branch name
#!/bin/bash
# This way you can customize which branches should be skipped when
# prepending commit message.
if [ -z "$BRANCHES_TO_SKIP" ]; then
BRANCHES_TO_SKIP=(master develop test)
fi
BRANCH_NAME=$(git symbolic-ref --short HEAD)
BRANCH_NAME="${BRANCH_NAME##*/}"
@andreipetcu
andreipetcu / gitflow-breakdown.md
Created January 12, 2017 14:05 — forked from JamesMGreene/gitflow-breakdown.md
A comparison of using `git flow` commands versus raw `git` commands.

Initialize

gitflow git
git flow init git init
git commit --allow-empty -m "Initial commit"
git checkout -b develop master

Connect to the remote repository

@andreipetcu
andreipetcu / foobar.php
Last active January 11, 2017 08:25
Interface return type
<?php
interface iFoo {
public function print(): iFoo;
}
interface iBar {
public function write(): iBar;
}
@andreipetcu
andreipetcu / fix-locale.sh
Created August 19, 2016 10:12
Fix Ubuntu's (14.04) locale issue
#!/bin/bash
export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
locale-gen en_US.UTF-8
sudo dpkg-reconfigure locales
@andreipetcu
andreipetcu / date.php
Created June 28, 2016 09:46
Date/time php helper
<?php
/**
* Calculates the difference between two timestamps
* @param integer $d1 first date
* @param integer $d2 second date
* @return string
*/
function dateDiff($d1, $d2) {
if ($d1 < $d2) {
@andreipetcu
andreipetcu / sshfs.sh
Created May 31, 2016 09:30
Mounting remote directory through SSH
sudo sshfs -o allow_other,IdentityFile=~/.ssh/id_dsa user@XXX.XXX.XXX.XXX:/remote/path /local/path
# Unmount the filesystem after you're done.
sudo umount /local/path
@andreipetcu
andreipetcu / curl_helper.php
Created May 19, 2016 13:06
Fetch content from URLs using Chrome headers and a cookie jar.
<?php
function fetch($url) {
$ch = curl_init();
$useragent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.101 Safari/537.36";
$headers = [];
$headers[] = "Cache-Control: max-age=0";
$headers[] = "Connection: keep-alive";
$headers[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
@andreipetcu
andreipetcu / deployer.sh
Created April 19, 2016 16:37
Gives proper permissions to a deployer
#!/bin/sh
# Usage: ./deployer.sh whateverUser /var/www
# If the user is already in other groups make sure to manually assign them to the deployer after running this script.
DEPLOYER=$1
WWWDIR=$2
# Makes www-data the user's primary group
sudo usermod -g www-data "$DEPLOYER"
@andreipetcu
andreipetcu / myappindicator_v5.py
Created February 20, 2016 19:25 — forked from candidtim/myappindicator_v5.py
Ubuntu AppIndicator to show Chuck Norris jokes
# This code is an example for a tutorial on Ubuntu Unity/Gnome AppIndicators:
# http://candidtim.github.io/appindicator/2014/09/13/ubuntu-appindicator-step-by-step.html
import os
import signal
import json
from urllib2 import Request, urlopen, URLError
from gi.repository import Gtk as gtk