Skip to content

Instantly share code, notes, and snippets.

@olegantonyan
olegantonyan / ctlr+s (cmd+s) save all in atom
Last active January 16, 2022 15:32
Atom save all shortcut
'.workspace, .workspace, .editor, .text-editor':
'cmd-s': 'window:save-all' # ctrl-s for Linux/Windows
@olegantonyan
olegantonyan / application.rb
Last active August 29, 2015 14:25
Monkey patch to_partial_path to fix namespaced models (https://github.com/rails/rails/issues/21004)
module ActiveModel
module Conversion
def to_partial_path
original_path = self.class._to_partial_path
parts = original_path.split('/')
return original_path if parts.length == 2
pluralized_parts = parts[0..-3].map { |p| p.pluralize }
"#{pluralized_parts.join('/')}/#{parts.last(2).join('/')}".freeze
end
end
@olegantonyan
olegantonyan / crud_responder.rb
Last active October 4, 2015 10:21
CrudResponder - DRYing controller actions. Now in gem https://github.com/olegantonyan/crud_responder
# lib/crud_responder.rb
module CrudResponder
include ActionView::Helpers::TextHelper
protected
def crud_respond(object, options = {})
method = options.fetch(:method, method_by_caller(caller))
success_url = options.fetch(:success_url) { default_redirect_url(method, object) }
error_action = options.fetch(:error_action) { default_render_action(method, object) }
@olegantonyan
olegantonyan / test_mixin.rb
Last active October 26, 2015 03:22
Mixin class methods
module Foo
def self.included base
base.send :extend, ClassMethods
end
module ClassMethods # the name doesn't matter as long as it match with line 3
def bar
puts 'hello'
end
end
[GEM_ROOT]/gems/activesupport-4.2.4/lib/active_support/inflector/methods.rb:263 :in `const_get`
261 constant.const_get(name)
262 else
263 candidate = constant.const_get(name)
264 next candidate if constant.const_defined?(name, false)
265 next candidate unless Object.const_defined?(name)
[GEM_ROOT]/gems/activesupport-4.2.4/lib/active_support/inflector/methods.rb:263 :in `block in constantize`
[GEM_ROOT]/gems/activesupport-4.2.4/lib/active_support/inflector/methods.rb:259 :in `each`
@olegantonyan
olegantonyan / gist:be8ec1b32c220ad35e79
Created December 22, 2015 06:15
reicast crash on start
Config dir is: /home/oleg/.config/reicast/
Data dir is: /home/oleg/.local/share/reicast/
Personality: 00000000
Updated personality: 00000000
Linux paging: 00001000 00001000 00000FFF
MAP 00800000 w/ 25165824
MAP 20000000 w/ 25165824
MAP 04000000 w/ 16777216
MAP 06000000 w/ 16777216
MAP 0C000000 w/ 0
@olegantonyan
olegantonyan / atom_update_check.sh
Created May 2, 2016 09:07
Linux RPM check Atom update
#!/bin/sh
NOTIFY_USER=oleg # optional, for kdialog
USER_DISPLAY=:0 # optional, for kdialog
LOCATION=`curl -I https://github.com/atom/atom/releases/latest | perl -n -e '/^Location: (.*)$/ && print "$1"'`
VERSION=`basename $LOCATION | perl -n -e '/(\d+.\d+.\d+)/ && print "$1"'`
echo "available version: $VERSION"
INSTALLED=`rpm -q atom | perl -n -e '/atom-(.*?)-/ && print "$1"'`
@olegantonyan
olegantonyan / audio_volume_normalize.rb
Created May 25, 2016 06:58
Normalize audio volume using ffmpeg and ruby
def normalize_volume(file)
output = `ffmpeg -i '#{file}' -af "volumedetect" -f null /dev/null 2>&1`
raise "Error getting audio volume from #{file} (#{$?})" unless $?.success?
max_volume = output.scan(/max_volume: ([\-\d\.]+) dB/).flatten.first
mean_volume = output.scan(/mean_volume: ([\-\d\.]+) dB/).flatten.first
return if !max_volume || !mean_volume
max_volume = max_volume.to_f
mean_volume = mean_volume.to_f
target_volume = -14.0
adjustment = target_volume - mean_volume
@olegantonyan
olegantonyan / userContent.css
Created March 10, 2017 10:30
Firefox dark theme fix inputs
/* ~/.mozilla/firefox/XXXXXX.default/chrome/userContent.css */
input {
border: 2px inset white;
background-color: white;
color: black;
-moz-appearance: none !important;
}
textarea {
border: 2px inset white;
@olegantonyan
olegantonyan / pulse_simple_play.py
Created November 10, 2017 04:41 — forked from ignacysokolowski/pulse_simple_play.py
Python: Play a WAV file with PulseAudio simple API
#!/usr/bin/env python
import ctypes
import wave
import sys
pa = ctypes.cdll.LoadLibrary('libpulse-simple.so.0')
PA_STREAM_PLAYBACK = 1
PA_SAMPLE_S16LE = 3