Skip to content

Instantly share code, notes, and snippets.

View parallel588's full-sized avatar

Maksim Pechnikov parallel588

  • WELLNUTS
  • Tampere
View GitHub Profile
@parallel588
parallel588 / leven.ex
Created April 30, 2017 19:14 — forked from plukevdh/leven.ex
Levenshtein in elixir
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)
@parallel588
parallel588 / exdeploy
Created March 31, 2017 06:33 — forked from dyerc/exdeploy
A script to handle deploying a Phoenix web app
#!/bin/bash
APP="my-app"
REMOTE_USER="deployer"
SERVER="example.com"
BUILD_DIR="/usr/src/${APP}"
DEPLOY_DIR="/opt/${APP}"
############
@parallel588
parallel588 / nginx-ssl.conf
Created February 24, 2016 18:46
Configuration to get an A+ on the Qualys SSL Labs test with fast performing and low overhead SSL ciphers. Works in combination with nginx 1.6.0 full and OpenSSL v1.0.1i.
# 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
@parallel588
parallel588 / ar_arel_wrapper.rb
Created January 18, 2016 11:02 — forked from tokland/ar_arel_wrapper.rb
Simple wrapper over arel
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):
class [Name]Service
attr_reader :date
def initialize(date)
@date = date
end
def call
end
class << self
@parallel588
parallel588 / rspec_model_testing_template.rb
Last active August 29, 2015 14:26 — forked from PWSdelta/rspec_model_testing_template.rb
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# 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:
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
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.
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(">") }
#
# MIT License - (c) 2011 John Mettraux
#
require 'rubygems'
require 'parslet' # gem install parslet
module MyJson