Skip to content

Instantly share code, notes, and snippets.

@ksylvan
ksylvan / mines.py
Last active Jun 11, 2020
MineSweeper
View mines.py
from random import randrange
class MinesGrid:
# Implement a sparse array to optimize space.
MINE = -1
class Row:
# Each row in the __a dict has the following
# structure a list, containing:
# [ empty_cells, {} ]
@ksylvan
ksylvan / Euler17.py
Last active May 4, 2020
Euler 17 in Python: Number to words
View Euler17.py
# 1 <= T <= 10
# 0 <= N <= 1e12
# 1e3 = Thousand
# 1e6 = Million
# 1e9 = Billion
# 1e12 = Trillion
# Project Euler 17
@ksylvan
ksylvan / linkedin.py
Created Mar 28, 2020
Justified Text question
View linkedin.py
# Question Description: Write a function that takes, as arguments, an integer representing line length in
# characters and a (long) string of text and returns the text with spaces and line breaks to produce a block of
# text justified to the given line length. For example, if the function were called as
# justify(25, "This is some sample text, really just enough to generate a few lines in the output to show what the text justify function is supposed to do.")
# This is some sample text,
# really just enough to
# generate a few lines in
# the output to show what
@ksylvan
ksylvan / main.py
Last active Mar 18, 2020
OurString and hasNext and getNext
View main.py
#
#
# _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
# |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|
# | | | |
# |H| |L| |W| |D|
# |E| |O| |O| |!|
# |L| |R|
# |L|
#
@ksylvan
ksylvan / calc.py
Last active Mar 13, 2020
Simple Calculator
View calc.py
# You are building an educational website and want
# to create a simple calculator for students to use.
# The calculator will only allow addition and subtraction
# of non-negative integers.
# We also want to allow parentheses in our input.
# Given an expression string using
# the "+", "-", "(", and ")"
# operators like "5+(16-2)", write a function to parse the
# string and evaluate the result.
View Effective_Engineer.md

FWIW: I didn't produce the content presented here (the outline from Edmond Lau's book). I've just copy-pasted it from somewhere over the Internet, but I cannot remember what exactly the original source is. I was also not able to find the author's name, so I cannot give him/her the proper credits.


Effective Engineer - Notes

What's an Effective Engineer?

@ksylvan
ksylvan / pihole_config.sh
Last active Nov 28, 2019
Pi-Hole Config for pi-hole in Docker container
View pihole_config.sh
#!/bin/bash
#
# After you start your Pi-Hole in a Docker container according
# to this: https://github.com/diginc/docker-pi-hole
#
# NOTE: On the Mac, I had to add "-h $(scutil --get LocalHostName)" to
# the "docker run" command. Otherwise, the Mac hostname was being reset
# to the random hostname generated for the container.
#
# Run this to replicate Will's setup here:
View letsencrypt.log
2017-08-23 01:48:43,076:DEBUG:certbot.main:certbot version: 0.17.0
2017-08-23 01:48:43,077:DEBUG:certbot.main:Arguments: ['--expand', '--standalone', '--agree-tos', '--rsa-key-size', '4096', '-m', 'postmaster@sylvan.com', '-d', 'spam.sylvan.com', '-d', 'mail.sylvan.com', '-d', 'postfixadmin.sylvan.com', '-d', 'sylvan.com', '-d', 'webmail.sylvan.com', '-d', 'www.sylvan.com']
2017-08-23 01:48:43,077:DEBUG:certbot.main:Discovered plugins: PluginsRegistry(PluginEntryPoint#manual,PluginEntryPoint#null,PluginEntryPoint#standalone,PluginEntryPoint#webroot)
2017-08-23 01:48:43,093:DEBUG:certbot.log:Root logging level set at 20
2017-08-23 01:48:43,094:INFO:certbot.log:Saving debug log to /var/log/letsencrypt/letsencrypt.log
2017-08-23 01:48:43,095:DEBUG:certbot.plugins.selection:Requested authenticator standalone and installer None
2017-08-23 01:48:43,189:DEBUG:certbot.plugins.selection:Single candidate plugin: * standalone
Description: Spin up a temporary webserver
Interfaces: IAuthenticator, IPlugin
Entry point: sta
@ksylvan
ksylvan / ansible-run.txt
Created Aug 4, 2017
Nice idempotence checking by Ansible. The first playbook is `bootstrap.yml` and the second is `mailserver.yml`
View ansible-run.txt
kayvan@thor mail-server:(master)$ make redo
ansible-playbook -u deploy bootstrap.yml
PLAY [all] ********************************************************************************************
TASK [Install python 2 if not there] ******************************************************************
ok: [netconnect.net]
TASK [Install sudo if not there] **********************************************************************
ok: [netconnect.net]
@ksylvan
ksylvan / GitLab
Created May 22, 2017
Gitlab runner for VM
View GitLab
#!/bin/sh
#
#IMAGE=gitlab/gitlab-ce:previous
IMAGE=gitlab/gitlab-ce
NAME=gitlab
PORTS="-p 443:443 -p 80:80 -p 22:22"
G_CONFIG=/etc/gitlab
You can’t perform that action at this time.