Skip to content

Instantly share code, notes, and snippets.

View ozgun's full-sized avatar

Ozgun Koyun ozgun

View GitHub Profile
@ozgun
ozgun / boolean_store_accessor.rb
Last active November 2, 2022 13:02
Using ActiveRecord::Store to store boolean fields
# File: app/models/concerns/boolean_store_accessor.rb
#
# When we submit a form in order to update a model, a booelan/checkbox field is posted
# as '1' or '0', and if we are using ActiveRecord::Store, posted value is stored in
# database as '1' or '0'. By the help of this module, we store '1' and '0'
# values as `true` or `false`.
#
# Example usage:
#
# ```
@ozgun
ozgun / xmonad.hs
Last active December 28, 2021 20:21
My XMonad config file
import XMonad
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageDocks
import XMonad.Util.Run(spawnPipe)
import XMonad.Config.Desktop
---import XMonad.Config.Gnome
import XMonad.Config.Xfce
import qualified Data.Map as M
import XMonad.Hooks.SetWMName
import XMonad.Actions.CycleWS
@ozgun
ozgun / cards_controller.rb
Created December 9, 2015 16:53
Custom Rails Responder for Service Objects
class Dashboard::Payments::CardsController < ::Dashboard::Payments::BaseController
self.responder = Core::CustomServiceResponder
respond_to :html
before_action :customer_required
def destroy
service = Payments::Stripe::DeleteCreditCard.new(current_user)
status_object = service.call(params[:identifier])
@ozgun
ozgun / action_mailer_ext.rb
Created July 5, 2011 12:33
Monkeypatch ActionMailer's recipients
# config/initializers/action_mailer_ext.rb
# For Rails 2.x
if Rails.env.staging?
class ActionMailer::Base
def recipients(*params)
@recipients = "staging@example.com"
end
@ozgun
ozgun / 20120913125411_change_store_settings_to_longtext.rb
Created November 27, 2013 08:42
Rails migration: text to longtext (MySQL)
class ChangeStoreSettingsToLongtext < ActiveRecord::Migration
def up
change_column :site_configs, :store_settings, :longtext
end
def down
change_column :site_configs, :store_settings, :text
end
end
@ozgun
ozgun / battery_status_check.sh
Created February 13, 2018 15:32
Battery status check
#!/bin/bash
# To see available batteries run "upower -e"
BATTERY_PERCENTAGE=`upower -i /org/freedesktop/UPower/devices/DisplayDevice |grep percentage |awk -F: '{ print $2}' |awk -F% '{gsub(/ /, ""); print $1 }' |awk -F, '{ print $1 }'`
if [ $((BATTERY_PERCENTAGE)) -lt 10 ]; then
notify-send -u critical -c device -i /usr/share/icons/gnome/48x48/status/battery-low.png "Battery Level Low!" "%$BATTERY_PERCENTAGE"
fi
# Crontab entry:
@ozgun
ozgun / my-vim-plugins.vim
Last active November 18, 2016 19:30
vim plugins I use
Plugin 'gmarik/Vundle.vim'
Bundle 'L9'
Plugin 'tpope/vim-dispatch'
Plugin 'tpope/vim-commentary'
Plugin 'tpope/vim-bundler'
Plugin 'tpope/vim-rails'
Plugin 'vim-ruby/vim-ruby'
@ozgun
ozgun / custom_responder.rb
Created June 23, 2015 08:17
Custom Responder
module MyModule
class CustomResponder < ActionController::Responder
include Responders::FlashResponder
include Responders::HttpCacheResponder
def has_errors?
case controller.action_name
when 'destroy'
resource.destroyed? ? false : true
else
@ozgun
ozgun / serving_files_with_nginx.txt
Last active August 23, 2016 03:03
Rails 3.2.x: Serving files with nginx using X-Accel-Redirect header (capistrano deploy)
# Assumptions:
* Rails 3.2.x
* nginx
* capistrano deploy
* "X-Accel-Mapping header missing" messages in nginx error.log file
* You want to serve static files with nginx instead of Rails
# nginx configuration:
"
" Ruby snippets
" Last change: August 6 2007
" Version> 0.1.0
" Maintainer: Eustáquio 'TaQ' Rangel
" License: GPL
" Thanks to: Andy Wokula and Antonio Terceiro for help and patches.
"
if exists("b:rubysnippets_ignore")
finish