Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Adam AdamMadrzejewski

🎯
Focusing
View GitHub Profile
@AdamMadrzejewski
AdamMadrzejewski / change_php_dir_permissions.php
Created Feb 29, 2016
PHP change directory permissions recursively on shared hostings
View change_php_dir_permissions.php
<?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 Jan 12, 2016
Short text by whole words + '...'. Super simple.
View shortener.php
<?php
if (strlen($property->pro_name) > 75)
{
$propertyName = implode(" ", explode( "\n", wordwrap($property->pro_name, 75))).'...';
}
else
{
$propertyName = $property->pro_name;
}
?>
View cinema-green-background.js
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 Sep 11, 2015
Prevent all cookies from being set
View cookiePreventer.js
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 Aug 31, 2015
All rules to be chaged inside ini.php to eneble big files upload in PHP
View bigupload.txt
; 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 Aug 13, 2015
Promise - document ready
View docready.js
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 Mar 13, 2015
Slice a string with .map and .call
View slicer.js
var map = Array.prototype.map;
var result = map.call("Hello World", function(x) { return x; });
@AdamMadrzejewski
AdamMadrzejewski / joomla.php
Last active Jul 15, 2016
Simple Joomla 3 external script with JSON result from database
View joomla.php
<?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 Jan 17, 2015
Capitaliza all words in a column
View capitalize
UPDATE `sample_table`
SET city = CONCAT(UCASE(LEFT(city, 1)),
SUBSTRING(LCASE(city), 2));
@AdamMadrzejewski
AdamMadrzejewski / input-filled.js
Created Jan 3, 2015
Sprawdzanie, za pomocą Javascript, czy pole jest wypełnione
View input-filled.js
(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);