View quora-dict.py
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
dic = {} | |
for idx, char in enumerate (string): | |
if char! =' ': | |
if char not in dic: | |
dic [char] = [idx] | |
else: | |
dic [char].append(idx) | |
View nixos-install-suggestion
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
Offer nixos-enter after nixos-install as Per https://nixos.wiki/wiki/Change_root | |
After one has installed NixOS as per the instructions at: https://nixos.org/manual/nixos/stable/index.html#sec-installation | |
consider prompting the user and offering to perform nixos-enter to chroot into /mnt. | |
This can allow the new user to explore their new installation before reboot; but it also teaches them how they might later | |
use the nix-enter command for rescue perposes. | |
Of course getting value of this is in providing enough information in the prompt to inform the user of the option, | |
offer them more info, and showing them what it's doing (much as the web page is already doing; but presented there |
View import_responder.py
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
#!/usr/bin/env python3.8 | |
import responder | |
# Raises: ModuleNotFoundError: No module named 'responder' |
View naive_decorator.py
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
def prefixer(fn, prefix): | |
'''Return a wrapper which prefix first (string) argument with prefix''' | |
def wrapper(output, *args, **kwargs): | |
output = '%s%s' % (prefix, output) | |
return fn(output, *args, **kwargs) | |
return wrapper | |
## Example of a decorator WITHOUT using the @wrapper syntactic sugar | |
## (to save ref to print if we want to use it later: old_print = print) |
View match_comma_numbers.py
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
# Regular expression to validate if a string is a valid integer with | |
# commas separating thousands, millions, billions and so on | |
import re | |
# start with some test cases: | |
good_tests = ['1', '12', '123', '1,234', '12,345', '123,456', | |
'1,234,567', '12,345,678', '123,456,789'] | |
fail_tests = ['1234', '1,2345', '12,34', '1,2', '1,23', '1.2', '1,234.5'] | |
# implement a test harness |
View parse_iwinfo_scan.awk
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
# Take output from iwinfo "$INTERFACE" scan command | |
# ... combine each stanza (record) into a single line and | |
# prefix with hostname | |
# Call with -v h="$HOSTNAME" | |
BEGIN {h=sprintf("%s:\t", h); line=h}; | |
/^[^ ]/ {print line; line=h}; | |
/^ / {line=sprintf("%s %s", line, $0)}; | |
END {print line} |
View rot13.py
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
#!/usr/bin/env python | |
from __future__ import print_function | |
from string import uppercase | |
key = dict() | |
for plain,code in zip(uppercase, uppercase[13:]+uppercase[:13]): | |
key[plain] = code | |
key[plain.lower()] = code.lower() | |
def rot13(msg): | |
results = ''.join([key.get(c,c) for c in msg]) |
View eratosthenes_sieve.py
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
#!/usr/bin/env python2 | |
''' Eratosthenes sieve | |
''' | |
from __future__ import print_function | |
import array | |
import time | |
start = time.time() |
View mystery_code.py
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
#/usr/bin/env python | |
from __future__ import print_function | |
import random | |
list1 = list('abc') # We can expand strings into lists with this: | |
list2 = list1[:] # Makes a (shallow) copy of the list | |
letter_counts = dict() |
View bignums.js
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
/* | |
7. Iterate over the "bigNums" array. | |
If any number is less than 10, replace it with "x". | |
Return "bigNums" | |
HINT: You will need to "loop" over the array and check "if" the numbers are "less than" 10 | |
Answer: This function should return ["x", 12, "x", 56, 19, "x", "x", "x", 14, 10, "x"] | |
*/ | |
let bigNums = [3, 12, 7, 56, 19, 9, 1, 5, 14, 10, 2]; |
NewerOlder