Skip to content

Instantly share code, notes, and snippets.

@xijo
xijo / gist.rb
Created June 18, 2011 16:03
Orthrus Gist Example
require 'rubygems'
require 'typhoeus'
require 'orthrus'
require 'json'
class Gist
include Orthrus
remote_defaults :base_uri => "http://gist.github.com"
define_remote_method :index, :path => "/api/v1/:format/gists/:login",
@xijo
xijo / bootstrap_pagination_renderer.rb
Created August 24, 2011 21:07
WillPaginate custom link renderer for twitters bootstrap pagination structure
class BootstrapPaginationRenderer < WillPaginate::ViewHelpers::LinkRenderer
include ActionView::Helpers::UrlHelper
def to_html
@current_page = @collection.current_page.to_i
links = @options[:page_links] ? windowed_links : []
links.unshift(page_link_or_span(previous_page, 'prev', @options[:previous_label].html_safe))
links.push(page_link_or_span(next_page, 'next', @options[:next_label].html_safe))
@xijo
xijo / oembed_translator.rb
Created November 28, 2012 23:34
Alternative oembed solutions
class OembedTranslator
include ActionView::Helpers::TagHelper
# usual stuff over here..
def embed
@content.gsub(/(?:<a.+?<\/a>)|((?:www|https?).*?)(?=\s|\Z)/) do |match|
match.present? or next # regexp not perfect yet, there are nil matches for some reason
oembed_code_for(match)
end
@xijo
xijo / .bash_profile
Last active December 26, 2015 12:39
.bash_profile
source /usr/local/opt/chruby/share/chruby/chruby.sh
source /usr/local/opt/chruby/share/chruby/auto.sh
source ~/.git-completion.bash
# source ~/.rake_cap_bash_autocomplete.sh
export EDITOR='subl -w'
export SKIP_CLEANUP_DIRECTORIES='1'
export ANSIBLE_REMOTE_USER='johannes.opper'
@xijo
xijo / confluence_pre.rb
Created January 28, 2015 20:47
Draft for a reverse_markdown-confluence gem
class ConfluencePre < ReverseMarkdown::Converters::Pre
def extract_language(node)
brush = node['class'].to_s[/brush:\s?(:?.*);/, 1]
brush || super
end
end
ReverseMarkdown::Converters.register :pre, ConfluencePre.new
require 'ffi'
module Hello
extend FFI::Library
ffi_lib 'target/release/libembed.dylib'
attach_function :process, [ :string ], :string
end
puts Hello.process('foo')
@xijo
xijo / Vagrantfile
Created July 13, 2015 20:20
Vagrant file, ready for local ansible development
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
remote_user = ENV['ANSIBLE_REMOTE_USER']
raise "You need to set ANSIBLE_REMOTE_USER in your shell" unless remote_user
@xijo
xijo / encoding_repairer.rb
Created August 3, 2015 15:55
Repair utf-8 strings that contain iso-8599 encoded utf-8 characters
class EncodingRepairer
REPLACEMENTS = {
"€" => "€", "‚" => "‚", "„" => "„", "…" => "…", "ˆ" => "ˆ",
"‹" => "‹", "‘" => "‘", "’" => "’", "“" => "“", "â€" => "”",
"•" => "•", "–" => "–", "—" => "—", "Ëœ" => "˜", "â„¢" => "™",
"›" => "›", "Å“" => "œ", "Å’" => "Œ", "ž" => "ž", "Ÿ" => "Ÿ",
"Å¡" => "š", "Ž" => "Ž", "¡" => "¡", "¢" => "¢", "£" => "£",
"¤" => "¤", "Â¥" => "¥", "¦" => "¦", "§" => "§", "¨" => "¨",
"©" => "©", "ª" => "ª", "«" => "«", "¬" => "¬", "®" => "®",
@xijo
xijo / subl_conf.json
Created September 15, 2015 23:29
Sublime Config
{
"auto_complete": true,
"color_inactive_tabs": true,
"color_scheme": "Packages/Theme - Afterglow/Afterglow.tmTheme",
"copy_with_empty_selection": true,
"ensure_newline_at_eof_on_save": true,
"file_exclude_patterns":
[
".tags*",
"tags",
[
{ "keys": ["ctrl+alt+a"], "command": "alignment" },
{ "keys": ["super+,"], "command": "reveal_in_side_bar"},
{ "keys": ["super+alt+r"], "command": "goto_definition" },
// Clipboard manager
{ "keys": ["super+x"], "command": "clipboard_manager_cut" },
{ "keys": ["super+c"], "command": "clipboard_manager_copy" },
{ "keys": ["super+v"], "command": "clipboard_manager_paste", "args": { "indent": true } },
{ "keys": ["super+ctrl+v"], "command": "clipboard_manager_paste", "args": { "indent": false } },
{ "keys": ["super+shift+v"], "command": "clipboard_manager_previous_and_paste" },