Skip to content

Instantly share code, notes, and snippets.

View julp's full-sized avatar

julp julp

View GitHub Profile
@julp
julp / foreign_keys.sql
Created September 18, 2010 17:19
try to guess tables dependencies via information_schema/foreign keys
SELECT DISTINCT t.table_name, rc.referenced_table_name
FROM information_schema.tables t
JOIN information_schema.table_constraints tc USING (table_schema, table_name)
LEFT JOIN information_schema.referential_constraints rc ON tc.table_schema = rc.constraint_schema AND tc.table_name = rc.table_name
WHERE t.table_schema='$DB'
/*AND t.table_name IN ('$TABLE1', '$TABLE2')*/
AND (tc.constraint_type = 'FOREIGN KEY' OR (rc.table_name IS NULL AND rc.constraint_schema IS NULL))
@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();
@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 / 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 / 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 / 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 / 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 / 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 / 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 / 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}/";
# }