Skip to content

Instantly share code, notes, and snippets.

View pawelztef's full-sized avatar

Paweł Stefaniak pawelztef

View GitHub Profile
@pawelztef
pawelztef / missing_indexes
Created December 10, 2016 01:00
Check missing indexes in Rails app
c = ActiveRecord::Base.connection
c.tables.collect do |t|
columns = c.columns(t).collect(&:name).select {|x| x.ends_with?("_id" || x.ends_with("_type"))}
indexed_columns = c.indexes(t).collect(&:columns).flatten.uniq
unindexed = columns - indexed_columns
unless unindexed.empty?
puts "#{t}: #{unindexed.join(", ")}"
end
end
@pawelztef
pawelztef / compton.conf
Last active January 29, 2021 21:31
my i3wm config file
#opacity-rule = ["99:class_g = 'Terminator'"];
#opacity-rule = ["85:class_g = 'Termite'"];
opacity-rule = ["99:class_g = 'Termite'"];
# Shadow
shadow = true;
no-dnd-shadow = true;
no-dock-shadow = true;
clear-shadow = true;
shadow-radius = 4;
shadow-offset-x = 0;
@pawelztef
pawelztef / vimrc
Created January 3, 2017 23:52
vimrc
"Pathogen - manage plugins
"-------------------------------------------------------------------------
execute pathogen#infect()
"---------------------------------------------------------------------------
" Basic settings
"-------------------------------------------------------------------------
let g:ruby_path = system('echo $HOME/.rbenv/shims')
let mapleader = "\<Space>"
@pawelztef
pawelztef / .bashrc
Last active October 11, 2017 04:39
.bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# set show-mode-in-prompt on
# set vi-ins-mode-string \1\2  \1\2
# set vi-cmd-mode-string \1\2  \1\2
ranger() {
if [ -z "$RANGER_LEVEL" ]; then
@pawelztef
pawelztef / _flash.html.erb
Last active August 9, 2021 02:16
rails flash messages with bootstrap 4
<div class="container">
<% flash.each do |type, msg| %>
<div class="alert <%= bootstrap_class_for_flash(type) %> alert-dismissable fade show">
<%= msg %>
<button class="close" data-dismiss="alert">x</button>
</div>
<% end %>
</div>
@pawelztef
pawelztef / database.yml.mysql
Last active October 11, 2017 05:06
ruby on rails database configuration exemples
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username:
password:
socket: /var/run/mysqld/mysqld.sock
development:
<<: *default
guard 'livereload' do
extensions = {
css: :css,
scss: :css,
sass: :css,
js: :js,
coffee: :js,
html: :html,
png: :png,
gif: :gif,
@pawelztef
pawelztef / slug_create
Created June 28, 2017 09:07
slugify text
function slugify(text)
{
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
}
@pawelztef
pawelztef / pretty_curl
Created December 12, 2017 12:50
pretty_curl
#!/bin/bash
# install jq JSON processor
# apt isntall jq
pretty_curl() {
curl "$1" | jq
}
@pawelztef
pawelztef / application_helper.rb
Created March 20, 2018 09:11
Ruby on Rails. Class "active" for menu items based on Path or Controller and Action names
module ApplicationHelper
def active_for(options = {})
name_of_controller = options[:controller] || nil
name_of_action = options[:action] || nil
request_path = options[:path] || nil
if request_path.nil?
if (name_of_action.nil? or name_of_action == action_name) and
name_of_controller == controller_name
'active'