Skip to content

Instantly share code, notes, and snippets.

View dejanstojanovic's full-sized avatar
🎧
Focusing

Dejan Stojanovic dejanstojanovic

🎧
Focusing
View GitHub Profile
@dejanstojanovic
dejanstojanovic / html5.localstorage.ex.js
Created October 28, 2018 11:08
HTML5 localStorage with expire
var localStorageEx = {
get: function (key) {
var value = localStorage[key];
if (value != null) {
var model = JSON.parse(value);
if (model.payload != null && model.expiry != null) {
var now = new Date();
if (now > Date.parse(model.expiry)) {
localStorage.removeItem(key);
return null;
@dejanstojanovic
dejanstojanovic / k8-service
Created September 6, 2018 10:15
k8 service commands and config
=================== M6-03
### Wrapping the hello-rc Replication Controller in a Service - the iterative way
$ kubectl expose rc hello-rc --name=hello.svc --target-port=800 --type=NodePort
$ kubectl describe svc hello-svc
=================== M6-04
### Wrapping the hello-rc Replication Controller in a Service - the iterative way
@dejanstojanovic
dejanstojanovic / k8-deployment
Created September 6, 2018 10:14
k8 deployment config and commands
#### m7-03
kubectl delete rc hello-rc
kubectl get pods
kubectl describe svc hello-svc
vim deploy.yml
kubectl create deployment
@dejanstojanovic
dejanstojanovic / read-file-lines.sh
Created August 28, 2018 08:35
Read text file line by line via bash
#!/bin/bash
while IFS='' read -r line || [[ -n "$line" ]]; do
echo $line
done < "$1"
var today = new Date();
var todayUtc = new Date(today.getUTCFullYear(),today.getUTCMonth(),today.getUTCDay(),today.getUTCHours(),today.getUTCMinutes(),today.getUTCSeconds(), today.getUTCMilliseconds());
console.log(today.toString());
console.log(todayUtc.toString());
class Program
{
static ConnectionMultiplexer redisConnection = ConnectionMultiplexer.Connect("<REDIS connection string>");
static void Main(string[] args)
{
var key = "counter.test";
var expiry = TimeSpan.FromMinutes(5);
IDatabase db = redisConnection.GetDatabase(3);
var count = db.StringIncrement(key, 1);
@dejanstojanovic
dejanstojanovic / CreateIISSite
Last active January 16, 2018 17:14 — forked from ifrahim/CreateIISSite
Create IIS Site using Powershell
#unzip -> https://stackoverflow.com/questions/27768303/how-to-unzip-a-file-in-powershell
#check -> http://geekswithblogs.net/QuandaryPhase/archive/2013/02/24/create-iis-app-pool-and-site-with-windows-powershell.aspx
#check -> https://docs.microsoft.com/en-us/iis/manage/powershell/powershell-snap-in-creating-web-sites-web-applications-virtual-directories-and-application-pools
# The following code will create an IIS site and it associated Application Pool.
# Please note that you will be required to run PS with elevated permissions.
# Visit http://ifrahimblog.wordpress.com/2014/02/26/run-powershell-elevated-permissions-import-iis-module/
@dejanstojanovic
dejanstojanovic / mbrola-pi-setup.sh
Last active October 12, 2017 17:21 — forked from sourceperl/say_cpu_temp.py
Text to speak software with espeak and mbrola for Raspberry Pi2 (under Raspbian/jessie)
# install espeak
sudo apt-get install espeak
# install mbrola
wget http://tcts.fpms.ac.be/synthesis/mbrola/bin/raspberri_pi/mbrola.tgz
tar xvzf mbrola.tgz
chmod 755 mbrola
sudo mv ./mbrola /usr/local/bin/
# install voices for mbrola
@dejanstojanovic
dejanstojanovic / LINQ-DistinctBy.cs
Created August 15, 2017 12:13
Distinct by a specific object property in LINQ
public static IEnumerable<TSource> DistinctBy<TSource, TKey> (this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
{
HashSet<TKey> seenKeys = new HashSet<TKey>();
foreach (TSource element in source)
{
if (seenKeys.Add(keySelector(element)))
{
yield return element;
}
}
@dejanstojanovic
dejanstojanovic / Gzip.java
Created September 1, 2016 13:20
Java gzip compress/decompress string
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
public class Gzip {