Skip to content

Instantly share code, notes, and snippets.

View lovasoa's full-sized avatar
🎯
Focusing

Ophir LOJKINE lovasoa

🎯
Focusing
View GitHub Profile
private static PrimitiveIterator.OfInt alphaChars(CharSequence s) {
return s.chars().filter(Character::isAlphabetic).map(Character::toLowerCase).iterator();
}
public static boolean compareAlphabeticCharacters(CharSequence a, CharSequence b) {
PrimitiveIterator.OfInt aStream = alphaChars(a);
PrimitiveIterator.OfInt bStream = alphaChars(b);
while (aStream.hasNext() && bStream.hasNext()) {
if (aStream.nextInt() != bStream.nextInt()) return false;
}
package com.qwant;
import org.ccil.cowan.tagsoup.jaxp.SAXParserImpl;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
package com.company;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Stream;
import static java.util.stream.Collectors.joining;
public class Main {
public static String decode(String morseCode) {
package com.company;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.Map;
public class Main {
static void hist(String codes, PrintStream out) {
Map<Character, Integer> map = new HashMap<>();
@lovasoa
lovasoa / memoize_async.js
Last active January 25, 2020 01:09
ES6 async memoize, using async/await and a Map to store the cache.
function memoize_async(func) {
const m = async function (key) {
if (!m.cache.has(key)) m.cache.set(key, await func.apply(this, arguments));
return m.cache.get(key);
};
m.cache = new Map();
return m;
};
@lovasoa
lovasoa / test.java
Last active September 26, 2018 16:41
package com.company;
import java.io.PrintWriter;
import java.sql.SQLException;
import static org.junit.Assert.assertEquals;
public class MainTest {
@org.junit.Test
@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