Skip to content

Instantly share code, notes, and snippets.

View ozgun's full-sized avatar

Ozgun Koyun ozgun

View GitHub Profile
@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'
"
" 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
" An example for a vimrc file.
"
" Maintainer: Bram Moolenaar <Bram@vim.org>
" Last change: 2002 May 28
"
" To use it, copy it to
" for Unix and OS/2: ~/.vimrc
" for Amiga: s:.vimrc
" for MS-DOS and Win32: $VIM\_vimrc
" for OpenVMS: sys$login:.vimrc
# $Id: vim-keys.conf,v 1.2 2010-09-18 09:36:15 nicm Exp $
#
# vim-keys.conf, v1.2 2010/09/12
#
# By Daniel Thau. Public domain.
#
# This configuration file binds many vi- and vim-like bindings to the
# appropriate tmux key bindings. Note that for many key bindings there is no
# tmux analogue. This is intended for tmux 1.3, which handles pane selection
# differently from the previous versions
class ConvertTextToMediumInPostAndPageTranslations < ActiveRecord::Migration
def up
change_column :post_translations, :text, :text, :limit => 64.kilobytes + 1
change_column :page_translations, :text, :text, :limit => 64.kilobytes + 1
end
def down
change_column :post_translations, :text, :text
change_column :page_translations, :text, :text
end
@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 / apps_controller.rb
Last active December 23, 2015 09:40
Nested conrtollers example
class Admin::AppsController < Admin::BaseController
before_filter :load_app
def index
@apps = App.all
end
def show
load_app
end
@ozgun
ozgun / download_remote_file.sh
Created December 11, 2015 12:28
Download last file from remote server with ssh
FILE_TO_DOWNLOAD=`ssh ozgun@app1.dev 'ls -Art /tmp/dir |tail -n 1'`
scp ozgun@app1.dev:/tmp/dir/${FILE_TO_DOWNLOAD} .
@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])