Skip to content

Instantly share code, notes, and snippets.

View svyatov's full-sized avatar
👨‍💻

Leonid Svyatov svyatov

👨‍💻
View GitHub Profile
@svyatov
svyatov / slack_delete.rb
Created July 9, 2017 20:20 — forked from jamescmartinez/slack_delete.rb
This Ruby script will bulk remove all Slack files older than 30 days. Just add your API token from https://api.slack.com/web#authentication into the token quotes at the top of the file.
require 'net/http'
require 'json'
require 'uri'
@token = ''
def list_files
ts_to = (Time.now - 30 * 24 * 60 * 60).to_i # 30 days ago
params = {
token: @token,
@svyatov
svyatov / round_percents.coffee
Created April 27, 2016 00:35
Round percents (lo-dash + coffee)
# Based on https://en.wikipedia.org/wiki/Largest_remainder_method
roundPercents: (values) ->
sum = 0
sumNeeded = 100
percents = _.map values, (value, i) ->
quotient = _.floor(value)
modulus = value % 1
sum += quotient
{
@svyatov
svyatov / le-renew-webroot
Last active October 4, 2020 03:23 — forked from thisismitch/le-renew-webroot
Let's Encrypt Auto-Renewal using the Webroot Plugin (Nginx)
#!/bin/bash
web_service='nginx'
config_file='/usr/local/etc/le-renew-webroot.ini'
le_path='/opt/letsencrypt'
exp_limit=15;
if [ ! -f $config_file ]; then
echo "[ERROR] config file does not exist: $config_file"
#!/bin/sh
# Try e.g. `cd /tmp; unidecode "\x{0000}" > cc.txt; open -e cc.txt`
echo ""
echo "Displaying ASCII control characters using caret notation in standard text views"
defaults write NSGlobalDomain NSTextShowsControlCharacters -bool true
echo ""
echo "Disable smart quotes and smart dashes as they're annoying when typing code"
defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false
@svyatov
svyatov / gist:4346444
Created December 20, 2012 16:27
Fix Java plug-in for browsers in Mac OS X 10.8

Fix Java plug-in for browsers in Mac OS X 10.8:

sudo mkdir -p /Library/Internet\ Plug-Ins/disabled
sudo mv /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin /Library/Internet\ Plug-Ins/disabled
sudo ln -sf /System/Library/Java/Support/Deploy.bundle/Contents/Resources/JavaPlugin2_NPAPI.plugin /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin

To re-enable Java SE 6 Web Start: sudo ln -sf /System/Library/Frameworks/JavaVM.framework/Commands/javaws /usr/bin/javaws

@svyatov
svyatov / gist:4319873
Last active December 9, 2015 19:49
Remove duplicated & old items form "Open with..." menu in Mac OS X (Mountain Lion included)

In terminal:

/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/\
LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain local\
-domain system -domain user

Then restart Finder: Alt + Right Click on Finder icon, then select Relaunch (at the menu's bottom).

@svyatov
svyatov / update_cache_counters.rake
Created December 6, 2012 16:11
Rails Rake Task: Update all cache counters
desc 'Update all cache counters'
task :update_cache_counters => :environment do
models_to_update = {}
# or: Rails.application.eager_load!
# Dir loads less, so it's faster
Dir.glob(Rails.root.join('app/models/*')).each { |model| require model }
# as a convention, cache counter column name must begin with assotiacion's name and end with '_count' suffix,
# e.g. 'comments_count', 'posts_count'
@svyatov
svyatov / analyse_nginx_log.rb
Created November 24, 2012 00:54
nginx log parser, reports top 10 consumers ip by traffic + gives some additional info (pages, urls hits)
bytes_per_ip = Hash.new(0)
urls_per_ip = Hash.new(0)
pages_per_ip = Hash.new(0)
files_extensions_per_ip = Hash.new()
# i = 0
File.foreach ARGV.shift do |line|
# Line example: [23/Nov/2012:06:26:53 +0400] 123.123.123.123 "GET /images/socializ/google-buzz.png HTTP/1.1" 200 2283 "-" www.domain.ru "http://www.domain.ru/page.html" "Opera/9.80 (J2ME/MIDP; Opera Mini/5.1.24009/28.3126; U; ru) Presto/2.8.119 Version/11.10"
/\A\[.+?\]\s(?<ip>.+?)\s"GET (?<url>.+?)\s.+?"\s[0-9]+\s(?<bytes>[0-9]+)\s/ =~ line
bytes_per_ip[ip] += bytes.to_i
@svyatov
svyatov / apt_update_cache.yml
Created November 6, 2012 18:32
Update apt cache once per play
---
- apt: update-cache=yes
only_if: is_unset("$apt_cache_updated")
register: apt_cache_updated
- name: set custom mc left panel mini status for root
ini_file: dest=/root/.config/mc/panels.ini
owner=root group=root mode=0644
section='New Left Panel'
option=user_status0
value='half type name | owner group | perm'
- name: enable mc left panel mini status for root
ini_file: dest=/root/.config/mc/panels.ini
owner=root group=root mode=0644