diff --git a/_100-days-of-code/2018-01-01-100-days-of-code-day001.markdown b/_100-days-of-code/2018-01-01-100-days-of-code-day001.markdown deleted file mode 100644 index 41ddeab..0000000 --- a/_100-days-of-code/2018-01-01-100-days-of-code-day001.markdown +++ /dev/null @@ -1,33 +0,0 @@ ---- -layout: post -title: "day 1" -date: 2018-01-01 -categories: programming ---- -# 100 Days of Code - -With a brand new year, comes a fresh start, a clean slate. I am going to begin -my new year with something I have just come across: [100daysofcode](http://100daysofcode.com/) challenge. -I have forked the 100 days of code repo from github and am using the log to -track my daily progress. It will be fun, and it will be a great way to keep me -accountable for building my python knowledge. Here is an example snippet from -the code I did for day 1. - -### Day 1: -{% highlight python %} - -def gen_ssh_keypair(): - """ Generate an RSA private / public keypair """ - key = RSA.generate(2048) - - # generate private key - output to file - with open('rsa_privkey.pem', 'wb') as privkey: - privkey.write(key.exportKey()) - - # generate public key - output to file - with open('rsa_pubkey.pem', 'wb') as pubkey: - pubkey.write(key.publickey().exportKey()) - - return 0 - -{% endhighlight %} diff --git a/_100-days-of-code/2018-01-01-100-days-of-code-day002.markdown b/_100-days-of-code/2018-01-01-100-days-of-code-day002.markdown deleted file mode 100644 index 09a7168..0000000 --- a/_100-days-of-code/2018-01-01-100-days-of-code-day002.markdown +++ /dev/null @@ -1,19 +0,0 @@ ---- -layout: post -title: "day 2" -date: 2018-01-02 -categories: programming ---- -# 100 Days of Code - -### Day 2: -Today we are going to make a Discord chat bot. Bots have always been -interesting to me. -Trying to make a computer program behave like a human sounds like a fun -challenge, and a great way to play some fun pranks on my friends on Discord. -So far, I have sketched up the initial framework in my python program using the -discordpy library. I will need to learn more about the following: -- asyncio -- coroutines -These seem to be two main concepts that this library uses, and it will help aid -my skills in the future when making programs that focus on performance. diff --git a/_100-days-of-code/2018-01-01-100-days-of-code-day003.markdown b/_100-days-of-code/2018-01-01-100-days-of-code-day003.markdown deleted file mode 100644 index c5f9ffa..0000000 --- a/_100-days-of-code/2018-01-01-100-days-of-code-day003.markdown +++ /dev/null @@ -1,17 +0,0 @@ ---- -layout: post -title: "day 3" -date: 2018-01-03 -categories: programming ---- - -# 100 Days of Code - -### Day 3: -Today I could not find time to work on the coding aspect of the bot, but I did -grab some audio recordings that I need for the bot. I am mainly making this bot -to prank my friends in discord with voice recordings of funny moments that -occur in discord. I am going to make it queryable via prepending commands with -a !. I still did get to code today for work. I am working on some stuff in -python and I have to write unit tests, so I wrote a test for a couple of -functions diff --git a/_100-days-of-code/2018-01-01-100-days-of-code-day004.markdown b/_100-days-of-code/2018-01-01-100-days-of-code-day004.markdown deleted file mode 100644 index 679e99c..0000000 --- a/_100-days-of-code/2018-01-01-100-days-of-code-day004.markdown +++ /dev/null @@ -1,16 +0,0 @@ ---- -layout: post -title: "day 4" -date: 2018-01-04 -categories: programming ---- - -# 100 Days of Code - -### Day 4: -Today I worked on some more unit tests with a program I am building at work. I -learned a good deal about unit test calls and the different assert options you -can pass. I also looked further into the discord python library and copied some of the -example bots into an examples directory in my repo. I will need to experiment -further with those and look up more information on asyncio and how to properly -use it. diff --git a/_100-days-of-code/2018-01-01-100-days-of-code-day005.markdown b/_100-days-of-code/2018-01-01-100-days-of-code-day005.markdown deleted file mode 100644 index 6de460b..0000000 --- a/_100-days-of-code/2018-01-01-100-days-of-code-day005.markdown +++ /dev/null @@ -1,27 +0,0 @@ ---- -layout: post -title: "day 5" -date: 2018-01-05 -categories: programming ---- - -# 100 Days of Code - -### Day 5: -Today I did not have the energy to do anything with my discord bot. I will work -on that tomorrow and sunday. I mainly just did some hacker rank problems -involving strings. Here is a post someone on hacker rank who is much more -clever than me for validating any characters in strings: - -```python -str = raw_input() -print any(c.isalnum() for c in str) -print any(c.isalpha() for c in str) -print any(c.isdigit() for c in str) -print any(c.islower() for c in str) -print any(c.isupper() for c in str) -``` - -that will return True or False if ANY of the characters contain alphanumberic, -alphabetical, a digit, lowercase, or uppercase. A nice little shortcut that I -will remember. diff --git a/_100-days-of-code/2018-01-01-100-days-of-code-day006.markdown b/_100-days-of-code/2018-01-01-100-days-of-code-day006.markdown deleted file mode 100644 index 26d90be..0000000 --- a/_100-days-of-code/2018-01-01-100-days-of-code-day006.markdown +++ /dev/null @@ -1,89 +0,0 @@ ---- -layout: post -title: "day 6" -date: 2018-01-06 -categories: programming ---- - -# 100 Days of Code - -### Day 6: -Today I made use of the python-nmap library and made a class that I will be -able to import into future modules. I started out making things like a ping sweeping tool and -banner grabber, as well as a ssl cipher suite checker. I made a subclass of the nmap -PortScanner class to start so I have access to all of those utilities. Subclasses are something I have been looking into recently. -It is an easy way to add existing functionality to another object. This class will end up being the base -library that I use when I make my own port scanning scripts. here is what I -have so far: - -```python -class NmapUtility(nmap.PortScanner): - - def __init__(self, hostname, hosts=False): - """ Initialize with hostname and optional list of hosts """ - self.hostname = hostname - - def scan_host(self, hostname, portrange): - """ Scan a host using nmap.scan """ - - return self.scan(hostname, portrange) - - def scan_hosts(self, hosts): - """ Scan a list of hosts """ - pass - - def ping_sweep(self, hosts): - """ Ping sweep a list of hosts """ - self.scan(hosts=hosts, arguments='-n -sP -PE -PA21,23,80,3389') - hosts_list = [(x, self[x]['status']['state']) for x in self.all_hosts()] - for host, status in hosts_list: - print('{0}:{1}'.format(host, status)) - - def nmap_version(self): - """ Get nmap version being used """ - - return self.nmapVersion() - - def command_line(self): - """ Run nmap.command_line """ - - return self.command_line - - def cipher_check(self, hostname, portrange): - """ Run --script ssl-enum-ciphers on hostname """ - - return self.scan(hostname, - portrange, - arguments='--script ssl-enum-ciphers') - - def get_csv(self): - """ Run scan.csv() """ - - return self.csv() - - def all_tcp(self, hostname=False): - """ Get all ports for tcp protocol in sorted output """ - if hostname: - return self[hostname].all_tcp() - - return self[self.hostname].all_tcp() - - def all_udp(self, hostname=False): - """ Get all ports for udp protocol in sorted output - requires scanHost() or scan() to be run first - """ - if hostname: - return self[hostname].all_udp() - - return self[self.hostname].all_udp() - - def banner_grab(self, portrange, hostname=False): - """ Grab banners from ports """ - - if hostname: - return self.scan(hostname, portrange, - arguments='-sV --script=banner') - return self.scan(self.hostname, portrange, - arguments='-sV --script=banner') - -``` diff --git a/_100-days-of-code/2018-01-01-100-days-of-code-day007.markdown b/_100-days-of-code/2018-01-01-100-days-of-code-day007.markdown deleted file mode 100644 index 3a91428..0000000 --- a/_100-days-of-code/2018-01-01-100-days-of-code-day007.markdown +++ /dev/null @@ -1,15 +0,0 @@ ---- -layout: post -title: "day 7" -date: 2018-01-08 -categories: programming ---- - -# 100 Days of Code - -### Day 7: -Took a break from coding on Sunday. Needed to take care of some things around -my apartment instead. Today, I ended up programming for a few hours while at -work. I learned more about initialization of objects and about unpacking -tuples. - diff --git a/_100-days-of-code/2018-01-01-100-days-of-code-day008.markdown b/_100-days-of-code/2018-01-01-100-days-of-code-day008.markdown deleted file mode 100644 index 32900e6..0000000 --- a/_100-days-of-code/2018-01-01-100-days-of-code-day008.markdown +++ /dev/null @@ -1,15 +0,0 @@ ---- -layout: post -title: "day 8" -date: 2018-01-09 -categories: programming ---- - -# 100 Days of Code - -### Day 8: -I installed the [xonsh](http://xon.sh/) shell on my home system after a -co-worker introduced me to it earlier today. I am going to be experimenting with it all night -and configuring it with runtime configs and importing my bash aliases and -functions. This is a really cool shell that will help me accelerate how quickly -I learn core skills of python. It's like Ipython and bash had a baby! I am in! diff --git a/_100-days-of-code/2018-01-01-100-days-of-code-day009.markdown b/_100-days-of-code/2018-01-01-100-days-of-code-day009.markdown deleted file mode 100644 index 6ed7282..0000000 --- a/_100-days-of-code/2018-01-01-100-days-of-code-day009.markdown +++ /dev/null @@ -1,14 +0,0 @@ ---- -layout: post -title: "day 9" -date: 2018-01-10 -categories: programming ---- - -# 100 Days of Code - -### Day 9: -Going to be writing some more add-ons to nmap module. Also, added an example of -a bubble sort algorithm in python, and accompanied it with a wikipedia -description of the algorithm. I am going to be looking into implementing -another type of sorting algorithm today. diff --git a/_100-days-of-code/2018-01-01-100-days-of-code-day010.markdown b/_100-days-of-code/2018-01-01-100-days-of-code-day010.markdown deleted file mode 100644 index 1e5608d..0000000 --- a/_100-days-of-code/2018-01-01-100-days-of-code-day010.markdown +++ /dev/null @@ -1,95 +0,0 @@ ---- -layout: post -title: "day 10" -date: 2018-01-11 -categories: programming ---- - -# 100 Days of Code - -### Day 10: -Made fibonacci programs from tutorials I found on youtube. One that introduces -the concept of memoization or storing results of recent function calls to -improve the speed of the recursive function. Also a basic bubblesort program in python -that I found from another tutorial. This is very basic stuff but I want to make sure I -know as much foundational knowledge as I can. Socrataca on youtube is a great -channel with lots of math and science themed videos. That is where I found -these tutorials. Here is a -[link](https://www.youtube.com/watch?v=Qk0zUZW-U_M&list=PLi01XoE8jYohWFPpC17Z-wWhPOSuh8Er-&index=18) -to the python video on the fibonacci sequence. -##### No Cache - -```python - -#!/usr/bin/env python3 -# this shows the fibonacci sequence with basic recursion. -# note that it gets very slow at the end due to the recursion - - -def fibonacci(n): - if n == 1: - return 1 - elif n == 2: - return 1 - elif n > 2: - return fibonacci(n-1) + fibonacci(n-2) - - -for n in range(1, 101): - print(n, ":", fibonacci(n)) -``` -#### Cache -```python - -#!/usr/bin/env python3 -# this introduces recursive fibonacci with a cache of recent function calls -# this is introducing memoization: caching recent function call results - -fibonacci_cache = {} - - -def fibonacci(n): - # If we have cached the value, then return it - if n in fibonacci_cache: - return fibonacci_cache[n] - - # compute nth term - if n == 1: - value = 1 - elif n == 2: - value = 1 - elif n > 2: - value = fibonacci(n-1) + fibonacci(n-2) - - fibonacci_cache[n] = value - return value - - -for n in range(1, 101): - print(n, ":", fibonacci(n)) -``` -#### Cache using functools lru_cache -```python -#!/usr/bin/env python3 -from functools import lru_cache - -@lru_cache(maxsize = 1000) -def fibonacci(n): - # check if type is positive int - if type(n) != int: - raise TypeError("n must be a positive int") - if n < 1: - raise ValueError("n must be a positive int") - - if n == 1: - return 1 - elif n == 2: - return 1 - elif n > 2: - return fibonacci(n-1) + fibonacci(n-2) - - -for n in range(1, 501): - print(n, ":", fibonacci(n)) -``` - diff --git a/_100-days-of-code/2018-01-01-100-days-of-code-day011.markdown b/_100-days-of-code/2018-01-01-100-days-of-code-day011.markdown deleted file mode 100644 index 1a4e316..0000000 --- a/_100-days-of-code/2018-01-01-100-days-of-code-day011.markdown +++ /dev/null @@ -1,34 +0,0 @@ ---- -layout: post -title: "day 11" -date: 2018-01-17 -categories: programming ---- - -# 100 Days of Code - -### Day 11: -Took a break on the weekend, but I am back at it. Today, I made a class for -decoding json data. Here is the code. I can use this with my xonsh shell now so -its proving to be useful. - -```python - -import os -import json -from pprint import pprint - -class JsonUtils(object): - """ Json utility library """ - - - def decode(self, json_file): - """ Decode a json string or file that contains json """ - if os.path.isfile(json_file): - with open(json_file, 'r'): - data = json.load(json_file) - return pprint(data) - else: - data = json.loads(json_file) - return pprint(data) -``` diff --git a/_100-days-of-code/2018-01-01-100-days-of-code-day012.markdown b/_100-days-of-code/2018-01-01-100-days-of-code-day012.markdown deleted file mode 100644 index e59e4be..0000000 --- a/_100-days-of-code/2018-01-01-100-days-of-code-day012.markdown +++ /dev/null @@ -1,19 +0,0 @@ ---- -layout: post -title: "day 12" -date: 2018-01-18 -categories: programming ---- - -# 100 Days of Code - -### Day 12: -Today I made basic aws scripts that interact with ec2 and s3. I am going to look -into designing programs that will migrate my existing OVH vps using a -combination of the API they provide, unix tools like rsync, and the AWS API. I -need to get better at interacting with boto3 so this will be perfect. -interacting with API's is fun and I really enjoy working with the HTTP -protocol. I also made a cronjob on my vps that will run a git pull of my -brendan.mcdevitt.tech repo, and jekyll is in watch mode so it will always stay -up to date as long as I am pushing to git. - diff --git a/_100-days-of-code/2018-01-01-100-days-of-code-day013.markdown b/_100-days-of-code/2018-01-01-100-days-of-code-day013.markdown deleted file mode 100644 index 5cc4305..0000000 --- a/_100-days-of-code/2018-01-01-100-days-of-code-day013.markdown +++ /dev/null @@ -1,67 +0,0 @@ ---- -layout: post -title: "day 13" -date: 2018-01-19 -categories: programming ---- - -# 100 Days of Code - -### Day 13: -Today I made a script that uses the Steam HTTP API to iterate through all -possible games/apps on steam and outputs the game/app name, and current player -count. It is a fun way for me to practice interacting with json dictionaries. - -```python -import json -import requests - -BASE_URL = 'https://api.steampowered.com' - - -def main(): - """ Loop through list of appids and feed appid list into retrieval of - current players in game corresponding to appid - """ - - appnames, appids = zip(*get_appid()) - - for appname, appid in zip(appnames, appids): - resp_data = json.loads(get_current_players(appid)) - player_count = resp_data['response']['player_count'] - print('Game Name: {}'.format(appname)) - print('Current Players: {}\n'.format(player_count)) - - -def get_current_players(appid): - """ Queries Steam API for number of current players in a game - - :param appid: The appid of the game title - :param type: `str` - - :returns: Returns string json response of number of current players - :rtype: `str` - """ - - url = '{}/ISteamUserStats/GetNumberofCurrentPlayers/v1/?key=KEY&format=json&appid={}'.format(BASE_URL, appid) - r = requests.get(url) - return r.text - - -def get_appid(): - """ Queries Steam API for appids - :returns: (appname, appid) - :rtype: `tuple` - """ - url = '{}/ISteamApps/GetAppList/v2'.format(BASE_URL) - r = requests.get(url) - json_data = json.loads(r.text) - apps = json_data['applist']['apps'] - appname_and_id = [(dic['name'], dic['appid']) for dic in apps] - - return appname_and_id - - -if __name__ == '__main__': - main() -``` diff --git a/_100-days-of-code/index.html b/_100-days-of-code/index.html deleted file mode 100644 index 43048ef..0000000 --- a/_100-days-of-code/index.html +++ /dev/null @@ -1,11 +0,0 @@ - - -
- -{% for item in site.100-days-of-code %} -{{ item.description }}
- -{% endfor %} - - diff --git a/_config.yml b/_config.yml index 8d806c6..1b0f6fa 100644 --- a/_config.yml +++ b/_config.yml @@ -14,7 +14,7 @@ # You can create any custom variable you would like, and they will be accessible # in the templates via {{ site.myvariable }}. title: brendan.mcdevitt.tech -email: bpmcdevitt@thelinuxspace.com +email: brendan@mcdevitt.tech description: > # this means to ignore newlines until "baseurl:" computers, free software, infosec, programming, gaming, system administration baseurl: "" # the subpath of your site, e.g. /blog @@ -27,9 +27,9 @@ markdown: kramdown theme: minima plugins: - jekyll-feed -collections: - 100-days-of-code: - output: true +#collections: +# 100-days-of-code: +# output: true # Exclude from processing. # The following items will not be processed, by default. Create a custom list diff --git a/_layouts/default.html b/_layouts/default.html index 100dfd9..b5abba9 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -1,11 +1,9 @@ - +