Skip to content

Instantly share code, notes, and snippets.

View onlyurei's full-sized avatar

Cheng Fan onlyurei

  • TikTok / ByteDance
  • San Francisco Bay Area, CA
View GitHub Profile
@onlyurei
onlyurei / cloudSettings
Last active August 19, 2021 01:45
Visual Studio Code Settings Sync Gist
{"lastUpload":"2021-08-19T01:45:43.216Z","extensionVersion":"v3.4.3"}
@onlyurei
onlyurei / gource.sh
Last active February 4, 2021 04:08 — forked from XueshiQiao/gource.sh
Generate a MP4 Video for your Git project commits using Gource!
# 1.install gource using HomeBrew
$ brew install gource
# 2.install avconv
git clone git://git.libav.org/libav.git
cd libav
# it will take 3-5 minutes to complie, be patient.
./configure --disable-yasm
make && make install
@onlyurei
onlyurei / .eslintrc.json
Created January 25, 2018 02:55
vue-prettier eslintrc example
{
"root": true,
"extends": [
"plugin:vue/recommended",
"groupon"
],
"plugins": [
"vue"
],
"parserOptions": {
<template>
<div v-if="length > 1" class="text-xs-center mt-5">
<v-pagination v-bind="{ length, totalVisible: totalVisibleResponsive, circle }"
v-model="page"/>
</div>
</template>
<script>
import { pagination, params } from '~/utils/mixins/pagination'
@onlyurei
onlyurei / nuxt-axios-cache.js
Created September 6, 2017 03:31 — forked from homerjam/nuxt-axios-cache.js
Simple plugin which decorates the community axios nuxt-module with an lru-cache
import hash from 'object-hash';
import sizeof from 'object-sizeof';
import lruCache from 'lru-cache';
const cacheEnabled = true;
const cacheMaxAge = 30 * 60 * 1000;
const cacheMaxSize = 128 * 1000 * 1000;
const getCacheKey = config => hash({
method: config.method,
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="cache-control" content="no-cache" />
<meta name="robots" content="noindex, nofollow" />
<title>Tire Size Calculator Help</title>
</head>
@onlyurei
onlyurei / add-students-validation.js
Created March 21, 2016 15:13
Relevant JS snippet for add students validation.
if (exports.addStudentsValidNames().length) {
exports.addStudentsCheckingUsernames(true);
$.post('/classroom/check', {
students: JSON.stringify(exports.addStudentsValidNames())
}, function (data) {
var hasErrors;
data.each(function (i) {
i.transfer = ko.observable(null);
i.errorFields = [];
i.warningFields = [];
@onlyurei
onlyurei / add-students.html
Created March 21, 2016 15:08
Demonstrating backend form validations.
<!-- ko ifnot: $parent.addStudentsModalEditingMode -->
<!-- ko ifnot: $parent.addStudentsShowExistingUsernameScreen -->
<h2 data-bind="string: 'confirm.new.students'" class="pull-left"></h2>
<div class="pull-right">
<button class="btn"
data-bind="string: 'add.students.validate.edits', click: function () { $parent.addStudentsValidateNames(true); },
enable: ($parent.addStudentsHasPotentialErrors() || $parent.addStudentsHasErrors()) && !$parent.addStudentsEditingFields() && !$parent.addStudentsCheckingUsernames()"></button>
<button class="btn"
data-bind="string: $parent.addStudentsDuplicateUsernames().length ? 'save.and.continue' : 'save.and.close', click: function () { $parent.addStudentsSaveAndClose(false); }, enable: $parent.addStudentsSaveAndCloseEnabled()"></button>
</div>
@onlyurei
onlyurei / knockout-custom-bindings-jquery-ui
Created April 19, 2015 05:43
Knockout Custom Bindings for jQuery UI Widgets (autocomplete, dragDrop, slider, sortable)
define(['Knockout.Raw', 'jQuery.UI', 'Sugar'], function (ko) {
ko.bindingHandlers.autocomplete = {
init: function (element, valueAccessor, allBindingsAccessor) {
var allBindings = allBindingsAccessor();
$(element).autocomplete(Object.merge({
select: function (event, ui) {
valueAccessor()(ui.item);
}
}, allBindings.autocompleteOptions));
@onlyurei
onlyurei / elevator-saga-balanced-solution
Last active August 5, 2021 21:17
Solution for Elevator Saga game (http://www.elevatorsaga.com)
{
init: function (elevators, floors) {
function queueDestinationForElevator(elevator, floorNum) {
if (elevator.destinationQueue.length) {
if (isElevatorGoingUp(elevator)) {
if (floorNum < elevator.destinationQueue[0]) {
if (elevator.currentFloor() < floorNum) {
elevator.destinationQueue.splice(0, 0, floorNum);
} else {