Skip to content

Instantly share code, notes, and snippets.

@victorcreed
victorcreed / news_letters_controller.rb
Created February 6, 2014 11:15
just for fun.... converted it into 1 line
class NewsLettersController < ApplicationController
def send_news_letter
#if params[:send_news_letter][:email].present?
# @user = User.new params[:send_news_letter]
# @user.save validate: false
# Notifier.send_news_letter(@user).deliver
# redirect_to root_path, notice: "Thanks for sharing. We'll keep you in the loop!"
#else
#redirect_to root_path, error: "Please provide your email for the newsletter."
redirect_to *lambda {lambda{ @user = User.new( params[:send_news_letter]); @user.save(validate: false); Notifier.send_news_letter(@user).deliver }.call if params[:send_news_letter][:email].present? ; return [root_path, (params[:send_news_letter][:email].present? ? { notice: "Thanks for sharing. We'll keep you in the loop!" } : {error: "Please provide your email for the news letter!"})] }.call
@victorcreed
victorcreed / setup_settings.rake
Created February 5, 2014 06:35
generate entries into predefined model
namespace :enriched do
desc "setup settings"
task setup_settings: :environment do
categories = YAML.load_file(File.join(Rails.root, "app", "yamls", "talents", "parent_categories.yml"))
categories["main_categories"].each { |main_category| main_setting, each_loop_method = Setting.create( body: main_category, role_type: "talents" ), lambda { |sub_category| sub_setting = Setting.create(body: sub_category, value: categories[main_category][sub_category]["value"], parent_id: main_setting.id, role_type: "talents")}; categories[main_category]["fields"].each( &each_loop_method ) }
end
end
class @FlashMessage
constructor: (@message, @flashType) ->
initHideFlashMessage: ->
$(".alert").slideUp -> $(this).remove()
hideFlashMessage: ->
setTimeout @initHideFlashMessage, 2000
render: ->
$("header").prepend("<p class='alert alert-#{@flashType} no-radius'>#{@message}</p>")
@hideFlashMessage()
@victorcreed
victorcreed / _form.html.erb
Last active December 27, 2015 18:09
really lazy and dont want to create mess in VIEW, so i used splat to passing dynamic parameters
<%= simple_form_for @job, html: { class: "form-horizontal" } do |f| %>
<% new_and_edit_form_fields.each do |column| %>
<%= f.input *column %>
<% end %>
<% end %>
@victorcreed
victorcreed / agent98.rb
Created October 12, 2013 07:22
bypassing NAT and firewall ruby. agent98.rb is a client secret_organization.rb is a server
require 'socket'
remote_host = "[some public address]"
punch = UDPSocket.new
punch.bind('', 6311)
punch.send('', 0, remote_host, 6311)
punch.close
# # Bind for receiving
@victorcreed
victorcreed / get_me_few_songs
Last active December 24, 2015 13:49
download all the songs from the songspk.name its first create the album locally then fetch all the songs of that album from, currently a list is getting download
#!/usr/bin/env ruby
require "rubygems"
require "nokogiri"
require "open-uri"
require "faraday"
doc = Nokogiri::HTML(open("http://www.songspk.name/a_list.html"))
doc.css(".ctlg-holder").each do |ul_holder|
ul_holder.css("li a").each do |anchor_holder|
@victorcreed
victorcreed / crap 1049
Last active December 22, 2015 19:29
another stupid experiment. I have to count the user individual project tasks' hours. User relation with Project is HBTM and task relation with Project is one project has many tasks. I want to Do User.find(1).projects.first.user_hours_count. so i achive this how
#### app/classes/activity_class.rb
require File.join(Rails.root, "app", "classes", "concerns", "methods")
class ActivityClass
include Classes::Concerns::Methods
def user_projects
user.projects.date_cont(params[:project_date_cont]).search(params[:project_search]).result( distinct: true ).collect do |project|
project.temp_user = user
def project.user_hours_count
@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
@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 / 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