Skip to content

Instantly share code, notes, and snippets.

View Achillefs's full-sized avatar

Achilles Charmpilas Achillefs

View GitHub Profile

Keybase proof

I hereby claim:

  • I am Achillefs on github.
  • I am magus (https://keybase.io/magus) on keybase.
  • I have a public key whose fingerprint is 2956 6B17 6EB2 1F74 D63A 4EEA 3A7A 7022 8708 136C

To claim this, I am signing this object:

@Achillefs
Achillefs / string.rb
Created December 3, 2012 23:56
Lightweight html extraction
class String
def links
self.scan /<a href\=\"[^"]*\"[^>]*>[^<]*<\/a>/
end
def images
self.scan /<img src\=\"[^"]*\"[^>]*>/
end
end
@Achillefs
Achillefs / article.rb
Created December 9, 2011 16:17
Sample Article class posting to a Wordpress blog via wp-json-api
require 'rubygems'
require 'open-uri'
require 'json'
require 'net/http'
# Please note that the vanilla wp-json-api plugin does not support user authentication for create_post.
# Check out my fork for authentication support: https://github.com/Achillefs/wp-json-api
class Article
API_URI = 'http://mywpblog.com/api/'
API_USER = 'my_wp_username'
@Achillefs
Achillefs / sitemap_generator.rb
Created October 26, 2011 17:21
Sitemap Generator
class SitemapGenerator
# For Rails 3.*, replace with include Rails.application.routes.url_helper
include ActionController::UrlWriter
def initialize model_name, options = {}
@host = options.delete(:host) || default_url_options[:host]
@model_name = model_name
@file = options.delete(:file) || model_name.to_s.pluralize
@changefreq = options.delete(:changefreq) || 'daily'
@lastmod = options.delete(:lastmod_method) || :updated_at
@Achillefs
Achillefs / gist:1004409
Created June 2, 2011 13:21
crawl_website.rb
%W[rubygems anemone].each {|r| require r}
site_root = "http://www.whatever.org/"
# Create the root folder
folder = URI.parse(site_root).host
FileUtils.mkdir_p(File.join(".",folder))
Anemone.crawl(site_root) do |anemone|
anemone.on_every_page do |page|
@Achillefs
Achillefs / permalink_fu.rb
Created April 18, 2011 12:56
Patched PermalinkFu to use I18n.transliterate on string
@Achillefs
Achillefs / transliterations.yml
Created April 18, 2011 12:52
Greek transliteration table for rails applications
el:
i18n:
transliterate:
rule:
α: a
ά: a
Α: a
Ά: a
β: v
Β: v
@Achillefs
Achillefs / google_product_api.rb
Created April 13, 2011 16:03
Perform product searches using the new Google Products API
require "uri"
require "active_support"
# Get auth token from Googles
auth_uri = "https://www.google.com/accounts/ClientLogin"
params = {
"accountType" => "HOSTED_OR_GOOGLE",
"Email" => "yer_gmail",
"Passwd" => "yer_gpass",
"source" => "organization-appname-version",
@Achillefs
Achillefs / autometal_net_http.rb
Created November 29, 2010 14:51
Net::HTTP with multiple bind address functionality
require "net/http"
module Net
class HTTP
alias :old_connect :connect
def connect
D "opening connection to #{conn_address()}..."
begin # HACK START
s = timeout(@open_timeout) do
TCPSocket.open(conn_address(), conn_port(), App.available_ip_addresses.rand)
end
@Achillefs
Achillefs / add_newlines_to_xml.rb
Created October 18, 2010 11:29
Add newlines to long ass XML files
Dir[File.join(%w[test fixtures files *.xml])].each do |file|
xml = File.read(file)
matches = xml.scan("\n")
if !matches or matches.size < 3
puts "#{file}: Not enough line brakes, adding them now..."
File.open(file,"w") do |f|
f.puts(xml.gsub(/(<[^\/]*>)/,"\n\\1"))
end
end
end