import java.io.File;
import java.awt.Color;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
public class ImageSimilarity {
public static BufferedImage getDifferenceImage(BufferedImage img1, BufferedImage img2) {
final int w = img1.getWidth(),
h = img1.getHeight(),
highlight = Color.MAGENTA.getRGB();
final int[] p1 = img1.getRGB(0, 0, w, h, null, 0, w);
final int[] p2 = img2.getRGB(0, 0, w, h, null, 0, w);
for (int i = 0; i < p1.length; i++) {
if (p1[i] != p2[i]) {
p1[i] = highlight;
}
}
final BufferedImage out = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
out.setRGB(0, 0, w, h, p1, 0, w);
return out;
}
public static void main(String[] args) throws Exception {
ImageIO.write(
getDifferenceImage(
ImageIO.read(new File("img1.png")),
ImageIO.read(new File("img2.png"))),
"png",
new File("diff.png"));
}
}
<p:commandButton value="Скрыть/Показать">
<f:ajax listener="#{exampleBean.toggleVisibility}" event="click" render="somePanel"></f:ajax>
</p:commandButton>
<h:panelGroup id="somePanel" layout="block" rendered="#{exampleBean.visible}">
<div>Трям!</div>
</h:panelGroup>
<h:panelGroup id="somePanel" layout="block" styleClass="#{(exampleBean.visible) ? 'hidden' : ''">
<div>Трям!</div>
</h:panelGroup>
<script>
function toggleVisibility(id) {
var table = document.getElementById(id);
if(table) {
var currentState = table.style.display || 'block';
if (currentState === 'block')
table.style.display = 'none';
else
table.style.display = 'block';
}
return false;
}
</script>
<p:commandButton value="Скрыть/Показать" onclick="toggleVisibility('globalform:visTest:checking');">
</p:commandButton>
from django.conf import settings
from django.core.cache import cache, get_cache
from django.utils.importlib import import_module
class UserRestrictMiddleware(object):
def process_request(self, request):
"""
Checks if different session exists for user and deletes it.
"""
if request.user.is_authenticated():
cache = get_cache('default')
cache_timeout = 86400
cache_key = "user_pk_%s_restrict" % request.user.pk
cache_value = cache.get(cache_key)
if cache_value is not None:
if request.session.session_key != cache_value:
engine = import_module(settings.SESSION_ENGINE)
session = engine.SessionStore(session_key=cache_value)
session.delete()
cache.set(cache_key, request.session.session_key,
cache_timeout)
else:
cache.set(cache_key, request.session.session_key, cache_timeout)
System.loadLibrary()
ищет библиотеку в java.library.path. В разных системах это свойство содержит разное значение по умолчанию:<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res/com.example.customviews">
<com.example.customviews.MyEditText
android:id="@+id/my_input"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:inputType="My text"
/>
</LinearLayout>
MyEditText text = (MyEditText) findViewById(R.id.my_input)
from django.apps import apps
from django.core import serializers
# Получаем список всех моделей всех приложений из INSTALLED_APPS
# и фильтруем django'вские
models = [model for model in apps.get_models() if not model.__module__.startswith('django')]
# Сериалзиуем в json полный QuerySet каждой модели
dump = ''
for m in models:
dump += serializers.serialize('json', m._default_manager.all())