Skip to content

Instantly share code, notes, and snippets.

@victorcreed
victorcreed / crap
Created March 29, 2013 17:06
metaprograming in controller or dynamic controller ruby on rails or whatever
class VideosController < ApplicationController
before_filter :video, only: [:show, :edit, :update, :watch, :buy, :rent]
def update
authorize! :update, @video
if @video.update_attributes params[:video]
redirect_to @video
else
render :edit
end
end
@victorcreed
victorcreed / crap v 1010
Created March 31, 2013 08:30
my dot file to copy current git project. sync this folder to any cloud service
mk_setup_backup(){
if [ "$#" -ne 1 ]
then
echo "Error!!!"
exit
else
mkdir -p $HOME/local_backups/$1
d_path=`pwd`
cd $HOME/local_backups/$1
git init --bare
@victorcreed
victorcreed / crap v 2020
Created April 5, 2013 17:48
my custom zsh theme still unstable but colors are aweful
#get_host=`pwd`
PROMPT='$fg[cyan] %m $fg[blue] © git: $(git_prompt_status) $fg[yellow] rvm: $(rvm current) $fg[red] $USER $fg[green].
→ $reset_color'
@victorcreed
victorcreed / crap
Created April 15, 2013 09:00
my optimization for vim...
VICTOR_VI_COMMAND=("vthis" "vmo" "vco" "view" "vconf" "vasset")
VICTOR_VI_PATH=("." "app/models/" "app/controllers/" "app/views/" "config/" "app/assets/")
tLen=${#VICTOR_VI_COMMAND[@]}
tfunc="$HOME/.tmp/t1"
function vi_init(){
for ((i=0; i < ${tLen}; i++));
do
(
echo "function \$VICTOR_VI_COMMAND[\$i]"
@victorcreed
victorcreed / crap 1010
Created April 19, 2013 07:55
dont know
%w(buy rent).each do |a|
define_method "user_#{a}_movies" do
instance_variable_get(:"@#{a}_movies").blank? ? instance_variable_set( :"@#{a}_movies", PublicActivity::Activity.where(owner_id: User.current.id, owner_type: "User", key: "video.#{a}")) : instance_variable_get(:"@#{a}_movies")
end
end
$ sudo aptitude install apache2 dnsmasq
$ sudo vim /etc/dnsmasq.conf
# ...
address=/dev/127.0.0.1
listen-address=127.0.0.1
$ sudo vim /etc/dhcp3/dhclient.conf
# uncomment line 20:
@victorcreed
victorcreed / crap 1011
Created May 30, 2013 10:52
another stupid test with draper gem, metaprograming. I hate to decorate object every time so i wrote this.. i will use this till i find out its a bad pratice. is it bad practice ... .still wonder :|
lib/oleku/presentation.rb
-----------------------------------------------
module Oleku
module Presentation
module Video
def self.included base
base.send :include, InstanceMethods
end
module InstanceMethods
def method_missing( meth, *args, &block)
@victorcreed
victorcreed / crap 1012
Created June 21, 2013 08:32
another stupid experiment to lazy to write code for conventional action's
class Dashboard::JobDescriptionsController < Dashboard::BaseController
skip_authorization_check
before_filter only: [:new, :create] { @job_description = JobDescription.send(:new, ( params[:job_description] if params[:job_description]) ) }
before_filter only: [:edit, :update] { @job_description = JobDescription.find(params[:id]) }
before_filter only: [:create, :update] do
if @job_description.send((@job_description.new_record? ? :save : :update_attributes), ( @job_description.new_record? ? {validate: true} : params[:job_description] ))
redirect_to edit_dashboard_job_description_path(@job_description), notice: "record successfuly #{params[:action]}d"
else
render params[:action] == "create" ? :new : :edit
end
@victorcreed
victorcreed / server.rake
Created September 3, 2013 06:44
automating restart server task for demonized rails server
namespace :vf do
namespace :server do
desc "stop server"
task :stop => :environment do
puts "-----------------Stoping Server----------------"
pid_file = "tmp/pids/server.pid"
pid = File.read(pid_file).to_i
puts "************pid = #{pid}"
Process.kill 9, pid
File.delete pid_file
@victorcreed
victorcreed / c1013
Last active December 22, 2015 05:18
it's was the monkey patch for shared uploads in capistrano. it will copy all the content from old uploads
1.9.1 :001 > Dir.glob("/root/projects/tellum/releases/**/public/uploads/user/photo").each do |p|
1.9.1 :002 > FileUtils.cp_r Dir["#{p}/*"], "/root/projects/tellum/shared/uploads/user/photo" rescue puts p
1.9.1 :003?> end