Skip to content

Instantly share code, notes, and snippets.

View twysto's full-sized avatar
😀
Enthusiastic

Loïc Liné twysto

😀
Enthusiastic
View GitHub Profile
@twysto
twysto / xml_to_array.php
Last active August 29, 2015 14:08
[PHP] One line "XML to Array"
<?php
$array = json_decode(json_encode(simplexml_load_string(file_get_contents("http://news.yahoo.com/?format=rss"))), TRUE);
@twysto
twysto / array_multi_unique.php
Last active July 21, 2017 07:57
[PHP] array_unique in a multi-dimensional array
<?php
function array_multi_unique($array) {
$tmp_ComparisonArray = $final_Array = Array();
foreach($array as $key => $value) {
if(!in_array($value[0], $tmp_ComparisonArray)) {
$tmp_ComparisonArray[] = $value[0];
@twysto
twysto / assoc_sort.php
Last active August 29, 2015 14:08
[PHP] sort on a particular key in an associative array
<?php
function assoc_sort($array, $on, $order = SORT_ASC, $preserve_keys = false) {
$new_array = $sortable_array = array();
if(count($array) > 0) {
foreach($array as $k => $v) {
if(is_array($v)) {
@twysto
twysto / datetime-to-timestamp.js
Last active August 29, 2015 14:08
[Javascript] One line "DateTime to Timestamp"
var timestamp = Date.parse("1999-12-31 00:00:00") / 1000;
@twysto
twysto / localstorage-howto.js
Last active August 29, 2015 14:08
[HTML5 / Javascript] LocalStorage How-to
// Create an object.
var obj = { "foo": "bar" };
// Store your object as a string.
localStorage["data"] = JSON.stringify(obj);
// Retrieve your object using `JSON.parse()`
console.log(JSON.parse(localStorage["data"]).foo);
@twysto
twysto / getRotationDegrees.js
Created November 15, 2014 02:43
[jQuery Plugin] getRotationDegrees.js
(function($) {
$.fn.getRotationDegrees = function() {
var angle = 0;
var matrix = this.css(("-webkit-" || "-moz-" || "-ms-" || "-o-") + "transform");
if((typeof matrix == 'string' || matrix instanceof String) && matrix != 'none') {
var values = matrix.split('(')[1].split(')')[0].split(',');
var a = values[0];
var b = values[1];
@twysto
twysto / gist:a104cb91c9a06111b7f7
Last active August 29, 2015 14:16
[PHP] String Array to Integers Array
function stringsArrayToIntegersArray($array) {
// Before : array("1", "2", "3");
$array = array_map(
create_function('$value', 'return (int)$value;'),
$array
);
// After : array(1, 2, 3);
<?php
function exportCSV(
iterable $items,
array $allowed_columns,
?string $sep = ';',
?string $filename = 'export.csv',
) {
$output = 'sep=' . $sep . PHP_EOL;
<?php
/**
* TODO: Have to make some verifications on a few extensions.
* For instance, xml can be found three times with three differents mime-types.
*/
$mime_types_extensions = array(
// "application/1d-interleaved-parityfec",
// "application/3gpp-ims+xml",
// "application/activemessage",
"application/andrew-inset" => "ez",
@twysto
twysto / php7.sh
Created December 31, 2015 12:56
PHP 7.0.0 (release) on Debian 8
#!/bin/bash
set -e
PHP_VERSION=7.0.0
# Dependencies
apt-get update
apt-get install -y \