Skip to content

Instantly share code, notes, and snippets.

View temochka's full-sized avatar
🪒
🐃

Artem Chistyakov temochka

🪒
🐃
View GitHub Profile
module OptimizedSolution where
import Control.Monad
import Data.List
import Data.Array
import Data.Char
readToken :: IO String
readToken = do
ch <- getChar
lex ch
@temochka
temochka / keybase.md
Created July 7, 2016 14:18
Keybase.io verification

Keybase proof

I hereby claim:

  • I am temochka on github.
  • I am achistyakov (https://keybase.io/achistyakov) on keybase.
  • I have a public key whose fingerprint is 7847 35BD F6BD FFDC 2132 2837 C8A3 DEB2 CE53 62C6

To claim this, I am signing this object:

@temochka
temochka / generator.rb
Created December 15, 2015 21:46
Generates a directory with X files with name length A spread by Y directories with name length A with depth Z
require 'securerandom'
require 'fileutils'
NUM_FILES = 35000
NUM_DIRECTORIES = 5000
NAME_LENGTH = 100
MAX_DIR_DEPTH = 10
MAX_FILES_PER_DIR = 100
MAX_DIRS_PER_DIR = 100
class EmailBatch
attr_reader :messages
delegate :<<, to: :messages
def initialize(messages = [])
@messages = messages
end
def deliver_now
@temochka
temochka / cloudfront.json
Last active October 7, 2015 20:29
IAM policy to deploy to S3 subdirectory via Beanstalk/Dploy
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Stmt1422638998000",
"Effect": "Allow",
"Action": [
"cloudfront:CreateInvalidation",
"cloudfront:GetDistribution"
],
@temochka
temochka / mail.rb
Created December 21, 2014 06:35
Oh, wait, since you’ve looked, I’m a text now. Heard of quantum mechanics?
require 'mail'
msg = Mail.new { body 'Text' }
# => #<Mail::Message:70116771523620, Multipart: false, Headers: >
msg.text?
# => false
puts msg
# Date: Sun, 21 Dec 2014 01:29:26 -0500
# Message-ID: <549668c6e2caa_33e13fc554c65be84831f@Artems-MacBook-Pro.local.mail>
# Mime-Version: 1.0
@temochka
temochka / euler.erl
Last active August 29, 2015 14:06
Solving Project Euler’s problems in Erlang. Most of the proposed solutions are very naive and inefficient and therefore only viable for educational purposes (if there were any other).
-module(euler).
-compile(export_all).
%% 1
%% Find the sum of all the multiples of 3 or 5 below 1000.
problem1() ->
lists:sum([I || I <- lists:seq(0,999), I rem 3 =:= 0 orelse I rem 5 =:= 0]).
%% 2
@temochka
temochka / pack_number.clj
Created August 7, 2014 13:44
A quick & dirty number to string packing implementation
(import '[java.util Random])
(def ^:const seed 42)
(def ^Random shuffler (Random. seed))
(def alphabet (->> "abcdefghijklmnopqrstuvwxyz0123456789"
(sort-by (fn [_] (.nextInt shuffler)))
vec))
(def N (count alphabet))
(defn pack-number
([n] (pack-number n ""))
([n buf]
@temochka
temochka / bounce_dump.rb
Last active August 29, 2015 14:04
Parsing a raw Postmark bounce dump. Ruby 2.0.0, mail 2.5.4, postmark 1.1.0
require 'mail'
require 'postmark'
client = Postmark::ApiClient.new('xxxx-xxxx-xxxx-xxxx')
bounce = client.get_bounces(offset: 0, count: 1).first
dump = client.dump_bounce(bounce[:id])
msg = Mail::Message.new(dump[:body])
headers = Hash[*msg.header.fields.flat_map { |f| [f.name, f.value] }]
# => {"Return-Path"=>"", "Date"=>"Tue, 29 Jul 2014 05:50:48 -0400", "From"=>"", "To"=>"", "Message-ID"=>"", "Subject"=>"Delivery report", "Mime-Version"=>"1.0", "Content-Type"=>"multipart/report; report-type=delivery-status; boundary=\"\"", "Content-Transfer-Encoding"=>"7bit", "X-Your-Custom-Header"=>"Value"}
@temochka
temochka / postmark_rails_headers.rb
Created April 29, 2014 14:39
An example of sending custom headers with postmark-rails and ActionMailer
class TestMailer < ActionMailer::Base
def email
headers['X-Tag-Via-Hash-Access'] = 'value'
headers 'X-Tag-Via-Headers-Method' => 'value'
mail(to: 'support@postmarkapp.com', from: 'tema@wildbit.com', subject: 'Headers test') do |format|
format.text { render text: 'Headers test' }
end