Skip to content

Instantly share code, notes, and snippets.

Avatar

Michał Trojanowski mtrojanowski

View GitHub Profile
@mtrojanowski
mtrojanowski / Fibonacci.java
Created Dec 21, 2017
An implementation of Fibonacci
View Fibonacci.java
private BigInteger f(int n, Map<Integer, BigInteger> cache) {
BigInteger result = cache.putIfAbsent(n, RESERVED);
if (result == null) {
int half = (n + 1) / 2;
CompletableFuture<BigInteger> completableFuture = new CompletableFuture<>();
CompletableFuture<BigInteger> futureResult = CompletableFuture.supplyAsync(() -> f(half - 1, cache));
futureResult.thenAcceptBothAsync(CompletableFuture.supplyAsync(
@mtrojanowski
mtrojanowski / awsdiskcount.php
Created Mar 8, 2015
Simple script to count AWS DiskSpace usage
View awsdiskcount.php
$size = 0;
$count = 0;
$keyMarker = null;
$params = [
'Bucket' => $bucket
];
do {
$params['KeyMarker'] = $keyMarker;
View mathFunc
<?php
/*
* Create an operation which will behave as the following
* set of functions (without using "if" statements):
*
* f(x) = 0, for x < 0;
* f(x) = x, for x >= 0 and x < 1;
* f(x) = 1, for x >= 1 and x < 2;
* f(x) = -x + 3, for x >=2 and x < 3;
@mtrojanowski
mtrojanowski / block.js
Created Dec 15, 2013
JS to block selecting text on a site.
View block.js
//courtesy of BoogieJack.com
function killCopy(e) {
return false;
}
function reEnable() {
return true;
}
document.onselectstart = new Function ("return false")
@mtrojanowski
mtrojanowski / cookies.php
Created Apr 22, 2013
Cookie information for webpages in Poland
View cookies.php
<?php if (empty($_COOKIE['cookies_accepted'])): ?>
<div id="cookies">
<div id="cookies_txt">
Informujemy, że nasza strona aby poprawnie działać korzysta z mechanizmu "cookies".
Nie wykorzystujemy plików "cookies" dla celów reklamowych.<br/>
Korzystając ze strony wyrażasz zgodę na używanie plików "cookies", zgodnie z aktualnymi ustawieniami przeglądarki.
<a href="" id="cookie_accept">Zamknij</a>
</div>
</div>
<?php endif; ?>
@mtrojanowski
mtrojanowski / gist:5221364
Created Mar 22, 2013
Sf 1.4. send an Excel file to browser
View gist:5221364
$this->getResponse()->clearHttpHeaders();
$this->getResponse()->setStatusCode(200);
$this->getResponse()->setContentType('application/vnd.ms-excel');
$this->getResponse()->setHttpHeader('Content-Disposition', "attachment; filename=filename.xls");
$this->getResponse()->setHttpHeader('Content-Transfer-Encoding', 'binary');
$this->getResponse()->setHttpHeader('Content-Length', $file_size);
return $this->renderText($file_contents);
You can’t perform that action at this time.