Skip to content

Instantly share code, notes, and snippets.

View chaoyangnz's full-sized avatar
🏠
Working from home

Chao Y chaoyangnz

🏠
Working from home
View GitHub Profile
import java.util.HashMap;
import java.util.Map;
/**
* Can be used in shorten url.
* Store urls in DB and get an id, then encode this id to a [a-zA-Z0-9] string
*/
public class Base62 {
Map<Character, Integer> char2int = new HashMap<>();
Map<Integer, Character> int2char = new HashMap<>();
@chaoyangnz
chaoyangnz / toolbox.xml
Created November 22, 2017 20:57 — forked from davidferguson/toolbox.xml
Blockly Deafult Blocks Toolbox
<xml id="toolbox" style="display: none">
<category name="{catLogic}" colour="210">
<block type="controls_if"></block>
<block type="logic_compare"></block>
<block type="logic_operation"></block>
<block type="logic_negate"></block>
<block type="logic_boolean"></block>
<block type="logic_null"></block>
<block type="logic_ternary"></block>
</category>
@chaoyangnz
chaoyangnz / gist:8920ec7c3900ee43120450327f9a8584
Created November 18, 2017 22:06 — forked from pfrazee/gist:8949363
In-Application Sandboxing with Web Workers

In-Application Sandboxing with Web Workers

A design rationale.

For the past fews years, the Web has been shifting control to the client. Given the limitations of remote services, developers are now looking for ways to "unhost" static applications – that is, break the dependency on remote servers while still using the Web platform.

One untapped technology for client-side control is the Web Worker Sandbox. This API lets the Page load, execute, and destroy separate Worker threads which use their own Virtual Machines. By using Worker Sandboxes to drive behavior, the Web can give users the choice of which software they run together, shifting development from a centralized SaaS model into a distributed and free (as in freedom) script-sharing model.

Worker Sandboxes can Execute Arbitrary Code

package life;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ForkJoinPool;
/**
* Example main program for running the sequential Game-of-Life.
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
/**
* Expression Calculator
*/
public class ExpressionCalculator {
public class ActivejdbcTransactionManager extends DataSourceTransactionManager {
@Override
protected Object doGetTransaction() throws TransactionException {
Object txObject = super.doGetTransaction();
Method getConnectionHolder = ReflectionUtils.findMethod(txObject.getClass(), "getConnectionHolder");
ConnectionHolder connectionHolder = (ConnectionHolder)ReflectionUtils.invokeMethod(getConnectionHolder, txObject);
Connection connection;
if(connectionHolder == null) {
try {
connection = this.getDataSource().getConnection();