Skip to content

Instantly share code, notes, and snippets.

View grammaticof's full-sized avatar

Francesco Grammatico grammaticof

View GitHub Profile
@grammaticof
grammaticof / gist:1994175
Created March 7, 2012 16:23
jQuery: open all external link to a new window
$(document).ready(function() {
$('a[href^="http://"]').filter(function() {
return this.hostname && this.hostname !== location.hostname;
}).attr('target', '_blank');
})
@grammaticof
grammaticof / gist:1994198
Created March 7, 2012 16:28 — forked from kled/gist:1994059
jQuery: HTML start page
<!DOCTYPE html>
<html>
<head>
<title>index</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
});
@grammaticof
grammaticof / snippet.js
Created March 14, 2012 16:58 — forked from necolas/snippet.js
jQuery: async load services
/*
* Updated to use the function-based method described in http://www.phpied.com/social-button-bffs/
* Better handling of scripts without supplied ids.
*
* N.B. Be sure to include Google Analytics's _gaq and Facebook's fbAsyncInit prior to this function.
*/
(function(doc, script) {
var js,
fjs = doc.getElementsByTagName(script)[0],
@grammaticof
grammaticof / gist:2043815 Capistrano: task to load production data into development database
desc "Load production data into development database"
task :import_remote_db do
filename = "dump.#{Time.now.strftime '%Y-%m-%d_%H:%M:%S'}.sql"
dbuser = "yourusername"
dbhost = "yourhostname"
dbpassword = "yourpassword"
application_db = "yourdatabasename"
local_db_host = "localhost"
local_db_user = "local_user_name"
@grammaticof
grammaticof / snippet.js
Created July 9, 2012 15:03 — forked from necolas/snippet.js
Optimised async loading of cross-domain scripts
/*
* Updated to use the function-based method described in http://www.phpied.com/social-button-bffs/
* Better handling of scripts without supplied ids.
*
* N.B. Be sure to include Google Analytics's _gaq and Facebook's fbAsyncInit prior to this function.
*/
(function(doc, script) {
var js,
fjs = doc.getElementsByTagName(script)[0],
@grammaticof
grammaticof / 1.html
Created August 24, 2012 15:42 — forked from mxriverlynn/1.html
backbone.js: how to get the model of the clicked html element
<script id="item-template" type="text/x-jquery-tmpl">
<li><a href="#">${name}</a></li>
</script>
@grammaticof
grammaticof / youtube-helper.js
Created August 28, 2012 16:59 — forked from kvnn/youtube-helper.js
Require.js Module for the YouTube Iframe API
define(["require", "exports"], function (require, exports) {
exports.YouTubeHelper = function (settings) {
// MEMBERS & DEFAULTS #################################################################################################################################################
var documentRef;
var originURL = ""; // for cross site checks
var targetContainer;
var target;
var parentContainer; // used for adding popups back into the original spot
@grammaticof
grammaticof / gist:3635239
Created September 5, 2012 11:22
JS - Mobile redirect
function mobile_redirect() {
var path = window.location.pathname;
if (path != null) {
window.location = 'http://host' + path
} else {
window.location = 'http://host/'
}
}
function setCookie(c_name, value, expiredays) {
var exdate = new Date();
@grammaticof
grammaticof / gist:3690660
Created September 10, 2012 12:31
Drupal - taxonomy term base block view
<?php
//code snippet for causing block to show based on a node's taxonomy term
$make_block_visible = FALSE;
$term_id_to_trigger_show_block = 19; // replace '19' your term id.
if ((arg(0) == 'node') && is_numeric(arg(1))) {
$values = array(
':nid' => arg(1),
':tid' => $term_id_to_trigger_show_block,
);
<?php
if ( $app['debug'] ) {
$logger = new Doctrine\DBAL\Logging\DebugStack();
$app['db.config']->setSQLLogger($logger);
$app->error(function(\Exception $e, $code) use ($app, $logger) {
if ( $e instanceof PDOException and count($logger->queries) ) {
// We want to log the query as an ERROR for PDO exceptions!
$query = array_pop($logger->queries);
$app['monolog']->err($query['sql'], array(