Skip to content

Instantly share code, notes, and snippets.

Avatar

摩羯行僧 ThomsonTang

View GitHub Profile
@ThomsonTang
ThomsonTang / CompoundActionOnVector.java
Created Aug 11, 2017
Compound Actions on a Vector that may Produce Confusing Results.
View CompoundActionOnVector.java
package com.thomson.jcip.ch5.building;
import java.util.Vector;
/**
* 验证同步集合类存在的问题:在同步集合类上执行复合操作有可能出现问题
*
* comes from the chapter5 of JCIP
*
* 同步集合类本身是线程安全的,所以将对象的状态委托给这些同步集合类来管理,就能保证线程安全性。但是还存在一种例外,如果在同一个集合类上执行复合操作,那么就会产生一些不符合预期的问题。
@ThomsonTang
ThomsonTang / updateUrlParameter.groovy
Last active Jan 17, 2017
change the value of a specified query string in a url.
View updateUrlParameter.groovy
/**
* change the value of a specified query string in a url.
*/
def updateUrlParameterValWithRegex(url, paraName, paraVal) {
assert url
def (path, paras) = url.tokenize('?')
println "the original url parameters:\n ${paras}"
def updatedUrl = paras.replaceFirst(/${paraName}=\w*/, "${paraName}=${paraVal}")
println "the updated url parameters:\n ${updatedUrl}"
"${path}${updatedUrl}"
@ThomsonTang
ThomsonTang / 0_reuse_code.js
Created Jan 13, 2017
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
View StackQueue.java
package datastructure.stackqueue;
interface Stack {
void push(Object obj);
Object pop();
boolean isEmpty();
}
class ArrayStack implements Stack {
private Object[] theArray;