Skip to content

Instantly share code, notes, and snippets.

@alashow
alashow / DateUtil.java
Last active August 29, 2015 14:12
TimeAgo
/*
* Copyright 2014. Alashov Berkeli
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
Ýaňagyňda reňkler barmy?
Gymyldap bilmejek derejede gorky gördüňmi?
Dişiňde galan zat ýaly, hiç ýere gitmeýän?
Mümkin sende maňa aýdarlyk zadyň bardyr?
Ýüregimde doly ornaşanyňy bileňokdyňmy?
Şu hepde sen barada her gije pikirlendim
Syrlary saklap bilýäňmi?
Umuman, näme üçündir seni ýadyma salýan aýdym tapdym
We men ony ýatyp galýançam gaýta-gaýta diňleýän
Içgilerimi düşegime döküp
package mover;
import java.io.File;
import java.nio.file.Files;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Moves files to folders with name founded year (4 length number in parenthesis) in file name. Can be used for ordering movie files
* Ex.: file name: The Bourne Identity (2002).mp4
@alashow
alashow / haproxy.cfg
Created September 11, 2016 20:14 — forked from T0MM0R/haproxy.cfg
Let's Encrypt Auto-Renewal script for HAProxy
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin
stats timeout 30s
user haproxy
group haproxy
daemon
maxconn 2048
@alashow
alashow / PrettyIntegers.java
Last active October 1, 2016 02:57
Convert long integers to "pretty" strings. Could be used for ids in pretty urls
package tm.alashow.playground;
public class PrettyIntegers {
public static void main( String args[] ) {
Character[] map = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K',
'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
'h', 'j', 'k', 'm', 'n', 'p', 'q', 'r', 's', 't',
'u', 'v', 'x', 'y', 'z', '1', '2', '3'};
/**
* Part of my utils class that I use in my apps.
* Contains only functions related to showing snackbars and toasts.
* Some string/resources are missing in this gist. Names of resources are self explanatory. Hence, it shouldn't be hard to define it in your resources.
*/
public class U {
public static float density = 1;
public static final int SNACK_DEFAULT = 0;
@alashow
alashow / Fibonacci.java
Last active October 2, 2017 06:46
Fibonacci in Java using tail call.
package tm.alashow.homework.datastructures.second;
import java.util.Locale;
import java.util.Scanner;
/**
* Created by alashov on 10/1/17.
*/
public class Fibonacci {
@alashow
alashow / user.js
Last active March 19, 2018 01:50
Force tumblr posts use hight quality images. Tempermonkey user script.
// ==UserScript==
// @name Tumblr image size converter
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Force tumblr post photos use high quality
// @author Alashov Berkeli
// @include https://www.tumblr.com/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js
// @grant none
// ==/UserScript==
/*
* Copyright (c) 2016 Alashov Berkeli
* It is licensed under GNU GPL v. 2 or later. For full terms see the file LICENSE.
*/
package tm.asmanoky.aziada.util.glide;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
@alashow
alashow / AppViewModelFactory.kt
Last active April 1, 2019 05:18
ViewModel dynamic parameters hack
class AppViewModelFactory @Inject constructor(
private val creators: @JvmSuppressWildcards Map<Class<out ViewModel>, Provider<ViewModel>>
) : ViewModelProvider.Factory {
var onViewModelCreate: ((viewModel: ViewModel) -> Unit)? = null
override fun <T : ViewModel> create(modelClass: Class<T>): T {
var creator: Provider<out ViewModel>? = creators[modelClass]
if (creator == null) {
for ((key, value) in creators) {