Skip to content

Instantly share code, notes, and snippets.

View yakovenkodenis's full-sized avatar
:octocat:

Denis Yakovenko yakovenkodenis

:octocat:
View GitHub Profile
/* bling.js */
window.$ = document.querySelectorAll.bind(document)
Node.prototype.on = window.on = function (name, fn) {
this.addEventListener(name, fn)
}
NodeList.prototype.__proto__ = Array.prototype
@yakovenkodenis
yakovenkodenis / capybara.rb
Created July 31, 2015 19:26
Capybara example
def sign_up(subdomain)
visit root_url(subdomain: false)
click_link 'Create Account'
fill_in 'Name', with: 'Denis'
fill_in 'Email', with: '[email protected]'
fill_in 'Password', with: 'pw'
fill_in 'Password confirmation', with: 'pw'
fill_in 'Subdomain', with: subdomain
click_button 'Create Account'
@yakovenkodenis
yakovenkodenis / FactoryGirl.rb
Created July 31, 2015 19:29
FactoryGirl example
# Пример файла в папке spec/factories
FactoryGirl.define do
factory :project do
sequence(:name) { |n| "My Project #{n}" }
client 'My Client'
archived false
end
end
# Использование в спеках
@yakovenkodenis
yakovenkodenis / Shoulda_matchers.rb
Created July 31, 2015 19:32
Model validations/assosiations spec
RSpec.describe Account, type: :model do
describe 'validations' do
it { should validate_presence_of :owner }
it { should validate_presence_of :subdomain }
it { should validate_uniqueness_of :subdomain }
it { should allow_value('denis').for(:subdomain) }
it { should allow_value('test').for(:subdomain) }
it { should_not allow_value('www').for(:subdomain) }
@yakovenkodenis
yakovenkodenis / rAF.js
Last active August 29, 2015 14:27 — forked from paulirish/rAF.js
requestAnimationFrame polyfill
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
// MIT license
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
@yakovenkodenis
yakovenkodenis / pubsub.js
Last active August 29, 2015 14:27 — forked from learncodeacademy/pubsub.js
Basic Javascript PubSub Pattern
//events - a super-basic Javascript (publish subscribe) pattern
var events = {
events: {},
on: function (eventName, fn) {
this.events[eventName] = this.events[eventName] || [];
this.events[eventName].push(fn);
},
off: function(eventName, fn) {
if (this.events[eventName]) {
@yakovenkodenis
yakovenkodenis / ceasar_cipher_and_cracker.py
Last active February 25, 2016 21:58
Encryptor, decryptor and cracker for the Ceasar cipher
import numpy as np
def cipher(text, alphabet='abcdefghijklmnopqrstuvwxyz', key=0):
result = ""
alphabet = alphabet.lower()
n = len(alphabet)
for char in text:
if char.isalpha():
new_char = alphabet[(alphabet.find(char.lower()) + key) % n]
@yakovenkodenis
yakovenkodenis / onetimepad.py
Created February 26, 2016 08:34
One Time Pad
import binascii
import itertools
def xor_strings(a, b):
return ''.join(
[chr(ord(x) ^ ord(y)) for x, y in zip(a, itertools.cycle(b))])
def xor_hex_strings(a, b):
@yakovenkodenis
yakovenkodenis / DES.py
Created May 1, 2016 09:21
DES algorithm that works with bit arrays and uses PKCS7 padding
import bitarray
import itertools
from collections import deque
class DES(object):
_initial_permutation = [
58, 50, 42, 34, 26, 18, 10, 2,
60, 52, 44, 36, 28, 20, 12, 4,
@yakovenkodenis
yakovenkodenis / rsa.py
Last active May 1, 2016 12:39
Simple RSA implementation that stores cipher array as a json string in base64.
import json
from random import randint
class RSA(object):
def __init__(self):
self.p, self.q = self.gen_p_q()
self.N = self.p * self.q
self.phi = self.euler_function(self.p, self.q)