Skip to content

Instantly share code, notes, and snippets.

View lovasoa's full-sized avatar
🎯
Focusing

Ophir LOJKINE lovasoa

🎯
Focusing
View GitHub Profile
@org.junit.Test
public void testClasses() {
class A {
}
A a = new A();
assertEquals(a, a);
assertTrue(new A[]{a, a, a}.equals(new A[]{a, a, a}));
assertEquals(new A(), new A());
@lovasoa
lovasoa / Main.java
Last active September 25, 2018 14:48
package com.company;
import java.io.*;
import java.nio.charset.Charset;
public class Main {
public static byte[] to1251Bytes(final String str) {
try {
final ByteArrayOutputStream os = new ByteArrayOutputStream(str.length());
@lovasoa
lovasoa / txt2sql.sh
Created September 24, 2018 15:56
Convert text a text file to sql statements, inserting a new value per line of text
#!/usr/bin/env bash
echo "CREATE TABLE lines (line TEXT);";
while read line; do
escaped=${line//\'/\'\'};
echo "INSERT INTO lines VALUES ('$escaped');";
done
@lovasoa
lovasoa / mysql2sqlite.awk
Last active October 28, 2018 23:44 — forked from esperlu/mysql2sqlite.sh
MySQL to Sqlite converter
#!/usr/bin/awk -f
# Converts a mysqldump file into a Sqlite 3 compatible file. It also extracts the MySQL `KEY xxxxx` from the
# CREATE block and create them in separate commands _after_ all the INSERTs.
# Awk is choosen because it's fast and portable. You can use gawk, original awk or even the lightning fast mawk.
# The mysqldump file is traversed only once.
# Usage: $ ./mysql2sqlite.awk < db-mysql.sql | sqlite3 database.sqlite
# Example: $ mysqldump --no-data -u root -pMySecretPassWord myDbase | ./mysql2sqlite.awk | sqlite3 database.sqlite
@lovasoa
lovasoa / server.js
Created June 14, 2018 12:30
Small node server to help testing how a client handles invalid or conflicting encodings. Launch it, then visit http://localhost:8000/?responseText=héhé&htmlCharset=iso-8859-1&headerCharset=windows-1251
var http = require('http');
var uparse = require('url').parse;
http.createServer(function ({url}, res) {
const {headerCharset, responseText, htmlCharset} = uparse(url, true).query;
const ctype = 'text/html' + (headerCharset ? '; charset=' + headerCharset : '');
res.writeHead(200, {'Content-Type': ctype});
const meta = htmlCharset ? `<meta charset="${htmlCharset}">` : ``;
res.end(`<!doctype html>
<html>
import Data.Maybe
import Data.List
import Data.Ord
data DicTrie = DicTrie [(Char, DicTrie)] deriving Show
emptyTrie = DicTrie []
mainDict = DicTrie [
('e', DicTrie[
('n', DicTrie[
@lovasoa
lovasoa / voc_sequencer.py
Created June 8, 2018 14:22
Create a vocabulary list
#!/usr/bin/env python3
from collections import Counter
import numpy as np
import pickle
MAX_COUNTER_SIZE = 2**16
MAX_SEQ_SIZE = 16
MAX_SIMILARITY = .75
#!/usr/bin/env python3
import pandas as pd
import numpy as np
import sys
import logging
def is_valid_line(line: bytes):
return line and b"SQLProxy" not in line and b"P2_COD" not in line
#version: 0.2
e s</w>
d e</w>
e n
a n
o n
t i
l e</w>
o u
e s
CREATE TABLE SUBJECT1 (
NAME VARCHAR(100),
SURNAME VARCHAR(100),
CITY VARCHAR(100)
);
INSERT INTO SUBJECT1
SELECT NAME, SURNAME, CITY
FROM SUBJECT
GROUP BY NAME, SURNAME, CITY;