Skip to content

Instantly share code, notes, and snippets.

View vishalzambre's full-sized avatar
🏠
Working Remotely

Vishal Zambre vishalzambre

🏠
Working Remotely
View GitHub Profile
@vishalzambre
vishalzambre / string_to_bool.rb
Last active November 12, 2020 09:16
Ruby String to Boolean
module StringToBooleanRefinementsService
refine String do
def to_bool
return true if self == true || self =~ /(true|t|yes|y|1)$/i
return false if self == false || self.blank? || self =~ /(false|f|no|n|0)$/i
raise ArgumentError, "invalid value for Boolean: \"#{self}\""
end
alias_method :to_b, :to_bool
@vishalzambre
vishalzambre / resque.service
Last active April 16, 2020 08:22
System Service for resque
## Add System Service for Resque
Copy below code and paste to /lib/systemd/system/resque.service
`vim /lib/systemd/system/resque.service`
```shell
[Unit]
Description=Resque Workers
[Service]
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
# Activate the gem you are reporting the issue against.
@vishalzambre
vishalzambre / 25347_join_table.rb
Last active April 3, 2017 09:40
Rails ActiveRecord join table withour id delete issue
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
# Activate the gem you are reporting the issue against.
@vishalzambre
vishalzambre / db.rake
Last active January 31, 2017 13:02
Dumps the database to db/APP_NAME.dump using rake rake db:dump and to restore rake db:restore
# lib/tasks/db.rake
namespace :db do
desc 'Dumps the database to db/APP_NAME.dump'
task dump: :environment do
cmd = nil
with_config do |app, host, port, db, user, password|
cmd = "PGPASSWORD='#{password}' pg_dump --host #{host} --username #{user} -p #{port} --verbose --clean --no-owner --no-acl --format=c #{db} > #{Rails.root}/db/#{app}.dump"
end
puts cmd
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
# Activate the gem you are reporting the issue against.
@vishalzambre
vishalzambre / sublime-settings
Created June 15, 2015 07:08
sublime user setting
{
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
"draw_white_space": "all",
"enable_tab_scrolling": false,
"font_size": 18,
"ignored_packages":
[
"Vintage"
],
"margin": 2,
@vishalzambre
vishalzambre / pre_push
Created May 29, 2015 11:29
Git: Prevent pushing to master
# For any repository you want to protect, you need to create a new file called pre-push in the .git/hooks directory.
# Also check that the pre-push file is executable (run chmod +x .git/hooks/pre-push on the command line) and try again :)
# Add following code snippets to $YOUR_REPO/.git/hooks/pre-push file
# Then run chmod +x $YOUR_REPO/.git/hooks/pre-push
#!/bin/bash
PROTECTED_BRANCH='master'
@vishalzambre
vishalzambre / curl.sh
Last active October 2, 2021 02:30
Using devise gem sign_in & sign_out API's with sessions
#login
curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d ' {"user":{"email":"<email>","password":"<passwd>"}}' http://localhost:3000/api/v1/sign_in.json
#logout
curl -v -H "Accept: application/json" -H "Content-type: application/json" -X DELETE http://localhost:3000/api/v1/sign_out.json?auth_token=<token>