Skip to content

Instantly share code, notes, and snippets.

View micc83's full-sized avatar

Alessandro Benoit micc83

View GitHub Profile
@micc83
micc83 / gist:9665159
Created March 20, 2014 14:37
Wordpress return 404
<?php
function return_page_404() {
global $wp_query;
$wp_query->set_404();
status_header(404);
}
@micc83
micc83 / default.vcl
Created July 4, 2014 07:39
WordPress custom Varnish configuration
backend default {
.host = "127.0.0.1";
.port = "8080";
}
acl purge {
"localhost";
"127.0.0.1";
}
@micc83
micc83 / tutorial-chat-app.html
Created July 16, 2014 08:04
Tutorial: Creare una chat in tempo reale con Firebase e login facebook
<!DOCTYPE html>
<html class="no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>MyApp</title>
<style>
@micc83
micc83 / Restfulizer.js
Created September 25, 2014 14:55
Ruby like delete links on laravel
/**
* Restfulizer
*
* Restfulize any hiperlink that contains a data-method attribute by
* creating a mini form with the specified method and adding a trigger
* within the link.
* Requires jQuery!
*
* Ex:
* <a href="post/1" data-method="delete">destroy</a>
@micc83
micc83 / wp_sync_roles.php
Last active August 29, 2015 14:07
Sync roles between different WordPress Blog inside the same schema on first login
<?php
/**
* Sync roles between different WordPress Blog
*
* Tables must be inside the same schema and you have to define
* custom user tables on wp-config.php in the SLAVE blog as follow:
+ define('CUSTOM_USER_TABLE', 'myprefix_users');
+ define('CUSTOM_USER_META_TABLE', 'myprefix_usermeta');
* Sync is run only at the first login on the alternative blog, any following
* role change must be manually sync.
@micc83
micc83 / fb.css
Created October 9, 2014 08:44
Facebook fix for truncated share box clicking on like button
/* Facebook fix */
.fb-like span{overflow:visible !important; width:450px !important; margin-right:-375px;z-index: 999;}
@micc83
micc83 / add_query_args.js
Created October 28, 2014 20:05
Add query args to url
/**
* Add query args
*/
function add_query_args(uri, params) {
var separator = uri.indexOf('?') !== -1 ? '&' : '?';
for (var key in params) {
if(params.hasOwnProperty(key)){
uri += separator + key + '=' + params[key];
separator = '&';
}
@micc83
micc83 / .htaccess
Created November 4, 2014 16:20
htaccess
# Apache Server Configs v2.11.0 | MIT License
# https://github.com/h5bp/server-configs-apache
# (!) Using `.htaccess` files slows down Apache, therefore, if you have
# access to the main server configuration file (which is usually called
# `httpd.conf`), you should add this logic there.
#
# https://httpd.apache.org/docs/current/howto/htaccess.html.
# ######################################################################
@micc83
micc83 / resetdb.sh
Last active October 20, 2015 13:20
Cronjob to drop tables and import dump file to MySql database
#!/bin/bash
mysqldump -u[username] -p[password] \
--add-drop-table --no-data [database] | \
grep -e '^DROP \| FOREIGN_KEY_CHECKS' | \
mysql -u[username] -p[password] [database]
mysql -u[username] -p[password] [database] < [dump_file.sql]
@micc83
micc83 / gist:5875218
Last active December 19, 2015 01:19
Find current client IP
<?php
/**
* Trova l'ip del cliente
*/
function mc_get_user_ip() {
// Tiro giù l'ip del client
if ( isset( $_SERVER["REMOTE_ADDR"] ) ) {
$ip = $_SERVER["REMOTE_ADDR"];
} elseif ( isset( $_SERVER["HTTP_X_FORWARDED_FOR"] ) ) {