Skip to content

Instantly share code, notes, and snippets.

@MattiJarvinen-BA
MattiJarvinen-BA / arrayPathFunctions.php
Created March 16, 2012 08:15
Simple unoptimized functions to translate PHP array notation string for example html input name and its value to array and vice versa.
<?php
/**
* Attach value $value to array path:
* attachValueToArrayPath('valueHere','foo[bar]')
* results array('foo'=>array('bar'=>'valuehere'));
*
* @param mixed $value
* @param string $path
* @return array
*/
@MattiJarvinen-BA
MattiJarvinen-BA / http_build_url.php
Created July 17, 2012 11:14
PHP replacement of http_build_url (PHP PECL pecl_http >= 0.21.0)
<?php
// handy script from tycoonmaster at gmail dot com
// http://fi2.php.net/manual/en/function.http-build-url.php#96335
// I didn't make this but I think it is useful so I store / share it here
if (!function_exists('http_build_url'))
{
define('HTTP_URL_REPLACE', 1); // Replace every part of the first URL when there's one of the second URL
define('HTTP_URL_JOIN_PATH', 2); // Join relative paths
define('HTTP_URL_JOIN_QUERY', 4); // Join query strings
@MattiJarvinen-BA
MattiJarvinen-BA / InputStrParser.php
Last active December 19, 2015 16:29
Parses input string into array while preserving all keys as is without changing &I+have+a+space=value into I_hava_a_space and same goes for dots and dashes in field name.
<?php
/**
* Input string parser that keeps variable keys in their original state.
*
* Input string keys containing '-','.',' ' are replaced by PHP with parse_str or $_POST
* with '_'. So &I+have+a+space=value becomes array('I_hava_a_space'=>'value')
*
* With InputStrParser->parseCharacterSafe('I+have+a+space=value') becomes
* array('I hava a space'=>'value')
*
@MattiJarvinen-BA
MattiJarvinen-BA / readZipFiles.php
Created March 12, 2015 14:53
Reading ZIP content file names as UTF-8 for saving into DB or something
<?php
/**
* Example for reading zip filenames as
* UTF-8 strings regardless of original
* filename encoding
*/
$Zip = new ZipArchive();
$open = $Zip->open($filename, ZIPARCHIVE::CHECKCONS);
@MattiJarvinen-BA
MattiJarvinen-BA / agnoster.zsh-theme
Last active April 23, 2021 06:44
Got tired of too long ZSH directory names with oh-my-zsh agnoster theme. To be placed in .oh-my-zsh/custom/themes/agnoster.zsh-theme
source $ZSH/themes/agnoster.zsh-theme
# Dir: current working directory
# %1 for one dir
# %2 for 2 you get it eventually
prompt_dir() {
prompt_segment blue black '%1~'
}
PROMPT='%{%f%b%k%}$(build_prompt) '
@MattiJarvinen-BA
MattiJarvinen-BA / ZSH with Bash on Ubuntu on Windows.md
Last active August 29, 2016 03:57
ZSH with Bash on Ubuntu on Windows

#ZSH with Bash on Ubuntu on Windows

ZSH as default shell ( if you have installed zsh!! )

Append to the bottom of the .bashrc

# Launch Zsh
if [ -t 1 ]; then
  exec zsh
fi