Skip to content

Instantly share code, notes, and snippets.

@iddoeldor
iddoeldor / BlacklistLucene.java
Created September 18, 2017 15:41
blacklist with wildcard using Lucene
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.StringField;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
@iddoeldor
iddoeldor / wawatchdog.js
Created November 19, 2017 17:30
watchdog
// chromium plugin
(function() {
Notification.requestPermission();
WebSocket.prototype._send = WebSocket.prototype.send;
WebSocket.prototype.send = function(data) {
this._send(data);
this.addEventListener('message', function(msg) {
console.log('>> ' + msg.data);
if (msg.data.includes("Presence")) {
var d = eval(msg.data.split(',').slice(1).join());
@iddoeldor
iddoeldor / MaxOverlap.java
Last active December 30, 2017 14:27
find the number of overlaps in calls
public static void main(String[] args) {
long[] begin = new long[]{1504848555000L,1504867164000L,1504893887000L,1504893409000L,1504860962000L,1504881065000L,1504839844000L,1504890726000L};
long[] end = new long[]{1504858555000L,1504869164000L,1504897887000L,1504896409000L,1504890962000L,1504981065000L,1504849844000L,1504990726000L};
maxOverlap(begin, end);
}
/**
* You have time-stamps (mentioned as integers), which represents phone call begin and end to call center.
* find the number of overlaps in calls that suggests to add more call center agents.
*/
@iddoeldor
iddoeldor / ReverseIP2Country.java
Last active January 6, 2018 14:38
reverse ip2country
import com.maxmind.geoip2.DatabaseReader;
import com.maxmind.geoip2.exception.GeoIp2Exception;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.nio.file.Files;
import java.nio.file.Paths;
import static java.nio.file.StandardOpenOption.*;
@iddoeldor
iddoeldor / port_killer.sh
Last active January 6, 2018 16:38
what to do when port is taken
# TODO refactor to function
sudo lsof -t -i:'8080' -sTCP:LISTEN # get process id that uses port 8080
ps -p $PID # get process info
ps -o ppid= -p $PID # sometimes killing the PID will not work because it's a child process, this will get parent process
sudo kill -9 $PID # of course. killing the process
# .bashrc
alias kill_port='kill -9 $(lsof -t -i:'$0' -sTCP:LISTEN)'
@iddoeldor
iddoeldor / MetadataExtractor.java
Created January 27, 2018 21:18
Iterating over html sites, extracting file's (currently only images) metadata in parallel using java8, Jsoup & Apache Tika
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.parser.AutoDetectParser;
import org.apache.tika.parser.ParseContext;
import org.apache.tika.parser.Parser;
import org.apache.tika.sax.BodyContentHandler;
@iddoeldor
iddoeldor / r.py
Created April 15, 2018 21:16
חידה. מציאת מיקום להעברת קו ישר בין נקודות על מערכת צירים כך שיהיה במרחק המינימלי ביניהן
import numpy as np
from matplotlib import pyplot as plt
y = [10, 20, 30, 40, 50, 52, 60, 70, 200]
x = np.random.uniform(low=1, high=200, size=(len(y),))
min_sum, Y = sum(y), 0
for cur_y in y:
cur_sum = 0
for j in y:
@iddoeldor
iddoeldor / Makefile
Created June 6, 2018 15:25
dump keychain to json
GCC_BIN=`xcrun --sdk iphoneos --find gcc`
SDK=`xcrun --sdk iphoneos --show-sdk-path`
#support iPhone 3GS and above, delete armv6 to avoid SDK error
ARCH_FLAGS=-arch armv7 -arch armv7s -arch arm64
LDFLAGS =\
-F$(SDK)/System/Library/Frameworks/\
-F$(SDK)/System/Library/PrivateFrameworks/\
-framework UIKit\
-framework CoreFoundation\
@iddoeldor
iddoeldor / r2.py
Last active August 12, 2018 10:11
"""
Riddle :
Room with 100 drawers each drawer contains a unique real number between 0..99
First man gets into the room and can open all drawers but can switch drawers only once
Second man will enter afterwards and will be asked to find a random number in 50 attempts
Both men can talk only before first man will get in and decide on strategy
Whats the best strategy ?
"""
from random import shuffle
from turtle import Turtle, Screen
<!DOCTYPE html>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
body {
background: repeat url('data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/7QCIUGhvdG9zaG9wIDMuMAA4QklNBAQAAAAAAGscAVoAAxslRxwCAAACAAAcAnQAV8KpIENoYWV5b3VuZ1dpbGxOZXZlckNoYWVvbGQgLSBodHRwOi8vd3d3LnJlZGJ1YmJsZS5jb20vcGVvcGxlL0NoYWV5b3VuZ1dpbGxOZXZlckNoYWVvbAD/4gxYSUNDX1BST0ZJTEUAAQEAAAxITGlubwIQAABtbnRyUkdCIFhZWiAHzgACAAkABgAxAABhY3NwTVNGVAAAAABJRUMgc1JHQgAAAAAAAAAAAAAAAAAA9tYAAQAAAADTLUhQICAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABFjcHJ0AAABUAAAADNkZXNjAAABhAAAAGx3dHB0AAAB8AAAABRia3B0AAACBAAAABRyWFlaAAACGAAAABRnWFlaAAACLAAAABRiWFlaAAACQAAAABRkbW5kAAACVAAAAHBkbWRkAAACxAAAAIh2dWVkAAADTAAAAIZ2aWV3AAAD1AAAACRsdW1pAAAD+AAAABRtZWFzAAAEDAAAACR0ZWNoAAAEMAAAAAxyVFJDAAAEPAAACAxnVFJDAAAEPAAACAxiVFJDAAAEPAAACAx0ZXh0AAAAAENvcHlyaWdodCAoYykgMTk5OCBIZXdsZXR0LVBhY2thcmQgQ29tcGFueQAAZGVzYwAAAAAAAAASc1JHQiBJRUM2MTk2Ni0yLjEAAAAAAAAAAAAAABJzUkdCIElFQzYxOTY2LTIuMQAAAAAAAA