This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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<>(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.company; | |
import java.io.PrintWriter; | |
import java.sql.SQLException; | |
import static org.junit.Assert.assertEquals; | |
public class MainTest { | |
@org.junit.Test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
echo "CREATE TABLE lines (line TEXT);"; | |
while read line; do | |
escaped=${line//\'/\'\'}; | |
echo "INSERT INTO lines VALUES ('$escaped');"; | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |