Skip to content

Instantly share code, notes, and snippets.

View dropmeaword's full-sized avatar

Luis Rodil-Fernandez dropmeaword

  • Amsterdam, Netherlands
View GitHub Profile
@dropmeaword
dropmeaword / wp_event_listings.php
Created January 30, 2012 09:54
Wordpress Event Type listings
<!-- lf: begin: list agenda event -->
<?php
query_posts(array('meta_key' => 'agenda_begins', 'orderby' => 'meta_value', 'post_type' => 'event', 'showposts' => 5));
if (have_posts()):
?>
<section class="agenda">
<h1><?php _e('Upcoming events'); ?></h1>
<dl class="eventListings">
<?php while(have_posts()): the_post(); ?>
<dt><a class="eventTitle" href="<?php the_permalink() ?>"><?php the_title(); ?></a></dt>
@dropmeaword
dropmeaword / gt_goteo_test.php
Last active December 10, 2015 10:18
Simple test that I ran in both CLI and Apache environments
<?php
$dir = dirname(__FILE__).'/locale';
$locale="nl_NL"; //"en_GB";
$domain="messages";
echo "dir = {$dir}\n";
echo "locale = {$locale}\n";
echo "domain = {$domain}\n\n";
@dropmeaword
dropmeaword / locales.php
Created December 31, 2012 14:26
This script will display the locales installed in your server.
<?php
/**
References :
1. http://en.wikipedia.org/wiki/ISO_3166-1#Officially_assigned_code_elements
*/
$country_codes = array(
'AF' => "AFGHANISTAN" ,
'AL' => "ALBANIA" ,
'DZ' => "ALGERIA" ,
@dropmeaword
dropmeaword / spawnuncacheddomain.php
Last active December 10, 2015 10:19
Rename the domain file to prevent caching from Apache
<?php
/**
* bypass gettext caching by using a clever file-renaming
* mechanism described in http://blog.ghost3k.net/articles/php/11/gettext-caching-in-php
*/
static protected function spawnUncachedDomain($locale, $domain) {
// path to the .MO file that we should monitor
$filename = "locale/{$locale}/LC_MESSAGES/{$domain}.mo";
$mtime = \filemtime($filename); // check its modification time
@dropmeaword
dropmeaword / Locale.php
Created January 2, 2013 10:06
Locale string parsing and normalizing from the Lithium framework.
<?php
/**
* Lithium: the most rad php framework
*
* @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
namespace lithium\g11n;
@dropmeaword
dropmeaword / goteo-gettext-conversion.txt
Created January 4, 2013 22:56
Explanation of how to write a script that will replace all of goteo's call to Text::get with the adecuate Text::_ call.
regex: (Text::get) -> replace with: _
regex: (?<=Text::get\(\')(.*)(?=\'\);) returns as match the contents of the id string used as a param, then you look it up in the db and replace it with the actual value. -> lu = lookup(match[0]) /s/match[0]/lu
@dropmeaword
dropmeaword / kobo-export.sh
Created January 22, 2013 20:04
Export annotations from Kobo Touch ereader (assumes /media/KOBOeReader as the mountpoint)
#!/bin/sh
# ----------------------------------------------------------------------
# Extract the bookmark annotations from the Kobo database.
# ----------------------------------------------------------------------
kobodir=/media/KOBOeReader
db="$kobodir/.kobo/KoboReader.sqlite"
sqlite3 "$db" 'select VolumeID,StartContainerPath,Text,Annotation from Bookmark;' |
awk -F'|' 'BEGIN{OFS="|"}{gsub("/", "_", $1); print}' |
sort -t/ -k1 -k2 -n -k4 -k5 -k6 -k7 -k8 |
sed ' s/[^|]*|// s/[^|]*|// s/|/\n\n/ s/$/\n\n/ '
@dropmeaword
dropmeaword / .bashrc
Created February 26, 2013 16:21
Show git branch on CLI prompt
function parse_git_branch () {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
YELLOW="\[\033[0;33m\]"
# Comment in the above and uncomment this below for a color prompt
PS1="${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w$Y$
@dropmeaword
dropmeaword / smaxabs.c
Created April 11, 2013 19:01
signed maximum absolute
int smaxabs(int a, int b) {
if((a < 0) && (b < 0)) {
return min(a, b);
} else if ((a < 0) && ( b > 0)) {
return ((abs(a) > b) ? a : b);
} else if ((a > 0) && ( b < 0)) {
return ((abs(b) > a) ? b : a);
} else {
return max(a, b);
}
@dropmeaword
dropmeaword / midifreq.c
Created April 11, 2013 21:51
MIDI to frequency conversions
double midi2freq(int midi)
{
double f;
f = exp (log (440.0) + (double)(midi - 69) * log (2.0) / 12.0);
return (f);
}
int freq2midi(double f)
{