Skip to content

Instantly share code, notes, and snippets.

View denyago's full-sized avatar
🤠

Denys Yahofarov denyago

🤠
View GitHub Profile
@denyago
denyago / rails_issue_5057.rb
Last active January 1, 2016 12:19 — forked from tilo/rails_issue_5057.rb
Minimal ActiveRecord setup with SQlite3
gem 'rails', '3.2.1'
require 'active_record'
puts "Active Record #{ActiveRecord::VERSION::STRING}"
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => ':memory:'
)
require 'erb'
require 'net/http'
require 'json'
template = %q{
This is one: <%= data_obj.one %>
The foo is <%= data_obj.foo %>
}
class MyDataObj
@denyago
denyago / natural_scroll.rb
Created September 8, 2013 10:13
Enables Natural Scrolling at Ubuntu like OS X has. Simple script to run on X start.
#!env ruby
# This script enables 'Natural scrolling' as in OS X.
#
# Usage:
# 1. Find your touchpad name by running xinput list
# 2. Run ./natural_scroll.rb 'touchpad name'
#
# Limitations:
# - Tested only on Ubuntu 13.04
#TODO:
# 1. Set up unicorn as service
# 2. Set nginx config
# 3. Create deploy
require "debugger"
$:<< File.join(File.dirname(__FILE__), 'stack')
$:<< File.join(File.dirname(__FILE__), 'lib')
require "capistrano_vars"

Compile FFmpeg on Ubuntu

This guide supports Ubuntu Precise Pangolin 12.04, Ubuntu Oneiric Ocelot 11.10, Ubuntu Natty Narwhal 11.04, and Ubuntu Maverick Meerkat 10.10. Separate guides are available for Ubuntu Lucid Lynx 10.04 and Ubuntu Hardy Heron 8.04. This guide will enable several external encoding and decoding libraries: libfaac (AAC encoder), libfdk-aac (AAC encoder), libmp3lame (MP3 encoder), libopencore-amr (AMR encoder/decoder), librtmp (for additional RTMP protocols), libtheora (Theora encoder), libvorbis (Vorbis encoder), libvpx (VP8 encoder/decoder), and libx264 (H.264 encoder). These are optional and may be omitted if desired. This guide will also install many filters (see the filter list in the [Filtering Guide](https://ffmpeg.org/trac/ffmpeg/wiki/Fi

@denyago
denyago / helper.rb
Created April 25, 2013 13:27
Unset Ruby constant
##
# Unsets constant `const_name` from all available Modules.
# Will not do anything, if constant not constantizable.
#
# Params:
# - const_name {Symbol} or {String} name of constant,
# able to be constantized
#
# Returns {Boolean} as a result of unsetting
def unset_const!(const_name)
@denyago
denyago / list.rb
Created March 2, 2013 10:49
List all models and their DB columns
# Load models
Dir.foreach("app/models") { |f| require f if f =~ /rb$/ }
ActiveRecord::Base.descendants.each do |klass|
next if klass == "Rack::OAuth2::Server::Issuer".safe_constantize or klass == "Rack::OAuth2::Server::ActiveRecord".safe_constantize
begin
klass.columns.each_with_index {|c, i| printf "%-20s | %-19s | %-29s | %-10s\n", (i==0 ? klass.name : ''), c.name, c.sql_type, (c.null ? '' : 'not null') }
rescue => e
puts "*"*10
puts "Error getting columns for #{klass}: #{e}"
@denyago
denyago / result.bash
Created December 13, 2012 10:53
Compilation of performance of comparations
      user     system      total        real
Date 38.260000   0.290000  38.550000 ( 39.010656)
Bool  2.180000   0.000000   2.180000 (  2.197462)
=> [ 38.260000   0.290000  38.550000 ( 39.010656)
,
  2.180000   0.000000   2.180000 (  2.197462)
]
@denyago
denyago / Gemfile
Created August 23, 2012 09:05
Add belongs_to_remote to preload collections of ActiveResources without N+1 requests
source :rubygems
gem 'pg'
gem "hashie"
gem 'activerecord', require: 'active_record'
gem 'activesupport'
gem 'activeresource', :require => 'active_resource'
gem "debugger"
source :rubygems
gem 'pg'
gem 'activesupport'
gem "debugger"
# DM2 staff
gem 'dm-mapper', git: "https://github.com/solnic/dm-mapper.git"