Astuces ezPDF PHP

Si vous lisez ceci… vous êtes surement entrain de galérer à afficher des accents ou caractères spéciaux avec un éditeur de PDF en PHP (ici ezPDF).

  • La première astuce est pour l’affichage du sigle €.

Essayez cette ligne :

$euro = iconv("UTF-8", "CP1252", "€");

La variable euro contiendra votre sigle euro affichable correctement sur le PDF ;)

 

  • La deuxième astuce est pour tout vos accents, sigles, etc :
$coeur = iconv("UTF-8", "CP1252", "œ");

$texte = "N°9: Ô mage aztèque, l'écuyer vêtu d'un kit hawaïen et de bijoux reçut au c".$coeur."ur l'âcre piqûre, de l'île où arrive son frêle canoë.");";

$bizarrerie = array('é', 'à', "'", 'ê', 'è', '°', 'Ô', 'ï', 'ç', 'â', 'û', 'î', 'ù', 'ë');

$remplacementBizzarerie = array(utf8_decode('é'),utf8_decode('à'),utf8_decode("'"),utf8_decode('ê'),utf8_decode('è'), utf8_decode('°'), utf8_decode('Ô'), utf8_decode('ï'), utf8_decode('ç'), utf8_decode('â'), utf8_decode('û'), utf8_decode('î'), utf8_decode('ù'), utf8_decode('ë'));

$texte = str_replace($bizarrerie , $remplacementBizzarerie , $texte);

Affichez votre texte sur le PDF et admirez :)

$texteSource

 

Easily deploy a local MongoDB cluster

When working with MongoDB, it surely comes a time when you want to try to make it scale. First, by adding replica set, then sharding and at least mix it together to create a simple cluster with replication on each shard. Then, you might want to test monitoring or other functionality, so you will need to launch your cluster, configure it.

If everything goes right, you’ll only need to start all your MongoDB instances. Not a big deal, easy to do it at each restart of your computer, just copy paste the right commands. But what if I need a fresh clean cluster to make my test? To answer this question, I wrote a simple script to easily deploy a local mongo cluster composed of one query router, three configuration routers and two shards, each being a replica set composed of one primary mongod and two secondary mongod.

This simple project is on my Github under the name simple-mongo-cluster. The readme describes on which port you’ll find which mongo. The script provides 5 operations: {init|start|configure|stop|clean}. I will quickly describe each of it.

The init operation creates all directories needed to store logs and data. All mongo instances will be started with the start parameter. To configure the cluster, use configure. For the cluster to be configured, you might need to call configure twice, because of shards sometimes not being added at first call. The stop operation is just about shutting down the whole cluster. At last, clean deletes all directories containing the cluster configuration files, data and logs so that you can start a fresh new cluster.

I hope it will help other developers who want to easily test and discover MongoDB cluster possibilities in a local environment as it helps me. If you have any suggestions, just let me know or fork the project, add your script and send me a pull request.

12 lines proxy with Node.js and Request

Easy and simple http proxy using Node.js and request.

var request = require('request')
  , http = require('http')
  , port = 8888
  , host = 'localhost'
  , proxy = http.createServer(function (req, res) {
    var x = request(req.url)
    req.pipe(x)
    x.pipe(res)
  })
proxy.listen(port, host, function () {
  console.log('Proxy running on port ' + port);
})

Code available on Github: node-simple-proxy.

It would be great to support https. And of course, you can do it without request.

Introducing FrameRain

I have been working on different projects since the beginning of the year. Today, I want to introduce FrameRain: a way to manage favourite videos from Youtube. The idea came out, after thinking that it would be great to have a place to store videos you prefer without the need of an account. Today, I’m happy to « open source » this project, as decided at the beginning. It is licensed under MIT.

I’ve built FrameRain using Node.js and Express for the server. Data persistence uses MongoDB. These are the only requirements to run FrameRain. Configuration can be found in the file config.json, but there are only a few things in it for now. FrameRain stores the miniature of each video, so that it does not rely on Youtube to display it.

It is possible to add some video to a playlist to watch them one after another. FrameRain uses youtube embedded player to prevent the need to go on youtube.com. Unfortunately, it doesn’t prevent youtube from tracking you. Moreover, I’m not satisfied with the way I implemented the player. It is working, but it will be hard to add another platform like vimeo or dailymotion using this implementation.

I should also consider password encryption. Among other things, an initial idea was to be able to manage playlist of videos, like for example, a music playlist, trailer playlist, funny playlist, … I’m planning to add it later.

This was a really fun project. I learned a lot about how to use Mongo and Mongoose. I will now work back on my other project which aimed at playing flac files in the browser. So, if you have any comments about FrameRain, don’t hesitate to contact me.