This file contains 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 ( | |
"bufio" | |
"log" | |
"os" | |
"strconv" | |
"strings" | |
) |
This file contains 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
✂️ | |
if id <= lastID { | |
log.Fatal("😭") | |
} | |
✂️ |
This file contains 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
type line struct { | |
id int | |
restOfLine string | |
} |
This file contains 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
func reader(fname string, out chan<- *line) { | |
defer close(out) // close channel on return | |
// open the file | |
file, err := os.Open(fname) | |
if err != nil { | |
log.Fatalf("open: %v", err) | |
} | |
defer file.Close() |
This file contains 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
func joiner(metadata, setIDs <-chan *line, out chan<- *line) { | |
defer close(out) // close channel on return | |
si := &line{} | |
for md := range metadata { | |
sep := "," | |
// add matching strength set (if left over from previous iteration) | |
if si.id == md.id { | |
md.restOfLine += sep + si.restOfLine | |
sep = " " |
This file contains 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
func main() { | |
// read metadata | |
metadataChan := make(chan *line) | |
go reader("metadata.csv", metadataChan) | |
// read strength set IDs | |
strengthSetChan := make(chan *line) | |
go reader("strength_sets.csv", strengthSetChan) | |
// join the two data streams |
This file contains 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
#include <unistd.h> | |
#include <sys/types.h> | |
int main(int argc, char *argv[]) { | |
pid_t pid = fork(); | |
if (pid == 0) { | |
// child 1 migrates to a new session | |
setsid(); | |
pid_t pid2 = fork(); | |
if (pid2 == 0) { |
This file contains 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
#include <time.h> | |
int main(int argc, char *argv[]) { | |
// run for 10 seconds | |
time_t end = time(0) + 10; | |
// do something | |
volatile int i; | |
while (time(0) < end) { | |
i++; |
This file contains 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
#include <unistd.h> | |
int main(int argc, char *argv[]) { | |
// wait | |
sleep(10); | |
// exit ok | |
return 0; | |
} |
This file contains 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
#include <unistd.h> | |
#include <sys/types.h> | |
#include <sys/wait.h> | |
int main(int argc, char *argv[]) { | |
pid_t pid = fork(); | |
if (pid == 0) { | |
// child exits immediately | |
return 0; | |
} |