Skip to content

Instantly share code, notes, and snippets.

View eristoddle's full-sized avatar

Stephan Miller eristoddle

View GitHub Profile
@eristoddle
eristoddle / file_parser.py
Created June 7, 2012 15:19
Parse files with mod date in folders and output html
"""
I use this for files I save in Epistle for Android when I save links from my6sense. Yes, a very specific use case, but it might be useful to others.
"""
import os, time, webbrowser, glob
l = [(os.stat(i).st_mtime, i) for i in glob.glob('*txt')]
l.sort()
files = [i[1] for i in l]
files.reverse()
<?php
use lithium\core\Libraries;
use lithium\net\http\Router;
use lithium\core\Environment;
/* define lithium library path */
define('LITHIUM_LIBRARY_PATH', dirname(__DIR__) . '/lithium/libraries');
if (!include LITHIUM_LIBRARY_PATH . '/lithium/core/Libraries.php') {
$message = "Lithium core could not be found. Check the value of LITHIUM_LIBRARY_PATH in ";
$message .= __FILE__ . ". It should point to the directory containing your ";
@eristoddle
eristoddle / htaccess_hack_finder.py
Created June 28, 2012 15:33
Find .htaccess hacks in your website with Python
import os
#Replace with name of directory to scan, i.e, your WP directory
dir = "/var/www/"
#Replace with string to find, in my case, this domain, which my site was redirecting to
to_find = "vlag-nerto.ru"
for root, dirs, files in os.walk(dir):
for file in files:
fullpath = os.path.join(root, file)
@eristoddle
eristoddle / piwikSiteLog.php
Created July 11, 2012 16:16
Simple script to correlate Piwik visits with a website changes log
<?php
//The url to your Piwik folder
$p_url = "";
//The id of your site in Piwik
$site_id = "";
//Your Piwik token_auth
$token_auth = "";
function write_log($message) {
$log_file = 'logfile.txt';
@eristoddle
eristoddle / dh_dyn_dns.py
Created August 10, 2012 20:22
Dynamic DNS Script for the Dreamhost API
#!/usr/bin/python
#Adapted from http://wiki.dreamhost.com/User:Datagrok/ddns
from dreamhostapi import DreamHostServerProxy
from os import environ
import urllib2
def main():
#Your Dreamhost API key
dh_api_key = ''
@eristoddle
eristoddle / headers.php
Created August 13, 2012 03:00
JSON API headers for PHP
<?php
//JSON headers
header('Cache-Control: no-cache, must-revalidate');
header('Expires: '.gmdate('D, d M Y H:i:s', time()).' GMT');
header('Content-type: application/json; charset=utf-8');
?>
@eristoddle
eristoddle / yt1.jquery.js
Created September 19, 2012 17:22
Very specific YouTube Jquery example
(function($){
$.fn.youtube = function(options){
return this.each(function(i, obj){
var $this = $(obj),
$playBtns = $this.find('.video .play-btn'),
player,
onPlayerReady = function(){
player.playVideo();
},
loadPlayer = function(id){
@eristoddle
eristoddle / jobserver.py
Created September 19, 2012 17:30
Very Tiny Python Job Server
#!/usr/bin/python
from lib import scheduler
import datetime, time
def eristoddle_post_server(every_min, run_time_min):
from core.myWP import zem_cb_eristoddle
every_sec = 60 * every_min
run_time = 60 * run_time_min
esched = scheduler.Scheduler()
etask = scheduler.Task("eristoddle_post",
@eristoddle
eristoddle / ngrams.py
Created September 19, 2012 17:32
Python simple ngrams
def multigrams(text, lower, upper):
grams = []
for i in range(lower, upper):
grams.extend(ngrams(text, i))
return grams
def multigrams_count(text, lower, upper):
counted_grams = {}
for n in multigrams(text, lower, upper):
try:
@eristoddle
eristoddle / ezinearticles.py
Created September 19, 2012 17:34
Python scrape EzineArticles.com
def get_ezinearticles(query, limit=25):
#returns 25
#TODO: Make get_goarticles and get_articlebase
def grab_article(url):
soup = BeautifulSoup.BeautifulSoup(URL(url).download())
return {"title": select(soup,"#article-title h1")[0].contents,
"body": select(soup,"#article-content")[0].contents,
"resource": select(soup,"#article-resource")[0].contents}
query = {"q":query}
soup = BeautifulSoup.BeautifulSoup(URL('http://ezinearticles.com/search/'\