Skip to content

Instantly share code, notes, and snippets.

View chalasr's full-sized avatar

Robin Chalas chalasr

View GitHub Profile
@chalasr
chalasr / SecurityController.php
Last active December 14, 2017 09:33
Generate a token manually in controller - LexikJWTAuthenticationBundle
<?php
namespace App\UserBundle\Controller;
use Doctrine\ORM\EntityManager;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
/**
@chalasr
chalasr / node-apache-vhost
Last active December 23, 2015 16:51
Working vhost for get content of yourdomain.fr:3000 by browsing yourdomain.fr
<VirtualHost *:80>
ServerName yourdomain.fr
ServerAlias www.yourdomain.fr
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass http://yourdomain.fr:3000/
@chalasr
chalasr / jekyll_gist_tag.rb
Last active April 8, 2021 10:45 — forked from imathis/gist_tag.rb
Embed gists in markdown files of a jekyll application by creating a custom Liquid tag
require 'cgi'
require 'digest/md5'
require 'net/https'
require 'uri'
module Jekyll
class GistTag < Liquid::Tag
def initialize(tag_name, text, token)
super
@text = text
@chalasr
chalasr / ClearIconsCacheOSX.md
Last active December 28, 2015 21:49
Clear icons cache on OSX

$ sudo find /private/var/folders/ -name com.apple.dock.iconcache -exec rm {} \;
$ sudo find /private/var/folders/ -name com.apple.iconservices -exec rm -rf {} \;
$ sudo rm -rf /Library/Caches/com.apple.iconservices.store

@chalasr
chalasr / commit-msg
Last active July 18, 2018 18:04
Beautify git commit message by capitalize message's first letter + prepend issue ID from ref.
#!/bin/bash
# original message
base=$(cat $1)
# ticket patterns
patterns=(ticket- issue- bug-)
# current branch name excluding namespace
current_branch=$(git symbolic-ref --short HEAD | cut -d/ -f2-)
# capitalize message's first char
message=`echo ${base:0:1} | tr '[a-z]' '[A-Z]'`${base:1}
@chalasr
chalasr / angularjs-interceptor.js
Created January 4, 2016 12:15 — forked from gnomeontherun/angularjs-interceptor.js
Intercept XHR/Ajax requests with AngularJS http interceptors. This allows you to globally intercept and modify requests and responses. You don't need to declare all of the methods, just the ones you need. Some example uses would be logging errors, adding extra headers, or triggering 'loading' screens. This intercepts ALL requests/responses, so y…
// Intercepting HTTP calls with AngularJS.
angular.module('MyApp', [])
.config(function ($provide, $httpProvider) {
// Intercept http calls.
$provide.factory('MyHttpInterceptor', function ($q) {
return {
// On request success
request: function (config) {
// console.log(config); // Contains the data about the request before it is sent.
@chalasr
chalasr / README.md
Last active January 8, 2016 12:36
Multiple remote on git-hosted repository

Assuming you have a repository hosted on git.server1.com and you want push it to another host.
Your remote "origin" is set to git.server1.com:username/repository.git

1- Create an empty repository from github interface

2- Add the "github" remote to your local repository

$ git remote add github git@github.com:username/repository.git

3- Add your previous commits into

@chalasr
chalasr / README.md
Last active January 8, 2016 22:52
Exclude specific extension from git add

Exclude files with ".php~" from GIT ADD :

git ls-files . | grep '\.php~$' | xargs git add

Exclude files already added by GIT ADD :

git ls-files . | grep '\.php~$' | xargs git reset --
@chalasr
chalasr / pre-commit
Created January 12, 2016 09:31
Pre-commit hook that performs php-cs-fixer on each changed files.
#!/usr/bin/php
<?php
exec('git diff --cached --name-status --diff-filter=ACM', $output);
foreach ($output as $file) {
$fileName = trim(substr($file, 1) );
if (pathinfo($fileName,PATHINFO_EXTENSION) == "php") {
$lint_output = array();
exec("php -l " . escapeshellarg($fileName), $lint_output, $return);
@chalasr
chalasr / ExampleRepository.php
Created January 13, 2016 18:06 — forked from gnugat/ExampleRepository.php
Declaring a Doctrine Repository as a service and injecting it a dependency.
<?php
namespace Acme\DemoBundle\Repository;
use Acme\DemoBundle\Dependency;
use Doctrine\ORM\EntityRepository;
/**
* Get this repository directly from the container: it will set the $dependency attribute.
* If you get it using Doctrine's "getRepository()", don't forget to call setDependency().