Skip to content

Instantly share code, notes, and snippets.

View ThomsonTang's full-sized avatar

摩羯行僧 ThomsonTang

View GitHub Profile
@ThomsonTang
ThomsonTang / CompoundActionOnVector.java
Created August 11, 2017 05:52
Compound Actions on a Vector that may Produce Confusing Results.
package com.thomson.jcip.ch5.building;
import java.util.Vector;
/**
* 验证同步集合类存在的问题:在同步集合类上执行复合操作有可能出现问题
*
* comes from the chapter5 of JCIP
*
* 同步集合类本身是线程安全的,所以将对象的状态委托给这些同步集合类来管理,就能保证线程安全性。但是还存在一种例外,如果在同一个集合类上执行复合操作,那么就会产生一些不符合预期的问题。
@ThomsonTang
ThomsonTang / updateUrlParameter.groovy
Last active January 13, 2022 13:00
change the value of a specified query string in a url.
/**
* 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 January 13, 2017 09:56
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
package datastructure.stackqueue;
interface Stack {
void push(Object obj);
Object pop();
boolean isEmpty();
}
class ArrayStack implements Stack {
private Object[] theArray;