Skip to content

Instantly share code, notes, and snippets.

public static InputStream readFromCacheSync(String imageUrl) {
CacheKey cacheKey = DefaultCacheKeyFactory.getInstance().getEncodedCacheKey(ImageRequest.fromUri(imageUrl), null);
StagingArea stagingArea = StagingArea.getInstance();
EncodedImage encodedImage = stagingArea.get(cacheKey);
if (encodedImage != null) {
return encodedImage.getInputStream();
}
try {
return readFromDiskCache(cacheKey);
@atma
atma / generate-git-authors.sh
Created September 27, 2017 03:27
Bash script for generating the list of authors in git repo
#!/bin/sh
git shortlog -se \
| perl -spe 's/^\s+\d+\s+//' \
| sed -e '/^CommitSyncScript.*$/d' \
> AUTHORS
@atma
atma / nginx-osx-install.sh
Last active July 30, 2017 02:38
Mac OS X nginx installation from source
# download PCRE and nginx source
sudo mkdir -p /usr/local/src
cd /usr/local/src
# copy PCRE to directory
# eg. cp /tmp/pcre-8.20.tar.gz /usr/local/src/
tar xzvf pcre-8.20.tar.gz
cd pcre-8.20
./configure --prefix=/usr/local
make && sudo make install && make clean
@atma
atma / docker-clean.sh
Created May 4, 2016 00:19
Clean all Docker containers and/or images
#clean all containers:
docker ps -a | sed '1 d' | awk '{print $1}' | xargs -L1 docker rm
#clean all images:
docker images -a | sed '1 d' | awk '{print $3}' | xargs -L1 docker rmi -f
// Woff font loader with localStorage caching
function loadFont(a, b, c, d) { function e() { if (!window.FontFace) return !1; var a = new FontFace("t", 'url("data:application/font-woff2,") format("woff2")', {}), b = a.load(); try { b.then(null, function () { }) } catch (c) { } return "loading" === a.status } var f = navigator.userAgent, g = !window.addEventListener || f.match(/(Android (2|3|4.0|4.1|4.2|4.3))|(Opera (Mini|Mobi))/) && !f.match(/Chrome/); if (!g) { var h = {}; try { h = localStorage || {} } catch (i) { } var j = "x-font-" + a, k = j + "url", l = j + "css", m = h[k], n = h[l], o = document.createElement("style"); if (o.rel = "stylesheet", document.head.appendChild(o), !n || m !== b && m !== c) { var p = c && e() ? c : b, q = new XMLHttpRequest; q.open("GET", p), q.onload = function () { q.status >= 200 && q.status < 400 && (h[k] = p, h[l] = q.responseText, d || (o.textContent = q.responseText)) }, q.send() } else o.textContent = n } };
//loadFont('Lato400', '/assets/fonts/lato/lato.woff.css', '/
@atma
atma / track_ajax_errors.js
Created April 29, 2015 17:54
Track JavaScript errors with Google Analytics
// jQuery AJAX errors handler
$(document).ajaxError(function (event, request, settings) {
ga(
'send',
'event',
'jQuery Ajax Error',
settings.url,
JSON.stringify({
result: event.result,
status: request.status,
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@atma
atma / example_ssl.conf
Created February 18, 2015 10:53
Nginx SSL configuration for A+ grade
listen 443 ssl spdy;
ssl on;
ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
ssl_session_cache shared:SSL:20m;
ssl_session_timeout 10m;
ssl_ciphers 'EECDH+ECDSA+AESGCM:AES128+EECDH:AES128+EDH:!RC4:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS:!CAMELLIA:!ADH';
ssl_prefer_server_ciphers on;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 10s;
@atma
atma / call-sample.html
Created November 11, 2014 12:35
An example usage of Google Experiments on client side only
<!-- Call immediately an experiment method to prevent a FOOC (Flash of original content) -->
<button class="btn btn-link" type="button" id="button">Click me</button>
<script>typeof __abt !== "undefined" && __abt.some && __abt.some();</script>
<div classs="another-html-content"></div>
(function(){
function addFont() {
var style = document.createElement('style');
style.rel = 'stylesheet';
document.head.appendChild(style);
style.textContent = localStorage.sourceSansPro;
}
try {
if (localStorage.sourceSansPro) {