Skip to content

Instantly share code, notes, and snippets.

EdwardDiehl / xml_parser.rb
Created March 12, 2016 10:38 — forked from kmile/xml_parser.rb
A small nokogiri xml reader DSL.
# A small DSL for helping parsing documents using Nokogiri::XML::Reader. The
# XML Reader is a good way to move a cursor through a (large) XML document fast,
# but is not as cumbersome as writing a full SAX document handler. Read about
# it here:
# Just pass the reader in this parser and specificy the nodes that you are interested
# in in a block. You can just parse every node or only look inside certain nodes.
# A small example:
EdwardDiehl / download-url-to-file.rb
Created April 4, 2016 20:35 — forked from johnjohndoe/download-url-to-file.rb
Ruby script to download a number of files from individual URLs via HTTP/HTTPS/FTP specified in an external file.
#!/usr/bin/env ruby
# Ruby script to download a number of files
# from individual URLs via HTTP/HTTPS/FTP
# specified in an external file.
# Author: Tobias Preuss
# Revision: 2013-04-18 16:26 +0100 UTC
# License: Creative Commons Attribution-ShareAlike 3.0 Unported
EdwardDiehl / colors.rb
Created April 15, 2016 09:41 — forked from firedev/colors.rb
Colors.rb – Functional programming in Ruby example
#!/usr/bin/env ruby
require 'paleta'
to_paleta = ->(color) {, color) rescue nil }
to_div = ->(str) {
"<div style='font-family: sans-serif; width: 5em; height: 3em;
line-height: 3em; display: inline-block; text-align: center;
margin: 0.25em; border-radius: 0.25em; padding: 1em;
background: ##{str}'>
EdwardDiehl / functional-utils.js
Created April 17, 2016 11:05 — forked from bendc/functional-utils.js
A set of pure and immutable ES2015 functions aimed to make functional JavaScript more idiomatic.
// array utils
// =================================================================================================
const combine = (...arrays) => [].concat(...arrays);
const compact = arr => arr.filter(Boolean);
const contains = (() => Array.prototype.includes
? (arr, value) => arr.includes(value)
: (arr, value) => arr.some(el => el === value)
EdwardDiehl /
Created June 11, 2016 09:39 — forked from iamatypeofwalrus/
A Rails 4 pluck in batches implementation


Sometimes you need to iterate over a ton of items and you don't want the overhead of creating AR objects out of all of them. Hell, you only need a few things! Well, #pluck has your back.

But what if you want to iterate over many tonnes of items?

Pluck in batches to the rescue!

This isn't the exact code that I use in my code base, but it is damn close.

EdwardDiehl / description.markdown
Created January 6, 2017 11:39 — forked from runemadsen/description.markdown
Reverse polymorphic associations in Rails

Polymorphic Associations reversed

It's pretty easy to do polymorphic associations in Rails: A Picture can belong to either a BlogPost or an Article. But what if you need the relationship the other way around? A Picture, a Text and a Video can belong to an Article, and that article can find all media by calling

This example shows how to create an ArticleElement join model that handles the polymorphic relationship. To add fields that are common to all polymorphic models, add fields to the join model.

EdwardDiehl / reseed.rake
Created January 7, 2017 19:26 — forked from nithinbekal/reseed.rake
Rake task to reset and seed Rails database
# Originally written by Justin French (2008):
# Modified to work with Rails 4.
desc 'Raise an error unless development environment'
task :safety_check do
raise "You can only use this in dev!" unless Rails.env.development?
EdwardDiehl / 000_postgresql_fancy_datatypes
Created January 15, 2017 09:20 — forked from pcreux/000_postgresql_fancy_datatypes
Postgresql fancy datatypes with Rails / ActiveRecord. Run it with `rake`!
# Postgresql fancy datatypes!
* array
* hstore (=~ hash)
* json
* jsonb
Philippe Creux - [@pcreux](
EdwardDiehl /
Created August 27, 2017 06:57 — forked from monolithed/
Mocha vs. Jasmine

Почему Mocha, а не Jasmine?

Ниже будут приведены аргументы в пользу выбора Mocha

  • Высокая популярность:
    — 4m против 400k загузок в месяц

  • Высокая активность:
    — 1 890 против 1400 коммитов (всего)
    — 171 против 101 коммитов (последний год)

EdwardDiehl / 1-sleep-es7.js
Created December 21, 2017 13:02 — forked from danharper/1-sleep-es7.js
ES7's async/await syntax.
// ES7, async/await
function sleep(ms = 0) {
return new Promise(r => setTimeout(r, ms));
(async () => {
await sleep(1000);