Skip to content

Instantly share code, notes, and snippets.

@fcamp
fcamp / pre-commit.sh
Created April 11, 2019 12:56
phpcs pre-commit hook
#!/bin/bash
# Allows running phpcs on files that are going to be committed within src/ folder
#
# ### Prerequisites and configuration
#
# Set git config variable that points to phpcs rules folder (you have to do this once)
#
# `git config --global user.phpcs-standard ~/path/of/coding-standard`
#
# Require phpcs for your project (if not already done. You can check it with `composer info`)
@fcamp
fcamp / PhpunitDataproviderExample.php
Last active May 16, 2018 15:30
PhpunitDataproviderExample
<?php
use PHPUnit\Framework\TestCase;
class DataTest extends TestCase
{
/**
* @dataProvider myProvider
*/
public function testMethod($a, $b, $expected)
{
@fcamp
fcamp / convert.sh
Created November 9, 2017 11:24
Generates an mp4 from a bunch of images overlaying modify date
#!/bin/bash
#Generates an mp4 from a bunch of images overlaying data
#Requires imagemagick and ffmpeg
#Generates the temporary images overlaying the date we wont
for i in *.jpg; do
echo $i
convert $i -pointsize 48 -gravity NorthWest -annotate 0 "%[date:modify]" tmp-$i
done
#make a 2hz video with the images
@fcamp
fcamp / BitmaskTrait.php
Last active February 3, 2016 15:44
A simple trait to work with bits
<?php
/**
* Trait BitmaskTrait
* Sometimes you need to work with bits... to manage permissions or statuses.
* https://gist.github.com/fcamp
*
* @link http://stackoverflow.com/questions/1277470/looking-for-real-world-examples-of-bitwise-operations-in-php
* @link http://blog.code-head.com/how-to-write-a-permission-system-using-bits-and-bitwise-operations-in-php
* @link http://php.net/manual/it/language.operators.bitwise.php#108679
*/
@fcamp
fcamp / Phonograph.php
Last active December 18, 2015 11:36
A simple buffer accumulator. Slightly inspired by Twig and Plates Section
<?php
/**
* Just a tiny Wrapper of ob_start / ob_end
* @author https://github.com/fcamp
*/
class Phonograph
{
private static $data = [];
private static $currentName = null;
@fcamp
fcamp / gist:9661911
Created March 20, 2014 11:36
Overwrite a git branch with another
# http://stackoverflow.com/questions/2862590/how-to-replace-master-branch-in-git-entirely-from-another-branch
# Overwrite a branch (branch_old) with another (branch_new)
git checkout branch_new
git merge -s ours branch_old
git checkout branch_old
git merge branch_new