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
#!/usr/bin/env bash | |
# For a similar tool for wrangling HTML rather than JSON, see | |
# [Pup](https://github.com/ericchiang/pup) | |
jq --run-tests <<'END-OF-JQ-TESTS' && echo -e "\e[7;30;42mSUCCESS: ALL TESTS PASSED\e[0;37;40m" || echo "\e[7;30;41mFAILURE\e[0;37;40m" | |
# jq code follows | |
# | |
# old shebang line: | |
#! /usr/bin/env jq -M --run-tests |
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
# How do you write a method in a base class that uses a constant value provided | |
# by its various subclasses? | |
class BaseGreeter | |
# This does not work, because GREETING is undefined. | |
# Apparently Ruby resolves all-caps identifiers (i.e., constants) using a | |
# different mechanism than for lower-case identifiers (i.e., methods). | |
def speak1 | |
begin |
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
{ | |
"nodes": [ | |
{"id": "Y", "group": 1, "groupcolor": "blue"}, | |
{"id": "BR1f", "group": 1}, | |
{"id": "BY1g", "group": 1}, | |
{"id": "B2h", "group": 2, "groupcolor": "orange"}, | |
{"id": "RB11f", "group": 2}, | |
{"id": "Y2j", "group": 3, "groupcolor": "purple"}, |
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
// Demonstration of how to emulate class-based dynamic redispatch in Go. | |
// This is a pattern in which a method of a base class, | |
// which is inherited by subclasses without override, | |
// is implemented in terms of overridden versions of other methods. | |
// | |
// This may be an answer to, or it may be tangential to, [a question on | |
// StackOverflow](https://stackoverflow.com/questions/49114057/idiomatic-way-to-mimic-proper-dynamic-dispatch-in-go). | |
// | |
// In Go, the right way to do it seems to be to have the inherited base-class | |
// method not be a method. Instead, it's a function that takes an interface |
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
// Game_Board will have two slots: | |
// .boardString represents the contents of the 9 cells of the board | |
// .winner indicates whether or not the game has been won, and by whom | |
// | |
// Each cell in the game board has a cell #, as shown in this chart: | |
// | | | |
// 0 | 1 | 2 | |
// ----+---+---- |
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
# Normally, you'd just say | |
# reverse STRING | |
# since Perl provides a builtin for this functionality, but that would be | |
# cheating based on the rules of the assignment. | |
# my $desrever = reverse_string(STRING); | |
# | |
# Return a reversed copy of the input string. | |
sub reverse_string { | |
return join '', reverse split //, $_[0]; |
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
/* | |
* char *ptr = reverse(STR); | |
* | |
* Reverse the characters of STR[] in place, and return STR. | |
*/ | |
char *reverse(char *s) { | |
char ch, *p, *q; | |
/* Point q at the last character in s[], or at &s[0] if s is empty. */ |