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
<?php | |
/** | |
* Input an object, returns a json-ized string of said object, pretty-printed | |
* | |
* @param mixed $obj The array or object to encode | |
* @return string JSON formatted output | |
*/ | |
function json_encode_pretty($obj, $indentation = 0) { | |
switch (gettype($obj)) { | |
case 'object': |
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
require 'gollum/frontend/app' | |
require 'digest/sha1' | |
class App < Precious::App | |
User = Struct.new(:name, :email, :password_hash, :can_write) | |
before { authenticate! } | |
before /^\/(edit|create|delete|livepreview|revert)/ do authorize_write! ; end | |
helpers do |
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
<?php | |
/** | |
* Transforms an under_scored_string to a camelCasedOne | |
*/ | |
function camelize($scored) { | |
return lcfirst( | |
implode( | |
'', | |
array_map( |
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
module Mojibake | |
# UTF-8 content, interpreted as latin1 | |
class Utf8 | |
CANARY = "æøåÆØÅ".chars.map { |c| c.encode(Encoding::UTF_8).force_encoding(Encoding::ISO_8859_1).encode(Encoding::UTF_8) }.freeze | |
def detect?(content) | |
CANARY.any? { |c| content.include?(c) } | |
end | |
def repair(content) |
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
# Load DSL and set up stages | |
require 'capistrano/setup' | |
# Include default deployment tasks | |
require 'capistrano/deploy' | |
# Include tasks from other gems included in your Gemfile | |
# | |
# For documentation on these, see for example: | |
# |
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 EmailValidation | |
SMTP_PORT = 25 | |
CONNECTION_TIMEOUT = 3 | |
READ_TIMEOUT = 3 | |
REGEX_SMTP_ERROR_BODY_PATTERN = /(?=.*550)(?=.*(user|account|customer|mailbox)).*/i.freeze | |
def initialize(verifier_domain:, verifier_email:) | |
@verifier_domain, @verifier_email = verifier_domain, verifier_email | |
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
var listId = $(this).parents().filter(function() { return $(this).data("list-id"); }).eq(0).data("list-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
# takes an array of hashes and prints as a table on the console | |
def table_print(rows) | |
table = [rows.first.keys.map(&:to_s)] + rows.map(&:values).map { |v| v.map(&:to_s) } | |
sizes = table.map { |row| row.map(&:size) }.transpose.map(&:max) | |
puts table.map { |row| row.each_with_index.map { |txt, idx| txt.rjust(sizes[idx]) }.join("\t") }.join("\n") | |
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 RubyPrint | |
def self.pp(mixed) | |
puts new.transform(mixed) | |
end | |
def transform(mixed, indentation = 1) | |
if mixed.is_a?(Hash) | |
transform_hash mixed, indentation | |
elsif mixed.is_a?(Array) |
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
# frozen_string_literal: true | |
require "active_record" | |
module JustAndExactly | |
module ActiveRecordExtensions | |
MultipleRecordsFound = Class.new(ActiveRecord::ActiveRecordError) | |
# Like +first!+, but will also fail if the query would match more than | |
# one record. |