Skip to content

Instantly share code, notes, and snippets.

@AaronPhalen
AaronPhalen / python_itertools.py
Last active April 21, 2020 03:26
Useful modules and examples from Python's itertools library.
# python_itertools.py highlights useful functions in python's itertools module
# Influenced by Raymond Chandler III pyvideo.org/video/2275 (Super Advanced Python Concepts)
# Author: Aaron Phalen | Twitter: @aaron_phalen | Email: [email protected]
from itertools import chain, combinations, permutations, compress, count, cycle, groupby
# 1. Itertools Chain Example
letters = ["a", "b", "c", "d"]
numbers = [1, 2, 3]
both = chain(letters, numbers)
@AaronPhalen
AaronPhalen / singleton.py
Last active September 21, 2015 22:58
Shows basic usage of Python Singleton
# singleton.py illustrates how to use singleton design pattern in python
# influenced by Trevor Pain https://www.youtube.com/watch?v=6IV_FYx6MQA
# Author: Aaron Phalen | Twitter: @aaron_phalen | Email: [email protected]
# In python, a singleton is a design patter which allows once instance of a class to be invoked
# or stored in memory.
class Singleton(object):
_instance = None
def __new__(self):
Author: Aaron Phalen | Twitter: @aaron_phalen | email: [email protected]
Basic Linux Shell Commands (Ubuntu 12.04)
==========================================
1. grep command
---------------
The grep commands allows for search functionality when working with
output strings, files, or directories.
# Author: Aaron Phalen | Twitter: @aaron_phalen | Email: [email protected]
# Example of python class factory
# Dynamically create classes
Class1 = type("Class1", (), {"name": "class 1"})
Class2 = type("Class2", (), {"name": "class 2"})
# create factory class
class SampleClass(object):
"""class factory"""
# Author: Aaron Phalen | Twitter: @aaron_phalen | Email: [email protected]
# Builder Design Pattern In Python
# Creating xml without builder as constract to example
from lxml import etree
root = etree.Element("root")
child = etree.Element("child")
child.text = "sample text"
root.append(child)
@AaronPhalen
AaronPhalen / python_collections.py
Last active September 24, 2015 05:17
Python Collections Basic Examples
#Author: Aaron Phalen | Twitter: @aaron_phalen | Email: [email protected]
# Useful modules and examples from python's collections library
from collections import namedtuple
# 1. Python collections namedtuple
Parameters = namedtuple("Parameters", "x y z")
parameters = Parameters(x="1", y="2", z="3")
# Output
print parameters
@AaronPhalen
AaronPhalen / basic_vim_commands.md
Last active December 14, 2023 17:02
Useful Vi Editor Commands

Author: Aaron Phalen | Twitter: @aaron_phalen | Email: [email protected]

#Useful Vi Editor Commands

  1. :w --> save to a file
  2. :q --> quit out of editor file
  3. :q! --> quit out of editor without saving file
  4. w --> move one word forward at a time in file
  5. b --> move one word back at a time in file
  6. :wq --> save file and quit editor
@AaronPhalen
AaronPhalen / python_xml_parser.py
Last active October 2, 2015 09:37
A Basix example on creating xml, reading xml, manipulating xml, and xml io
# Author: Aaron Phalen | Twitter: @aaron_phalen | Email: [email protected]
# Example of parsing xml in python with various librarie: read, write, modify, io
try:
import xml.etree.cElementTree as ET
except:
import xml.etree.ElementTree as ET
from xml.dom import minidom
@AaronPhalen
AaronPhalen / linux_file_remove_restore.txt
Last active September 28, 2015 10:06
Various Linux file system commands including file recovery techniques
Linux File Remove Command And Recovery
======================================
Motivation:
Since using an Ubuntu 12.04 server for the last couple years, I had not once erroneously
keystroked a faulty rm command. As a Linux users knows, the rm commands is used to remove a file or directory.
Futhermore, like most Linux commands various options can be added, such as: -r, -f, -i, etc.
While not pertinent to the discusion, I will define these quickly for the inquisitve reader:
1. -r recursively delete directory and child files/directories.
@AaronPhalen
AaronPhalen / linux_ssh.txt
Last active December 15, 2016 07:36
Basic commands for configuring ssh in linux
Author: Aaron Phalen | Twitter: @aaromn_phalen | Email: [email protected]
Basic SSH Configuration Commands
================================
1. Installation
a) sudo apt-get install openssh-server
b) sudo apt-get install openssh-client
2. Configuration