Skip to content

Instantly share code, notes, and snippets.

@mars
mars / register_chrome_with_window_size.rb
Created October 13, 2013 01:58
Set window size for Capybara/Selenium/chromedriver
Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new(app,
browser: :chrome,
desired_capabilities: {
"chromeOptions" => {
"args" => %w{ window-size=1024,768 }
}
}
)
end
@mars
mars / set_default_host.rb
Created August 17, 2023 20:10
Rails unified host override for use with apps behind a CDN (Rack middleware, supports OmniAuth)
# Rack middleware that reads environment variable HOST (value such as: app.example.com)
# to override request Host headers, forcing the app to use this value for URLs & redirects.
#
# If env var HOST is unset, then this middleware does nothing.
#
# Useful for when a Rails app is the origin behind a CDN/proxy, so that all generated
# URLs point to the canonical hostname of the CDN, and not the origin itself.
#
# For a Rails app,
# - save this file in config/initializers/set_default_host.rb
Action & Adventure based on a book from the 1960s (4082)
Action & Adventure based on a book from the 1970s (2410)
Action & Adventure based on a book from the 1980s (704)
Action & Adventure based on real life from the 1980s (1051)
Action & Adventure directed by Andrew V. McLaglen (2282)
Action & Adventure directed by Cirio H. Santiago (4323)
Action & Adventure directed by Clint Eastwood (4998)
Action & Adventure directed by Corey Yuen (291)
Action & Adventure directed by George Archainbaud (3183)
Action & Adventure directed by George Sherman (3198)
@mars
mars / await-url-response.bash
Created January 3, 2022 22:34
Await a URL returning a specific response status, like 200
#!/bin/bash
set -u
echo "Checking for response status ${1} from URL: ${2}"
try_count=0
while true
do
((try_count++))
response_status="$(curl -s -o /dev/null -w "%{http_code}" "${2}")"
if [ "$response_status" == "${1}" ]
@mars
mars / create-react-app-on-heroku.sh
Created July 29, 2016 01:12
Create a React app & deploy to Heroku
## Global install of the app generator
npm install -g create-react-app
## Setup the app (first-time only)
create-react-app my-app
cd my-app
git init
# Create the Heroku app; requires free account at https://www.heroku.com/
heroku create -b https://github.com/heroku/heroku-buildpack-static.git
@mars
mars / install.md
Last active December 19, 2019 22:26 — forked from Micka33/install.md
Cassandra on Mac OS X

Installing Cassandra on Mac OS X

Install Homebrew

Homebrew is a great little package manager for OS X. If you haven't already, installing it is pretty easy:

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
@mars
mars / .bash_profile
Last active October 22, 2018 21:48
bash prompt git status
[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile
function parse_git_dirty {
git diff --quiet || echo " ▲ "
}
function parse_git_branch {
e=`echo $( { git status; } 2>&1 ) | tr '[:upper:]' '[:lower:]'`
if [[ ! $e =~ 'not a git repository' ]]
then git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)] /"
fi
@mars
mars / foo.rb
Created June 27, 2018 23:09 — forked from mtsmfm/foo.rb
convert from json hyper schema to swagger spec
require 'yaml'
require 'pathname'
require 'active_support/all'
def convert(f)
filename = Pathname.new(f)
yaml = YAML.load_file(filename)
name = filename.basename('.yml').to_s
File.write(filename, {
@mars
mars / reactjs-filepicker.js
Last active March 8, 2018 05:09
Use Filepicker.io with React.js (v0.14, ES2015, & JSX)
/*
Filepicker lib must be loaded from script tag in HTML:
<script type="text/javascript" src="//api.filepicker.io/v2/filepicker.js"></script>
*/
class FilepickerInput extends React.Component {
componentDidMount() {
const filepickerElement = this.refs.filepicker;
if (typeof filepicker !== 'undefined') {
// Single-page app integration: https://developers.filepicker.com/docs/support/integration/117
@mars
mars / development.js
Last active May 11, 2017 17:22
Webpack config to support environment variables in JS source
module.exports = {
WEBPACK_ENV: JSON.stringify('development'),
FOO: JSON.stringify('per-environment foo value')
};