Skip to content

Instantly share code, notes, and snippets.

@moorbrook
moorbrook / gist:6bf724293aea559932ea5a8ddf2283a3
Created July 26, 2017 00:45
Find unique referrers in apache/nginx access log
# regexps found here http://www.seehuhn.de/blog/52
import re
parts = [
r'(?P<host>\S+)', # host %h
r'\S+', # indent %l (unused)
r'(?P<user>\S+)', # user %u
r'\[(?P<time>.+)\]', # time %t
r'"(?P<request>.+)"', # request "%r"
r'(?P<status>[0-9]+)', # status %>s
#List unique values in a DataFrame column
pd.unique(df.column_name.ravel())
#Convert Series datatype to numeric, getting rid of any non-numeric values
df['col'] = df['col'].astype(str).convert_objects(convert_numeric=True)
#Grab DataFrame rows where column has certain values
valuelist = ['value1', 'value2', 'value3']
df = df[df.column.isin(value_list)]
@moorbrook
moorbrook / gist:2773518
Created May 23, 2012 06:17
Workaround to reduce PDF size for MagCloud
MagCloud upload limit: 300MB
Because of buggy Acrobat and/or PDF file, using just PDF Optimizer didn't quite work, here's the workaround:
1) Use ColorSync Utility to downsample images to 300 dpi using a custom Quartz filter. Using export in Preview did not show the extra Quartz filters. You have to use ColorSync Utility.
2) Flattening transparency is critical to reducing file size.
Use PDF Optimizer in Acrobat to do this.
However, if you use [High Resolution] some of the fonts get messed up -- The solution is to create a custom transparency flattener modeled after [High Resolution] setting but with the addition of "Convert all text to outlines."
@moorbrook
moorbrook / gist:2038397
Created March 14, 2012 18:21
embed code for fanuc keysheet replacement
<object id="doc_25915" name="doc_25915" height="1000" width="100%" type="application/x-shockwave-flash" data="http://d1.scribdassets.com/ScribdViewer.swf" style="outline:none;" > <param name="movie" value="http://d1.scribdassets.com/ScribdViewer.swf"> <param name="wmode" value="opaque"> <param name="bgcolor" value="#ffffff"> <param name="allowFullScreen" value="true"> <param name="allowScriptAccess" value="always"> <param name="FlashVars" value="document_id=29210722&access_key=key-7jfj5uhqas5sfdwsi1o&page=1&viewMode=list"> <embed id="doc_25915" name="doc_25915" src="http://d1.scribdassets.com/ScribdViewer.swf?document_id=29210722&access_key=key-7jfj5uhqas5sfdwsi1o&page=1&viewMode=list" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" height="1000" width="100%" wmode="opaque" bgcolor="#ffffff"></embed> </object>
=== Epic Snow Leopard Upgrayyyyd Guide ===
Son, you’re now living in the land of 64-bit systems.
That means that some of your 32-bit shit is now broken.
Not all is lost.
== Fixing MySQL weirdness
section_179 = case 1) equip_cost if equip_cost < 250,000
case 2) 250,000 if equip_cost > 250,000 and equip_cost >= 800,000
case 3) 250,000 - (equip_cost - 800,000) if equip_cost > 800,000 and equip_cost < 1050,000
case 4) 0 if equip_cost >= 1050,000
bonus_50%_depreciation = (equip_cost - section_179) * 0.5
regular_depreciation = (equip_cost - section_179 - bonus_50%_depreciation) * 1/7
total_first_year_depreciation = section_179 + bonus_50%_depreciation + regular_depreciation