Chao Yang

Nothing seek, nothing find


  • Home

  • Minibooks

  • Projects

  • Résumé

  • Archive

  • About

  • Search
close

CORS revisit

Published at: 2018-03-24   |   Categories: Web     |   Reading: 138 words ~1min
Origin The issue stems from the same-origin policy which forces the browsers to restrict the resource access of a different origin (e.g. different domain) when: - AJAX request - Web Fonts (for cross-domain font usage in @font-face within CSS) - Images/video frames drawn to a canvas using drawImage. - Stylesheets (for CSSOM access). - others CORS is a technique for relaxing the same-origin policy and similar techniques include JSONP, or server-side proxy which were used in the past.
Read More »

Notes - CSS in Depth

Published at: 2018-03-06   |   Categories: CSS     |   Reading: 1322 words ~7min
Nearly every web programmer I met says: I know CSS, even someone told me “CSS is simple”. So they naturally write CSS in their skill set of CV. But wait, just writing several lines of CSS statements does not necessarily mean you are a qualified CSS user. This is the reason why I plan to learn CSS in depth. What I expect is to get a solid knowledge about how to write large scale CSS and understand why it works when layouting or styling.
Read More »

Javascript testing frameworks

Published at: 2017-11-27   |   Categories: Javascript     |   Reading: 249 words ~2min
I wrote front-end testing code less frequently. I heard a lot of frameworks used by my colleagues, like Karma, Jasmine, Chai, Mocha, Jest. you name it. Why so much complex? In the Java ecosystem, we have JUnit for the test runner, it provides test suites and all kinds of assert expressions. If we need to mock some dependencies, we use Mokito or others like. That’s enough. So when it comes to Javascript, I am really confused with so many frameworks/libraries.
Read More »

Build OpenCV 3.3 Android SDK on Mac OSX

Published at: 2017-11-03   |   Categories: IoT     |   Reading: 125 words ~1min
By default, the official OpenCV Android SDK doesn’t contain the contrib libraries, like Aruco. prerequisite NDK r10e https://dl.google.com/android/repository/android-ndk-r10e-darwin-x86_64.zip Android SDK Note: please degrade the Android SDK tools version, 25.2.4 is fine for me http://dl-ssl.google.com/android/repository/tools_r25.2.5-macosx.zip Go to ~/Library/Android/sdk, rename tools to tools.bak, then unzip the tools_rxxx.zip to sdk/tools directory. Why? because otherwise, android command has been deprecated) opencv 3.3.1 git clone https://github.com/opencv/opencv.git opencv_contrib git clone https://github.
Read More »

A developer learns design

Published at: 2017-06-29   |   Categories: Design     |   Reading: 224 words ~2min
I do not forget the time when I crafted a Flash animation in my university and I also had a dream to design a 3D game on my own. So now I have some time to realize my dream and start a learning plan. I bought Affinity Photo and Affinity Designer which are great applications and I am pretty obsessed with these two. I also learn how to program with Unity and 3D model with Maya.
Read More »

Kotlin Pitfalls

Published at: 2017-05-27   |   Categories: Tutorial     |   Reading: 363 words ~2min
Type system val list: List<String> = java.util.ArrayList() Why does it work? java.util.ArrayList is not a subclass of kotlin.List, and kotlin.List is actually read-only. Because in bytecode level, kotlin.List is just java.util.List! I decompile the class Kotlin compiled: import java.util.ArrayList; import java.util.List; import kotlin.Metadata; @Metadata(mv={1, 1, 6}, bv={1, 0, 1}, k=2, d1={"\000\b\n\000\n\002\020\002\n\000\032\006\020\000\032\0020\001��\006\002"}, d2={"a", "", "kotlin_demo"}) public final class _1Kt { public static final void a() { List list = (List)new ArrayList(); } } You can think as if java.
Read More »

pseudo-random number & shuffle

Published at: 2017-04-26   |   Reading: 282 words ~2min
Pseudo random number Given a seed, and you will always get the next number, which is predictable. So that is reason why it is called pseudo random. A simple algorithm is Linear congruential generator. next random = (a * random + c) mod 2^32 The initial random is seed. Java implementation In next(bits) method: nextseed = (oldseed * multiplier + addend) & mask; here, multiplier is 0x5DEECE66DL, addend is 0xBL, mask is (1L << 48) - 1.
Read More »

Swift 3.0 for a Java or ES6/TypeScript developer

Published at: 2017-01-19   |   Reading: 801 words ~4min
Basic Operators Assignment Operator let b = 10 // constant var a = 5 // variable a = b let is not the same as that in ES6. It is more or like final in Java. It means the variable (value or reference) cannot be changed once initialization. But let in Swift has stronger semantics, which enable immutability or constant. It means not only the reference cannot be mutable but also the object it refers cannot be mutable.
Read More »

ElementRef vs. ViewContainerRef vs. TemplateRef

Published at: 2016-12-27   |   Reading: 407 words ~2min
In Angular2, there are many *Ref class: ElementRef, ViewContainerRef, TemplateRef. What do they means? Nearly every components (Components, Attribute Directives, Structural Directives) have ViewContainerRef, which is the host of its view. ViewContainerRef has two important methods: createEmbeddedView(templateRef: TemplateRef<C>, context?: C, index?: number) : EmbeddedViewRef<C> This method is to create a view from a HTML template. createComponent(componentFactory: ComponentFactory<C>, index?: number, injector?: Injector, projectableNodes?: any[][]) : ComponentRef<C> This method is to initialize a component and insert its host view to the view container.
Read More »

ThreadLocal

Published at: 2016-09-05   |   Reading: 978 words ~5min
how to use? Basically, ThreadLocal is used for these scenarios: whenever you set a value/reference within this thread, you can get it from this thread. But it cannot guarantee you can ONLY get it from this thread. When wrongly used, it may cause something counter-intuitive. For example, when you set a value/reference to a ThreadLocal, you also share it with other threads (say other threads can access the reference and mutable it.
Read More »

Dive into JMM

Published at: 2016-09-05   |   Reading: 54 words ~1min
JMM is an advanced and abstract topic in Java. It provides well-defined semantics for synchronization and help us reason the code execution in a multi-thread enviorionment. Keywords: main memory, local memory, reordering, visibility, memory barrier/fence What do the issues come from? References The JSR-133 Cookbook for Compiler Writers Memory Barriers and JVM Concurrency //TODO

Double Checked Locking in lazy-initialization Singleton

Published at: 2016-09-02   |   Reading: 851 words ~4min
double-checked locking idiom (aka. DCL) broken versions Here we follow the evolution process of how to create a lazy-initialization singleton. // naive version public class Singleton { private static Singleton DEFAULT; public static Singleton getDefault() { if(DEFAULT == null) { DEFAULT = new Singleton(); } return DEFAULT; } private Singleton() {} // other instance methods } Race condition: - when thread 1 has executed if(DEFAULT == null) and then is preempted by thread 2.
Read More »

thread interrupt and cancelable mechanism

Published at: 2016-08-23   |   Reading: 247 words ~2min
To begin with, I issue some questions: - what does Thread#interrupt() do? - what is the difference between Thread#isInterrupted() and Thread.interrupted? - do I have to respond to interruption event? - when an InterruptedException is thrown? - how should I handle the caught InterruptedException? - how do I implement a cancelable mechanism for my task by polling interruption event? - apart from wait(), sleep(), join(), are there other scenarios throwing InterruptedException?
Read More »

Java array has length field?

Published at: 2016-08-22   |   Reading: 814 words ~4min
Today, a coworker asked me in which part of object header the length of an array object is stored. Since in my impression, the object header is of two machine words. But a book said for array, there must be length information stored in the object header. But where? array is special There is no “class definition” of an array (you can’t find it in any .class file), they’re a part of the language itself.
Read More »

String intern

Published at: 2016-08-22   |   Reading: 1482 words ~7min
Several simple code snippets // Sample1 char[] chars = {'h', 'e', 'l', 'l', 'o'}; String str1 = new String(chars); System.out.println(str1 == str1.intern()); print: true // Sample2 String str1 = new String("hello"); System.out.println(str1 == str1.intern()); print: false // Sample3 String a = "hello"; String b = new String("hello"); String c = new String("h" + "e" + "l" + "l" + "o"); String d = b.intern(); How many String objects is created?
Read More »

How JVM handle method invocation

Published at: 2016-08-22   |   Reading: 1251 words ~6min
Introduction Five forms of method invocation in Java: - invokevirtual - invokeinterface - invokestatic - invokespecial - invokedynamic invokestatic and invokevirtual Of these, invokestatic and invokevirtual are easy to understand. invokevirtual is the default behaviour when we invoke an instance method. invokestatic is used to invoke the class method based on the type of the reference, not the class of the object when we invoke the static method through the instance rather than the class name.
Read More »

Dynamic Proxy revisit

Published at: 2016-08-15   |   Reading: 16483 words ~78min
Dynamic Proxy in JDK Proxy is a class which can get the proxy class and create the proxy instance. It has a private default constructor and a protected constructor with a contractor argument: InvocationHandler. InvocationHandler is an interface which we can apply our code into the generated proxy class. It has only one method: Object invoke(Object proxy, Method method, Object[] args) Proxy has four static methods: static Class<?> getProxyClass(ClassLoader loader, Class<?
Read More »

DbVisualizer Tips

Published at: 2016-04-21   |   Reading: 114 words ~1min
DbVisualizer Tips How do we execute stored procedure? use @call stored_procedure_name; Parameterize SQL with variables Write your SQL as select * from table1 where a = ${param}$ Execute it and the “Enter data for variables” window will pop up. Parameterize SQL with markers Write your SQL as select * from table1 where a = :marker Execute it and the “Enter data for markers” window will pop up.
Read More »

Understand when to rollback

Published at: 2016-03-04   |   Reading: 751 words ~4min
Prepare At first, I create a table: CREATE TABLE "SYSTEM"."TEST" ( "ID" NUMBER(*,0), "NAME" VARCHAR2(200 BYTE), CONSTRAINT "TEST_PK" PRIMARY KEY ("ID") ); Then, create a stored procedure: CREATE PROCEDURE sp_insert (x NUMBER) IS BEGIN -- Do some inserts here. INSERT INTO test VALUES (x, 'insert by stored procedure'); -- Sometimes there might be an error. IF x = 2 THEN RAISE_APPLICATION_ERROR(-20000, 'Wooops...'); END IF; EXCEPTION WHEN OTHERS THEN --Rollback all the changes and then raise the error again.
Read More »

Oracle Statement-Level ROLLBACK

Published at: 2016-03-01   |   Reading: 474 words ~3min
Oracle Statement-Level ROLLBACK (undo of a transaction) Purpose Use the ROLLBACK statement to undo work done in the current transaction or to manually undo the work done by an in-doubt distributed transaction. Articles Related Oracle Database - Deadlock Oracle Database - Distributed Transactions Oracle Database - Locks Oracle Database - Row Locks (TX) Oracle Database - TableSpace Oracle Database - Transactions Oracle Database - UNDO (Rollback Segment) PL/SQL - Autonomous Transactions (Pragma)
Read More »
1 2 3 4 5 6 7
Chao

Chao

Programmer & Life explorer

138 Blogs
49 Categories
20 Tags
RSS
GitHub Linkedin
© 2009 - 2018 Chao Yang
Powered by - Hugo v0.30.2
Theme by - NexT