Skip to content

Instantly share code, notes, and snippets.

View Naatan's full-sized avatar

Nathan Rijksen Naatan

View GitHub Profile
@Naatan
Naatan / object_to_array
Created November 11, 2011 20:48
Converts objects to array, recursively
function object_to_array($ob)
{
if (!is_array($ob) AND !is_object($ob))
{
return $ob;
}
$ob = (array) $ob;
foreach ($ob AS $k => $v)
@Naatan
Naatan / flatten_array
Created November 11, 2011 20:54
Converts multi dimensional array / object to single depth array
function flatten_array($array, $parents = '')
{
if ( !is_array($array) AND !is_object($array))
{
return array($parents . $array);
}
$array = (array) $array;
$flat = array();
@Naatan
Naatan / PHP Yaml encode
Created April 20, 2012 15:20
Tries to convert a PHP variable of any type to yaml. This is EXTREMELY experimental, I'm just playing around.
<?php
function renderYaml($result, $prefix = '', $indentation = 0, $ptype = '')
{
$result = json_decode(json_encode($result)); // convert key based arrays to objects
$indent = $prefix;
for ($c=0;$c<$indentation; $c++) {
$indent = ' ' . $indent;
@Naatan
Naatan / PHP Comment Parser
Created September 25, 2012 18:17
Very Basic PHP Comment Parser
<?php
class Parser
{
function parse($data)
{
$result = array();
preg_match_all('/\/\*\*\s*?\n(.*?)\*\/\s*?\n\s*?(?:public)\s*?function\s*?([a-z0-9_-]*?)\(/si', $data, $matches, PREG_SET_ORDER);
@Naatan
Naatan / lipsum_helper.php
Created April 19, 2013 16:50
Lightweight lipsum generator
<?php
function lipsum($amount = 5, $punct = false)
{
$words = ['lorem', 'ipsum','dolor','sit','amet,','consectetur','adipiscing','elit','praesent',
'iaculis','interdum','congue','cras','ac','dictum','nulla.','quisque','quis','neque',
'nibh','curabitur','consequat','scelerisque','magna,','in','lacinia','nibh',
'scelerisque','eget','in','sed','ante','sit','amet','sem','cursus','mollis',
'quisque','venenatis','velit','nec','felis','varius','eu','auctor','odio',
'scelerisque.','nullam','id','enim','leo','donec','eu','ipsum','non','lectus','dapibus'];
@Naatan
Naatan / gist:5733336
Created June 8, 2013 00:37
Override phabricator "Project" terminology to say "Tags"
translation.override
Current Value: {
"Projects" : "Tags",
"Project" : "Tag",
"Type a project name..." : "Type a tag name...",
"Create a New Project" : "Create a New Tag",
"Create New Project" : "Create New Tag",
"Create Project" : "Create Tag",
"Associate Projects" : "Add Tags",
@Naatan
Naatan / gist:5770489
Last active December 18, 2015 10:39
YouTrack show estimation totals on agile board (userscript)
// ==UserScript==
// @name YouTrack show agile estimation totals
// @namespace http://
// @version 0.1
// @match http://*.myjetbrains.com/*/agile/*
// ==/UserScript==
function run() {
$(".sb-column").each(function(index)
@Naatan
Naatan / Convert_Selection_to_Bootstrap_3.js
Last active December 26, 2015 11:28
Komodo Edit/IDE Macro - Convert Bootstrap 2 selection to Bootstrap 3 Based on code from https://github.com/divshot/bootstrap3_upgrader
(function()
{
var selection = ko.views.manager.currentView.selection;
if (selection == "") return;
function convert()
{
selection = selection.replace(/\<\%/g, '&lt;%');
selection = selection.replace(/\%\>/g, '%&gt;');
@Naatan
Naatan / executeAsPHP.js
Created November 8, 2013 18:09
Komodo Macro API Concept (pseudo-code)
api.macro.register({
id: "executeAsPHP",
execute: function() {
var selection = api.editor.getSelectedContents() || api.editor.getEditorContents();
var tempFile = api.files.writeTempFile(selection);
api.commands.executeAndOutput("php -d display_errors=true " + tempFile.path);
},
@Naatan
Naatan / executeAsPHP.js
Last active November 21, 2017 08:07
Komodo Macro - Execute file/selection as PHP
new function()
{
/**
* Execute Macro
*
* @returns {void}
*/
this.exec = function()
{