Skip to content

Instantly share code, notes, and snippets.

@sharshenov
sharshenov / gist:0b5a454ea3282cc779dfce0f93bdab24
Last active November 8, 2021 16:18
ubuntu remove blue dot from slack icon in tray
#!/bin/sh
# https://superuser.com/a/1536290
# npm install -g asar
set -ex
killall slack || true
mkdir -p ~/tmp/slack
asar extract /usr/lib/slack/resources/app.asar ~/tmp/slack
@sharshenov
sharshenov / truncatable.rb
Created April 10, 2020 13:18
Truncate string attributes to database limit in Rails
# frozen_string_literal: true
# Usage:
# Place it in app/models/concerns dir
#
# Include in class
# class Product < ApplicationRecord
# include Truncatable
# end
#
@sharshenov
sharshenov / nginx.conf
Created January 10, 2018 17:45
Nginx forward proxy with requests rate throttling
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#!/bin/bash
# add to /etc/rc.local
# su -c '/home/rails/scripts/talkzzz'
#
# add to /home/rails/.profile
# PATH=$HOME/scripts/:$PATH
#
APP="api_hd"
#возьмем, например, связь one-to-many и вложенными атрибутами
class Gallery < ActiveRecord::Base
has_many :images
accepts_nested_attributes_for :images
end
class Image < ActiveRecord::Base
belongs_to :gallery, required: true
@sharshenov
sharshenov / .kitchen.yml
Created November 11, 2016 04:11
kitchen configuration with cached chef-client
---
driver:
name: vagrant
synced_folders: [
["~/.chef/pkgs", "/tmp/chef-pkgs"]
]
provisioner:
name: chef_zero
chef_omnibus_url: file:///tmp/chef-pkgs/install.sh
@sharshenov
sharshenov / gist:c09ed8955692ca98d371eeb42a1b6d45
Created August 28, 2016 07:36
exchange gem NBKR external API
module Exchange
module ExternalAPI
class Nbkr < XML
API_URL = "http://nbkr.kg/XML/daily.xml"
CURRENCIES = %W(kgs usd eur kzt rub).map(&:to_sym)
def update opts={}
@sharshenov
sharshenov / gist:edaca25b3b9094359c95f4ae66cd4222
Created July 22, 2016 16:55
Using wkhtmltopdf without X server
apt-get install wkhtmltopdf
apt-get install xvfb
echo -e '#!/bin/bash\nxvfb-run -a --server-args="-screen 0, 1024x768x24" /usr/bin/wkhtmltopdf -q $*' > /usr/bin/wkhtmltopdf.sh
chmod a+x /usr/bin/wkhtmltopdf.sh
ln -s /usr/bin/wkhtmltopdf.sh /usr/local/bin/wkhtmltopdf
wkhtmltopdf http://www.google.com output.pdf
@sharshenov
sharshenov / throttler.rb
Created April 19, 2016 18:08
Basic throttler
class Throttler
class << self
def limit *attrs
throttler.limit *attrs
end
private
@sharshenov
sharshenov / gist:793e6dee2c5bee9d82d6
Last active December 5, 2016 16:47
Конфигурация elasticsearch для нужд небольших проектов(никакого HighAvailability & Load Balancing)
# Добавляем репозиторий для oracle java
add-apt-repository ppa:webupd8team/java
# Добавляем репозиторий для elasticsearch
wget -qO - https://packages.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
echo "deb http://packages.elastic.co/elasticsearch/2.x/debian stable main" | sudo tee -a /etc/apt/sources.list.d/elasticsearch-2.x.list
# Обновить систему
apt-get update && apt-get dist-upgrade -y && apt-get autoremove -y && apt-get clean