| require "json" | |
| struct = { "a" => 1, "b" => 2, "c" => [1, 2, 3], "d" => [{ "e" => 3 }, nil, false, true, [], {}] } | |
| source = JSON.dump(struct) | |
| tokens = [] | |
| index = 0 | |
| until source.empty? | |
| tokens << |
irb - command to launch ruby interpreter in any directory
rails c - command lets you interact with your Rails application from the command line
reload! - reload rails environment if you had changed model functionality
gem outdated - show all outdated gems on project
gem update [<gem_name>] - update a specific gem
./bin/webpack-dev-server - start webpacker dev server for fast compiling
code $(bundle show gem_name) - shortcut to open a Ruby gem in VS Code
| export const DEBOUNCE_DEFAULT_DELAY = 200; | |
| export default function debounce(func, delay = DEBOUNCE_DEFAULT_DELAY) { | |
| let timeout; | |
| return function(...args) { | |
| if (timeout) { | |
| clearTimeout(timeout); | |
| } | |
| timeout = setTimeout(() => { |
This is just some code I recently used in my development application in order to add token-based authentication for my api-only rails app. The api-client was to be consumed by a mobile application, so I needed an authentication solution that would keep the user logged in indefinetly and the only way to do this was either using refresh tokens or sliding sessions.
I also needed a way to both blacklist and whitelist tokens based on a unique identifier (jti)
Before trying it out DIY, I considered using:
| importScripts('https://www.gstatic.com/firebasejs/7.8.2/firebase-app.js') | |
| importScripts('https://www.gstatic.com/firebasejs/7.8.2/firebase-messaging.js') | |
| firebase.initializeApp({ | |
| apiKey: "---", | |
| authDomain: "test.firebaseapp.com", | |
| databaseURL: "https://test.firebaseio.com", | |
| projectId: "test", | |
| storageBucket: "test.appspot.com", | |
| messagingSenderId: "11111111111", |
| /** | |
| * useScroll React custom hook | |
| * Usage: | |
| * const { scrollX, scrollY, scrollDirection } = useScroll(); | |
| */ | |
| import { useState, useEffect } from "react"; | |
| export function useScroll() { | |
| const [lastScrollTop, setLastScrollTop] = useState(0); |
| # ~ Dispatch jQuery events as regular DOM events ~ | |
| # | |
| # Delegated events are given a new name in the format `jquery:<original event name>`. | |
| # If you delegate `ajax:send` you will be able to listen for `jquery:ajax:send` | |
| # on native event listeners such as Stimulus actions and `EventTarget.addEventListener`. | |
| # | |
| # Notes: | |
| # * The first parameter must be called "event". | |
| # * The parameters can be accessed as members on the `event.detail` object. | |
| # |