Skip to content

Instantly share code, notes, and snippets.

@mustafaakin
mustafaakin / SQLTester.java
Last active March 19, 2022 16:32
Flink Streaming SQL Example
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.api.java.tuple.Tuple3;
import org.apache.flink.streaming.api.TimeCharacteristic;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.timestamps.AscendingTimestampExtractor;
import org.apache.flink.table.api.Table;
import org.apache.flink.table.api.TableEnvironment;
import org.apache.flink.table.api.java.StreamTableEnvironment;
import org.apache.flink.types.Row;
@jlafourc
jlafourc / consume-bom.gradle
Last active August 16, 2019 08:09
Gradle scripts to generate a BOM and then consume that BOM
plugins {
id "io.spring.dependency-management" version "1.0.0.RC2"
}
project.group = com.company
project.version = 1.0.0
project.ext.name = company-project
dependencyManagement {
imports {
@alexpchin
alexpchin / socket-cheatsheet.js
Created December 15, 2015 16:58
A quick cheatsheet for socket.io
// sending to sender-client only
socket.emit('message', "this is a test");
// sending to all clients, include sender
io.emit('message', "this is a test");
// sending to all clients except sender
socket.broadcast.emit('message', "this is a test");
// sending to all clients in 'game' room(channel) except sender
@r0yfire
r0yfire / README.md
Created October 12, 2015 23:09
Python script to convert mysqldump output to JSON file

mysqldump to JSON

Python script to convert mysqldump output to JSON file. Most of the code was borrowed from github.com/jamesmishra/mysqldump-to-csv

You'll want to update the 'parse_row' function to map each item in a row to a dictionary.

Running the script

@nolanlawson
nolanlawson / protips.js
Last active August 22, 2024 14:19
Promise protips - stuff I wish I had known when I started with Promises
// Promise.all is good for executing many promises at once
Promise.all([
promise1,
promise2
]);
// Promise.resolve is good for wrapping synchronous code
Promise.resolve().then(function () {
if (somethingIsNotRight()) {
throw new Error("I will be rejected asynchronously!");
// 其实这题可以写的很简单,它的关键根本不是CAS操作。
// 使用一个标志(flag也好,status判断也罢)来避免Start和Dispose重入是很容易
// 想到的手段,很多同学也这么做了。大部分同学遇到的问题是:假如StartCore已经
// 启动,那么如何让Dispose方法等待其完成。有些同学用while (true),有些同学用
// 锁,但都避免不了让Dispose线程等待Start线程。
// 这里“避免等待”的关键在于要跳出思维界限:谁说DisposeCore方法一定要在Dispose
// 方法里执行的?我们就不能在Start里销毁对象吗?
@apurvam
apurvam / graphdb-simulator.cpp
Last active December 16, 2020 19:55
A program which simulates the read and write behavior of LinkedIn's GraphDB
/* Instructions on compilation and execution
* =========================================
*
* Compile this program with pthreads:
*
* g++ -Wall -lpthread -o graphdb-simulator graphdb-simulator.cpp
*
* Before you run this program, you need to create the following
* directories:
*
@breznik
breznik / MyServerHandler.java
Created August 12, 2013 22:13
Example code that works when the HttpPostRequestDecoder's setDiscardThreshold(0) method is called, but fails otherwise.
package net.reznik.gist;
import static io.netty.buffer.Unpooled.copiedBuffer;
import static io.netty.handler.codec.http.HttpHeaders.isKeepAlive;
import static io.netty.handler.codec.http.HttpHeaders.Names.CONTENT_TYPE;
import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST;
import static io.netty.handler.codec.http.HttpResponseStatus.OK;
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufOutputStream;
@fsword
fsword / multi_try.erl
Last active December 10, 2015 02:28 — forked from anonymous/multi_try.erl
-module(multi_try).
-export([dothese/1]).
dothese(FuncArray) ->
Me = self(),
lists:foreach(fun(F) -> spawn(fun() -> F(Me) end) end, FuncArray),
spawn(fun() -> timer:sleep(200), Me ! timeout end),
Result = get_result("",length(FuncArray)),
io:format("result: ~p~n", [Result]).
anonymous
anonymous / multi_try.erl
Created December 24, 2012 03:18
实现一个API,API内部有两个http接口A,B并发调用,如果都在200ms内返回,则合并结果输出,如果B比A慢,且B耗时超过200ms,则丢弃B调用只返回A结果
-module(multi_try).
-export([dothese/1]).
dothese(FuncArray) ->
Me = self(),
lists:foreach(fun(F) -> spawn(fun() -> F(Me) end) end, FuncArray),
spawn(fun() -> timer:sleep(1000), Me ! timeout end),
Result = get_result("",length(FuncArray)),
io:format("result: ~p~n", [Result]).