Skip to content

Instantly share code, notes, and snippets.

View mtrojanowski's full-sized avatar

Michał Trojanowski mtrojanowski

View GitHub Profile
@mtrojanowski
mtrojanowski / expose_dockerized_idsvr.sh
Last active March 21, 2023 12:00
Updated ngrok config and command to work with ngrok v3
#!/bin/bash
set -m
mkdir -p $HOME/.ngrok2
CONFIG_FILE="$HOME/.ngrok2/curity.yml"
if [[ ! -e "$CONFIG_FILE" ]]; then
cat <<EOF > ${CONFIG_FILE}
console_ui: false
tunnels:
@mtrojanowski
mtrojanowski / Fibonacci.java
Created December 21, 2017 13:36
An implementation of Fibonacci
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 March 8, 2015 11:54
Simple script to count AWS DiskSpace usage
$size = 0;
$count = 0;
$keyMarker = null;
$params = [
'Bucket' => $bucket
];
do {
$params['KeyMarker'] = $keyMarker;
<?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 December 15, 2013 15:27
JS to block selecting text on a site.
//courtesy of BoogieJack.com
function killCopy(e) {
return false;
}
function reEnable() {
return true;
}
document.onselectstart = new Function ("return false")
@mtrojanowski
mtrojanowski / cookies.php
Created April 22, 2013 18:18
Cookie information for webpages in Poland
<?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 March 22, 2013 13:42
Sf 1.4. send an Excel file to browser
$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);