git clone https://gist.github.com/ishu3101/6fb35afd237e42ef25f9
mv 6fb35afd237e42ef25f9 ConvertTo-Markdown
cd ConvertTo-Markdown
| # Author: Vlad Niculae <[email protected]> | |
| # Makes use of memory_profiler from Fabian Pedregosa | |
| # available at https://github.com/fabianp/memory_profiler | |
| from IPython.core.magic import Magics, line_magic, magics_class | |
| class MemMagics(Magics): | |
| @line_magic | |
| def memit(self, line='', setup='pass'): |
| #!/usr/bin/env python3 | |
| import sys | |
| import subprocess | |
| print(sys.argv[1]) | |
| with open(sys.argv[1]) as file: | |
| changed = file.read().replace('jane', 'jdoe') | |
| file.seek(0) |
| #!/bin/bash | |
| > oldFiles.txt | |
| files=$(grep ' jane ' ../data/list.txt | cut -d ' ' -f 3 -s) #--output-delimiter='/n') | |
| echo $files | |
| cd .. | |
| echo $PWD |
| import os | |
| import csv | |
| # Create a file with data in it | |
| def create_file(filename): | |
| with open(filename, "w") as file: | |
| file.write("name,color,type\n") | |
| file.write("carnation,pink,annual\n") | |
| file.write("daffodil,yellow,perennial\n") | |
| file.write("iris,blue,perennial\n") |
| import os | |
| import csv | |
| # Create a file with data in it | |
| def create_file(filename): | |
| with open(filename, "w") as file: | |
| file.write("name,color,type\n") | |
| file.write("carnation,pink,annual\n") | |
| file.write("daffodil,yellow,perennial\n") | |
| file.write("iris,blue,perennial\n") |
| import os | |
| def new_directory(directory, filename): | |
| # Before creating a new directory, check to see if it already exists | |
| if os.path.isdir(directory) == False: | |
| os.mkdir(directory) | |
| # Create the new file inside of the new directory | |
| os.chdir(directory) | |
| if os.path.isfile(filename) == False: |
| import os | |
| def parent_directory(): | |
| # Create a relative path to the parent | |
| # of the current working directory | |
| os.chdir('..') | |
| relative_parent = os.path.abspath(os.getcwd()) | |
| # Return the absolute path of the parent directory | |
| return relative_parent |
| def file_date(filename): | |
| # Create the file in the current directory | |
| # For mknod the root priveleges are required | |
| os.mknod(filename) | |
| timestamp = os.path.getmtime(filename) | |
| # Convert the timestamp into a readable format, then into a string | |
| time = datetime.datetime.fromtimestamp(timestamp) | |
| time = str(time) | |
| # Return just the date portion | |
| # Hint: how many characters are in “yyyy-mm-dd”? |
| import os | |
| def create_python_script(filename): | |
| comments = "# Start of a new Python program" | |
| with open(filename, 'a+') as f: | |
| f.write(comments) | |
| print(f.read()) | |
| filesize = os.path.getsize(filename) | |
| return(filesize) |