Skip to content

Instantly share code, notes, and snippets.

View quangnd's full-sized avatar
💭
Obsidian hooker :")

Nguyen Dang Quang quangnd

💭
Obsidian hooker :")
View GitHub Profile
@quangnd
quangnd / leap-year-swift.md
Last active March 4, 2024 16:53
Swift Learning - Tutor 1 - Leap year

Exercise 1 - Leap year

You are given a year, determine if it’s a leap year. A leap year is a year containing an extra day. It has 366 daysinstead of the normal 365 days. The extra day is added in February, which has 29 days instead of the normal 28 days. Leap years occur every 4 years. 2012 was a leap year and 2016 will also be a leap year.

The above rule is valid except that every 100 years special rules apply. Years that are divisible by 100 are not leap years if they are not also divisible by 400. For example 1900 was not a leap year, but 2000 was. Print Leap year! or Not a leap year! depending on the case.

Hint: Use the remainder (%) operator to check for divisibility by 4. Don’t forget to check the special case when year is divisible by 100.

let year = 2014
@quangnd
quangnd / README.md
Created March 6, 2017 10:01 — forked from alber70g/README.md
Visual Studio Code (VS Code) shell script for use with Git Bash

VS Code Shell Shortcut for Git Bash

Put this file code in C:\Users\<username>\AppData\Local\Code\bin aside code.cmd.

Assuming this path is already in your %PATH% you can now run the command to open a file

code file.txt
@quangnd
quangnd / states_hash.json
Created December 14, 2016 11:40 — forked from mshafrir/states_hash.json
US states in JSON form
{
"AL": "Alabama",
"AK": "Alaska",
"AS": "American Samoa",
"AZ": "Arizona",
"AR": "Arkansas",
"CA": "California",
"CO": "Colorado",
"CT": "Connecticut",
"DE": "Delaware",
@quangnd
quangnd / fixCommands.md
Last active November 25, 2016 16:31
Fix home brew update error!!!

Error: /usr/local must be writable! on MacOS Sierra

Solution

sudo chgrp -R admin /usr/local
sudo chmod -R g+w /usr/local

@quangnd
quangnd / arrayUtilities.js
Created November 15, 2016 06:53
Array & utility functions
// Flat 2D array to 1D arry
var arr=[[1,2],[3,4],[5,6]];
var result=[].concat(...arr);
console.log(result); //output: [ 1, 2, 3, 4, 5, 6 ]
// ------------------------
// Produce a specified number of repeating characters:
function repeat(s,n){
return [...Array(n+1)].join(s);
@quangnd
quangnd / reduceExamples.js
Last active November 24, 2023 19:57
Some examples about reduce() in Javascript
//Example 1 - Calculate average value of an array (transform array into a single number)
var scores = [89, 76, 47, 95]
var initialValue = 0
var reducer = function (accumulator, item) {
return accumulator + item
}
var total = scores.reduce(reducer, initialValue)
var average = total / scores.length
/*Explain about function
import React from "react";
import { render } from "react-dom";
const ParentComponent = React.createClass({
getDefaultProps: function() {
console.log("ParentComponent - getDefaultProps");
},
getInitialState: function() {
console.log("ParentComponent - getInitialState");
return { text: "" };
@quangnd
quangnd / radioGroup.js
Created November 8, 2016 07:27
Send Props to Children in React
//Original link: http://jaketrent.com/post/send-props-to-children-react/
function RadioOption(props) {
return (
<label>
<input type="radio" value={props.value} name={props.name} />
{props.label}
</label>
)
}
@quangnd
quangnd / JS Learning: Arrays - Water flow
Last active June 4, 2022 19:27
JS Learning: Arrays - Water flow
/*
Coding in function infiniteLoop. function accept 3 parameters. The 1st parameter is arr, it's a 2D array, it contains three 1D array. The 2nd parameter is d ,it's a string. The 3rd parameter is n, it's a number.
You can think of arr as a moat, the elements of arr like water constantly flow in. The direction of flow is controlled by the parameter d. The value of d can be "left" or "right". "left" means the "river" moves to the left. All elements in the 1D array are to the left moving n position, if beyond the bounds of the array and the element is moved to the tail on the left side of the array; if it exceeds the left boundary element would be moved to the tail of 3rd array(like a circle). Right is also similar to the operation, but it is moving to the right.
Finally, return arr.
Example:
infiniteLoop( [[1,2,3],[4,5,6],[7,8,9]],"left",1)
should return [[2,3,4],[5,6,7],[8,9,1]]
@quangnd
quangnd / ReactBindingApproaches.js
Created August 30, 2016 08:06 — forked from coryhouse/ReactBindingApproaches.js
React Binding Approaches
// Approach 1: Use React.createClass
var HelloWorld = React.createClass({
getInitialState() {
return { message: 'Hi' };
},
logMessage() {
// this magically works because React.createClass autobinds.
console.log(this.state.message);
},