Skip to content

Instantly share code, notes, and snippets.

View yangli-io's full-sized avatar
😆
Having a great time

Yang Li yangli-io

😆
Having a great time
View GitHub Profile
import { createContext, useContext, FC, ReactNode, useState } from 'react'
interface State {
loading: boolean,
currentRound: number,
}
interface IContext {
state: State,
setState: React.Dispatch<React.SetStateAction<State>>
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import './button.scss';
export default class Something extends Component {
let lastData;
render() {
const { price } = this.props;
const lastPrice = lastData;
it('should render a random id everytime', () => {
const lastId = component.find('input').prop('id');
const secondComponent = shallow(<Input />);
expect(secondComponent.find('input').prop('id')).to.equal(lastId);
});
it('should link the id between label and input', () => {
const labelHtmlFor = component.find('label').prop('htmlFor');
const inputId = component.find('input').prop('id');
expect(labelHtmlFor).to.equal(inputId);
{"data":{"banks":[{"value":801041,"label":"ABN AMRO BANK N.V. HONG KONG"},{"value":18810,"label":"AMERICAN EXPRESS BANK LTD."},{"value":840652,"label":"AUSTRALIA AND NEW ZEALAND BANK"},{"value":87261,"label":"BANK OF CHINA"},{"value":107352,"label":"BANK OF CHINA (HONG KONG) LTD"},{"value":542972,"label":"BANK OF COMMUNICATIONS"},{"value":888083,"label":"BANK OF COMMUNICATIONS CO LTD"},{"value":679566,"label":"BSI LTD HONG KONG BRANCH"},{"value":681878,"label":"CHINA CITIC BANK INTERNATIONAL"},{"value":208627,"label":"CHINA CONSTRUCTION BANK (ASIA)"},{"value":93775,"label":"CHIYU BANKING CORPORATION LTD"},{"value":336843,"label":"CHONG HING BANK LIMITED"},{"value":617031,"label":"CITIBANK (HONG KONG) LIMITED"},{"value":507117,"label":"CITIC BANK INTERNATIONAL LIMIT"},{"value":26740,"label":"CITIC KA WAH BANK LIMITED"},{"value":747741,"label":"CREDIT SUISSE AG, HONG KONG BR"},{"value":27574,"label":"DAH SING BANK LIMITED"},{"value":343439,"label":"DBS BANK (HK) LTD"},{"value":94288,"label":"DBS BANK (HONG KONG
@yangli-io
yangli-io / app.js
Created November 18, 2015 09:42
Login page
$('#register').submit(function(event){
event.preventDefault();
var data = {
username: $('#username').val(),
password: $('#password').val(),
email: $('#email').val()
}
$.post('https://fewd20.herokuapp.com/register', data, function(data){
var url = 'https://fewd20.herokuapp.com/data';
var usedNames = [];
$('#send').click(function(){
$.get(url, function(data, status){
for (var i = 0; i < data.length; i++) {
if (usedNames.indexOf(data[i].name) === -1) {
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
var images = ['images/food1.jpg', 'images/food2.jpg', 'images/food3.jpg'];
var votes = [0, 0, 0]; //This is the average
var vote;
var imageNum = 0;
var average
$('#back').click(function(){
if (imageNum !== 0){
imageNum --;
angular.module('app', []).directive('ngDebounce', function($timeout) {
return {
restrict: 'A',
require: 'ngModel',
priority: 99,
link: function(scope, elm, attr, ngModelCtrl) {
if (attr.type === 'radio' || attr.type === 'checkbox') return;
elm.unbind('input');
@yangli-io
yangli-io / ng-debounce.js
Last active August 29, 2015 14:13 — forked from tommaitland/ng-debounce.js
Updated debounce to not debounce after a certain amount of characters.
angular.module('app', []).directive('ngDebounce', function($timeout) {
return {
restrict: 'A',
require: 'ngModel',
priority: 99,
link: function(scope, elm, attr, ngModelCtrl) {
var debounce;
var maxLength; //maximum length for debounce to take effect
if (attr.type === 'radio' || attr.type === 'checkbox') return;