Skip to content

Instantly share code, notes, and snippets.

@alexhsamuel
alexhsamuel / ipblock.md
Last active July 29, 2016 21:55
IP block calculator

Overview

In this assignment, you will write a program that performs computations on IP blocks. As you may already know, Internet Protocol version 4 (IPv4, or often just IP) is the main network protocol used on the Internet.

An IP address, which identifies a computer on the Internet, is an unsigned 32-bit integer. It is traditionally written as four 8-bit numbers, with the highest (most significant) number first, separated by dots. For example, the IP number 0xACD9002E is written "172.217.0.46".

An IP block, often called a subnet, is a group of IP addresses that share the same bit prefix: all addresses in the block share the same leading (most significant) bits, in their binary representation. The block is traditionally written as an IP address followed by a slash and the number of bits in the prefix. The prefix size is between 0 and 32.

For example, "172.217.0.46/24" is the block consisting of all addresses that share the same first 24 bits w

@alexhsamuel
alexhsamuel / linked-list.js
Last active August 2, 2016 20:16
Javascript linked list complexity demo
var now;
if (typeof performance !== 'undefined') {
// In the browser.
now = function () {
return performance.now() * 1E-3;
}
} else {
// In node.
now = function () {
var hr = process.hrtime();
@alexhsamuel
alexhsamuel / clone-open-prs
Last active August 10, 2016 15:15
Tool to clone all open PRs of a GitHub repo into a subdirectory.
#!/usr/bin/env node
// -*- javascript -*-
/**
* Tool to clone all open PRs of a GitHub repo into a subdirectory.
*
* Usage:
*
* clone-open-prs USER/REPO DIR
*
@alexhsamuel
alexhsamuel / Style.java
Created January 14, 2017 19:56
practice emulating a coding style
public class Style {
/*
* Assume this method is correctly formatted.
*/
public static char convertBinaryToHexDigit( final boolean[] src,
final int srcPos )
{
if( src.length==0 ){
throw new IllegalArgumentException( "Cannot convert an empty array." );
@alexhsamuel
alexhsamuel / Main.java
Created January 14, 2017 22:20
code quality exercise
package nyc.c4q.ac33.cal;
import java.util.Calendar;
import java.util.GregorianCalendar;
// https://www.redcort.com/us-federal-bank-holidays/
public class Main {
public static void main(String[] args) {
final int month = Integer.valueOf(args[0]);
@alexhsamuel
alexhsamuel / index.html
Created July 15, 2017 19:07
Side-by-side definition list // source http://jsbin.com/juzegew
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Side-by-side definition list</title>
<style id="jsbin-css">
/*
* {
border: 1px solid red;
@alexhsamuel
alexhsamuel / disable-ligatures.py
Created November 27, 2017 15:50
disable font ligatures in Jupyter notebooks
from IPython.core.display import HTML
HTML("""
<style>
body { font-feature-settings: "liga" 0; }
</style>
""")
@alexhsamuel
alexhsamuel / stuff.py
Created November 6, 2019 02:09
stuff TTY input
import fcntl
import os
import sys
import termios
def stuff(text):
tty_name = os.ttyname(sys.stdin.fileno())
tty_fd = os.open(tty_name, os.OWRONLY)
try:
old_attr = termios.tcgetattr(tty_fd)