Skip to content

Instantly share code, notes, and snippets.

View AdamMadrzejewski's full-sized avatar
🎯
Focusing

Adam AdamMadrzejewski

🎯
Focusing
  • Journey Digital
  • Auckland, New Zealand
View GitHub Profile
@AdamMadrzejewski
AdamMadrzejewski / change_php_dir_permissions.php
Created February 29, 2016 10:09
PHP change directory permissions recursively on shared hostings
<?php
file_fix_directory(dirname(__FILE__));
function file_fix_directory($dir, $nomask = array('.', '..')) {
if (is_dir($dir)) {
// Try to make each directory world writable.
if (@chmod($dir, 0755)) {
echo "<p>Cambio permessi directory a 0755: " . $dir . "</p>";
}
}
@AdamMadrzejewski
AdamMadrzejewski / shortener.php
Created January 12, 2016 14:05
Short text by whole words + '...'. Super simple.
<?php
if (strlen($property->pro_name) > 75)
{
$propertyName = implode(" ", explode( "\n", wordwrap($property->pro_name, 75))).'...';
}
else
{
$propertyName = $property->pro_name;
}
?>
if (document.URL.substr(-6) == 'secret') {
document.body.style.setProperty("background-image", "none", "important")
document.body.style.setProperty("background-color", "#10FF00", "important")
}
@AdamMadrzejewski
AdamMadrzejewski / cookiePreventer.js
Created September 11, 2015 15:43
Prevent all cookies from being set
Object.defineProperty(document, 'cookie', {
get: function () { return ''; },
set: function () { console.warn('Cookie prevented from being set. Please accept cookie privacy police first and refresh the page.'); }
});
@AdamMadrzejewski
AdamMadrzejewski / bigupload.txt
Created August 31, 2015 08:43
All rules to be chaged inside ini.php to eneble big files upload in PHP
; Maximum size of POST data that PHP will accept.
post_max_size = 256M
; Maximum allowed size for uploaded files.
upload_max_filesize = 256M
; Maximum execution time of each script, in seconds
max_execution_time = 600
; Maximum amount of time each script may spend parsing request data
@AdamMadrzejewski
AdamMadrzejewski / docready.js
Created August 13, 2015 13:44
Promise - document ready
HTMLDocument.prototype.ready = function () {
return new Promise(function(resolve, reject) {
if (document.readyState === 'complete') {
resolve(document);
} else {
document.addEventListener('DOMContentLoaded', function() {
resolve(document);
});
}
});
@AdamMadrzejewski
AdamMadrzejewski / slicer.js
Created March 13, 2015 19:16
Slice a string with .map and .call
var map = Array.prototype.map;
var result = map.call("Hello World", function(x) { return x; });
@AdamMadrzejewski
AdamMadrzejewski / joomla.php
Last active July 15, 2016 07:58
Simple Joomla 3 external script with JSON result from database
<?php
defined('_JEXEC') or die('Restricted access');
define('DS', DIRECTORY_SEPARATOR);
// Use these variables for direct file access
// define('_JEXEC', 1);
// define('JPATH_BASE', realpath(dirname(__FILE__)));
require_once (JPATH_BASE.DS.'includes'.DS.'defines.php');
require_once (JPATH_BASE.DS.'includes'.DS.'framework.php');
@AdamMadrzejewski
AdamMadrzejewski / capitalize
Created January 17, 2015 16:20
Capitaliza all words in a column
UPDATE `sample_table`
SET city = CONCAT(UCASE(LEFT(city, 1)),
SUBSTRING(LCASE(city), 2));
@AdamMadrzejewski
AdamMadrzejewski / input-filled.js
Created January 3, 2015 14:13
Sprawdzanie, za pomocą Javascript, czy pole jest wypełnione
(function () {
// pobieramy wszystkie formularze na stronie
var forms = document.querySelectorAll('form');
// pobieramy wszystkie pola formularzy na stronie
var inputs = document.querySelectorAll('.form__content__input');
var isFilledClass = 'is-filled';
// konwertujemy obiekt typu HTML NodeList do obiektu typu tablicowego
forms = Array.prototype.slice.call(forms);
inputs = Array.prototype.slice.call(inputs);