Skip to content

Instantly share code, notes, and snippets.

@fcingolani
fcingolani / wp-cron.sh
Created June 14, 2011 19:02
Bash Script to execute wp-cron.php on a Multisite Wordpress.
#!/bin/sh
db_host="host";
db_user="user";
db_pass="password";
db_name="database";
domains=`mysql --silent --skip-column-names --host $db_host --user $db_user -p$db_pass $db_name --execute "SELECT domain FROM wp_blogs WHERE archived = '0' AND spam = '0' AND deleted = '0';"`;
for domain in $domains; do
the_date=`date`;
@fcingolani
fcingolani / so7422487.php
Created September 15, 2011 03:03
Answer to Stack Overflow's Question #7422487
<?php
/*
* Plugin Name: Answer to Stack Overflow's Question #7422487
* Plugin URI: http://stackoverflow.com/questions/7422487/wordpress-urls-for-categories-and-years
* Description: :)
* Author: Federico Cingolani
* Version: 1.0.0
* Author URI: http://twitter.com/fcingolani
*/
@fcingolani
fcingolani / mpris-tweet.rb
Created November 20, 2011 02:44
Ruby #nowplaying for Twitter: MPRIS & Web Intents.
#!/usr/bin/ruby
require 'rubygems'
require 'mpris'
require 'cgi'
require 'launchy'
require 'gdata'
#obtenemos la metadata
md = MPRIS.new.player.metadata
@fcingolani
fcingolani / index.html
Created August 9, 2012 02:16
How to render a full PDF using Mozilla's pdf.js
<html>
<body>
<!-- really dirty! this is just a test drive ;) -->
<script type="text/javascript" src="https://raw.github.com/mozilla/pdf.js/gh-pages/build/pdf.js"></script>
<script type="text/javascript">
function renderPDF(url, canvasContainer, options) {
var options = options || { scale: 1 };
@fcingolani
fcingolani / gist:3502952
Created August 28, 2012 19:24
Wordpress - Count published posts with taxonomy term
function fc_count_posts_with_term($term_name, $taxonomy)
{
global $wpdb;
$term = get_term_by( 'name', $term_name, $taxonomy );
$st = $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->posts p
INNER JOIN $wpdb->term_relationships tr
ON (p.ID = tr.object_id)
INNER JOIN $wpdb->term_taxonomy tt
@fcingolani
fcingolani / wp-backup.sh
Created October 5, 2012 13:41
Wordpress Backup bash script
#!/bin/bash
NOW=$(date +"%Y-%m-%d-%H%M")
DB_USER=""
DB_PASS=""
DB_NAME=""
DB_HOST=""
TREE_FILE="$NOW.tar.gz"
@fcingolani
fcingolani / socialite-extras.js
Created October 12, 2012 03:32
Socialite.js - Facebook Like Box and Twitter Embedded Timeline extension
(function() {
Socialite.widget('facebook', 'likebox', {
init: function(instance) {
var el;
el = document.createElement('div');
el.className = 'fb-like-box';
Socialite.copyDataAttributes(instance.el, el);
instance.el.appendChild(el);
if (window.FB && window.FB.XFBML) {
@fcingolani
fcingolani / index.haml
Created November 11, 2012 17:12
HAML HTML5 Boilerplate
!!! 5
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
%html.no-js
<!--<![endif]-->
%head
%meta{ charset: "utf-8"}
@fcingolani
fcingolani / import_csv_to_sqlite.php
Last active April 8, 2024 02:52
PHP function to import a CSV into an SQLite database. Creates a table if needed. Uses PDO.
<?php
function import_csv_to_sqlite(&$pdo, $csv_path, $options = array())
{
extract($options);
if (($csv_handle = fopen($csv_path, "r")) === FALSE)
throw new Exception('Cannot open CSV file');
if(!$delimiter)
$delimiter = ',';
@fcingolani
fcingolani / generate-wordpress-wxr.php
Created June 18, 2013 20:34
Generate a WXR file from shell. Intended for BIG WordPress installations.
<?php
error_reporting(E_ALL ^ E_NOTICE);
define( 'WXR_VERSION', '1.2' );
/**
* Generates the WXR export file for download
*
* @since 2.1.0
*