Skip to content

Instantly share code, notes, and snippets.

View Hexodus's full-sized avatar

Adrian Maleska Hexodus

  • Wiesbaden - Germany
View GitHub Profile
@Hexodus
Hexodus / browser_language_extraction.php
Created March 12, 2016 13:08
Extracts the browser language. Returns the first two letters i.e.: de, en, fr
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
echo $lang;
@Hexodus
Hexodus / recaptcha_secure_token_generation.php
Created March 12, 2016 13:15
Google ReCaptcha secure token generation using slushie class from: https://github.com/slushie/recaptcha-secure-token/blob/master/lib/ReCaptchaToken.php Secure token makes it possible to use ReCaptcha for testing on localhost.
<?PHP
use ReCaptchaSecureToken\ReCaptchaToken as ReCaptchaToken;
require_once("ReCaptchaToken.php");
//Generate recaptcha token
$recaptcha_config = [
'site_key' => 'your-site-key',
'site_secret' => 'your-site-secret-key'
];
$recaptcha_token = new ReCaptchaToken($recaptcha_config);
@Hexodus
Hexodus / simple_url_routing.php
Created March 12, 2016 13:05
Rewrites all url requests to index.php and stores the path in the url variable which is being processed into $uri variable (to prevent empty values).
//.htaccess code
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
//PHP part
@Hexodus
Hexodus / Tar current directory except subdirectory
Created June 22, 2014 13:24
This shows how to tar the current directory except the unwanted subdirectory files.
tar cvpzf backup.tgz --exclude='dir_to_exculde/*' *
tar cvpzf backup.tgz --exclude='dir_to_exculde/*'
--exclude='dir_to_exculde' *
//The last asteric means that the current dir is used. Keep in mind that files with a dot aren't included.
//The secound example excludes also the directory from being included otherwise it would be included as empty one...
@Hexodus
Hexodus / sort_multi_dimensional_associative_array_by_value.php
Created March 30, 2016 18:59
This sorts a multidimensional associative array and keeps the values. Please note that uasort() and usort() are sorting an array and not returning a new one.
uasort($array_to_sort, function($a, $b)
{
return $a['order'] - $b['order'];
});
phonegap plugin add cordova-plugin-app-version --save
/*
'--save' command also saves the plugin in the config.xml
*/
@Hexodus
Hexodus / unity_first_level_child_of
Last active April 14, 2017 11:50
How to find out if an element is the first child of some other game object in unity?Unity GetComponentsInChildren method return all children which is not what's needed. So I'm using this method for this purpose instead.
/**
* find out if child is first level child of given GO
* @return Transform
**/
bool IsFirstLevelChildOf(Transform root, Transform child)
{
bool isFirstLevel = false;
var children = root.GetComponentsInChildren<Transform>();
foreach(var c in children) {
if (c.parent == root && c == child) {
@Hexodus
Hexodus / UnityLateStart
Last active April 14, 2017 11:50
While Unit doesen't offer a LateStart() this is to be use meanwhile
void Start ()
{
StartCoroutine (LateStart());
}
IEnumerator LateStart()
{
yield return new WaitForEndOfFrame ();
// Do your magic here!
@Hexodus
Hexodus / composer_help.snippets
Last active April 17, 2017 07:23
Composer basic command line commands for installing and updating packages.
//installs "packagename" latest version
composer require vendorname/packagename
//installs package version 1.2
composer require vendorname/packagename 1.2
//installs package version above 1.2 but lesser then 2.0
composer require vendorname/packagename 1.2.*
//installs package version above 1.2 but lesser then 2.0
var input_string = document.getElementById('my-input').innerText;
var output_element = document.getElementById('my-output');
//here we go
var right_text = input_string.substring(0, input_string.indexOf(":"));
output_element.innerText = right_text;