Skip to content

Instantly share code, notes, and snippets.

@Glamdring
Glamdring / location.js
Created April 23, 2015 13:30
Коментари в кода на postbank.bg :)
/**************************************************************************************/
/**************************************************************************************/
/**************************************************************************************/
var cnst_city_selected_zoom_level = 17;
function Cacher(url, icon) {
var cnst_dictionary = {
dict_cmd_choose_city:{bg:"Моля изберете град", en:"Please choose city"},
};
var self = this;
@Glamdring
Glamdring / LegislationStats.java
Created May 21, 2016 21:35
Legislation effort of the Bulgarian executive branch and legislature
package legislation;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Glamdring
Glamdring / PluralityVoting.java
Last active August 3, 2016 06:44
Analyzing the results in case Bulgaria had plurality voting on past elections
package bg.elections.pv;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
package foo;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.xbill.DNS.AAAARecord;
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 7.
domain,ttl,aaaa-ttl,cname-ttl,miltiple-ttls,ns-root,ns-ttl,a-count,aaaa-count,a-records,aaaa-records,ns-records,cname
facebook.com,300,300,,false,facebook.com,128517,1,1,"31.13.66.36","2a03:2880:f113:83:face:b00c:0:25de","a.ns.facebook.com.,b.ns.facebook.com.",
twitter.com,300,,,false,dynect.net,42239,4,0,"199.16.156.102,199.16.156.198,199.16.156.70,199.16.156.230","","ns1.p34.dynect.net.,ns3.p34.dynect.net.,ns4.p34.dynect.net.,ns2.p34.dynect.net.",
google.com,300,300,,false,google.com,128501,1,1,"216.58.209.14","2a00:1450:4017:803:0:0:0:200e","ns3.google.com.,ns4.google.com.,ns1.google.com.,ns2.google.com.",
youtube.com,300,300,,false,google.com,128505,1,1,"216.58.209.206","2a00:1450:4017:803:0:0:0:200e","ns3.google.com.,ns4.google.com.,ns1.google.com.,ns2.google.com.",
wordpress.org,600,,,false,wordpress.org,54943,2,0,"66.155.40.249,66.155.40.250","","ns4.wordpress.org.,ns3.wordpress.org.,ns1.wordpress.org.,ns2.wordpress.org.",
linkedin.com,300,300,,false,dynect.net,47775,1,1,"108.174.10.10","2620:109:c002:
Площад Вид Вид (2) Вид (3)
Атанас Буров площад
Баба Неделя широк тротоар
Бански градинка
Бойко градинка
Братя Прошек кръстовище
България градинка площад
Васил Левски кръстовище кръгово паметник
Велчова завера кръстовище паркинг
Възраждане градинка
@Glamdring
Glamdring / signtext.js
Created June 11, 2017 13:40
WebCrypto API electronic signature
<html>
<head>
<script type="text/javascript">
function sign(input, password) {
// salt should be Uint8Array or ArrayBuffer
var saltBuffer = str2ab('e85c53e7f119d41fd7895cdc9d7bb9dd');
// don't use naive approaches for converting text, otherwise international
// characters won't have the correct byte sequences. Use TextEncoder when
// available or otherwise use relevant polyfills
@Glamdring
Glamdring / GiavaRateLimiter.java
Last active July 14, 2017 12:37
Guava rate limiter
private RateLimiter createGuavaRateLimiter() {
double permitsPerSecond = ((double) hourlyLimit) / (60d * 60); // hourlyLimit / seconds-per-hour
logger.info("Creating rate limiter with {} permits per seconds", permitsPerSecond);
RateLimiter rateLimiter = RateLimiter.create(permitsPerSecond);
// initialize with a full number of permits. Use refleciton, as guava does not expose that functionality
try {
Class<?> limiterClass = Class.forName("com.google.common.util.concurrent.SmoothRateLimiter");
Field field = ReflectionUtils.findField(limiterClass, "storedPermits");
ReflectionUtils.makeAccessible(field);
ReflectionUtils.setField(field, rateLimiter, hourlyLimit);
public class SimpleRateLimiter {
private Semaphore semaphore;
private int maxPermits;
private TimeUnit timePeriod;
private ScheduledExecutorService scheduler;
public static SimpleRateLimiter create(int permits, TimeUnit timePeriod) {
SimpleRateLimiter limiter = new SimpleRateLimiter(permits, timePeriod);
limiter.schedulePermitReplenishment();
return limiter;
@Glamdring
Glamdring / BookAnalyzer.java
Last active July 24, 2017 21:52
Анализ на предизборните пропагандни книги на Монитор/Телеграф
package test;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;