被误解是表达者的宿命
夫言发于心,而闻者异解,此理之常也。年齿愈增,默然愈甚。 盖阅历既深,乃知世相纷纭,人情幽邃,非片语可尽其实。欲求辞达意周,则患其繁;欲求辞简意赅,则惧其偏。 复观众生:所历殊途,境界悬隔,智识云泥。虽同观一物,所见深浅迥异;共闻一语,所会旨趣悬殊。理喻之难,甚于登天。 是以倦于置喙,但守方寸。于洪流大势,静观而已矣——言既难契于众听,身亦莫挽乎滔滔之势。
夫言发于心,而闻者异解,此理之常也。年齿愈增,默然愈甚。 盖阅历既深,乃知世相纷纭,人情幽邃,非片语可尽其实。欲求辞达意周,则患其繁;欲求辞简意赅,则惧其偏。 复观众生:所历殊途,境界悬隔,智识云泥。虽同观一物,所见深浅迥异;共闻一语,所会旨趣悬殊。理喻之难,甚于登天。 是以倦于置喙,但守方寸。于洪流大势,静观而已矣——言既难契于众听,身亦莫挽乎滔滔之势。
乙巳孟夏,驱车西行。临海之涯,以观沧溟。 但见洪波接天,浩渺无极。碧水如倾万顷之琉璃,远岫若浮数点之云墨。长风浩浩,卷雪浪而崩云;鸥鹭翩翩,掠寒烟而忘机。极目骋怀,始知宇宙之宏阔;俯身掬水,乃觉浮生之须臾。 昔人云:“寄蜉蝣于天地,渺沧海之一粟。”信哉斯言!吾辈营营于尘网,汲汲于微名,常为蜗角之争,所累寸心。今对汪洋之无始无终,感山海之不移不易,方悟营营者如朝露,汲汲者若飞尘。此身不过沧海一苇,此世不过白驹过隙,复何忧之能扰?复何欲之难平? 愿效鸥鹭之忘机,观潮汐之信诺。得失随浪卷,宠辱付云流。当此碧海青天,惟觉清风入怀,俗虑尽涤。后之视今,亦犹今之视昔,惟愿览者共析此中真意,莫为浮云遮望眼。
龙舞春风瑞气生,万家灯火喜新程。 绿柳摇曳暖日长,桃花扬香迎早春。 星河月影共辉映,海外天涯同乾坤。 千山水长故乡景,浊酒一杯归家魂。
了解github action后,第一步想到的是改造下这个博客。利用github action的工作流,做到直接在github上编辑markdown,保存后,触发一个设定的workflow,做到编译,部署编译好的静态网站到GitHub pages。 这里面关键是,如何部署编译好的静态网站到Github Pages。我用的是hexo这个静态网站生成器,代码是在一个独立repo,与要部署的目标repo不同。在GitHub的runner也就是服务器上,如何设置github credentials,从而能从那里部署是关键。 几番搜索发现了有个现成的github action: hexo-action。简单总结下: Generate a deploy key pair. ssh-keygen -t rsa -C "username@example.com" Public key is saved in github page repo’s Settings/Deploy Keys. Private key is saved as a secret in source repo’s Settings/Secrets, e.g., named DEPLOY_KEY. Add the github workflow: name: Blog CICD on: push: branches: - 'main' jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: submodules: true - name: Use Node.js uses: actions/setup-node@v3 with: node-version: '20.x' - name: Install dependencies run: npm install hexo - name: Deploy id: deploy uses: sma11black/hexo-action@v1.0.3 with: deploy_key: ${{ secrets.DEPLOY_KEY }} user_name: github_action 这是第一篇自动部署的文章。Let’s see if it works. ...
二月听到学友新歌 张学友的新单曲又十年,旋律简单,歌词动人。恰好今年也是来美十年,人生前18年在家乡,7年裤子大,简单一算,西雅图已经是故乡外呆的最久的地方。 这几年随着小红书转码热门话题,十年前,我也算是半个转码。 但当时没有leetcode,没有bootcamp,也没有社交热度。只是作为相关专业电子信息工程,在学校就学了很多计算机相关课程,任何课题也都离不开代码。能动手实现并且立马看到成效比偏理论的通信更吸引我,于是毕业前就顺利成章的锁定专门找计算机行业工作。 年纪渐渐增长才发觉自己是被时间追着跑,一眨眼又是一个十年,连想停下来喘口气都是奢侈的。 一生有几个理想能够扛得住岁月 还不如好好地过越来越少的明天 一眨眼 又是一个十年 那些瓜葛纠结 在某一天突然迎刃而解
于2023/06去看即将搬入的新家有感 旭日起山巅,夕阳落湖边。 闹市取幽径,转角见屋檐。
于2021年7月18日别谷歌奔赴新征程有感而作 序 微软五年,谷歌两载,如白驹过隙,忽然而已。 山河壮阔,星辰辽远,纵跬步咫尺,又是好风景。 银鞍白马微风软,飒沓流星谷中歌。 风鹏正举九万里,食苹鹿鸣下山河。
A cheatsheet that gets you started. The original tutorial can be found here Main function The normal version: object Hello { def main(args: Array[String]) = { println("Hello, world") } } The version that extends App trait object Hello extends App { println("Hello, world") } // To access args. object Hello extends App { if (args.size == 0) println("Hello, you") else println("Hello, " + args(0)) } As you may notice: no ; needed as ending in Scala. Variables The type in declaration is optional. val s: String = "hello" // val for immutable, final in Java. val s = "hello" // Same as above. var i: Int = 42 // var for mutable. var i = 42 // Same as above. Built-in types: val b: Byte = 1 // 8-bit signed [-128, 127](-2^7 to 2^7-1, inclusive) val s: Short = 1 // 16-bit signed. val x: Int = 1 // 32-bit signed. val l: Long = 1 // 64-bit signed. val f: Float = 3.0 // 32-bit IEEE 754 single-precision float. val d: Double = 2.0 // 64-bit IEEE 754 double-precision float. val c: Char = 'a' // 16-bit unsigned Unicode character. val s: String = "str" // A sequence of Char BigInt and BigDecimal for large numbers: ...
一个场景 当内存无法加载全部数据时,如何从包含未知大小的数据流中随机选取k个数据,并且要保证每个数据被抽取到的概率相等。 水塘抽样 把上述问题具体化为给定一个未知大小数组data[],从中选取k个数,要求每个数被选中的概率相等。假设数组长度为n,则每个数被选中概率应为k/n。 策略是: 对最前面k个数,直接放到数组chosen[]即chosen[i] = data[i] 0 <= i < k。 对data[i], i >= k,先生成个[0...i)间的随机数(左闭右开),假设rand(0, i) = j,则如果j < k,则做替换chosen[j] = data[i]。否则,nothing happens. 如此反复直到结束。 Java实现如下: public class ReservoirSampling { private Random rand = new Random(); public int[] sampling(int[] data, int k) { int[] chosen = new int[k]; int i = 0; for (int d : data) { if (i < k) { chosen[i] = d; } else { int j = rand.nextInt(i); if (j < k) { chosen[j] = d; } } ++i; } return chosen; } } 每个元素被选中概率相等的证明如下: ...
A quick review of Java Collection and Map key methods. Array based collections usually have: Method Time complexity add O(1) insert(int index) O(N) remove O(1) remove(int index) O(N) find(Object value) O(N) PriorityQueue, TreeSet and TreeMap are implemented based on balanced tree, thus: Method Time complexity offer O(logN) poll O(logN) peek O(1) Overview via a diagram Collections extends Iterable which has below key methods: Method Description boolean hasNext() This method returns true if the iterator has more elements. object next() It returns the element and moves the cursor pointer to the next element. void remove() This method removes the last elements returned by the iterator. List methods Method Description void add(int index, E element) Inserts the specified element at the specified position in this list (optional operation). boolean add(E e) Appends the specified element to the end of this list (optional operation). boolean addAll(Collection<? extends E> c) Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection’s iterator (optional operation). Eget(int index) Returns the element at the specified position in this list. E set(int index, E element) Replaces the element at the specified position in this list with the specified element (optional operation). booleanisEmpty() Returns true if this list contains no elements. int size() Returns the number of elements in this list. <T> T[] toArray(T[] a) Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array. E.g., String[] y = x.toArray(new String[0]); Queue methods Method Description void add(E e) Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions, returning true upon success and throwing an IllegalStateException if no space is currently available. E element() Retrieves, but does not remove, the head of this queue. boolean offer(E e) Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions. E peek() Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty. E poll() Retrieves and removes the head of this queue, or returns null if this queue is empty. E remove() Retrieves and removes the head of this queue. Dequeue / LinkedList Methods Method Description void addFirst(E e) Inserts the specified element at the front of this deque if it is possible to do so immediately without violating capacity restrictions, throwing an IllegalStateException if no space is currently available. void addLast(E e) Inserts the specified element at the end of this deque if it is possible to do so immediately without violating capacity restrictions, throwing an IllegalStateException if no space is currently available. boolean offerFirst(E e) Inserts the specified element at the front of this deque unless it would violate capacity restrictions. boolean offerLast(E e) Inserts the specified element at the end of this deque unless it would violate capacity restrictions. E peekFirst() Retrieves, but does not remove, the first element of this deque, or returns null if this deque is empty. E peekLast() Retrieves, but does not remove, the last element of this deque, or returns null if this deque is empty. E pollFirst() Retrieves and removes the first element of this deque, or returns null if this deque is empty. E pollLast() Retrieves and removes the last element of this deque, or returns null if this deque is empty. E pop() Pops an element from the stack represented by this deque. void push(E e) Pushes an element onto the stack represented by this deque (in other words, at the head of this deque) if it is possible to do so immediately without violating capacity restrictions, throwing an IllegalStateException if no space is currently available. E removeFirst() Retrieves and removes the first element of this deque.` E removeLast() Retrieves and removes the last element of this deque. Summary of Deque methods First Element (Head) Last Element (Tail) Throws exception Special value Throws exception Special value Insert addFirst(e) offerFirst(e) addLast(e) offerLast(e) Remove removeFirst() pollFirst() removeLast() pollLast() Examine getFirst() peekFirst() getLast() peekLast() Comparison of Queue and Deque methods Queue Method Equivalent Deque Method add(e) addLast(e) offer(e) offerLast(e) remove() removeFirst() poll() pollFirst() element() getFirst() peek() peekFirst() Comparison of Stack and Deque methods Stack Method Equivalent Deque Method push(e) addFirst(e) pop() removeFirst() peek() getFirst() Method Description boolean add(E e) Adds the specified element to this set if it is not already present. TreeSet methods Method Description boolean add(E e) E ceiling(E e) Returns the least element in this set greater than or equal to the given element, or null if there is no such element. E first() Returns the first (lowest) element currently in this set. E floor(E e) Returns the greatest element in this set less than or equal to the given element, or null if there is no such element. SortedSet headSet(E toElement) Returns a view of the portion of this set whose elements are strictly less than toElement. NavigableSet headSet(E toElement, boolean inclusive) Returns a view of the portion of this set whose elements are less than (or equal to, if inclusive is true) toElement. E higher(E e) Returns the least element in this set strictly greater than the given element, or null if there is no such element. E last() Returns the last (highest) element currently in this set. E lower(E e) Returns the greatest element in this set strictly less than the given element, or null if there is no such element. E pollFirst() Retrieves and removes the first (lowest) element, or returns null if this set is empty. E pollLast() Retrieves and removes the last (highest) element, or returns null if this set is empty. NavigableSet subSet(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive) Returns a view of the portion of this set whose elements range from fromElement to toElement. SortedSet subSet(E fromElement, E toElement) Returns a view of the portion of this set whose elements range from fromElement, inclusive, to toElement, exclusive. SortedSet tailSet(E fromElement) Returns a view of the portion of this set whose elements are greater than or equal to fromElement. NavigableSet tailSet(E fromElement, boolean inclusive) Returns a view of the portion of this set whose elements are greater than (or equal to, if inclusive is true) fromElement. Map methods Method Description V get(Object key) Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key. V put(K key, V value) Associates the specified value with the specified key in this map (optional operation). boolean containsKey(Object key) Returns true if this map contains a mapping for the specified key. boolean containsValue(Object value) Returns true if this map maps one or more keys to the specified value. Set<Map.Entry<K,V» entrySet() Returns a Set view of the mappings contained in this map. Set keySet() Returns a Set view of the keys contained in this map. Collection values() Returns a Collection view of the values contained in this map. Default methods: ...