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 / 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;
@Hexodus
Hexodus / map_replace.js
Created April 17, 2017 15:23
Map Replace function. Replace multiple keys inside string with multiple values http://stackoverflow.com/a/15605648/1600193
String.prototype.map_replace = function (values) {
var string = this, key;
for (key in values) {
string = string.replace(new RegExp('\\{' + key + '\\}', 'gm'), values[key]);
}
return string
}
//usage
jQuery.fn.messagePlugin = function(){
var selectedObjects = this;
return {
saySomething : function(message){
$(selectedObjects).each(function(){
$(this).html(message);
});
return selectedObjects; // Preserve the jQuery chainability
},
anotherAction : function(){
<?PHP
$my_URL="http://some-website.com/mydata.txt";
$lines = file($my_URL);
foreach ($lines as $line_num => $line)
{
echo $line_num." ".$line;
}
?>
@Hexodus
Hexodus / equal_columns.css
Created April 20, 2017 13:24
Equal size columns with pure CSS. Uses bottom-padding-margin-trick where the overstanding elements will be cutted to proper size by overflow:hidden. From http://stackoverflow.com/questions/1205159/html-css-making-two-floating-divs-the-same-height
#container {
overflow: hidden;
width: 100%;
}
#left-col {
float: left;
width: 50%;
background-color: orange;
padding-bottom: 500em;
margin-bottom: -500em;
@Hexodus
Hexodus / globals_vs_constants_vs_define.php
Last active April 23, 2017 21:02
$GLOBALS vs define() vs const; It depends. I would go for `define()` because it has a more compact syntax in usage. But `define()` can only hold scalar values in PHP < 7.0 In case you need i.e. an associative array you have no other choice then to go for ` $GLOBALS` or use PHP >=7.0. From http://stackoverflow.com/questions/10691404/php-best-way-…
// Storing a single value works fine with define
define( 'ROOT_DIR', dirname(dirname(__FILE__)) . '/' );
// But not for complex data types like this array
$USERPIC_PARAMS = array(
"user_root" => "images/users",
"padding_length" => 8,
"split_length" => 4,
"hash_length" => 12,
"hide_leftover" => false
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
@Hexodus
Hexodus / htaccess_ssl_wp
Last active July 27, 2017 11:07
Force SSL for Wordpress via htaccess. Works for both single Blogs or Multisite. Just add below RewriteEngine On RewriteBase / #Force SSL code here On shared hosting it could produce to much redirections - when you convert from http to https. So it's better to rewrite all url's first (but after switching ssl on your hosting on) to reduce them. Th…
#Force SSL
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]