Skip to content

Instantly share code, notes, and snippets.

View jelaniwoods's full-sized avatar

Jelani Woods jelaniwoods

View GitHub Profile
@jelaniwoods
jelaniwoods / web-scraping-quickstart.md
Last active March 9, 2022 03:00
Quickstart basic web scraping in Rails using HTTP.rb

Web Scraping

Add this to your Gemfile and run bundle install in the Terminal.

gem "http"

You can follow along in the rails console.

Embed a Google Map in a Rails View template

Step 1

Copy and paste the following code into your View template.

<div>
  <div id="map" style='width: 800px; height: 400px;'></div>
</div>

How to share your Gitpod workspace

In the top right corner of your running workspace, you will see your avatar. By clicking on your avatar, you will open the following dropdown.

gitpodclickshare-annotated

After clicking on the “Share Running Workspace” option, the following pop up will appear. To share your workspace, click the “Share” button and then provide the person you are sharing with the displayed URL. It is important to note that only the workspace owner can start up the workspace. This means that if the workspace is not running, whoever has the share link will not be able to view the workspace.

gitpodsharerunning-annotated

namespace(:dev) do
desc "Hydrate the database with some dummy data to look at so that developing is easier"
task({ :prime => :environment}) do
`rm -rf screenshots`
`mkdir screenshots`
start_time = Time.now
browser = Ferrum::Browser.new(headless: true, slowmo: 0.05, browser_options: {"disable-gpu": true, "no-sandbox": true})
browser.goto("https://duckduckgo.com")
browser.screenshot(path: "screenshots/duckduckgo.png")
# input = browser.at_xpath("//div[@id='searchform']/form//input[@type='text']")

I'm trying to write tests for a gem that is mounted in a Rails app. It's similar to a Rails Engine, except it's a Sinatra app that is mounted alongside the Rails app using the Rack Builder method.

I've configured config.ru like so

require_relative 'config/environment'

map '/git' do
  run WebGit::Server
end

Take this git graph as an example:

* ef99623 (c-branch) Other spaces
*   3c391fc (master) Merge branch 'b-branch'
|\
* | f0c357b Add spaces
| | * bc9833b (HEAD -> b-branch) Another space
| |/
p "first argument " + ARGV[0]
p "second argument " + ARGV[1]
remaining = ""
for argument in ARGV do
if argument != ARGV[0] && argument != ARGV[1]
remaining = remaining + argument
end
end

AJAX

Step 1: Ensure jQuery is installed.

  • Check your Gemfile for gem "jquery3", add it if it’s not there.
    • In app/assets/application.js, ensure it looks like:
/*
*= require_self
*//= require rails-ujs
*//= require jquery3