Skip to content

Instantly share code, notes, and snippets.

Avatar

Tomislav trajakovic

  • Score Alarm
  • Zagreb
View GitHub Profile
@trajakovic
trajakovic / Android TimeExpiringLruCache.java
Created Mar 31, 2013
I've took original Android's LruCache, and implemented time expiration parameter, so when you call next time "get", and value is timed-out, you'll get null (and old entry will be removed from cache).
View Android TimeExpiringLruCache.java
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import android.os.SystemClock;
public class TimeExpiringLruCache<K, V> {
private final LinkedHashMap<K, V> map;
private final HashMap<K, Long> validityTime;
@trajakovic
trajakovic / Rx.Observable.cacheWithExpiration-demo.js
Last active Mar 22, 2021
RxJs extension implementation for cache results with time expiration
View Rx.Observable.cacheWithExpiration-demo.js
var slowJob = Rx.Observable.defer(function () {
return Rx.Observable.return(Math.random() * 1000).delay(2000);
});
var cached = slowJob.cacheWithExpiration(5000);
var last = Date.now();
function repeat() {
last = Date.now();
cached.subscribe(function (data) {
@trajakovic
trajakovic / docker_1.13_manual_install_centos.sh
Created Mar 28, 2017
Docker 1.13 manual installation on CentOS7 for Openshfit Origin 1.5.0.rc0 (since latest docker version is 17.03, oc cluster up is not happy with version)
View docker_1.13_manual_install_centos.sh
yum install wget
wget https://yum.dockerproject.org/repo/main/centos/7/Packages/docker-engine-1.13.1-1.el7.centos.x86_64.rpm
wget https://yum.dockerproject.org/repo/main/centos/7/Packages/docker-engine-selinux-1.13.1-1.el7.centos.noarch.rpm
#nice site with pckgs: https://pkgs.org/
#package for docker-engine-selinux
yum install -y policycoreutils-python
rpm -i docker-engine-selinux-1.13.1-1.el7.centos.noarch.rpm
@trajakovic
trajakovic / openssl_split_one_pem_to_multiple.sh
Created Oct 23, 2013
Split SSL PEM multiple certificates into files
View openssl_split_one_pem_to_multiple.sh
wget -O - http://curl.haxx.se/ca/cacert.pem | awk 'split_after==1{n++;split_after=0} /-----END CERTIFICATE-----/ {split_after=1} {print > "cert" n ".pem"}'
@trajakovic
trajakovic / sysctl-conf.sh
Last active Mar 20, 2019
High performance sysctl.conf
View sysctl-conf.sh
#!/bin/bash
#check if this script is running in su mode
func_check_for_root() {
if [ ! $( id -u ) -eq 0 ]; then
echo "ERROR: $0 Must be run as root, Script terminating" ;exit 7
fi
}
func_check_for_root
@trajakovic
trajakovic / fedora-install-nodejs.sh
Last active Feb 16, 2019
Install node.js on fedora (23+).(v5.10.1)
View fedora-install-nodejs.sh
#!/usr/bin/env bash
func_check_for_root() {
if [ ! $( id -u ) -eq 0 ]; then
echo "ERROR: $0 Must be run as root, Script terminating" ;exit 7
fi
}
func_check_for_root
#SETUP PARAMS
@trajakovic
trajakovic / BootstrapFormHelper.php
Last active Dec 16, 2018
This file is taken from https://github.com/CCadere/CakePHP-Forms-Bootstrap-2.3-Helper/blob/master/View/Helper/BootstrapFormHelper.php, and slightly modified/extended. Added support for has-error bs3 validation error class.
View BootstrapFormHelper.php
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
*
* Licensed under The MIT License
*
* Copyright (c) La Pâtisserie, Inc. (http://patisserie.keensoftware.com/)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('FormHelper', 'View/Helper');
@trajakovic
trajakovic / compile-elixir-v1.6.3.sh
Last active Mar 10, 2018
Compile and install Erlang 20.2 from source on Ubuntu 16.04 (Xenial Xerus or Linux Mint Sylvia 18.3). Compile and install Elixir 1.6.3 on Ubuntu 16.04
View compile-elixir-v1.6.3.sh
# requirement: erlang, git
ELIXIR_VERSION="1.6.3"
sudo apt-get update && sudo apt-get install -y git && \
rm -rf /tmp/code/elixir/${ELIXIR_VERSION} && mkdir -p /tmp/code/elixir/${ELIXIR_VERSION} && cd /tmp/code/elixir/${ELIXIR_VERSION} && \
git clone -b "v${ELIXIR_VERSION}" --single-branch --depth 1 https://github.com/elixir-lang/elixir.git . && \
make clean test && \
sudo make install && \
cd && rm -rf /tmp/code/elixir && \
echo "Check your elixir version by typing 'iex --version'"
@trajakovic
trajakovic / react-native-clear-all.sh
Last active Mar 2, 2018 — forked from EQuimper/clear.txt
React-Native clear Watchman + Cache + Temp
View react-native-clear-all.sh
rm /tmp/haste-* /tmp/flow /tmp/metro-* /tmp/socketcluster/ -rf && watchman watch-del-all
yarn start -- --reset-cache
@trajakovic
trajakovic / generate_files.sh
Created Apr 20, 2017
Generate binary files with random content...and calculate their sha256
View generate_files.sh
#!/bin/bash
#size magnitude
sizes=( "" "K" "M" )
for magnitude in "${sizes[@]}"; do
for size in `seq 1 5 51`; do
echo "Generating ${size}${magnitude}"
head -c ${size}${magnitude} </dev/urandom >file-${size}${magnitude}.bin