Skip to content

Instantly share code, notes, and snippets.

View wghglory's full-sized avatar
🏀

Derek Wang wghglory

🏀
View GitHub Profile
@wghglory
wghglory / axios-catch-error.js
Created February 2, 2021 05:38 — forked from fgilio/axios-catch-error.js
Catch request errors with Axios
/*
* Handling Errors using async/await
* Has to be used inside an async function
*/
try {
const response = await axios.get('https://your.site/api/v1/bla/ble/bli');
// Success 🎉
console.log(response);
} catch (error) {
// Error 😨

Array with simple types like integer, string

/* push a new element */
const addCounter = (arr) => {
  // return arr.concat([0]); // old way
  return [...arr, 0]; // ES6 way
};
@wghglory
wghglory / StarRating.js
Created May 23, 2017 19:44
React Star Rating
/*
* usage: <StarRating totalStars={7} starsSelected={3} />
*/
import React from 'react';
import PropTypes from 'prop-types';
const Star = ({ selected = false, onClick = f => f }) =>
<div className={(selected) ? "star selected" : "star"}
onClick={onClick}>
@wghglory
wghglory / github-markdown.css
Last active May 17, 2017 20:55
vscode GFM preview. Use https://rawgit.com to convert gist url to usable url. Then paste it to settings.json
body {
-ms-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%;
line-height: 1.5;
color: #333;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
font-size: 16px;
line-height: 1.5;
word-wrap: break-word;
}
@wghglory
wghglory / gQuery.js
Created May 5, 2017 05:39
a jquery-like framework
//定义一个对象 - 名字是$$
var $$ = function () {};
$$.prototype = {
constructor: $$,
init: function () {
this.stringExtend();
this.MathExtend();
this.arrayExtend();
},
@wghglory
wghglory / index.html
Created April 29, 2017 06:16
modular, object literal, oop
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Create a New Pen</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
@wghglory
wghglory / pubsub.js
Created April 29, 2017 06:15
publish subscribe pattern
//events - a super-basic Javascript (publish subscribe) pattern
var events = {
events: {},
on: function(eventName, fn) {
this.events[eventName] = this.events[eventName] || [];
this.events[eventName].push(fn);
},
off: function(eventName, fn) {
if (this.events[eventName]) {
for (var i = 0; i < this.events[eventName].length; i++) {
@wghglory
wghglory / markdown-here.css
Created March 1, 2017 00:55
Primary style
/*
primary style
*/
.markdown-here-wrapper {
font-size: 16px;
}
pre, code {
font-size: 14px;
@wghglory
wghglory / PageCollection.cs
Created February 16, 2017 17:55
Pagination logic
using System.Collections.Generic;
namespace Common
{
/// <summary>
/// 分页逻辑处理类
/// </summary>
public class PageCollection
{
/// <summary>