This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Primes do | |
# Print out first N prime numbers | |
def get(n) do | |
Stream.iterate(1, &(&1 + 1)) | |
|> Enum.reduce_while(0, fn number, count -> | |
print_if_prime(n, count, number) | |
end) | |
end | |
defp print_if_prime(n, count, _) when count >= n, do: {:halt, count} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# THIS DESTROYS MANY HEROKU APPS!!!! | |
# USE CAUTION! | |
# ИСПОЛЬЗУЙ ВНИМАНИЕ! | |
KEYWORD = diesel | |
heroku apps -A | grep $KEYWORD | cut -d' ' -f1 | xargs -L1 bash -c 'app=$0; heroku apps:destroy --app $app --confirm $app' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rm -rf mrd.log | |
rm -rf mrd.err | |
# Anything in round braces is a subshell. By default it runs in foreground as well, | |
# but if you add "&" at the end - it would run as a sub-process. | |
( | |
echo "Waiting for mrd to start." | |
while true; do | |
sleep 1s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def export_to_csv(csv, record) | |
row = [] | |
row << record.id | |
row << record.title | |
row << record.owner.name | |
row << record.get_validation_data(RecordValidator.instance) | |
# More boring-ass code like that here. | |
# ... | |
rescue Exception => ex | |
error = Exception.new("#{ex.message}, on #{record.class} ID #{record.id}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def export_to_csv(csv, record) | |
row = [] | |
row << record.id | |
row << record.title | |
row << record.owner.name | |
row << record.get_validation_data(RecordValidator.instance) | |
# More boring-ass code like that here. | |
# ... | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MigrateToNewContentStructure < ActiveRecord::Migration | |
FIND_EMBEDDED_RECIPE_REGEX = /!insert_recipe\((\d+)\)/ | |
def up | |
ActiveRecord::Base.transaction do # Just wrap the bastard in the transaction block. | |
Recipe.all.each do |recipe| | |
recipe.content_block = ContentBlock.create!(...) | |
recipe.save! | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This class uses the pdftk toolkit. | |
class PdfToolkit | |
# Merges some pdf files to output file | |
# | |
# options | |
# :from_files - array of source pdf files | |
# :to_file - output file | |
# |