Skip to content

Instantly share code, notes, and snippets.

View TSMMark's full-sized avatar
🐶

Mark Allen TSMMark

🐶
View GitHub Profile
@TSMMark
TSMMark / ._README.md
Last active April 30, 2022 21:04
alias `binding.pry` as `debugger` in .pryrc pry config file

alias binding.pry as debugger in .pryrc pry config file

The Problem

In my experience, debugger is easier for people to remember and to type. And so most devs on our team prefer typing debugger over binding.pry. However, debugger is worse than binding.pry because it doesn't use Pry, which is better than standard byebug / irb repl.

The Solution

Alias binding.pry as debugger. Now we should be able to use debugger and binding.pry interchangeably, and it will always use Pry!

@TSMMark
TSMMark / pipe.js
Created September 9, 2021 17:07
Ben Lesh's Pipe function
// https://twitter.com/BenLesh/status/1435711312617746432
const pipe = (start, ...fns) => fns.reduce((prev, fn) => fn(prev), start);
// Example usage:
// pipe(source, map(fn), filter(fn))
@TSMMark
TSMMark / update_with_latest_master.yml
Last active March 31, 2021 15:40
GH Action Workflow to merge master into current branch when a label is added to a PR
# .github/workflows/update_with_latest_master.yml
#
# This is a Github Action Workflow to merge master into current branch when a label is added to a PR.
# Label: `update with latest master`
#
# 1) Add this yml file to your github workflows directory.
# 2) Add the issue/pr label: `update with latest master` to your project.
# 3) Any time you want to merge master into a branch, just add the `update with latest master` label to it!
#
# NOTE: This will trigger a new commit on your branch, potentially triggering CI, and other workflows.
@TSMMark
TSMMark / check_parameter_types.rb
Created February 10, 2021 01:44
Check if a method has kwargs and/or ordered params
# Has kwargs? (Keyword arguments)
def method_has_keyword_parameters?(method)
method.parameters.any? do |param|
type, _name = param
type == :key
end
end
# Has ordered arguments?
@TSMMark
TSMMark / useYouTubeIframeAPIReady.ts
Created January 28, 2021 01:02
React hook to return boolean true once the YouTube Iframe API is ready (onYouTubeIframeAPIReady)
const useYouTubeIframeAPIReady = (): boolean => {
const [isReady, setIsReady] = useState<boolean>(false)
useEffect(() => {
if (window.YT.Player) {
setIsReady(true)
return
}
window['onYouTubeIframeAPIReady'] = () => {
@TSMMark
TSMMark / create-post.ts
Last active December 9, 2020 20:36
next.js netlify aws lambda higher order function composition handler middleware
export const handler: Handler = compose(
httpRespond(),
httpMethod('POST'),
)(async ({ body }: APIGatewayEvent) => ({
post: await createPost(JSON.parse(body))
}))
/*
Recently wrote some Next.js/Netlify functions to run in AWS Lambdas.
@TSMMark
TSMMark / useSelectedItems.js
Last active July 26, 2019 04:29
useSelectedItems
// Default use:
const [selectedMedias, addId, removeId] = useSelectedItems(medias)
// Example of how to select an item
map(medias, ({ id, title }) => <a onClick={() => addId(id)}>{ id } { title }</a>)
// Example of how to deselect an item
map(selectedMedias, ({ id, title }) => <a onClick={() => removeId(id)}>{ id } { title } is selected!</a>)
@TSMMark
TSMMark / cloudSettings
Last active June 12, 2023 20:09 — forked from StevePotter/cloudSettings
Visual Studio Code Settings Sync Gist
{"lastUpload":"2020-09-14T17:18:10.569Z","extensionVersion":"v3.4.3"}
@TSMMark
TSMMark / rake_utils.rb
Created December 4, 2018 05:01
Load rakefile once only
module RakeUtils
class << self
# Load the rakefile, unless it's already been loaded.
def load_rakefile
@load_rakefile ||= begin
load "#{PROJECT_ROOT_PATH}/Rakefile"
true
@TSMMark
TSMMark / clear-peer-deps.js
Created June 4, 2018 20:45
clear-peer-deps - remove peerDependency records from node_modules/* recursively
const fs = require('fs')
function replaceInFile ({ file, pattern, replacement }) {
fs.readFile(file, 'utf8', (err, data) => {
if (err) {
return console.log(err)
}
const result = data.replace(pattern, replacement)