Skip to content

Instantly share code, notes, and snippets.

View sshkarupa's full-sized avatar

Sergey Shkarupa sshkarupa

View GitHub Profile
# Place this file inside your ~/.idlerc/ folder
# or paste its contents inside
# /path/to/python/idlelib/config-highlight.def
# Adapted from SublimeText's Monokai
[monokai]
normal-foreground= #F8F8F2
normal-background= #272822
keyword-foreground= #F92672
keyword-background= #272822
@sshkarupa
sshkarupa / xhr.rb
Last active August 29, 2015 14:26 — forked from aaronmoodie/gist:1308100
Sinatra: render template partial without layout when requested va Ajax
if request.xhr?
# renders :template_partial without layout.html
slim :template_partial, :layout => false
else
# renders as normal inside layout.html
slim :template_partial
end
@sshkarupa
sshkarupa / sinatra_jquery_test.rb
Last active August 29, 2015 14:26 — forked from mr-rock/sinatra_jquery_test.rb
An example of Sinatra working with Ajaxified JQuery based on some pieces of code published by Rafael George on the Sinatra Google Group.
require 'sinatra'
require 'dm-core'
require 'haml'
DataMapper.setup(:default, 'sqlite3::memory:')
class Message
include DataMapper::Resource
property :id, Serial
@sshkarupa
sshkarupa / puzzles.rb
Last active September 4, 2015 11:41 — forked from hrumhrumble/puzzles.rb
# В системе авторизации есть ограничение:
# логин должен начинаться с латинской буквы,
# состоять из латинских букв, цифр, точки и минуса,
# но заканчиваться только латинской буквой или цифрой;
# минимальная длина логина — один символ, максимальная — 20.
# Напишите код, проверяющий соответствие входной строки этому правилу. Придумайте несколько способов решения задачи и сравните их.
class AuthOne
def initialize login
@login = login
@sshkarupa
sshkarupa / capybara cheat sheet
Created December 11, 2015 20:26 — forked from zhengjia/capybara cheat sheet
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@sshkarupa
sshkarupa / production.rb
Last active February 27, 2016 09:19 — forked from vkurennov/production.rb
Пример конфига unicorn
# paths
app_path = "/home/deployer/qna"
working_directory "#{app_path}/current"
pid "#{app_path}/current/tmp/pids/unicorn.pid"
# listen
listen "/tmp/unicorn.qna.sock", backlog: 64
# logging
stderr_path "log/unicorn.stderr.log"
@sshkarupa
sshkarupa / monit.rc
Last active February 28, 2016 10:03 — forked from vkurennov/monit.rc
Пример конфига для запуска процессов через monit
### Unicorn ###
check process unicorn
with pidfile "/home/deployer/qna/current/tmp/pids/unicorn.pid"
start program = "/bin/su - deployer -c 'cd /home/deployer/qna/current && RAILS_ENV="production" /home/deployer/.rbenv/bin/rbenv exec bundle exec unicorn -c /home/deployer/qna/current/config/unicorn/production.rb -E deployment -D'"
stop program = "/bin/su - deployer -c 'kill -0 `cat /home/deployer/qna/current/tmp/pids/unicorn.pid`'"
if memory usage > 90% for 3 cycles then restart
if cpu > 90% for 2 cycles then restart
if 5 restarts within 5 cycles then timeout
### Nginx ###
@sshkarupa
sshkarupa / ubuntu-raid.sh
Last active December 2, 2016 21:20 — forked from umpirsky/ubuntu-raid.sh
Install Ubuntu on RAID 0 and UEFI/GPT system
# http://askubuntu.com/questions/505446/how-to-install-ubuntu-14-04-with-raid-1-using-desktop-installer
# http://askubuntu.com/questions/660023/how-to-install-ubuntu-14-04-64-bit-with-a-dual-boot-raid-1-partition-on-an-uefi%5D
sudo -s
apt-get -y install mdadm
apt-get -y install grub-efi-amd64
sgdisk -z /dev/sda
sgdisk -z /dev/sdb
sgdisk -n 1:0:+100M -t 1:ef00 -c 1:"EFI System" /dev/sda
sgdisk -n 2:0:+4G -t 2:fd00 -c 2:"Linux RAID" /dev/sda
@sshkarupa
sshkarupa / check-uri.rb
Created June 7, 2016 19:44 — forked from murdoch/check-uri.rb
Check if uri exists
## just some ways to check if a url exists
# method 1 - from Simone Carletti
require "net/http"
url = URI.parse("http://www.google.com/")
req = Net::HTTP.new(url.host, url.port)
res = req.request_head(url.path)
# method 2 - from some kid on the internet
require 'open-uri'
@sshkarupa
sshkarupa / install_ffmpeg_ubuntu.sh
Created June 29, 2016 10:03 — forked from xdamman/install_ffmpeg_ubuntu.sh
Install latest ffmpeg on ubuntu 12.04 or 14.04
#!/bin/bash
# Bash script to install latest version of ffmpeg and its dependencies on Ubuntu 12.04 or 14.04
# Inspired from https://gist.github.com/faleev/3435377
# Remove any existing packages:
sudo apt-get -y remove ffmpeg x264 libav-tools libvpx-dev libx264-dev
# Get the dependencies (Ubuntu Server or headless users):
sudo apt-get update