Skip to content

Instantly share code, notes, and snippets.

@dpapathanasiou
dpapathanasiou / gist:2790853
Created May 25, 2012
Using Microsoft’s Translator API with Python
View gist:2790853
#!/usr/bin/python
"""
msmt.py
Functions to access the Microsoft Translator API HTTP Interface, using python's urllib/urllib2 libraries
"""
import urllib, urllib2
@dpapathanasiou
dpapathanasiou / gist:2790864
Created May 25, 2012
Using lxml to parse the Microsoft API translation result from the xml
View gist:2790864
#!/usr/bin/python
from lxml import etree
def get_text_from_msmt_xml (xml):
"""Parse the xml string returned by the MS machine translation API, and return just the text"""
text = []
doc = etree.fromstring(xml)
for elem in doc.xpath('/foo:string', namespaces={'foo': 'http://schemas.microsoft.com/2003/10/Serialization/'}):
@dpapathanasiou
dpapathanasiou / text_grabber.py
Created Oct 27, 2012
How to extract just the text from html page articles
View text_grabber.py
"""
A series of functions to extract just the text from html page articles
"""
from lxml import etree
default_encoding = "utf-8"
def newyorker_fp (html_text, page_encoding=default_encoding):
"""For the articles found on the 'Financial Page' section of the New Yorker's website
@dpapathanasiou
dpapathanasiou / gist:4329613
Created Dec 18, 2012
Simple Social Media "Share" Buttons
View gist:4329613
<div><!-- social media share buttons -->
<a href="http://www.facebook.com/" onclick="window.location = 'http://www.facebook.com/share.php?u=' + encodeURIComponent(window.location); return false"><img src="http://i.imgur.com/aLnZg.png" alt="Share on Facebook" border="0" /></a>
<a href="http://twitter.com/" onclick="window.location = 'http://twitter.com/home/?status=' + encodeURIComponent(window.location); return false"><img src="http://i.imgur.com/oFrLG.png" alt="Tweet This" border="0" /></a>
<a href="http://www.linkedin.com/" onclick="window.location = 'http://www.linkedin.com/shareArticle?mini=true&url=' + encodeURIComponent(window.location); return false"><img src="http://i.imgur.com/mwHNU.png" alt="Share on LinkedIn" border="0" /></a>
<a href="https://plus.google.com/" onclick="window.location = 'https://plus.google.com/share?url=' + encodeURIComponent(window.location); return false"><img src="http://i.imgur.com/tzMMp.png" alt="Share on Google+" border="0" /></a>
@dpapathanasiou
dpapathanasiou / sha1sum.sh
Last active Dec 16, 2015
Since mac osx does not have the sha1sum tool installed (why, Apple, why?) this script gets openssl to produce the same output.
View sha1sum.sh
#!/bin/sh
# since mac osx does not have the sha1sum tool installed
# this script gets openssl to produce the same output
if [ $# -ne 1 ]
then
echo "Usage:\n\n$0 [file to check]"
else
openssl sha1 $1 | sed 's/.*(\(.*\))= \(.*\)$/\2 \1/'
@dpapathanasiou
dpapathanasiou / mouseTrackPlot.R
Created Jun 19, 2013
This gist contains functions to plot the data logged by the buckabuckaboo plugin (https://github.com/dpapathanasiou/buckabuckaboo) as an animated sequence of lines per distinct IP address (visitor) against a grayed-out background image which represents the page on the site being monitored using R (http://www.r-project.org/).
View mouseTrackPlot.R
#
# mouseTrackPlot.R
#
# Functions to plot the data logged by the buckabuckaboo plugin (https://github.com/dpapathanasiou/buckabuckaboo)
# as an animated sequence of lines per distinct IP address (visitor) against a grayed-out background image
# which represents the page on the site being monitored using R (http://www.r-project.org/).
#
# To run this inside an R repl, use these commands:
#
# > source("mouseTrackPlot.R")
View camel.pl
#!/usr/bin/perl -w # camel code
use strict;
$_='ev
al("seek\040D
ATA,0, 0;");foreach(1..3)
{<DATA>;}my @camel1hump;my$camel;
my$Camel ;while( <DATA>){$_=sprintf("%-6
9s",$_);my@dromedary 1=split(//);if(defined($
_=<DATA>)){@camel1hum p=split(//);}while(@dromeda
@dpapathanasiou
dpapathanasiou / Makefile
Last active Aug 29, 2015
Makefile for libmodbus
View Makefile
SHELL = /bin/sh
CC = gcc
FLAGS = -I /usr/local/include/modbus
LDIR = /usr/local/lib
LIBS = -lmodbus
%: %.c
$(CC) $(FLAGS) $^ -o $@ -L$(LDIR) $(LIBS)
@dpapathanasiou
dpapathanasiou / dst.py
Created Aug 16, 2014
How to tell if Daylight Savings Time is in effect using Python
View dst.py
from datetime import datetime
import pytz
def is_dst ():
"""Determine whether or not Daylight Savings Time (DST)
is currently in effect"""
x = datetime(datetime.now().year, 1, 1, 0, 0, 0, tzinfo=pytz.timezone('US/Eastern')) # Jan 1 of this year
y = datetime.now(pytz.timezone('US/Eastern'))
@dpapathanasiou
dpapathanasiou / ComodoSSL_HOWTO.md
Last active Jan 10, 2019
Installing Comodo SSL Certificates
View ComodoSSL_HOWTO.md

Create the Certificate Signing Request (CSR) file

openssl req -nodes -newkey rsa:4096 -keyout example_com.key -out example_com.csr

Prepare the Bundle file

Unzip the file Comodo sends back and create a single certificate bundle file.