Skip to content

Instantly share code, notes, and snippets.

View luojiyin1987's full-sized avatar
💭
I may be slow to respond.

luo jiyin luojiyin1987

💭
I may be slow to respond.
View GitHub Profile
@luojiyin1987
luojiyin1987 / FilterRestaurantsbyVegan-FriendlyPriceandDistance.js
Created October 24, 2020 15:18
尝试使用函数式编程 解耦复杂度
/**
* @param {number[][]} restaurants
* @param {number} veganFriendly
* @param {number} maxPrice
* @param {number} maxDistance
* @return {number[]}
*/
var filterRestaurants = function(restaurants, veganFriendly, maxPrice, maxDistance) {
function isVeganFriendly(rest) {
if (veganFriendly === 1)
@luojiyin1987
luojiyin1987 / v8.md
Created August 7, 2020 03:34 — forked from kevincennis/v8.md
V8 Installation and d8 shell usage

Installing V8 on a Mac

Prerequisites

  • Install Xcode (Avaliable on the Mac App Store)
  • Install Xcode Command Line Tools (Preferences > Downloads)
  • Install depot_tools
    • git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
    • sudo nano ~/.bash_profile
  • Add export PATH=/path/to/depot_tools:"$PATH" (it's important that depot_tools comes first here)
@luojiyin1987
luojiyin1987 / latency.txt
Created April 19, 2020 01:20 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script>
function loadResource(links, fnSuccess, fnError) {
var script = document.createElement('script');
APP_NAME = Private Repo
RUN_USER = git
RUN_MODE = prod
[database]
DB_TYPE = mysql
HOST = mysql.gogs.lab.com:3306
NAME = gogs
USER = gogs
PASSWD = gogs
DOCKER_GOGS_IMAGE=gogs/gogs:0.11.91
GOGS_DOMIAN=git.luojiyin.top
DOCKE_MYSQL_IMAGE=mysql:5.7.16
MYSQL_HOST=mysql.gogs.lab.com
DOCKER_REDIS_IMAGE=redis:5.0-alpine
REDIS_HOST=cache.gogs.lab.com
version: '3.6'
services:
gitea:
image: gitea/gitea:1.10.3
environment:
- USER_UID=1000
- USER_GID=1000
- APP_NAME=Private
@luojiyin1987
luojiyin1987 / FindFirstandLastPositionofElementinSortedArray.js
Created February 10, 2020 15:28
Find First and Last Position of Element in Sorted Array
/**
* @param {number[]} nums
* @param {number} target
* @return {number[]}
*/
var searchRange = function(nums, target) {
const left = lowerBound(nums, target);
const right = upperBound(nums, target);
if (left < right) {
return [left, right - 1];
@luojiyin1987
luojiyin1987 / haveSameContents.js
Last active January 27, 2020 13:30
haveSameContents javascript
const haveSameContents = (a,b) => {
for(const v of new Set([...a, ...b]))
if (a.filter(e => e === v).length !== b.filter(e => e===v).length)
return false;
return true;
};
console.log(haveSameContents([1,2,4], [2,4,1]));
const isNumber = val => typeof val === 'number' && val === val;
其次,如果想要在 Python shell (Python的互動介面)中能夠只利用變數名稱就展示用來表示 Mylist 的字串,光是 __str__ 還不夠,這必須要覆寫 __repr__:
class Mylist:
def __init__(self):
self._mylist=list()
def __len__(self):