Skip to content

Instantly share code, notes, and snippets.

View julp's full-sized avatar

julp julp

View GitHub Profile
@julp
julp / cut_on_nearest_word_at.php
Created October 1, 2012 15:54
Couper le texte sur le mot le plus proche pour un extrait (début) de texte limité à X graphèmes
<?php
function cut_on_nearest_word_at($string, $length = 150) {
$start = grapheme_substr($string, 0, $length);
$byte_offset = strlen($start);
$ubrk = IntlBreakIterator::createWordInstance(ini_get('intl.default_locale'));
$ubrk->setText($string);
$byte_offset = $ubrk->preceding($byte_offset);
return substr($string, 0, $byte_offset);
}
@julp
julp / is_full_path.cmake
Created September 22, 2012 16:30
Réécriture de SystemTools::FileIsFullPath
########## Private ##########
# From Source/cmInstallGenerator.cxx:
# std::string cmInstallGenerator::GetInstallDestination() const
# {
# std::string result;
#
# if(!this->Destination.empty() && !cmSystemTools::FileIsFullPath(this->Destination.c_str())) {
# result = "${CMAKE_INSTALL_PREFIX}/";
# }
@julp
julp / markdown.php
Created August 2, 2012 12:50
PHP: parsing Markdown with sundown extension and geshi for syntax highlighting
<?php
require_once(__DIR__ . '/geshi.php');
class GeshiExtendedHTMLRender extends \Sundown\Render\HTML
{
public function blockCode($code, $language)
{
if (!$language) {
return '<pre><code>' . htmlspecialchars($code, NULL, 'UTF-8') . '</code></pre>';
}
@julp
julp / introspection.cmake
Last active October 7, 2015 09:37
Dump CMake internal state
cmake_minimum_required(VERSION 2.8)
set(public_debug_namespace "DEBUG_")
set(private_debug_namespace "_${public_debug_namespace}")
set(
"${public_debug_namespace}_source_properties"
ABSTRACT
COMPILE_DEFINITIONS
COMPILE_DEFINITIONS_<CONFIG>
@julp
julp / is_file_on_ram.c
Created July 8, 2012 21:18
Is given file stored on a RAM based file system ?
bool is_file_on_ram(const char *path)
{
#ifdef HAVE_STATFS
# ifdef BSD
# include <sys/param.h>
# include <sys/mount.h>
# else
# include <sys/vfs.h>
# include <linux/magic.h>
@julp
julp / dump_ucol_rules.c
Created May 2, 2012 13:18
Dump ICU UCollator rules
#include <stdio.h>
#define icu_error(status, function) \
fprintf(stderr, "ICU Error \"%s\" from " function "()\n", u_errorName(status))
#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
#define USTRING_SIZE(array) ARRAY_SIZE(array)
#define USTRING_LENGTH(array) (USTRING_SIZE(array) - 1)
#include <unicode/ustdio.h>
@julp
julp / unescape.php
Created March 7, 2012 12:45
Unicode unescaping (\uXXXX + \Uxxxxxxxx)
<?php
$in = '\u0041\U00000062';
$out = transliterator_create('Hex-Any')->transliterate($in);
var_dump($out); # string(2) "Ab"
@julp
julp / pdo_mysql_profiler.php
Created March 8, 2011 16:24
(v2) Profiling MySQL/PDO queries
<?php
namespace Julp;
if (isset($_SERVER['PHP_ENV']) && $_SERVER['PHP_ENV'] == 'development' && function_exists('ob_tidyhandler')) {
/*
tidy.default_config is:
indent: true
indent-spaces: 4
output-xhtml: yes
wrap: 0
@julp
julp / pdo_mysql_profiler.php
Created February 19, 2011 18:19
Profiling MySQL/PDO queries
<?php
namespace Julp;
if (isset($_SERVER['PHP_ENV']) && $_SERVER['PHP_ENV'] == 'development' && function_exists('ob_tidyhandler')) {
/*
tidy.default_config is:
indent: true
indent-spaces: 4
output-xhtml: yes
wrap: 0
@julp
julp / DependenciesManager.php
Last active September 23, 2015 18:27
manage dependencies by topological sort
<?php
class DependenciesManager
{
const NOT_VISITED = 1;
const IN_PROGRESS = 2;
const VISITED = 3;
private $_nodeStates = array();
private $_names = array();
private $_relatedNames = array();