Skip to content

Instantly share code, notes, and snippets.

View mauricios's full-sized avatar
🎯
Focusing

Mauricio Sánchez mauricios

🎯
Focusing
View GitHub Profile
@mauricios
mauricios / varnish_vcl_remove_cookies.vcl
Created June 30, 2016 20:35
Varnish 3 VCL to make cache removing cookies
backend default {
.host = "localhost";
.port = "8080";
}
sub vcl_recv {
set req.backend = default;
if (req.url !~ "(/admin)") {
unset req.http.cookie;
@mauricios
mauricios / LoginService.php
Last active September 8, 2016 16:23
eZ Platform Service to login user programatically
<?php
namespace Vendor\MyLoginBundle\Services;
use Symfony\Component\HttpFoundation\RequestStack,
Symfony\Component\HttpFoundation\Response,
Symfony\Component\HttpFoundation\Cookie;
class LoginService
{
@mauricios
mauricios / macOS-tweaks.sh
Created September 13, 2016 15:31
macOS tweaks
#!/bin/bash
# Tweaks for macOS
# Disable ruber band bouncing scrolling
sudo defaults write -g NSScrollViewRubberbanding -int 0
# Disable all animations
sudo defaults write NSGlobalDomain NSAutomaticWindowAnimationsEnabled -bool false
# Enable press and hold key to repeat
@mauricios
mauricios / swapfile.sh
Last active November 10, 2016 15:39
Creates a Swap file in Ubuntu 14.04, useful for increase memory in virtual machines
#!/bin/sh
# Creates swap file
sudo dd if=/dev/zero of=/swapfile bs=1G count=1 &&
sudo chmod 600 /swapfile &&
sudo mkswap /swapfile &&
sudo swapon /swapfile;
# Remove swap file
sudo swapoff /swapfile &&
@mauricios
mauricios / apache-redirect.conf
Last active November 30, 2016 20:50
Apache Rewrite rules to redirect hostnames
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect to WWW all domain variants but wwww variant
# Redirect all domains that include the keywords target-domain, redirect-domain1, redirect-domain2
# Excluding www.target-domain.com, www.no-redirect-domain1.com and www.no-redirect-domain2.com
# To www.target-domain.com
RewriteCond %{HTTP_HOST} ^(?!www\.target-domain\.com|.*\.no-redirect-domain1\.com)(.*\.|)(target-domain|redirect-domain1|redirect-domain2)\..*$ [NC]
RewriteRule ^(.*)$ http://www.target-domain.com$1 [R=301,L]
# Create a CSV with query results and save it to a file
SELECT * FROM table INTO OUTFILE '/var/lib/mysql-files/table.csv' FIELDS ENCLOSED BY '"' TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\r\n';
# Get selected fields and include a related field from other table
SELECT tableA.filed1, tableA.field2, tableB.filed1, tableB.field2 FROM tableA INNER JOIN tableB ON tableA.id = tableB.id;
# Filter fields with wildcard and order by a cetain field
SELECT * FROM table WHERE field1 LIKE '%@example.com' ORDER BY field2
# Find unique duplicated records of a certain field
@mauricios
mauricios / aws_ec2_user_data_hostname.yml
Created November 14, 2016 20:45
AWS EC2 User Data setting hostname
#cloud-config
apt_upgrade: false
preserve_hostname: true
runcmd:
- hostname "Hostname-`ec2metadata --instance-id`"
- echo "127.0.0.1 Hostname-`ec2metadata --instance-id`" >> /etc/hosts
- echo "Hostname-`ec2metadata --instance-id`" > /etc/hostname
@mauricios
mauricios / Preferences.sublime-settings
Last active May 15, 2017 18:01
SublimeText 3 User preferences
{
"always_show_minimap_viewport": true,
"bold_folder_labels": true,
"color_scheme": "Packages/Material Theme/schemes/Material-Theme-Lighter.tmTheme",
"font_options":
[
"gray_antialias",
"subpixel_antialias",
"bold",
"no_round"
@mauricios
mauricios / aws_cloudwatch_logs_iam_policy.json
Last active May 30, 2017 22:00
AWS CloudWatch Logs IAM policy
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:DescribeLogStreams"
@mauricios
mauricios / atom-config.cson
Last active August 27, 2017 14:32
Atom preferences file
"*":
"ansible-vault":
vault_automatic_de_and_encrypt: true
"atom-beautify":
php: {}
"autocomplete-ansible":
pythonPaths: "/usr/local/Cellar/ansible/2.3.2.0_1/libexec/bin/python2.7"
autosave:
enabled: true
core: