Skip to content

Instantly share code, notes, and snippets.

View daniel-sc's full-sized avatar

Daniel Schreiber daniel-sc

  • ti&m
  • Offenbach, Germany
View GitHub Profile
@daniel-sc
daniel-sc / flightphp stream file
Created November 3, 2014 09:59
Extend Flightphp to stream file
Flight::map('stream', function($resource){
Flight::response()->sendHeaders();
while ($buf = fread($resource, 1024)) {
echo $buf;
ob_flush();
flush();
}
exit(0);
});
@daniel-sc
daniel-sc / Dockerfile-php5-4
Last active November 10, 2015 08:15
Reproducing goaop classloading error in shutdown function
FROM php:5.4-cli
COPY . /
ENTRYPOINT ["php"]
CMD ["/shutdown-with-goaop.php"]
@daniel-sc
daniel-sc / Main.java
Created November 30, 2015 15:44
Analyze MS-Project files - calculate delay from original plan
import net.sf.mpxj.MPXJException;
import net.sf.mpxj.ProjectFile;
import net.sf.mpxj.Task;
import net.sf.mpxj.mpp.MPPReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
import java.util.logging.*;
@daniel-sc
daniel-sc / podio-php_proxy_hack.php
Last active January 28, 2016 17:24
Workaround for podio-php with http proxy sending multiple http responses
// \Podio::request
$raw_response = preg_replace('/^.*\r\n\r\nHTTP/s', 'HTTP', $raw_response);
$header = preg_split('/\r\n\r\n/s', $raw_response, 2)[0];
$raw_headers_size = strlen($header) + 4;
@daniel-sc
daniel-sc / list-transitive-references.py
Last active June 16, 2016 08:53
Build a generic (transitive) reference tree for any source files.
import re
import argparse
import os
import pprint
import mimetypes
parser = argparse.ArgumentParser(description='Listing transitive references.')
parser.add_argument('start', nargs='+', help='Starting file(s).')
parser.add_argument('--pattern', default='[\'"]([^\'":[\]]+\.(?:png|jpg|gif|xml|html?|php|js))[\'"]',
help='Regex for matching references. \
#!/bin/bash
# copy to: /etc/cron.hourly/check-wlan
# test with: sudo run-parts --test /etc/cron.hourly
if ifconfig wlan0 | grep "inet addr:" ; then
logger "wifi ok"
exit
else
logger "Network down! Attempting reconnection."
@daniel-sc
daniel-sc / create-test-subtasks.js
Created June 26, 2019 15:21
bookmarklet to automatically create jira subtasks for testing
// convert via https://mrcoles.com/bookmarklet/
var tasks = prompt('Tasks mit Kommas abgetrennt eingeben:', 'Test planen,Testdaten definieren,Tests erstellen,Test durchführen & dokumentieren').split(',');
var match = window.location.pathname.match(/[A-Z]+-[0-9]+/);
if (match[0]) {
var task = match[0];
var match = task.match(/[A-Z]+/);
var project = match[0];
var promises = [];
for (var i = 0; i < tasks.length; i++) {
@daniel-sc
daniel-sc / Item.java
Created October 2, 2014 13:31
Java toString() Parser - creates object/instance from toString() output (-string)
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.log4j.Logger;
const minCharCode = Math.min(...'aAzZ019-_.:,'.toUpperCase().split('').map(c => c.charCodeAt(0)));
const maxCharCode = Math.max(...'aAzZ019-_.:,'.toUpperCase().split('').map(c => c.charCodeAt(0)));
const alphabetSize = maxCharCode - minCharCode + 2;
console.log(minCharCode, maxCharCode, alphabetSize, Number.MAX_SAFE_INTEGER, Number.MIN_SAFE_INTEGER);
function toNumber(char) {
return char.toUpperCase().charCodeAt(0) - minCharCode + 1;
}
@daniel-sc
daniel-sc / bitbucket-to-teams-webhook.js
Created April 5, 2023 09:49
Deno script that can be deployed to https://deno.com/deploy and registered as a bitbucket webhook to notifiy new PRs in a MS Teams channel.
import { Application, Router } from 'https://deno.land/x/oak/mod.ts';
// Load environment variables
const PORT = 8080;
const TEAMS_WEBHOOK_URL = 'https://XYZ.webhook.office.com/webhookb2/XYZ';
const TARGET_USERNAME = 'xyz';
if (!TEAMS_WEBHOOK_URL || !TARGET_USERNAME) {
throw new Error('Missing required environment variables.');
}