Skip to content

Instantly share code, notes, and snippets.

View kcjpop's full-sized avatar
🕳️

An Cao kcjpop

🕳️
View GitHub Profile
// App.js
import * as Analytics from 'modules/analytics';
import * as Auth from 'modules/auth';
import * as Search from 'modules/search';
import * as Users from 'modules/users';

// HOC to check logged in user
function checkAuthentication(Component) {
@kcjpop
kcjpop / index.js
Created November 19, 2018 12:02
Count consecutive chunks of a number array
const assert = require('assert')
function f(n) {
const [result, counter, num] = (n + '').split('').map(Number)
.reduce(([result, count, num], n) => {
if (num == null) return [result, 1, n]
if (n !== num) return [
[...result, [count, num]],
1,
@kcjpop
kcjpop / bookmarklet.js
Created September 5, 2018 12:16
Remove promoted link, stories, whatever on Quora
javascript:function clean(){document.querySelectorAll(".HyperLinkFeedStory").forEach(e=>e.remove()),document.querySelectorAll(".Bundle").forEach(e=>e.classList.contains("AnswerStoryBundle")?null:e.remove())}const dom=document.querySelector(".paged_list_wrapper"),ob=new MutationObserver(clean);ob.observe(dom,{childList:!0,subtree:!0}),clean();
@kcjpop
kcjpop / book-list.md
Last active November 9, 2022 06:23
Books I should read

Computer Science

  • A Philosophy of Software Design - John Ousterhout
  • Building Microservices: Designing Fine-Grained Systems
  • Building RESTful Web services with Go
  • Clean Architecture
  • Code That Fits in Your Head
  • Compilers: Principles, Techniques, and Tools
  • Concurrency in Go: Tools and Techniques for Developers 1st Edition
  • Database System Concepts
  • Designing Data-Intensive Applications
console.log(`
================================================================================
Question 1:
================================================================================
`)
function makeBearer(str, keyName = 'test_token') {
const map = str
.trim()
.split(';')
.map(s => s.trim().split('='))
const data = [
{ first: 'Squall', last: 'Leonhart', level: 99, hp: 4151 },
{ first: 'Rinoa', last: 'Heartilly', level: 84, hp: 3593 },
{ first: 'Zell', last: 'Dincht', level: 99, hp: 3984 },
{ first: 'Selphie', last: 'Tilmitt', level: 79, hp: 3009 },
{ first: 'Quistis', last: 'Trepe', level: 90, hp: 3548 },
{ first: 'Irvine', last: 'Kinneas', level: 99, hp: 3847 }
]
const Ordering = {
function fake(whatever) {
new Promise(success => setTimeout(success, 1000))
return Promise.resolve(whatever)
}
function _callAPI() {
return fake([
{ id: 1, title: 'Foo', vehicles: [{ vId: 3 }] },
{ id: 3, title: 'Foo', vehicles: [{ vId: 3 }] },
{ id: 4, title: 'Foo', vehicles: [{ vId: 3 }] },
const arr = [
['Adept Ropecaster', '2 snapmaw hearts, 2 shell-walker hearts', 5000],
['Adept Hunter Bow', '2 watcher hearts, 2 stormbird hearts', 6500],
['Adept Sling', '2 crystal braiding, 2 luminous braiding', 6500],
['Adept Tripcaster', '2 scrapper hearts, 2 grazer hearts', 7500],
['Adept War Bow', '2 trampler hearts, 2 thunderjaw hearts', 8000],
['Adept Sharpshot Bow', '2 sawtooth hearts, 2 longleg hearts', 8000],
['Adept Rattler', '2 goose skins, 2 rat skins, 2 raccoon skins', 9500],
['Adept Blast Sling', '2 lancehorn hearts, 2 charger hearts', 14000],
['Adept Banuk Sickness Eater', '2 grazer hearts, 2 snapmaw hearts', 7600],
const remLast = x => {
if (x == null || x === 0) return null
const s = `${x}`
return parseInt(s.substr(0, s.length - 1), 10)
}
const add = x => y => x + y
const sub = x => y => x - y
const mul = x => y => x * y
const neg = x => -x
grid-widths = {
'5': 5 / 100,
'10': 1 / 10,
'15': 15 / 100,
'20': 1 / 5,
'25': 1 / 4,
'30': 3 / 10,
'33': 1 / 3,
'35': 35 / 100,
'40': 2 / 5,