Skip to content

Instantly share code, notes, and snippets.

And what about pgettext and npgettext? They are there in the gettext documentation, but there aren't in PHP. They're very useful if you have the same messages for translation, but in different contexts, so they should be translated separately and probably differently.
Fortunately, there is a simple work-around, which may help:
From the gettext.h header one can find out that pgettext() is only a macro calling dcgettext() internally with properly mangled parameters - msgctxt and msgid are glued together with use of ASCII char 4 [EOT, End Of Text]. The same way they're written in .mo files, so it's possible to refer them this way.
Here's my "emulated" pgettext() function:
<?php
if (!function_exists('pgettext')) {
@pherrymason
pherrymason / html5_data-json.php
Created December 13, 2013 16:17
Store JSON in data attribute
<?php
$data = array('id'=>1, 'name'=>'will');
echo '<div data-post="'.htmlentities( json_encode($data) ) . '">'.
"<script>
var obj = $('div').data('post');
</script>";
@pherrymason
pherrymason / import database.sh
Created December 13, 2013 09:24
Import database from .sql (CLI)
mysql --password=user_password --user=username databasename < file.sql
@pherrymason
pherrymason / analytics tracking events.js
Created December 10, 2013 09:54
Analytics Tracking
function trackEvent( zone ){
// If ga is available & loaded.
if( typeof(ga)!=='undefined' ){
// https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide
// Use universal analytics @todo
}
else
{
var _gaq = window._gaq || []; // For tracking analytics
@pherrymason
pherrymason / distance.js
Created October 30, 2013 21:15
Distance Between Points
// Manual: Haversine Formula: shortest route over a sphere
function distance(latlng1, latlng2) {
var R = 6371, // Radius of the earth, in km. Need miles? change to 3961
dLat = (latlng2.lat - latlng1.lat) * (Math.PI/180),
dLon = (latlng2.lng - latlng1.lng) * (Math.PI/180),
a = Math.sin(dLat/2)*Math.sin(dLat/2) +
Math.cos(latlng1.lat * (Math.PI/180)) *
Math.cos(latlng.lat * (Math.PI/180)) *
Math.sin(dLon/2) * Math.sin(dLon/2),
c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)),
-ms-word-break: break-all;
word-break: break-all;
// Non standard for webkit
word-break: break-word;
-webkit-hyphens: auto;
-moz-hyphens: auto;
hyphens: auto;
@pherrymason
pherrymason / detect.ad.block.js
Created October 24, 2013 15:12
Detect ADblock
var AdBlocker = function(){
if(typeof(window.google_render_ad)=="undefined")
{
//They're blocking ads, do something else.
return true;
}
else if( typeof(window.google_jobrunner)=='undefined')
{
return true;
@pherrymason
pherrymason / markdown description
Created October 22, 2013 07:57
Markdown CheatSheet
Links
[I'm an inline-style link](https://woogle.com)
[I'm a reference-style link definition][texto de referencia arbitrario]
[I'm a reference-style link definition][1]
O déjalo vacío y usa el [enlace como texto propio]
@pherrymason
pherrymason / osx_snapshots.md
Created October 22, 2013 07:22
Pantallazo OSX
  • ⌘-Shift-3: Take a screenshot of the screen, and save it as a file on the desktop
  • ⌘-Shift-4, then select an area: Take a screenshot of an area and save it as a file on the desktop
  • ⌘-Shift-4, then space, then click a window: Take a screenshot of a window and save it as a file on the desktop
  • ⌘-Control-Shift-3: Take a screenshot of the screen, and save it to the clipboard
  • ⌘-Control-Shift-4, then select an area: Take a screenshot of an area and save it to the clipboard
  • ⌘-Control-Shift-4, then space, then click a window: Take a screenshot of a window and save it to the clipboard

In Leopard and later, the following keys can be held down while selecting an area (via ⌘-Shift-4 or ⌘-Control-Shift-4):

  • Space, to lock the size of the selected region and instead move it when the mouse moves
@pherrymason
pherrymason / new_gist_file.sh
Created September 30, 2013 09:45
Cómo crear una nueva rama de la nada
git checkout --orphan newbranch
git rm -rf .
<do work>
git add your files
git commit -m 'Initial commit'