The difference between $*
and $@
lies in the way they behave when
they occur inside double quotes: $*
behaves in the normal way,
whereas $@
creates a separate double-quoted string for each
command-line argument. That is, "$*"
behaves as if you had written
"$1 $2 $3"
, whereas "$@"
behaves as if you had written "$1" "$2" "$3"
.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
func main() { | |
c := make(chan string) | |
done := make(chan int) | |
const N = 10000000 | |
go func() { | |
for range N { | |
c <- "Hello!" | |
<-c |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func main() { | |
in := make(chan int) | |
out := in | |
for range 1000000 { | |
c := make(chan int) | |
go relay(c, out) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"fmt" | |
"log" | |
"net/http" | |
"golang.org/x/crypto/acme/autocert" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
certbot certonly -d example.com --standalone |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example usage of Go's new range over func feature. | |
// See https://github.com/golang/go/issues/61897. | |
package main | |
import "fmt" | |
func natural(yield func(int) bool) { | |
for i := 0; true; i++ { | |
if !yield(i) { | |
break |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Tic Tac Toe game | |
# | |
# Usage: python3 tictactoe.py size players... | |
import random | |
# Board represents a tictactoe board with width == height == size >= 1. | |
# Valid positions are [1..size^2] (inclusive). | |
class Board: | |
def __init__(self, size): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Experimenting with Dijkstra's mutual exclusion problem. | |
// See "Solution of a Problem in Concurrent Programming Control" | |
// https://dl.acm.org/doi/pdf/10.1145/365559.365617 for details. | |
// | |
// Here, each "computer" is incrementing `a` a million times. | |
// There's N=2 computers, so we expect a=2e6 at the end. | |
// We got a<2e6. Not sure why. My guess is line 31,32 is not atomic, | |
// allowing multiple goroutine to execute the critical section at the same time. | |
package main |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Bijection from integers to rationals, showing rational numbers are countably infinite. | |
# | |
# Note that f is a bijection from positive integers to positive fractions. | |
# Finding a bijection from integers to rationals (ℤ → ℚ) is left as an exercise to the reader. | |
from fractions import Fraction | |
from math import ceil | |
def main() -> None: | |
for i in range(1, 100): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import matplotlib.pyplot as plt | |
NDAYS = 365 | |
def main(): | |
sim = [0 for _ in range(NDAYS+2)] | |
N = 1000 | |
for _ in range(N): | |
for i in range(len(sim)): |
NewerOlder