Skip to content

Instantly share code, notes, and snippets.

View julien-f's full-sized avatar

Julien Fontanet julien-f

View GitHub Profile
@julien-f
julien-f / array_extract.php
Last active December 15, 2015 23:59
Pseudo-equivalent to the `list()` construct but for associative arrays.I don't know if this function can be useful but here it is anyway.
<?php
/**
* Extracts a list of values from an array.
*
* @param array $values
* @param array $vars An array containing keys to be extracted and
* references to the variables that should be assigned.
*/
function array_extract(array $values, array $vars)
@julien-f
julien-f / .editorconfig
Last active February 1, 2019 15:12
EditorConfig
# http://EditorConfig.org
#
# Julien Fontanet's configuration
# https://gist.github.com/julien-f/8096213
root = true
[*]
charset = utf-8
end_of_line = lf
<?php
// It must be a class because the destructor is used to restore the
// object.
class Resilient
{
public static function &create()
{
// A variable is created containing a instance of this class.
$ref = new self();
@julien-f
julien-f / index.html
Last active August 29, 2015 14:00
SVG to canvas
<html>
<head>
<meta charset="utf-8">
<title>SVG to canvas</title>
</head>
<body>
<svg height="100" width="100" xmlns="http://www.w3.org/2000/svg" version="1.1">
<circle cx="50" cy="50" r="45"></circle>
</svg>
<canvas height="100" width="100"></canvas>
@julien-f
julien-f / index.js
Last active August 29, 2015 14:00
Efficient storage of an hollow symetric matrix
// Let M be a n×n hollow symmetric matrix.
// M = ⋅ | M(0, 1) | M(0, 2) | … | M(0, n - 1)
// ⋅ | ⋅ | M(1, 2) | … | M(1, n - 1)
// ⋅ | ⋅ | … | … | M(n - 2, n - 1)
//
// M can be stored as an array A.
// M(i, j) = A(i * (i - 1) / 2 + j) for j < i.
// Hollow symmetric matric.
var HSM = function (n) {
@julien-f
julien-f / rsvg.js
Last active August 29, 2015 14:01
SVG to PNG/PDF
/**
* Pros:
* - do not need files (works with buffers/streams)
*
* Cons:
* - do not work with external stylesheets
* - librsvg2 headers must be installed
* - synchronous
*
* > apt-get install librsvg2-dev
@julien-f
julien-f / README.md
Last active August 29, 2015 14:01
gulpfile.js

My gulpfile.js

Features

  • watch and livereload in development mode
  • embedded server
  • rules are as simple as possible (DRY)
  • rules are semantic

Dependencies

@julien-f
julien-f / index.js
Last active June 2, 2017 06:51
d3.js in Node.js
/**
* > npm install d3
*/
// In Node.js, d3.js works in a virtual document provided by jsdom.
var d3 = require('d3');
//--------
// Create the SVG element.
@julien-f
julien-f / index.html
Last active August 29, 2015 14:03
Offline canvas to PNG
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Offline canvas to PNG</title>
</head>
<body>
<script>
// Create the canvas and set its size.
var canvas = document.createElement('canvas');
@julien-f
julien-f / is.js
Last active August 29, 2015 14:04
`is.*()` function
// It is probably best to use `lodash.is*` instead but this is a lightweight alternative :)
var is = module.exports = (function () {
var toS = Object.prototype.toString
var _ = function (ref) {
ref = toS.call(ref)
return function (val) {
return (toS.call(val) === ref)
}
}