Skip to content

Instantly share code, notes, and snippets.

@honwhy
honwhy / gist:d7aecec03c3e22012f64
Last active August 29, 2015 14:05
use regular expression in sed command
#!/bin/bash
# 在Linux终端使用sed命令,使用正则表达式时+没有被当作元字符
# 1. 使用如下命令
sed -i '/^[0-9]+/d' some.txt
cat some.txt
# 并不能够将数字开头的行删除
# 2. 使用如下命令
sed -i '/^[0-9]\+/d' some.txt
@honwhy
honwhy / gist:af426d38ae34c6da2a14
Created August 11, 2014 14:18
善用history历史记录
在终端输入的命令被记录在history中
只是输入history就可以看到从前的命令
如果要再次执行从前的命令,只要 !1725
!linenumber 即可
@honwhy
honwhy / delete empty files
Created August 14, 2014 14:51
批量删除文件大小为0的文件
honwhy@eos:images$ find . -size 0
./18342-106vq6i
./16601-1bgsvrc
./16601-v389qr
./16601-1lsd6ei
./21398-haoave
./18342-zwtoqd
./18342-1404c4x
./20513-1b0wtmo
./18342-14g3r6i
@honwhy
honwhy / gist:fa372b5b136e893b390e
Created August 20, 2014 03:27
删除文件289行开始都结尾的内容
sed -i '289,$d' filename
@honwhy
honwhy / server.js
Created May 26, 2016 14:31
ajax 302 code
var http = require('http');
http.createServer(function(req, res) {
if(req.url == '/') {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(makeHtml());
} else if(req.url == '/ajax302'){
res.writeHead(302, {
'Content-Type': 'text/html',
//'Location': 'http://localhost:9000/forward' // alert 200
'Location': 'https://github.com/join' // alert 0
@honwhy
honwhy / gist:23e6be984e0117196e59eb458e6ac6ba
Created November 18, 2018 11:02
dump_java_process.sh
# dump script from http://dubbo.apache.org/zh-cn/docs/dev/principals/dummy.html
JAVA_HOME=/usr/java
OUTPUT_HOME=~/output
DEPLOY_HOME=`dirname $0`
HOST_NAME=`hostname`
DUMP_PIDS=`ps --no-heading -C java -f --width 1000 | grep "$DEPLOY_HOME" |awk '{print $2}'`
if [ -z "$DUMP_PIDS" ]; then
echo "The server $HOST_NAME is not started!"
@honwhy
honwhy / MultiThreadHashMap.java
Created March 17, 2019 08:48
MultiThreadHashMap
public class MultiThreadHashMap {
private static final Object PRESENT = new Object();
public static void main(String[] args) throws InterruptedException, BrokenBarrierException {
final Map<String,Object> map = new HashMap<>(); //let map do resize multiple times
int N = 1000;
final CyclicBarrier cyclicBarrier = new CyclicBarrier(N+1);
for (int i = 0; i < N; i++) {
new Thread(new Runnable() {
@Override
public void run() {
@honwhy
honwhy / AesDemo.java
Created October 18, 2019 17:08
aes cbc demo
package com.honey;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Random;
public class AesDemo {
@honwhy
honwhy / ConsumerQueueDemo.java
Created October 20, 2019 10:45
ConcurrentLinkedQueue vs BlockingQueue
package com.honey;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.*;
public class ConsumerQueueDemo {
public static void main(String[] args) {
//making hot spot code
@honwhy
honwhy / TcpTimeClient.java
Created December 17, 2019 15:54
selector in client side(sorry forget the link from stackoverflow)
package com.honey;
import java.io.File;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.SocketChannel;
import java.util.ArrayList;