Skip to content

Instantly share code, notes, and snippets.

View slawo-ch's full-sized avatar

Slawomir Chodnicki slawo-ch

  • Twineworks GmbH
  • Berlin, Germany
View GitHub Profile
@slawo-ch
slawo-ch / graph.clj
Last active December 9, 2015 09:02
Topological sort in clojure (Tarjan's depth first algorighm)
(ns twineworks.util.graph)
(defn ^:private toposort-visit [n g state]
(let [{:keys [unmarked processing processed]} state]
(when (contains? processing n)
(throw (ex-info "cannot toposort a cyclic graph" {:cause :cyclic-graph
:cycle-node n
:state state
:graph g})))
@slawo-ch
slawo-ch / LexerTest.java
Created September 7, 2017 17:08
Test for lexing script with and without globals
import org.jcodings.Encoding;
import org.jruby.Ruby;
import org.jruby.common.NullWarnings;
import org.jruby.lexer.ByteListLexerSource;
import org.jruby.lexer.LexerSource;
import org.jruby.lexer.LexingCommon;
import org.jruby.lexer.yacc.RubyLexer;
import org.jruby.parser.ParserConfiguration;
import org.jruby.parser.ParserSupport;
import org.jruby.parser.RubyParserResult;
@slawo-ch
slawo-ch / split.awk
Last active April 6, 2024 16:41
split mysql dump to csv's
BEGIN {
# file starts with DDL statements that go into header.sql
table = "header";
sql = 1
}
{
# -- step 1 --
# determine whether current line contains a DDL sql statement or
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
while (($key, $value) = each(%transformFiles)) {
open my $dataFile, $key or die "Can't open '$key': $!";
open my $transformFile, '>', $value or die "Can't open '$value': $!";
my $line=<$dataFile>;
chomp($line);
$line =~ s/\r*//g;
print $transformFile $line, "\t", "Adjusted M1", "\n";
DROP TABLE IF EXISTS saas_response_final;
CREATE TABLE saas_response_final AS
SELECT ge.accountId
, ge.addressLine2
, ge.city
, ge.state
, ge.zip
, ge.description
, srje.status
, COALESCE(srje.letterGrade, '---')
@slawo-ch
slawo-ch / randomuser.json
Created October 28, 2019 20:41
randomuser.json
{
"results": [
{
"gender": "male",
"name": {
"title": "mr",
"first": "brad",
"last": "gibson"
},
"location": {
@slawo-ch
slawo-ch / randomusers_optimized.json
Created October 28, 2019 21:40
Query response after tweaking the query
{
"results": [
{
"gender": "female",
"name": {
"title": "Ms",
"first": "Friedhilde",
"last": "Meißner"
},
"location": {
DROP TABLE IF EXISTS location;
CREATE TABLE location (
location_id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
country TEXT,
state TEXT,
city TEXT
);
CREATE INDEX location_lookup ON location
Creation_Time,Sensor_Time,Arrival_Time,x,y,z
1560991054000,1560991,1398347034631,0.079008654,0.12210429,9.419987
1561001064000,1561001,1398347034642,0.088585466,0.12330139,9.416395
1561011043000,1561011,1398347034651,0.092176765,0.10534488,9.417592
...