Skip to content

Instantly share code, notes, and snippets.

View jamesyang124's full-sized avatar

James Yang jamesyang124

  • HTC
  • Richmond, California
View GitHub Profile
@jamesyang124
jamesyang124 / Jenkinsfile.groovy
Created August 8, 2017 12:05 — forked from Faheetah/Jenkinsfile.groovy
Jenkinsfile idiosynchrasies with escaping and quotes
node {
echo 'No quotes in single backticks'
sh 'echo $BUILD_NUMBER'
echo 'Double quotes are silently dropped'
sh 'echo "$BUILD_NUMBER"'
echo 'Even escaped with a single backslash they are dropped'
sh 'echo \"$BUILD_NUMBER\"'
echo 'Using two backslashes, the quotes are preserved'
sh 'echo \\"$BUILD_NUMBER\\"'
echo 'Using three backslashes still results in preserving the single quotes'
@jamesyang124
jamesyang124 / Base64.md
Created May 25, 2017 08:36 — forked from barrysteyn/Base64.md
OpenSSL Base64 En/Decode: Portable and binary safe.

OpenSSL Base64 Encoding: Binary Safe and Portable

Herewith is an example of encoding to and from base64 using OpenSSL's C library. Code presented here is both binary safe, and portable (i.e. it should work on any Posix compliant system e.g. FreeBSD and Linux).

License

The MIT License (MIT)

Copyright (c) 2013 Barry Steyn

@jamesyang124
jamesyang124 / c_compile_process.md
Last active May 6, 2017 18:11
Review of C Makefile and compile process.

Compile & Linking

  1. C compile source file then link object files and include libs to an executable prorgram.
  2. Linking phase is runned by ld.exe another program, or as.exe as assembly program.
  3. To compile and link a program as a shared library(.dll in windows, .so in Unixes), use -shared.
  4. By default compile will inlcude default dependencies, cpp -v to check the list.
g++ -Wall -g -o Hello.exe Hello.cpp
@jamesyang124
jamesyang124 / account-rails-app-dev-notes.md
Last active April 29, 2017 05:02
Pick rails 5.1.0 with React as progressive replacement of 4.2.8 with Backbone/Coffee.
@jamesyang124
jamesyang124 / what-forces-layout.md
Created April 8, 2017 16:39 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Element

Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()

Why typeclass?

Polymorphism and Decoupling.

Polymorphism

  1. Parametric

List of Int, list of Double, types are as type parameters in a context(List), not as types of direct values(without context) which infer the idea of ad-hoc polymorphism

@jamesyang124
jamesyang124 / scala_collection_guide.md
Last active February 15, 2023 11:21
Scala Collection Guide

Traversabel#flatten

If a type class extend or transform to GenTraversableOnce type, then it is flattenable. But you have to write your own GenTraversableOnce rule

import scala.language.implicitConversions
implicit def int2Traversable[T <: Any](n: T): Traversable[Any] = n match {
  case x: List[Any] => x
  case c => Traversable[T](c)
}
@jamesyang124
jamesyang124 / slick_3.2.0_inner_case_class_error.md
Last active March 15, 2017 07:36
slick-3.2.0 inner case class with final keyword

Slick 3.2.0 source code generator prepend final key word for Entity type case class generation, this leads the issue have not been resolved since years:

https://issues.scala-lang.org/browse/SI-4440

The workaround is to create custom source code generator then override that def caseClassFinal = true to false instead.

Related thread:

slick/slick#1665

@jamesyang124
jamesyang124 / main.go
Created March 10, 2017 10:59 — forked from sogko/main.go
[graphql-go] Mutation example with `graphql-go/handler`
package main
import (
"github.com/graphql-go/graphql"
"github.com/graphql-go/handler"
"net/http"
)
type Todo struct {
ID string `json:"id"`

Review of Effective Ruby

Item 2

All Objects Could Be nil

All objects are mutable by default. It can be nil, using nil?, is_a?, to_a, etc. to help the value validaiton for method input.

Item 3