Skip to content

Instantly share code, notes, and snippets.

@harssh
harssh / gist:3d70c2bcc944e6423d4a790c70316719
Created January 17, 2023 15:54 — forked from cdale77/gist:d8502ef11373862f8eaa
Recursively copy and rename files with Ruby
#!/usr/bin/env ruby
require 'fileutils'
files = Dir["*/*.PDF"].collect{|f| File.expand_path(f)}
files.each_with_index do |file, index|
puts "copying file #{index}"
FileUtils.cp file, "pdf/#{index}.pdf"
end
@harssh
harssh / gist:22cd4ec60e6c28541a18e4d1490b6682
Created January 12, 2023 20:38 — forked from kyleroberthammond/gist:a544e0a4ee5f6380b6a22698fb585ba6
Test Dropzone.js File Uploads With Capybara
Test Dropzone.js File Uploads With Capybara
Dec 29, 2014
Integration tests involving complex JS interactions are a pain, especially with something like drag and drop file uploads (you can’t exactly drag something into a headless browser). My recent use case was an AngularJS application using Dropzone.js with Ruby on Rails on the backend, so I needed a way to make Dropzone play nicely with Capybara Webkit. Here is the spec helper I ended up with:
def drop_in_dropzone(file_path)
# Generate a fake input selector
page.execute_script <<-JS
fakeFileInput = window.$('<input/>').attr(
{id: 'fakeFileInput', type:'file'}
@harssh
harssh / company.rb
Created November 3, 2022 16:02 — forked from davinmsu/company.rb
remove duplicates from activerecord
def self.dedupe
# find all models and group them on keys which should be common
grouped = all.group_by{|model| [model.title,model.info,model.address,model.phone] }
grouped.values.each do |duplicates|
# the first one we want to keep right?
first_one = duplicates.shift # or pop for last one
# if there are any more left, they are duplicates
# so delete all of them
duplicates.each{|double| double.destroy} # duplicates can now be destroyed
end
@harssh
harssh / deployUser_config.md
Last active September 6, 2022 13:36 — forked from learncodeacademy/deployUser.md
Adding a deploy user in Linux with some less headache goodies (not typing or using password)

(wherever it says url.com, use your server's domain or IP)

Login to new server as root, then add a deploy user

sudo useradd --create-home -s /bin/bash deploy
sudo adduser deploy sudo
sudo passwd deploy

And Update the new password

@harssh
harssh / create_gemset
Created July 14, 2022 23:26 — forked from rab1234/create_gemset
rails_prep.rb - a ruby script to prepare a new rails application
#!/bin/bash
#
# I use this bash script to create an rvm gemset for a new rails app
# and I call this script from my rails_prep.rb ruby script
#
echo "create new gemset for new rails application ..."
#rvm --create 1.9.2@$1 # <--> this instruction does not work, but the following does
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" && rvm --create @$1
# -------------------------------
# Use the gemset we just created
@harssh
harssh / ruby-upload-s3.rb
Created July 14, 2022 23:20 — forked from db42/ruby-upload-s3.rb
Ruby script to upload a file to amazon s3
require 'aws-sdk-s3' # v2: require 'aws-sdk'
ACCESS_KEY_ID = ""
SECRET_ACCESS_KEY = ""
REGION_ID = "us-east-1"
BUCKET_NAME = "bucket-name"
def uploadS3
credentials = Aws::Credentials.new(
ACCESS_KEY_ID,
@harssh
harssh / find_dups.rb
Created July 5, 2022 22:29 — forked from rob-murray/find_dups.rb
Rails find duplicate records
columns_that_make_record_distinct = [:some_id, :another_name]
distinct_ids = Model.select("MIN(id) as id").group(columns_that_make_record_distinct).map(&:id)
duplicate_records = Model.where.not(id: distinct_ids)
# Using these pry gems -- copy to your Gemfile
# group :development, :test do
# gem 'awesome_print' # pretty print ruby objects
# gem 'pry' # Console with powerful introspection capabilities
# gem 'pry-byebug' # Integrates pry with byebug
# gem 'pry-doc' # Provide MRI Core documentation
# gem 'pry-rails' # Causes rails console to open pry. `DISABLE_PRY_RAILS=1 rails c` can still open with IRB
# gem 'pry-rescue' # Start a pry session whenever something goes wrong.
# gem 'pry-theme' # An easy way to customize Pry colors via theme files
# end
@harssh
harssh / macos-tmux-256color.md
Created June 26, 2022 01:00 — forked from bbqtd/macos-tmux-256color.md
Installing tmux-256color for macOS

Installing tmux-256color for macOS

  • macOS 10.15.5
  • tmux 3.1b

macOS has ncurses version 5.7 which does not ship the terminfo description for tmux. There're two ways that can help you to solve this problem.

The Fast Blazing Solution

Instead of tmux-256color, use screen-256color which comes with system. Place this command into ~/.tmux.conf or ~/.config/tmux/tmux.conf(for version 3.1 and later):

@harssh
harssh / gist:44ab26fafe3f24f300ea1e8445270bf5
Created June 17, 2022 14:10 — forked from ssjr/gist:5970762
My setup for Ruby on Rails with Mac OS X

My initial setup for Ruby on Rails development

Note: I'm using Mac OS X Lion (10.7.5)

All links, commands and order to install

  1. Download Xcode
  2. Open Xcode, Xcode (menu) > Preferences... > Downloads. Install Command Line Tools
  3. Install Homebrew
  • ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"