In software, abstraction is removing details which
are unimportant, leaving what is important.
For example, the list abstraction removes usually-unimportant
details such as growth rate and pointer arithmetic for element access,
leaving important details such as order and accessing elements by index.
For some applications, the usually-unimportant details of growth rate and
pointer arithmetic are essential, but for most applications, these
details obscure.
Graph a timeline of your Ninja build with this gnuplot script:
Collaboration tests cover code using a collaborator (but
excluding the collaborators)
Contract tests cover use by a collaborator
Integrated cover code including its collaborators
Mocks of collaboration tests are the same as
actions of contract tests.
Assertions of contract tests are the same as
stubs of collaboration tests.
Collaboration test
Contract test
Arrange
Call to interface method
Arrange (mock)
Act
Result of interface method
Arrange (stub)
Assert
Act
Assert
I wrote a one-off script to migrate backup archives from
Duplicity to Borg. It and alternates between duplicity restore and borg create
for the last Duplicity backup of each month. I'm sharing it here just in
case I need it in the future. It's definitely full of spaghetti.
Rough instructions:
Run TZ=UTC duplicity collection-status
file:///path/to/archive
>archive-status
Run gpg --export-secret-keys --armor
key|GNUPGHOME="${PWD}/gpghome" gpg --import
--passphrase-file /dev/null
$COLUMNS=`tput cols`PAGER='sh -c "col -bpx|lolcat -f|less -R"' man lsLS(1)UserCommandsLS(1)NAMEls-listdirectorycontentsSYNOPSISls[OPTION]...[FILE]...DESCRIPTIONListinformationabouttheFILEs(thecurrentdirectorybydefault).Sortentriesalphabeticallyifnoneof-cftuvSUXnor--sortisspecified.Mandatoryargumentstolongoptionsaremandatoryforshortoptionstoo.-a,--alldonotignoreentriesstartingwith.-A,--almost-all
Yesterday, I decided to finally debug an issue on my home network.
This post documents my investigations.
Scenario
I have three relevant nodes on my network:
Router
A Netgear router running OpenWRT (Linux).
straglum (192.168.2.206)
My workstation. Attached to the br-lan or eth0.1 interface on my
router via Wi-Fi.
strager-nas (192.168.3.89)
My network-attached storage. Attached to the eth0.2 interface on my
router via a cable.
Desired state: straglum can connect to strager-nas via SSH.
strager-nas cannot connect to straglum (or any other node on the work, or
the public internet).
Current state: straglum cannot connect to strager-nas via SSH.
I don't know what strager-nas can connect to.
Investigation
First, I made sure the strager-nas machine was powered on. It wasn't,
so I hit the power button.
Hypothesis
strager-nas is entirely offline or has a broken network
configuration.
Test
On the router, run ping strager-nas and ssh
strager-nas.
Results
At first, ping showed no pongs. After waiting a minute, ping
finally showed pongs. ssh failed with No matching algo
kex.
Conclusion
strager-nas is online. strager-nas' network is configured properly.
strager-nas' SSH service is running.
I still can't talk to strager-nas from straglum, so turning on
strager-nas was insufficient.
Hypothesis
The router is failing to route TCP and ICMP packets from straglum
to strager-nas.
Test
On the router, run tcpdump host strager-nas. On
straglum, run ping strager-nas and ssh
strager-nas.
Results
tcpdump showed the TCP and ICMP packets coming from straglum
destined for strager-nas. tcpdump also showed the TCP and ping
responses, coming from strager-nas destined for straglum.
Conclusion
The router successfully routes TCP and ICMP packets from straglum
to strager-nas. Additionally, strager-nas is responding to ping and SSH
requests.
According to tcpdump, everything is working fine. Perhaps tcpdump is
capturing packets before the firewall drops them.
Hypothesis
The iptables rules which should permit traffic from strager-nas to
straglum are not taking effect. The firewall is blocking traffic.
Test
Add probe rules to the router's iptables, attempt to connect from
straglum, and observe iptables' counters:
After adding this rule, I started receiving ping responses, and was
able to connect to strager-nas from straglum via SSH. We have made
progress!
However, I was able to connect to straglum's SSH server from
strager-nas. This is undesireable; strager-nas shouldn't be able to
initiate connections to other hosts. We need a way to allow new
connections into strager-nas but not new connects from strager-nas.
Hypothesis
For the strager-nas-to-straglum packets being blocked by the
router's iptables, the connect state is not ESTABLISHED.
The state must be something else.
Test
Add probe rules to the router's iptables, attempt to ping strager-nas
from straglum, and observe iptables' counters:
The output looks odd. [UNREPLIED] looks very suspicious.
Perhaps this is the cause? I think connection tracking may be turned off
somehow.
Hypthesis
Connection tracking is disabled.
Test
Run iptables -t raw -vL and see if any packets have
tracking disabled.
Results
$iptables -t raw -vLChain PREROUTING (policy ACCEPT 937 packets, 570K bytes) pkts bytes target prot opt in out source destination 486K 409M delegate_notrack all -- any any anywhere anywhereChain OUTPUT (policy ACCEPT 416 packets, 492K bytes) pkts bytes target prot opt in out source destinationChain delegate_notrack (1 references) pkts bytes target prot opt in out source destination 259 65085 zone_lan_nas_notrack all -- eth0.2 any anywhere anywhereChain zone_lan_nas_notrack (1 references) pkts bytes target prot opt in out source destination 66 18466 CT all -- any any anywhere anywhere CT notrack
Conclusion
Tracking is indeed disabled for strager-nas' interface on the
router. Tracking is enabled for other interfaces.
Something inside OpenWRT must have created the notrack
rule and the zone_lan_nas_notrack chain. I looked through the
LuCl web interface, and sure enough, the "Force connection tracking"
checkbox for the lan_nas firewall zone is
unchecked.
Solution
I forced connection tracking for the lan_nas zone in the
UI, turned off my manual ACCEPT rule, and pinged. I got a
response. Success!
Idea for a tutorial for teaching programming to beginners:
Learn I/O programming with no logic. Maybe CLI or Arduino.
Learn logic programming with no I/O. Create tic-tac-toe. Code for a
GUI is provided for you.
Swap the pre-made GUI of the tic-tac-toe program with an
Arduino-based UI (also pre-made).
The goal of this tutorial is to encourage learners to think of logic
and I/O as separate things. The two components can be developed
independently. Logic can be decoupled from its user-visible
interface.
Remove elements from the end of a JavaScript array by manipulating its
length property:
The extract method refactoring is symmetrical to the inline
function optimization. What other symmetries are there between
refactoring and optimization?
Brainstorm of refactorings which relate to optimizations
In C++, initializing a const reference automatic variable might make a
reference to an unnamed temporary:
structs{intb:6;};voidf(){smy_s;my_s.b=6;constint&b=my_s.b;// Copy!assert(b==6);my_s.b+=1;assert(my_s.b==7);// b was a copy to my_s.b (and not a reference to// my_s.b) and remains unchanged.assert(b==6);}
voidg(){chara[]="hello world";char*cs=a;conststd::string&s=cs;// Copy!assert(s=="hello world");a[0]='y';assert(strcmp(cs,"yello world")==0);// s was a copy of cs (not a reference to cs) and// remains unchanged.assert(s=="hello world");}
I think this behavior is familiar for function parameters, but is
fragile for automatic variables.