Skip to content

Instantly share code, notes, and snippets.

View panlw's full-sized avatar
🎯
Focusing

Neo Pan panlw

🎯
Focusing
View GitHub Profile
// Rename files with a sequence number leading
ls |% { $i=0 }{ $i++; Rename-Item -NewName ('{0:2d}_{1}.png' -f $i,$_.basename) }
// List file name with size in MBs
ls |% { '{0,16} = {1} MB' -f $_.name, [math]::round($_.length/1mb) }
@panlw
panlw / ValueObjectBuilder.java
Last active January 21, 2020 14:31
Deserialize immutable lombok annotated objects with jackson
// https://www.baeldung.com/jackson-deserialize-immutable-objects
// https://stackoverflow.com/questions/49999492/immutable-lombok-annotated-class-with-jackson/50030088
@Builder(builderClassName = "ValueObjectBuilder")
@JsonDeserialize(builder = ValueObject.ValueObjectBuilder.class)
@Value
@EqualsAndHashCode(of = {...})
public class ValueObject {
@JsonPOJOBuilder(withPrefix = "")
@panlw
panlw / latency.txt
Created January 4, 2020 13:25 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
// Constructing
// We now have the completed internal state machine, but we have yet to expose either a method of resolving the promise or of observing it. Lets start by adding a way of resolving the promise.
var PENDING = 0;
var FULFILLED = 1;
var REJECTED = 2;
function Promise(fn) {
// store state which can be PENDING, FULFILLED or REJECTED
var state = PENDING;
@panlw
panlw / Int16sToFlt32sTest.java
Created July 16, 2019 07:28
16 位整型转 32 位浮点型
package cn.kinco.test;
import org.junit.Test;
import java.nio.ByteBuffer;
import java.util.Arrays;
/**
* @author neo.pan
* @since 2019-07-16
@panlw
panlw / README-Template.md
Created August 30, 2018 09:18 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@panlw
panlw / curl.md
Created July 5, 2018 03:19 — forked from subfuzion/curl.md
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@panlw
panlw / MongoUtil.java
Created June 8, 2018 03:19
Timestamp in ObjectId of MongoDB
public abstract class EdpMongoUtil {
/**
* @param objectId ObjectId of MongoDB
* @return time of java.time.Instant
*/
public static Instant timeFromObjectId(String objectId) {
return Instant.ofEpochMilli(Integer.parseInt(objectId.substring(0, 8), 16) * 1000);
}
@panlw
panlw / macosx-install-php-oracle-oci8.md
Created June 1, 2018 03:15 — forked from thinhhung/macosx-install-php-oracle-oci8.md
install Oracle PHP Extension (oracle OCI8) - instantclient for Mac OS 10.8 - homebrew environnement

Installation

This procedure is tested on Mac OS X 10.12.5 with Developpers tools installed (xCode).

PHP 7.1 installed with Homebrew.

Preparation

Download the following files from Oracle website (yes, you need to create an account and accept terms):

@panlw
panlw / dnsmasq OS X.md
Created May 27, 2018 16:16 — forked from ogrrd/dnsmasq OS X.md
Setup dnsmasq on OS X

Never touch your local /etc/hosts file in OS X again

To setup your computer to work with *.dev domains, e.g. project.dev, awesome.dev and so on, without having to add to your hosts file each time.

Requirements

Install