Skip to content

Instantly share code, notes, and snippets.

View sadovnik's full-sized avatar

Cyril Sadovnik sadovnik

  • тута здеся
View GitHub Profile
function lazyLoadImages() {
var lazyImages = document.getElementsByTagName('img[data-src]');
for (var i = 0; i < lazyImages.length; i++) {
if (!lazyImages[i].getAttribute('data-src')) {
return;
}
var imageUrl = lazyImages[i].getAttribute('data-src');
lazyImages[i].setAttribute('src', imageUrl);
class Human
attr_reader :health
def initialize
@health = 100
end
def smoke_cigarette
@health -= 1
end
style.
.metroheading {
font-size: 1.3em;
line-height: 1.3em;
font-family: Georgia, Times New Roman;
}
.heading {
font-size: 2em;
line-height: 1.3em;
font-family: Georgia, Times New Roman;
@sadovnik
sadovnik / benchmark.rb
Created March 30, 2018 13:25
Keep-alive vs new TCP connection each time
require "excon"
require "benchmark"
n = 10000
Benchmark.bm(30) do |benchmark|
benchmark.report("reuse connection") do
client = Excon.new("http://localhost:8080", persistent: true)
n.times do
@sadovnik
sadovnik / lol-commits-post-commit-hook.sh
Created November 9, 2017 11:41
lolcommits `.git/hooks/post-commit` configuration resolving black photo issue
#!/bin/sh
### lolcommits hook (begin) ###
LANG="en_US.UTF-8" && PATH="/Users/cyril/.rbenv/versions/2.3.5/bin:/usr/local/bin:$PATH" && if [ ! -d "$GIT_DIR/rebase-merge" ] && [ "$LOLCOMMITS_CAPTURE_DISABLED" != "true" ]; then lolcommits --capture --delay 1 --stealth --fork; fi
### lolcommits hook (end) ###
@sadovnik
sadovnik / ssh_add_memo.md
Last active November 8, 2017 15:34
git stderr: Permission denied (publickey)
ssh-add ~/.ssh/id_rsa
@sadovnik
sadovnik / nvim-python-match-tag-always.md
Last active April 19, 2021 05:09
neovim nvim MatchTagAlways error fix

If you get this error when open neovim:

$ nvim

MatchTagAlways unavailable: requires python.
Press ENTER or type command to continue

Try to install neovim package:

@sadovnik
sadovnik / gist:7614ed390a7f1db38abe520a1b5eb609
Created February 17, 2017 18:59
Git: replace commit author name and email on every commit that matches
git filter-branch --env-filter '
oldname="Cyril"
oldemail="old.email@example.com"
newname="Cyril Sadovnik"
newemail="new.email@example.com"
[ "$GIT_AUTHOR_EMAIL" = "$oldemail" ] && GIT_AUTHOR_EMAIL="$newemail"
[ "$GIT_COMMITTER_EMAIL" = "$oldemail" ] && GIT_COMMITTER_EMAIL="$newemail"
[ "$GIT_AUTHOR_NAME" = "$oldname" ] && GIT_AUTHOR_NAME="$newname"
[ "$GIT_COMMITTER_NAME" = "$oldname" ] && GIT_COMMITTER_NAME="$newname"
' head
@sadovnik
sadovnik / env_nginx.conf
Created February 6, 2017 12:49
How to pass an environment variable from Nginx to PHP
location ~ \.php$ {
# Variable FOO_ENV_VARIABLE with value "bar"
fastcgi_param FOO_ENV_VARIABLE bar;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
@sadovnik
sadovnik / set_swap.sh
Created December 6, 2016 11:34
Set swap (useful for Vagrant machines)
#!/bin/sh
# size of swapfile in megabytes
swapsize=2048
# does the swap file already exist?
grep -q "swapfile" /etc/fstab
# if not then create it
if [ $? -ne 0 ]; then