Skip to content

Instantly share code, notes, and snippets.

View DylanCh's full-sized avatar

H Chen DylanCh

View GitHub Profile
@DylanCh
DylanCh / FakeLocalStorage.js
Created August 11, 2017 18:34
Node.JS localStorage
var localStorage = require('localStorage');
localStorage.setItem('Apple',
`{
"Products" : [
{ "name": "iPhone"},
{ "name": "iPad"},
{ "name": "MacBook Pro"}
]
}`);
'use strict';
var rowHandler = ()=>{
var table = document.getElementById("table1");
var rows = table.getElementsByTagName("tr");
for (i = 0; i < rows.length; i++) {
var curRow = table.rows[i];
var onclikHandler = (row)=>{
return ()=>{
var cell = row.getElementsByTagName("td")[3];
var color = cell.innerHTML;
var axios = require('axios');
var url = "<THE LINK TO THE ENDPOINT OF API THAT HOSTS THE ABOVE DATA>";
// the HTML markup that begins with headers,
//references to CSS and Javascript libraries, etc
var html = '<html><head>'
/* Add references here (I am using Bootstrap and jQuery)*/
+'</head><body class="container">'
+'<div class="row">'
+'<table class="table">'
class Product {
public string name { get; set; }
public string category { get; set; }
}
// Route: /[Controller name]/Apple
public ContentResult Apple() {
var response = getResponse(); // get the deserilized object(or a list of objects)
StringBuilder html = new StringBuilder("<html><head>"
+ " <link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css\" >"
+ "</head><body class=\"container\">"
private AppleInc getResponse() {
string json = "";
/* Get HTTP response as JSON string (see explanation below)*/
// Transform JSON into a C# object
var apple = JsonConvert.DeserializeObject<AppleInc>(json);
<!-- Headers, etc above -->
<div class="row">
<table class="table">
<thead>
<tr>
<th>name</th>
<th>category</th>
</tr>
</thead>
var arr = [];
for (var i = 0; i<90000; i++){
arr.push([i]);
}
var newArr =[];
var startTime = new Date().getTime();
newArr = arr.reduce((previous,current)=>{
return previous.concat(current);
},[]);
console.log(new Date().getTime()-startTime);
var startTime = new Date().getTime();
arr.forEach((e)=>{
e.forEach((elem)=>{
newArr.push(elem);
});
});
console.log(new Date().getTime()-startTime);