Skip to content

Instantly share code, notes, and snippets.

View claptimes5's full-sized avatar

Avi Leavitt claptimes5

View GitHub Profile
@tkrotoff
tkrotoff / #mockWindowLocation.ts
Last active June 5, 2024 13:46
Jest/Vitest mocks for JSDOM window.location & window.history
/* eslint-disable unicorn/no-null */
/*
* Resetting window.location between tests is unfortunately a hard topic with JSDOM.
*
* https://gist.github.com/tkrotoff/52f4a29e919445d6e97f9a9e44ada449
*
* FIXME JSDOM leaves the history in place after every test, so the history will be dirty.
* Also its implementations for window.location and window.history are lacking.
* - https://github.com/jsdom/jsdom/blob/22.1.0/lib/jsdom/living/window/Location-impl.js
@jeroenvollenbrock
jeroenvollenbrock / aws-cloudfront-basic-auth.js
Last active April 8, 2024 15:51
AWS-CloudFront-basic-auth
var USERS = {
protecteddir: [{
username: 'user',
password: 'pass',
}],
};
//Response when auth is not valid.
var response401 = {
statusCode: 401,
@raphael-leger
raphael-leger / lazyWithRetry.js
Last active April 17, 2024 17:51
React LazyWithRetry
import { lazy } from 'react';
const lazyWithRetry = (componentImport) =>
lazy(async () => {
const pageHasAlreadyBeenForceRefreshed = JSON.parse(
window.localStorage.getItem(
'page-has-been-force-refreshed'
) || 'false'
);
@danwhitston
danwhitston / browser_testing_on_wsl.md
Last active March 31, 2022 21:39
Browser testing for Ruby from within Windows Subsystem for Linux

This is a rough guide to setting up browser testing through Selenium on Windows Subsystem for Linux (WSL), aka Bash on Ubuntu on Windows. It assumes the following environment:

  • Windows 10, running WSL
  • A Ruby dev environment, running inside WSL
  • Code that we want to test using a web driver, in this case Selenium, with a Capybara and RSpec test framework

The coding project folders are stored in the main Windows filing hierarchy and accessed via dev/mnt, but that makes no real difference to development and testing other than making it possible to edit the code using a GUI based editor within Windows.

The problem with browser testing in WSL is that it relies on opening and controlling a web browser, and browsers don’t work on WSL at present as it deliberately doesn’t include X Windows or some other GUI manager - it’s meant to be command line after all. So while you can apt-get firefox, trying to actually run it isn’t going to work.

@drippdropp
drippdropp / gist:dafa128bfd4a9c5f0144
Created August 28, 2014 18:01
Basic Email Validation Method!
def extract_emails_from_string(string)
email_validation_regex =
Regexp.new(/([a-z0-9A-Z\+\_\.\'\!\#\$\%\&\~\{\}\|\-]+\@[a-z0-9A-Z\+\_\.\'\!\#\$\%\&\~\{\}\|\-]+)/i)
string.scan(email_validation_regex).flatten.join(', ')
end
@jcave
jcave / DigitalOcean-BasicRailsSetup.md
Last active February 12, 2016 01:52
How to set up a DigitalOcean server with their 1-click Ubuntu/Rails/Ngnix/Unicorn/Mysql install

Basic Rails App on Digital Ocean / Ngnix / Unicorn

Most of this I got from the DigitalOcean file.

  1. Sign up for an account at digitalocean.com. Create a droplet using the pre-configed Ubuntu 12.10/Rails/Ngix/Unicorn option and using an ssh key if you set one up first. [An overview can be found here.] (https://www.digitalocean.com/community/articles/how-to-set-up-ssh-keys--2) If you don’t set up an SSH key, that's okay, DigitialOcean (DO) will send you one to your email.
  2. Once setup with an IP, point your domain or subdomain to the IP from wherever you are hosting as an A record. Log in using ssh root@ip.address.of.server. Enter your password if needed.
  3. Type passwd into the console to change the password of root to something you can remember.
  4. If you want add a new user so you don’t have to use root then type adduser [username] in the console. Feel free to fill out the Fu
@JamesDullaghan
JamesDullaghan / digitalocean.md
Created July 6, 2013 20:54
Deploy rails app to digitalocean with nginx, unicorn, capistrano & postgres

Deploy Rails app to digitalocean with nginx, unicorn, capistrano & postgres

Create droplet of your liking (ubuntu 12.10 x32)

ssh to root in terminal with your server ip

ssh root@123.123.123.123

Add ssh fingerprint and enter password provided in email

@srpouyet
srpouyet / create_related_users.rb
Last active November 2, 2019 03:05
Self referential HABTM (has_and_belongs_to_many) in Rails 3
@toranb
toranb / filtersortpagemixin.js
Created September 24, 2012 02:37
filter/sort/pagination mixin for ember.js
var get = Ember.get;
/**
* @extends Ember.Mixin
*
* Implements common filter / sort / pagination behavior for array controllers
* */
Ember.FilterSortSliceMixin = Ember.Mixin.create({
filterBy: '',
@dschneider
dschneider / gist:2941985
Created June 16, 2012 17:15
RSpec - Stub Remote IP Request
ActionDispatch::Request.any_instance.stub(:remote_ip).and_return("192.168.0.1")