Skip to content

Instantly share code, notes, and snippets.

View marydn's full-sized avatar
🦙

Mary De Nóbrega marydn

🦙
View GitHub Profile
@marydn
marydn / LoginSuccessHandler.php
Created December 20, 2013 20:57
Custom URL redirect by role after success login on Symfony 2 using a service listener without FOSUser Bundle.
# src/Acme/DemoBundle/Security/Authentication/Handler/LoginSuccessHandler.php
<?php
namespace Acme\DemoBundle\Security\Authentication\Handler;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Router;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\SecurityContext;
@marydn
marydn / example.html.twig
Created January 14, 2014 18:30
Render all flash messages from Symfony in Twig.
{% for label, flashes in app.session.flashbag.all %}
{% for flash in flashes %}
<div class="alert alert-{{ label }}">
{{ flash }}
</div>
{% endfor %}
{% endfor %}
@marydn
marydn / clean-file-name-dash.php
Last active June 25, 2017 17:41
Clean the name for a file and avoid rewrite files when they are being uploaded to server. Rename it by adding a sequential number at the end of name, before extension.
<?php
// Just keep letters and numbers.
// Replace everything else with dash, even spaces.
//------------------------------------------------------------------------------
$path = dirname(__FILE__);
$file = 'Dos elefantes.mp4'; // Already exists in server
$filename = substr($file, 0, strrpos($file, '.'));
@marydn
marydn / token.php
Created April 26, 2014 16:19
Generate token
<?php
// 32-byte length
$token = md5(uniqid(mt_rand(), true));
// 256
$token = bin2hex(mcrypt_create_iv(128, MCRYPT_DEV_RANDOM));
@marydn
marydn / unique_values_multidimensional_array.php
Created October 19, 2016 09:59
One-liner scripts collection
// Remove duplicate values from a multi-dimensional array in PHP
$input = array_map('unserialize', array_unique(array_map('serialize', $input)));
@marydn
marydn / utils.js
Created June 12, 2017 09:01
Get query params using javascript
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
};
@marydn
marydn / .gitconfig
Created February 8, 2018 11:23
GIT aliases
lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --
count-month = shortlog -sne --since="01 Jan 2018" --before="31 Dec 2018"
yolo = !git add -A && git commit -m \"$(curl -s whatthecommit.com/index.txt)\"
clean-local-branches = branch --merged | egrep -v \"(^\\*|master|dev)\" | xargs git branch -d
@marydn
marydn / project.local
Created February 26, 2018 08:51
Nginx virtualhost for Symfony2
server {
server_name project.local;
root /var/www/project/web;
location / {
# try to serve file directly, fallback to app.php
try_files $uri /app.php$is_args$args;
}
# DEV
@marydn
marydn / remove_tweets.py
Last active September 26, 2018 14:58
Delete tweets programmatically. You need to install pip install tweepy.
#!/usr/bin/python
from __future__ import print_function
import tweepy
import itertools
import datetime
# OAuth application
consumer_key = "<<CONSUMER_KEY>>"
consumer_secret = "<<CONSUMER_SECRET>>"
@marydn
marydn / docker-cleanup-resources.md
Created March 6, 2019 07:22 — forked from bastman/docker-cleanup-resources.md
docker cleanup guide: containers, images, volumes, networks

Docker - How to cleanup (unused) resources

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

delete volumes

// see: https://github.com/chadoe/docker-cleanup-volumes

$ docker volume rm $(docker volume ls -qf dangling=true)

$ docker volume ls -qf dangling=true | xargs -r docker volume rm