Skip to content

Instantly share code, notes, and snippets.

@jirkapinkas
jirkapinkas / gist:efcfcf15d5c63265f5a9be8ef3d05175
Last active December 6, 2016 14:26
Postgresql unused indexes
SELECT pg_stat_all_indexes.*, pg_size_pretty(pg_relation_size(indexrelname::regclass))
FROM pg_stat_all_indexes
WHERE schemaname = 'public'
and indexrelname not in (
select distinct tc.constraint_name
from
information_schema.table_constraints tc,
information_schema.key_column_usage kc
where
tc.constraint_type in ('PRIMARY KEY', 'UNIQUE')
package com.test.example2;
public class MainOperation {
public static void main(String[] args) throws Exception {
{
long startMillis = System.currentTimeMillis();
System.out.println("START OP 1");
Operation1.runOp1(500);
System.out.println("END OP 1");
import java.util.stream.*;
public class c_12_Deadlock {
public static void main(String[] args) {
Sync sync1 = new Sync(); // S1
Sync sync2 = new Sync(); // S2
Thread thread1 = new Thread(() -> { // T1
sync1.perform(sync2);
public static void saveToXml(Clovek clovek) {
try {
JAXBContext jaxbContext = JAXBContext.newInstance(Clovek.class);
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(clovek, new File("clovek.xml"));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public class ThreadSafeNot {
private static int counter = 0;
public static void main(String[] args) throws InterruptedException {
Thread thread1 = new Thread(() -> {
for(int i = 0; i < 1_000_000; i++) {
counter++;
}
});
@jirkapinkas
jirkapinkas / Block Bingling Xia spam websites
Created January 29, 2017 14:42
Incomplete list of Bingling Xia proxy spam websites, feed this to Google disawow tool
# How to use it:
# https://support.google.com/webmasters/answer/2648487
domain:o-2.info
domain:cacompany.trade
domain:lookupbear.trade
domain:uscompanies.info
domain:how-old-am-i-today.info
domain:l2lh.info
domain:1tr.info
domain:floridareg.trade
<authentication-manager>
<!-- BASIC INSPIRATION: -->
<!-- http://krams915.blogspot.cz/2012/01/spring-security-31-implement_3065.html -->
<authentication-provider user-service-ref="myUserDetailsService">
<password-encoder hash="bcrypt" />
</authentication-provider>
</authentication-manager>
select translate('žluťoučký kůň pěl ódy', 'žťčýůěóňěščřžýáíé', 'ztcyueonescrzyaie') from dual;
@jirkapinkas
jirkapinkas / gist:7985f079d6f91e4db4a1c7303007d6fe
Last active June 2, 2017 05:45
Thread starvation example (in lots of runs delete isn't called at all)
import java.util.ArrayList;
import java.util.List;
public class MainThreadStarvation {
private static List<Integer> list = new ArrayList<>();
private static final Object mutex = new Object();
public static void main(String[] args) throws InterruptedException {
import java.util.*;
import java.util.concurrent.*;
import java.util.stream.*;
public class WeighAnimalAction extends RecursiveAction {
private int start;
private int end;
private Double[] weights;