Skip to content

Instantly share code, notes, and snippets.

@cbeier
cbeier / gist:343311
Created March 25, 2010 08:26
Convert XML to Ruby Hash (using Nokogiri)
# USAGE: Hash.from_libxml(YOUR_XML_STRING)
require 'xml/libxml'
# adapted from
# http://movesonrails.com/articles/2008/02/25/libxml-for-active-resource-2-0
class Hash
class << self
def from_libxml(xml, strict=true)
begin
XML.default_load_external_dtd = false
@kyoto
kyoto / coderwall.coffee
Created July 10, 2011 09:13
Coderwall Badge Script for Blogs (or any other Web Page)
# coderwall.coffee
# Display coderwall.com badges
username = "hermanjunge"
el = $(".coderwall")
$.getJSON "http://www.coderwall.com/#{username}.json?callback=?", (data) ->
el.empty()
for item in data.data.badges
$("<img>")
.attr(
@judofyr
judofyr / fizzbuzz.rb
Created August 1, 2012 21:37 — forked from JEG2/fizzbuzz.rb
Writing FizzBuzz with flip-flops
a=b=c=(1..100).each do |num|
print num, ?\r,
("Fizz" unless (a = !a) .. (a = !a)),
("Buzz" unless (b = !b) ... !((c = !c) .. (c = !c))),
?\n
end
@voigt
voigt / disqus.js
Last active August 31, 2016 09:06
Disqus widget for Ghost blog posts
<div id="disqus_thread"></div>
<script type="text/javascript">
var disqus_shortname = 'example'; // required: replace example with your forum shortname
var disqus_identifier = '{{post.id}}'; // make sure to use the post.id as an identifier, otherwise disqus will use the pages url per default, which might be problematic...
/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
@robd
robd / bundle_gem_libs.rb
Last active October 27, 2017 17:20
Rubymine bundle dependencies
# This script is to work round the problem of broken RubyMine dependencies for bundle files.
# It uses an undocumented feature for RubyMine (but available in Intellij Idea) to create a
# gems library xml file and update the iml file.
#
# See Rubymine issues:
# https://youtrack.jetbrains.com/issue/RUBY-16428
# https://youtrack.jetbrains.com/issue/RUBY-15026
# https://youtrack.jetbrains.com/issue/RUBY-14542
#
# Usage:
@coneybeare
coneybeare / filter.rb
Created October 2, 2012 15:14
A script for Transmission that runs after a completed download. It scans for downloaded television shows then attempts to place them in the correct organizational directory on the local machine, removing the torrent as well.
#!/usr/bin/env ruby
require 'fileutils'
# SETUP
# Details about the local transmission service
transmission_remote_location = "/usr/sbin/transmission-remote"
transmission_server_port = "mini.local:9091"
# The place where downloaded but unsorted tv show torrents land
downloads_television_directory = "/Volumes/Drobo/Downloads/Television/"
# These are my notes from the PragProg book on CoffeeScript of things that either
# aren't in the main CS language reference or I didn't pick them up there. I wrote
# them down before I forgot, and put it here for others but mainly as a reference for
# myself.
# assign arguments in constructor to properties of the same name:
class Thingie
constructor: (@name, @url) ->
# is the same as:
@ddlsmurf
ddlsmurf / output.txt
Last active May 22, 2021 11:27
YAML succinct tutorial #tutorial #yaml
# Example with basic types
---
hash:
  string: some text
  number: 12345
  array_of_bool: [on, off, true, false, yes, no]
  ruby symbol: :symbol
  array:
    - item one
    - item two
@mislav
mislav / stupid-json.rb
Created December 21, 2011 12:31
Stupid simple JSON parser & generator
# encoding: utf-8
#
## Stupid small pure Ruby JSON parser & generator.
#
# Copyright © 2013 Mislav Marohnić
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files (the “Software”), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify,
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
@ttscoff
ttscoff / cdt.bash
Created June 12, 2014 14:22
cdt function to change directory based on a tag filing system
# In my tag-filing system where top-level "context" folders are tagged with
# "=Context" tags and subfolders are tagged with "@project" tags, this function
# lets me quickly cd to any tagged folder in my filing system. The first
# argument is a context folder, the rest are a chain of subfolders. The
# subfolders don't need to be contiguous, and the matching is fuzzy.
cdt() {
local fuzzy
local root
local sub
local list