Skip to content

Instantly share code, notes, and snippets.

@gaearon
gaearon / 00-README-NEXT-SPA.md
Last active May 5, 2024 15:12
Next.js SPA example with dynamic client-only routing and static hosting

Next.js client-only SPA example

Made this example to show how to use Next.js router for a 100% SPA (no JS server) app.

You use Next.js router like normally, but don't define getStaticProps and such. Instead you do client-only fetching with swr, react-query, or similar methods.

You can generate HTML fallback for the page if there's something meaningful to show before you "know" the params. (Remember, HTML is static, so it can't respond to dynamic query. But it can be different per route.)

Don't like Next? Here's how to do the same in Gatsby.

@pesterhazy
pesterhazy / indexeddb-problems.md
Last active April 19, 2024 02:40
The pain and anguish of using IndexedDB: problems, bugs and oddities

This gist lists challenges you run into when building offline-first applications based on IndexedDB, including open-source libraries like Firebase, pouchdb and AWS amplify (more).

Note that some of the following issues affect only Safari. Out of the major browsers, Chrome's IndexedDB implementation is the best.

Backing file on disk (WAL file) keeps growing (Safari)

When this bug occurs, every time you use the indexeddb, the WAL file grows. Garbage collection doesn't seem to be working, so after a while, you end up with gigabytes of data.

Random exceptions when working with a large number of indexeddb databases (Safari)

@berndverst
berndverst / VSCodeUserSettings.json
Last active April 6, 2024 00:14
VS Code: Override Terminal Colors with Solarized Dark regardless of Theme
{
"workbench.colorCustomizations": {
"terminal.foreground": "#839496",
"terminal.background": "#002833",
"terminal.ansiBlack": "#003541",
"terminal.ansiBlue": "#268bd2",
"terminal.ansiCyan": "#2aa198",
"terminal.ansiGreen": "#859901",
"terminal.ansiMagenta": "#d33682",
"terminal.ansiRed": "#dc322f",
@timvisee
timvisee / falsehoods-programming-time-list.md
Last active May 4, 2024 11:33
Falsehoods programmers believe about time, in a single list

Falsehoods programmers believe about time

This is a compiled list of falsehoods programmers tend to believe about working with time.

Don't re-invent a date time library yourself. If you think you understand everything about time, you're probably doing it wrong.

Falsehoods

  • There are always 24 hours in a day.
  • February is always 28 days long.
  • Any 24-hour period will always begin and end in the same day (or week, or month).
@joshdover
joshdover / README.md
Last active September 28, 2023 21:38
Idiomatic React Testing Patterns

Idiomatic React Testing Patterns

Testing React components seems simple at first. Then you need to test something that isn't a pure interaction and things seem to break down. These 4 patterns should help you write readable, flexible tests for the type of component you are testing.

Setup

I recommend doing all setup in the most functional way possible. If you can avoid it, don't set variables in a beforeEach. This will help ensure tests are isolated and make things a bit easier to reason about. I use a pattern that gives great defaults for each test example but allows every example to override props when needed:

Turning Off Github Issues

My friend Michael Jackson turned off github issues on one of his smaller projects. It got me thinking...

Maintainers getting burned out is a problem. Not just for the users of a project but the mental health of the maintainer. It's a big deal for both parties. Consumers want great tools, maintainers want to create them, but maintainers don't want to be L1 tech support, that's why they

@jakimowicz
jakimowicz / the % notation in ruby.md
Last active April 4, 2024 13:59
%Q, %q, %W, %w, %x, %r, %s, %I, %i

%Q, %q, %W, %w, %x, %r, %s, %i

Perl-inspired notation to quote strings: by using % (percent character) and specifying a delimiting character.

Any single non-alpha-numeric character can be used as the delimiter, %[including these], %?or these?, %~or even these things~.

Strings

% or %Q

@lengarvey
lengarvey / staging.rb
Created June 29, 2014 11:28
Enabling Rails 4.1 mail previews in staging (or any other env besides development)
# put this in your staging.rb file. Obviously you'll need more config than this it's just an example.
Rails.application.configure do
config.action_mailer.preview_path ||= defined?(Rails.root) ? "#{Rails.root}/test/mailers/previews" : nil
config.autoload_paths += [config.action_mailer.preview_path]
routes.append do
get '/rails/mailers' => "rails/mailers#index"
get '/rails/mailers/*path' => "rails/mailers#preview"
end
@staltz
staltz / introrx.md
Last active May 3, 2024 13:00
The introduction to Reactive Programming you've been missing
@tomriley
tomriley / mongiod_mysql_migrator.rb
Created April 10, 2014 17:24
Migrate a Mongoid / MongoDB database to an ActiveRecord based SQL one. One method to convert the schema, another to migrate data. Copes with most basic data types. Some hacks to infer TEXT columns. Converts embeds_one relationships to AR aggregations. I wrote this for a one-time migration. It could be a good starting point for someone doing the …
# Migrate schema and data from Mongoid to MySQL ActiveRecord
class MongoidMysqlMigrator
def randomize_auto_increment_values(source_models, from=5500, to=10500)
source_models.each do |model|
value = rand(from-to)+from
sql = %(ALTER TABLE #{model.name.tableize} AUTO_INCREMENT=#{value})
puts sql
ActiveRecord::Base.connection.execute(sql)
end