Skip to content

Instantly share code, notes, and snippets.

View fvosberg's full-sized avatar

Frederik Vosberg fvosberg

View GitHub Profile
@fvosberg
fvosberg / php
Last active September 25, 2020 09:18
A very lightweight php backtrace
<?php
$debug_backtrace = debug_backtrace();
$output = [];
foreach ($debug_backtrace as $debug) {
if (isset($debug['class'])) {
$o = $debug['class'];
}
$o .= '::' . $debug['function'];
@fvosberg
fvosberg / main.php
Created May 27, 2014 09:46
Shell execute for debugging
<?php
function shelli($command){
$ouput = [];
$return = '';
exec($command, $output, $return);
echo "<hr><hr>\n";
echo "Executing \"$command\" with return value \"$return\".\n";
echo "<hr><pre>\n" . implode($output, "\n") . "</pre><hr><hr>\n";
}
@fvosberg
fvosberg / translate method
Created August 6, 2014 10:12
Translate in Extbase Controller
<?php
protected function translate( $key, $arguments = array()) {
$extensionName = $this->request->getControllerExtensionName();
return \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate($key, $extensionName, $arguments);
}
<?php
$tempFile = tmpfile();
$tempFileMetaData = stream_get_meta_data( $tempFile );
fwrite($tempFile, $string);
// path of the temp file
$tempFileMetaData['uri'];
// deletes the tmp file
@fvosberg
fvosberg / main.php
Created October 7, 2014 16:03
Long open connection
apache_setenv('downgrade-1.0','true');
apache_setenv('force-response-1.0','true');
ini_set('output_buffering', 'off');
while( @ob_end_flush() );
ini_set('implicit_flush', true);
flush();
echo "sending";
flush();
@fvosberg
fvosberg / gist:c41ad554de3f44e81676
Created October 8, 2014 10:29
Javascript html special chars
function escapeHtml(text) {
var map = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#039;'
};
return text.replace(/[&<>"']/g, function(m) { return map[m]; });
@fvosberg
fvosberg / Views.yaml
Created December 1, 2014 10:22
Overwrite paginate template via views.yaml
-
requestFilter: 'parentRequest.isPackage("My.Package") && isSubPackage("ViewHelpers\Widget") && isController("Paginate")'
options:
templatePathAndFilename:
'resource://My.Package/Private/Templates/ViewHelpers/Widget/Paginate/Index.html'
@fvosberg
fvosberg / 0_reuse_code.js
Last active August 29, 2015 14:10
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@fvosberg
fvosberg / CustomActionController.php
Created January 29, 2015 10:20
Get an invalid object in the "show form" action
public function initializeNewAction() {
if( !$this->request->hasArgument('newObject') && $this->request->getHttpRequest()->hasArgument('newObject') ) {
$this->request->setArgument('newObject', $this->request->getHttpRequest()->getArgument('newObject'));
}
}
@fvosberg
fvosberg / apache.conf-chef
Created July 15, 2015 07:32
Small Lamp Config
# for small servers
default['apache']['timeout'] = 30
default['apache']['keepaliverequests'] = 10
default['apache']['keepalivetimeout'] = 5
# only for prefork
default['apache']['prefork']['startservers'] = 3
default['apache']['prefork']['minspareservers'] = 3
default['apache']['prefork']['maxspareservers'] = 5
default['apache']['prefork']['maxrequestworkers'] = 10
default['apache']['prefork']['maxconnectionsperchild'] = 0