Skip to content

Instantly share code, notes, and snippets.

Learning Javascript and algorithm

Aaron youyiqin

Learning Javascript and algorithm
View GitHub Profile
View sed.js
var fs = require('fs');
var util = require('util');
function main() {
var args = process.argv.slice(2);
if (args.length === 3) {
var regex = eval(args[0]);
jcouyang / contribution-svg.rb
Last active Nov 10, 2020
SVG image for your github contributions calendar
View contribution-svg.rb
require "nokogiri"
require "open-uri"
url = "{params['username']}"
document = Nokogiri::HTML(open(url))
contrib_boxes = document.css('svg.js-calendar-graph-svg')[0]
width = (params['width']||54*13-2).to_i
height = (params['height']||89).to_i
ninehills / delay
Created Mar 9, 2011
View delay
# 参数1:延迟的时间,单位s
# 参数2:需要执行的命令
# example:
# delay 10 "conky -d"
sleep $1
exec $2
wavded / promise.js
Last active May 6, 2021
Promise A+ Implementation
View promise.js
"use strict"
var Promise = function () {
this.state = 'pending'
this.thenables = []
Promise.prototype.resolve = function (value) {
if (this.state != 'pending') return
this.state = 'fulfilled'
bluejava / Soon
Last active May 18, 2021
A Very Fast Javascript thread yield (see blog posting)
View Soon
// See
// This is a very fast "asynchronous" flow control - i.e. it yields the thread and executes later,
// but not much later. It is far faster and lighter than using setTimeout(fn,0) for yielding threads.
// Its also faster than other setImmediate shims, as it uses Mutation Observer and "mainlines" successive
// calls internally.
// WARNING: This does not yield to the browser UI loop, so by using this repeatedly
// you can starve the UI and be unresponsive to the user.
// Note: For an even faster version, see
var soon = (function() {
hackjutsu / example.js
Last active Jul 1, 2021
[Highlight.js + line number] This snippet adds line number support to Highlight.js. Besides, special css trick is applied to stop the line numbers from being selected and copied. #tags: highlight, lepton
View example.js
import HighlightJS from 'highlight.js'
createHighlightedCodeBlock (content, language) {
let lineNumber = 0
const highlightedContent = HighlightJS.highlightAuto(content, [language]).value
/* Highlight.js wraps comment blocks inside <span class="hljs-comment"></span>.
However, when the multi-line comment block is broken down into diffirent
table rows, only the first row, which is appended by the <span> tag, is
highlighted. The following code fixes it by appending <span> to each line
Jaykul / Get-MsdnKeys.ps1
Last active Sep 8, 2021
PowerShell + Selenium Demo: Getting Started, and reusing cookies with Invoke-Request
View Get-MsdnKeys.ps1
# It might work in 4, but I'm not testing there. Lower you'll have to tweak code
#requires -Version 5.0
# Your Live ID for MSDN login
# Pick a browser to use. Defaults to Firefox (which doesn't seem to require an external Driver file)
slikts /
Last active Dec 12, 2021
Up to date answer about when to use React context or Redux (Redux Toolkit)

React context vs Redux in 2020

The [React docs][condoc] give some example use cases for context:

Context is designed to share data that can be considered “global” for a tree of React components, such as the current authenticated user, theme, or preferred language.

The common property of these use cases is that data like the current theme doesn't change often and needs to be shared deep down the component tree, which would be cumbersome with "[prop drilling][drill]". Something else that needs to be shared everywhere is the application state when using a "single source of truth" pattern, so it would follow that the context API would help with that as well, but there's a catch: components that use context will rerender every time that the provided value changes, so sharing the whole application state through context would cause excessive render lifecycles.

JerryC8080 / RexChainesPhone.js
Created Mar 21, 2016
View RexChainesPhone.js
4G号段 177
View Python Socket 编程详细介绍.md

Python Socket 编程详细介绍

Python 提供了两个基本的 socket 模块:

  • Socket 它提供了标准的BSD Socket API。
  • SocketServer 它提供了服务器重心,可以简化网络服务器的开发。

下面讲解下 Socket模块功能。

Socket 类型