Skip to content

Instantly share code, notes, and snippets.

View leonlaser's full-sized avatar
🍪

Leon Dietsch leonlaser

🍪
View GitHub Profile
@leonlaser
leonlaser / test_disk_speed
Last active March 21, 2019 14:19
[Test disk speed] #dd #hdd #disk #server #speedtest #speed #io
#!/bin/bash
# bs=file size
# count=number of tries
# if=input file
# of=output file
# conv='sync' (macos) / 'fadatasync' (linux) wait for I/O-Cache to write data on disk
dd bs=${bs:-1024} count=${count:-256} if=/dev/zero of=dd_zero_file conv=sync && rm dd_zero_file
@leonlaser
leonlaser / count_ips_in_logfile
Created March 18, 2019 12:39
[Count IPs from apache access log] #apache #accesslog #log #ip #bash #tail #sort #uniq
#!/bin/bash
tail -n10000 $logfile | cut -f3 -d' ' | sort | uniq -c | sort
@leonlaser
leonlaser / typo3_page_cachetags.php
Last active March 20, 2019 11:53
[Cache handling in TYPO3 CMS via TSConfig/TypoScript/PHP] #cache #user #page #tags #tsconfig #typoscript #typo3
<?php
// PHP: Add cache tag to page
$GLOBALS['TSFE']->addCacheTags(['tagname', 'tagname2']);
@leonlaser
leonlaser / typo3_maintenance_mode_via_env.php
Last active March 21, 2019 09:47
[TYPO3 CMS for maintenance mode via environment variables] #typo3 #maintenance #devip #adminonly
<?php
if(getenv('TYPO3_MAINTENANCE')) {
$GLOBALS['TYPO3_CONF_VARS']['FE']['pageUnavailable_force'] = 1;
$GLOBALS['TYPO3_CONF_VARS']['FE']['pageUnavailable_handling'] = getenv('TYPO3_MAINTENANCE_REDIRECT_URL');
$GLOBALS['TYPO3_CONF_VARS']['FE']['pageUnavailable_handling_statheader'] = 'HTTP/1.0 503 Service Temporarily Unavailable';
$GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'] = '127.0.0.1,::1,' . getenv('TYPO3_MAINTENANCE_DEVIPMASK');
$GLOBALS['TYPO3_CONF_VARS']['BE']['adminOnly'] = 2;
}
@leonlaser
leonlaser / run_in_bg
Last active March 22, 2019 10:52
[Run command in background and save pid] #bash #nohup #pid #background
#!/bin/bash
nohup $command > ${logfile:-"nohup.log"} 2>&1&
echo $! > ${pidfile:-"nohup.pid"}
@leonlaser
leonlaser / search_file_with_regex
Last active March 21, 2019 14:27
[Search file/log with grep/regex and count occurrences] #regex #grep #file #logfile
#!/bin/bash
grep "$regex" -o $file | sort | uniq -c
@leonlaser
leonlaser / show_all_errors.php
Created March 18, 2019 11:37
[Show all php errors] Enable and show all php errors except for E_NOTICE #php #errors
<?php
error_reporting(E_ALL ^ E_NOTICE);
ini_set('display_errors', 1);
@leonlaser
leonlaser / tcadefaults_example.typoscript
Created March 18, 2019 11:35
[TSConfig default values for TCA] #typo3 #tca #tsconfig #table
TCAdefaults.pages {
author = Max Mustermann
layout = 2
hidden = 1
}
@leonlaser
leonlaser / force_ssl.htaccess
Last active March 18, 2019 11:37
[Apache https redirect] #apache #htaccess #redirect #rewrite #https #ssl
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
@leonlaser
leonlaser / mysql_tables_by_size.sql
Created March 18, 2019 11:31
[MySQL tables sorted by size] #mysql #sql #table #size
SELECT
table_schema as `Database`,
table_name AS `Table`,
round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB`
FROM information_schema.TABLES
ORDER BY (data_length + index_length) DESC;