Skip to content

Instantly share code, notes, and snippets.

@lfender6445
lfender6445 / gist:9919357
Last active March 10, 2024 16:43
Pry Cheat Sheet

Pry Cheat Sheet

Command Line

  • pry -r ./config/app_init_file.rb - load your app into a pry session (look at the file loaded by config.ru)
  • pry -r ./config/environment.rb - load your rails into a pry session

Debugger

@lfender6445
lfender6445 / ruby_hash_fetch_vs_fetch_block.rb
Last active December 12, 2023 08:47
Ruby - Hash#fetch vs #fetch with block performance
# Benchmarks time difference between TEST_HASH.fetch(:baz, '') and TEST_HASH.fetch(:baz) { '' }
p 'Key does not exist -----'
TEST_HASH = { foo: :bar }
def operation
TEST_HASH.fetch(:baz, '')
end
def elaboration_time(&block)
s = Time.now
@lfender6445
lfender6445 / applescript_force_internal_microphone.scpt
Last active November 7, 2022 19:25
AppleScript - Switch to hardware mic
-- Force mac book pro 10.13.3 to switch audio input to hardware mic
tell application "System Preferences" to activate
tell application "System Preferences"
reveal anchor "input" of pane id "com.apple.preference.sound"
end tell
tell application "System Events" to tell process "System Preferences"
select (row 1 of table 1 of scroll area 1 of tab group 1 of window "Sound" whose value of text field 1 is "Internal Microphone")
end tell
quit application "System Preferences"
@lfender6445
lfender6445 / Foo.js
Last active May 6, 2021 17:18 — forked from tadjohnston/Foo.js
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import Baz from 'baz'
class Foo extends Component {
static propTypes = {
baz: PropTypes.bool,
list: PropTypes.array,
}
@lfender6445
lfender6445 / gist:6226290
Created August 13, 2013 22:22
restrict googleplaces by United States so it only returns zipcodes and states
// Application Javascript - see https://github.com/lfender6445/google_places for full example
var autocomplete, input, address = {};
$(document).ready(function(){
input = $("#searchBox");
$("#searchBox").clearOnFocus();
$('form').submit(function(){ return false; });
});
var init = function(){
@lfender6445
lfender6445 / when_to_write_e2e_tests.md
Last active October 26, 2020 19:38
When should I write an end to end test?

When should I write an end to end test?

a feature is to be considered in 'critical path' if it would require a rollback after breaking

When should I write an e2e test?

  • the feature overlaps with critical path
    • product and managment can help determine this designation
  • AND when unit tests alone are not sufficient or testing an interaction

When should I write a unit test?

@lfender6445
lfender6445 / get_deployment_url.sh
Last active October 19, 2020 20:28
get_deployment_url.sh
#!/bin/bash
# Output the current deployment URL for a PR.
# - Automatically determines the PR for your current branch if possible.
# Dependencies: `gh` and `jq`
ME=`basename $0`
# helpFunction([error message])
helpFunction()
{
@lfender6445
lfender6445 / example.js
Last active September 22, 2020 12:56
cannot-set-headers-after-they-are-sent-to-the-client.js
// exmaple.js
var express = require('express')
var app = express()
app.get('/foo', function (req, res) {
res.redirect(301, '/bar')
res.send('hello world') // should not set body while redirect in flight
})

== bin/development.ts (4 issues) == 20-106: Function startServer has 56 lines of code (exceeds 25 allowed). Consider refactoring. [structure] 40-50: Similar blocks of code found in 3 locations. Consider refactoring. [duplication] 52-62: Similar blocks of code found in 3 locations. Consider refactoring. [duplication] 64-74: Similar blocks of code found in 3 locations. Consider refactoring. [duplication]

== coverage/lcov-report/block-navigation.js (2 issues) == 2-78: Function init has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. [structure] 2-78: Function init has 57 lines of code (exceeds 25 allowed). Consider refactoring. [structure]

#! /bin/bash
function runCheck() {
while :; do
curl 'https://ww8.ikea.com/clickandcollect/us/receive/' \
-H 'authority: ww8.ikea.com' \
-H 'pragma: no-cache' \
-H 'cache-control: no-cache' \
-H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36' \
-H 'dnt: 1' \