This file contains hidden or 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 Levenshtein do | |
| def first_letter_check(one_letter, two_letter) do | |
| case one_letter == two_letter do | |
| true -> 0 | |
| false -> 1 | |
| end | |
| end | |
| def distance(string_1, string_1), do: 0 | |
| def distance(string, ''), do: :string.len(string) |
This file contains hidden or 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 | |
| APP="my-app" | |
| REMOTE_USER="deployer" | |
| SERVER="example.com" | |
| BUILD_DIR="/usr/src/${APP}" | |
| DEPLOY_DIR="/opt/${APP}" | |
| ############ |
This file contains hidden or 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
| # I've used the configuration below for all my nginx instances and gotten an A+ on the Qualys SSL Test | |
| # (https://www.ssllabs.com/ssltest/index.html). It satisfies requirements for PCI Compliance and | |
| # FIPS. Includes OCSP Stapling (http://en.wikipedia.org/wiki/OCSP_stapling) and HTTP Strict Transport | |
| # Security (http://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security). | |
| # - Not vulnerable to the Heartbleed attack. | |
| # - Not vulnerable to the OpenSSL CCS vulnerability (CVE-2014-0224) with OpenSSL v1.0.1i 6 Aug 2014 & Nginx 1.6.0 | |
| # - SSL Handshake takes <80ms on most modern server hardware | |
| # Use within the "server" scope among other directives |
This file contains hidden or 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 'active_record' | |
| require 'arel' | |
| # Ruby-like syntax in AR conditions using the underlying Arel layer (Rails >= 3.0). | |
| # | |
| # What you would usually write like this: | |
| # | |
| # User.where(["users.created_at > ? AND users.name LIKE ?", Date.yesterday, "Mary"]) | |
| # | |
| # can now be written like this (note those parentheses required by the operators precedences): |
This file contains hidden or 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 [Name]Service | |
| attr_reader :date | |
| def initialize(date) | |
| @date = date | |
| end | |
| def call | |
| end | |
| class << self |
This file contains hidden or 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 is a skeleton for testing models including examples of validations, callbacks, | |
| # scopes, instance & class methods, associations, and more. | |
| # Pick and choose what you want, as all models don't NEED to be tested at this depth. | |
| # | |
| # I'm always eager to hear new tips & suggestions as I'm still new to testing, | |
| # so if you have any, please share! | |
| # | |
| # @kyletcarlson | |
| # | |
| # This skeleton also assumes you're using the following gems: |
This file contains hidden or 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 generate_ean13(twelve) | |
| twelve = twelve.to_s | |
| return nil unless twelve.length == 12 && twelve.match(/\d{11}/) | |
| arr = (0..11).to_a.collect do |i| | |
| if (i+1).even? | |
| twelve[i,1].to_i * 3 | |
| else | |
| twelve[i,1].to_i | |
| end |
This file contains hidden or 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 'rubygems' | |
| require 'faraday' | |
| require 'socksify' | |
| require 'socksify/http' | |
| require 'awesome_print' | |
| # This is a SOCKS monkey patch for Faraday, with example use/unit test. | |
| # Notes: | |
| # * It is altered to work with SOCKS5 authentication. | |
| # * net_http_class must return a Faraday::Adapter::NetHttp instance. |
This file contains hidden or 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 HtmlTag < Parslet::Parser | |
| root(:tag) | |
| rule(:tag) do | |
| ( open_tag | close_tag | self_closing_tag ).as(:html_tag) | |
| end | |
| rule(:self_closing_tag) { str("<") >> tag_name >> attributes? >> (spaces? >> str("/")) >> str(">") } | |
| rule(:open_tag) { str("<") >> tag_name >> attributes? >> str(">") } | |
| rule(:close_tag) { str("</") >> tag_name >> str(">") } |
This file contains hidden or 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
| # | |
| # MIT License - (c) 2011 John Mettraux | |
| # | |
| require 'rubygems' | |
| require 'parslet' # gem install parslet | |
| module MyJson |