Skip to content

Instantly share code, notes, and snippets.

@josephmosby
josephmosby / ForexPull.vb
Created December 22, 2010 16:37
Pulls Forex data from OANDA
Private Sub ForexPull()
' Created by Joseph H. Mosby on 12/22/2010
' GitHub version removes some employer-specific code
' Declare variables
Dim rngFXMo As Range
Dim rngFXDa As Range
Dim rngFXYe As Range
Dim strFXMo As String
@josephmosby
josephmosby / HideRows.vb
Created December 23, 2010 19:51
Simple script to hide spreadsheet rows based on criteria.
Sub HideRows()
Dim testRow As Integer
Dim testSht As Worksheet
Set testSht = Worksheets("Sheet1")
testRow = 2
While Cells(testRow, 1).Value <> "Total"
If Cells(testRow, 2).Value = "" And Cells(testRow, 4).Value = "" And Cells(testRow, 6).Value = "" Then
If Cells(testRow, 1).Value <> "" Then
@josephmosby
josephmosby / str2listbreaker.py
Created December 23, 2010 23:20
Python function for splitting a string into a list, no delimiters required and all characters/operators together
def propListBreaker(x):
listmsg = re.split(r'(\D)',x)
for i in listmsg:
try:
listmsg.remove("")
except:
break
return listmsg
@josephmosby
josephmosby / gist:2713759
Created May 16, 2012 20:40
The Weeds of Github

The Weeds of Markdown

Consider this a first experiment in John Gruber's Markdown. For the uninitiated, Markdown is a syntax combined with a tool that allows you to take specially formatted text and translate it into HTML. Though most out-of-the-box blogging platforms handle this conversion for bloggers, it gets a bit dicier as more customization is added.

I'm not going to get into the weeds of Markdown syntax, as Mr. Gruber's explanation is far better than mine. Instead, I'm going to do a brief intro on how to write a Python script to perform the task you'll most often need to do with Markdown: convert .md files to browser-readable HTML.

pip install markdown

The Markdown libraries are now standard in the PyPi repository and can be installed through pip (or your method of choice). Markdown has no dependencies and is a relatively quick install.

@josephmosby
josephmosby / gist:2713770
Created May 16, 2012 20:41
markdown_parser.py
import markdown
import codecs
import sys
# First argument passed in must be an MD-compliant file.
# Second argument is the file to write to.
# For discussion, check here: https://gist.github.com/2713759
md_file = codecs.open(sys.argv[1], mode='r', encoding='utf8')
md_input = md_file.read()
@josephmosby
josephmosby / gist:3008524
Created June 28, 2012 02:53
Choose Your Favorite Color
<h1>Choose Your Favorite Color</h1>
<p>You will be shown two colors side by side. Pick your favorite color of the two. This is based on your personal opinion.</p>
<p>&nbsp;</p>
<p>Choose your color:</p>
<table width="100%" cellpadding="5px" border="1" bordercolor="black">
<tbody>
<tr height="100px">
<td bgcolor="${color_hex1}"><br />
<!-- the ${color_hex1} variable is the syntax for the first color we'll input. -->
@josephmosby
josephmosby / striptags.py
Created October 1, 2012 03:30
Strip out all tags from HTML and return content
def strip_out_tags(html):
out_of_tags = []
inside_tags = []
words = []
beginning_pos = 0
end_pos = 0
if html[beginning_pos] == '<':
in_tags = True
else:
in_tags = False
@josephmosby
josephmosby / replace.py
Created October 2, 2012 23:30
Recursive Find/Replace
def apply_converter(match, replacement, test_string):
if match in test_string:
pos = test_string.find(match)
new_string = test_string.replace(match, replacement)
return apply_converter(converter, new_string)
else:
return test_string
@josephmosby
josephmosby / gist:4227884
Created December 6, 2012 20:09
Week One of Ruby on Rails: RSpec Gripe #1

This will either be the first of a series of posts on "how I became a Ruby convert" or "why Ruby is the worst language on the planet."

I've spent the last two years of my life working with Python and its popular web frameworks (Django, webapp2, and Flask). Python was the first language I ever learned, so I'm admittedly a bit biased toward the "Pythonic" way of doing things. Python favors readability of code, but it also favors exactitude. I can push bits around in memory with the same ease as a GET request. The entire community feels like it's made up of scientists who want to support that - so libraries follow the Pythonic way of doing things. Boolean tests are written the same way in each library as they are in the core Python language.

So you can imagine my frustration when I start working with Ruby on Rails... and specifically, RSpec.

Let's take a look at a webapp2 test:

import unittest
@josephmosby
josephmosby / gist:4242213
Created December 8, 2012 22:15
Week One of Ruby on Rails: Step Backwards

I am taking a step back in my Ruby on Rails journey, as it seems that my initial goals may have been a bit too ambitious.

As I said in a previous post, this is not my first foray into web applications. I've been working with Python and its associated frameworks for some time. When I was asked by a friend to work with Ruby, I thought that there would be a fair amount of similarities between Rails and Django given the structural similarities between Ruby and Python. I could not have been more wrong.

The Ruby and Python communities have taken their languages in completely different directions, and that's just fine. Ruby has no Benevolent Dictator for Life like Guido van Rossum, and 37signals has rejected any implications that their organization can be the sole deciders for Rails. That leaves a community free to evolve however it chooses to do so. There are pros and cons to this. Ruby (and consequently, Rails) has the ability to