Skip to content

Instantly share code, notes, and snippets.

View LucienLee's full-sized avatar
🦌

Lucien Lee LucienLee

🦌
View GitHub Profile
@LucienLee
LucienLee / longest-bi-value-seq.js
Created July 17, 2019 11:23
find longest bi-value sequence
function solution(A) {
let mark = new Set();
let curLength = 0;
let consecutiveSeq = 1;
let allSeqLength = [];
for(let i = 0; i < A.length; i++) {
let num = A[i];
if (!mark.has(num) && mark.size < 2) {
curLength++;
@LucienLee
LucienLee / anomalies.js
Last active August 6, 2021 07:14
JavaScript Anomalies
/* Closure */
const buttons = document.getElementsByClassName('three-buttons');
for (var i = 0; i < 3; i++) {
buttons[i].addEventListener(function(){
console.log(i)
});
}
// Click 1st button -> 2
// Click 2nd button -> 2
// Click 3rd button -> 2

Definitely, CSS Grids is most expected feature in production enviroment. The reason behind that is Grids free us from one way flow layout to two dimensions layout, which enable more creative and possibility on web design. In the pass, we layouted element in normal flow and exploited float and absolute positioning to get more complex layout. That limited us think layout as flow stream, which is from left to right, top to bottom. To make complex layout, we had to used absolute positioning and calculate the position in js.

Grids change that in more elegant way, like table layout but more responsive, flexible and semantic. We could think layout as a two dimensions cells grid(table) and align elements by specifying the cells, which is more intuition and clear. The best part is that cell size is responsive. For exmaple, minmax() could assign mininum and maximum of grid size and fr unit provide the way to assign partitions of each grid cells.

Moreover, grid-gap provide elegant way to set gutt

@LucienLee
LucienLee / parser.js
Created March 15, 2017 15:02
JsonParser
function JsonParser() {}
JsonParser.prototype.parse = function(inputStr) {
let trimmed = inputStr.replace(/ /g, '')
if (isArray(trimmed)) {
return parseArray(trimmed)
} else if (isObject(trimmed)) {
return parseObj(trimmed)
}
}
// Open Script Editor and Export this as an Application
//
// Then drop a keynote file on it in the Finder and it will properly resize
// and rotate everything so the Keynote file becomes usable as a prototype
// in the iPhone keynote app
// rotateDocument exported function
//
// Accepts a Keynote document and will rotate
// all the slides and elements in the slide 90 degrees
using UnityEngine;
using System.Collections;
public class ThirdPersonController : MonoBehaviour {
public GameObject player;
public GameObject mainCamera;
public GameObject cameraCollisionBox;
public CollisionCounter probe;
public CollisionCounter cameraProbe;
using UnityEngine;
using System.Collections;
public class ThirdPersonController : MonoBehaviour {
public GameObject player;
public GameObject mainCamera;
public GameObject cameraCollisionBox;
public CollisionCounter cameraProbe;
public CollisionCounter probe;
using UnityEngine;
using System.Collections;
public class ThirdPersonController : MonoBehaviour {
public GameObject player;
public GameObject mainCamera;
public GameObject cameraCollisionBox;
public CollisionCounter cameraProbe;
@LucienLee
LucienLee / gist:058964d07f081080dc33
Last active August 29, 2015 14:08
list example
var $list = $('ul');
// make an <li> element
var makeItem = function(text){
var $li = $('<li><input type="text"><span></span></li>');
if(text){
$li.find('input').val(text);
$li.find('span').text(text);
}
return $li;
@LucienLee
LucienLee / joystick
Last active December 17, 2019 14:26
Sanwa joystick on Arduino example code
//A0 = green, A1 = yellow, A2 = orange, A3 = red
#define downPin 14
#define upPin 15
#define rightPin 16
#define leftPin 17
void setup() {
Serial.begin(9600);