TLDR: Use for...of
instead of forEach()
in asynchronous code.
For legacy browsers, use for...i
or [].reduce()
To execute the promises in parallel, use Promise.all([].map(...))
const anagramWords = (input) => { | |
let sameWord = {}; | |
for (let i = 0; i < input.length; i++) { | |
const sorted = input[i].split(""); | |
for (let j = 0; j < sorted.length; j++) { | |
for (let k = 0; k < sorted.length - j - 1; k++) { | |
if (sorted[k] > sorted[k + 1]) { | |
let temp = sorted[k]; |
// ___ ___ ___ | |
// _____ / /\ ___ ___ / /\ / /\ | |
// / /::\ / /:/_ / /\ / /\ / /:/_ / /::\ | |
// / /:/\:\ / /:/ /\ / /:/ / /:/ / /:/ /\ / /:/\:\ | |
// / /:/~/::\ / /:/ /:/_ / /:/ / /:/ / /:/ /:/_ / /:/~/:/ | |
// /__/:/ /:/\:| /__/:/ /:/ /\ / /::\ / /::\ /__/:/ /:/ /\ /__/:/ /:/___ | |
// \ \:\/:/~/:/ \ \:\/:/ /:/ /__/:/\:\ /__/:/\:\ \ \:\/:/ /:/ \ \:\/:::::/ | |
// \ \::/ /:/ \ \::/ /:/ \__\/ \:\ \__\/ \:\ \ \::/ /:/ \ \::/~~~~ | |
// \ \:\/:/ \ \:\/:/ \ \:\ \ \:\ \ \:\/:/ \ \:\ | |
// \ \::/ \ \::/ \__\/ \__\/ \ \::/ \ \:\ |
# -*- coding: utf8 -*- | |
import socket | |
# host = socket.gethostname() | |
# port = 5000 | |
host = '192.168.0.100' # 對server端為主機位置 | |
port = 5555 | |
address = (host, port) |
/* | |
This script is meant to be used with a Google Sheets spreadsheet. When you edit a cell containing a | |
valid CSS hexadecimal colour code (like #000 or #000000), the background colour will be changed to | |
that colour and the font colour will be changed to the inverse colour for readability. | |
To use this script in a Google Sheets spreadsheet: | |
1. go to Tools » Script Editor » Spreadsheet; | |
2. erase everything in the text editor; | |
3. change the title to "Set colour preview on edit"; |
// based on the math here: | |
// http://math.stackexchange.com/a/1367732 | |
// x1,y1 is the center of the first circle, with radius r1 | |
// x2,y2 is the center of the second ricle, with radius r2 | |
function intersectTwoCircles(x1,y1,r1, x2,y2,r2) { | |
var centerdx = x1 - x2; | |
var centerdy = y1 - y2; | |
var R = Math.sqrt(centerdx * centerdx + centerdy * centerdy); | |
if (!(Math.abs(r1 - r2) <= R && R <= r1 + r2)) { // no intersection |
#!/bin/bash | |
### steps #### | |
# verify the system has a cuda-capable gpu | |
# download and install the nvidia cuda toolkit and cudnn | |
# setup environmental variables | |
# verify the installation | |
### | |
### to verify your gpu is cuda enable check |
{{/* ACTUAL CODE DONT TOUCH */}} | |
{{$hasContent := false}} {{$content := false}} {{$contentV := ""}} {{$channel := false}} {{$channelV := .Channel.ID}} | |
{{$flags := cslice "-channel" "-content"}} | |
{{- range $k, $v := .CmdArgs -}} | |
{{- if eq . "-content"}} {{$content = true}} {{else if in $flags .}} {{$content = false}} {{end -}} | |
{{- if and ($content) (not (eq . "-content"))}} {{$hasContent = true}} {{$contentV = joinStr " " $contentV .}} {{end -}} | |
{{- if eq . "-channel"}} {{$channel = true}} {{else if in $flags .}} {{$channel = false}} {{end -}} | |
{{- if and ($channel) (not (eq . "-channel"))}} {{$checkChannel := reReplace `<|>|#` . ""}} {{with getChannelOrThread $checkChannel}} {{$channelV = .ID}} {{end}} {{end -}} | |
{{- end -}} |
apt-get install squid
htpasswd -md /etc/squid3/users myuserlogin`