Skip to content

Instantly share code, notes, and snippets.

View angelikatyborska's full-sized avatar

Angelika Tyborska angelikatyborska

View GitHub Profile
@angelikatyborska
angelikatyborska / inject_vs_each_with_object.rb
Created January 30, 2016 16:26
A comparison of Ruby's Enumerable#inject and Enumerable#each_with_object
require 'benchmark'
module InjectVsEachWithObject
ARRAY_LENGTH = 10_000
ARRAY = (1..ARRAY_LENGTH).to_a
REPETITIONS = ARGV[0].nil? ? 100 : ARGV[0].to_i
def self.immutable_inject
REPETITIONS.times do
ARRAY.inject(0) { |sum, n| sum + n }
@angelikatyborska
angelikatyborska / chars_all_vs_regexp.rb
Created February 29, 2016 11:14
Checking if a string includes only allowed characters - a comparision of using chars.all? vs. regular expressions
require 'benchmark'
module CharsAllVsRegexp
VALID_CHARS = %w(A C G T)
REGEXP = Regexp.new("\\A(#{ VALID_CHARS.join('|') })*\\z")
ARRAY_LENGTH = 10000
STRING_LENGTH = 5000
STRINGS_GENERATOOR = ->(chars) do
ARRAY_LENGTH.times.with_object([]) do |n, strings|
@angelikatyborska
angelikatyborska / .eslintrc
Created August 26, 2017 11:58
A sample Eslint configuration
{
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 7,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true,
"modules": true,
"experimentalObjectRestSpread": true
}
@angelikatyborska
angelikatyborska / .stylelintrc
Last active August 26, 2017 11:59
A sample stylelint configuration
{
"defaultSeverity": "warning",
"plugins": [
"stylelint-scss",
"stylelint-order"
],
"extends": "stylelint-config-sass-guidelines",
"rules": {
"scss/selector-no-redundant-nesting-selector": true,
"scss/dollar-variable-pattern": "^_?[a-z\\-0-9]+$",
@angelikatyborska
angelikatyborska / download.js
Created October 23, 2017 13:54
Download a CSV file gotten using fetch (necessary when headers needed, eg. with token authorization)
fetch(request).then(
response => {
if (response.status >= 200 && response.status < 300) {
if (response.headers.get('Content-Type') === 'text/csv') {
response.text().then(
text => {
const windowUrl = window.URL || window.webkitURL;
const blob = new Blob([text], {type: 'text/csv'});
const url = windowUrl.createObjectURL(blob);
window.location = url;
@angelikatyborska
angelikatyborska / _Netstat.md
Created April 27, 2018 07:08
List the number of open HTTP connections per IP in Linux

List the number of open HTTP connections per IP in Linux

This was useful when fighting a DDoS attack on one of our web servers.

Credit for it goes to our server provider, Memset, who helped us to stop the attack.

@angelikatyborska
angelikatyborska / GitCommitEmoji.md
Created June 22, 2018 14:04 — forked from parmentf/GitCommitEmoji.md
Git Commit message Emoji
@angelikatyborska
angelikatyborska / split-first-vs-downcase-first.exs
Created August 6, 2018 06:51
Performance test to two different approaches to Exercism's Word Count in Elixir
defmodule Words do
def count_with_downcase_first(sentence) do
sentence
|> downcase_and_split
|> count_words
end
def count_with_split_first(sentence) do
sentence
|> split_and_downcase
@angelikatyborska
angelikatyborska / file.sh
Created March 1, 2019 08:36
Add user that can sudo without a password
useradd foo --create-home -G sudo
echo 'foo ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
@angelikatyborska
angelikatyborska / script.sh
Created March 1, 2019 10:18
Append to a 644 root owned file
# as sudoer, non-root:
echo 'foo' | sudo tee -a /etc/hosts
# or
sudo bash -c "echo 'foo' >> /etc/hosts"
# this does NOT work
sudo echo 'foo' >> /etc/hosts