Skip to content

Instantly share code, notes, and snippets.

@Herve07h22
Herve07h22 / useObserver.ts
Last active December 16, 2022 12:32
Observable/Observer in React with 65 lines of TypeScript
import { useEffect, useState } from "react";
class EventBus<T> {
_handlers: Set<(t: T) => void> = new Set();
subscribe(handler: (t: T) => void) {
this._handlers.add(handler);
}
unsubscribe(handler: (t: T) => void) {
this._handlers.delete(handler);
}

Fixing Webpacker 3.3.0 + Rails 5.1.5

Heroku hosting trouble

Heroku may not detect a correct buildpack for your JS dependencies, then you have to set it manually:

heroku buildpacks:add heroku/nodejs -i 1
heroku buildpacks:add --index 2 https://github.com/heroku/heroku-buildpack-ruby

Plugging a Datepicker

Let's put an end to datepicker suffering! Follow this steps to have your shiny new datepicker working in no time! (and remind yourselves of JS plugins in Rails)

Note: We recommend using Bootstrap Datepicker (try your own luck with anything different and remember, jQuery-UI's datepicker sucks, don't use it). These are the only three links you need:

  1. Docs
  2. Demo. Where you can play with different settings.
@samueljseay
samueljseay / es6-import-cheat-sheet.md
Created June 2, 2017 02:35
ES6 exports / imports cheat sheet
// default exports
export default 42;
export default {};
export default [];
export default (1 + 2);
export default foo;
export default function () {}
export default class {}
export default function foo () {}
@devilleweppenaar
devilleweppenaar / yarn_with_wercker_build.yml
Last active May 19, 2019 20:48
yarn with wercker - build step
build:
steps:
- script:
name: install yarn
code: npm install -g yarn
- script:
name: report yarn version
code: yarn --version
- script:
name: set yarn cache
@olivierlacan
olivierlacan / migrate_postgresql_database.md
Last active March 24, 2022 20:30
How to migrate a Homebrew-installed PostgreSQL database to a new major version (9.3 to 9.4) on OS X. See upgraded version of this guide: http://olivierlacan.com/posts/migrating-homebrew-postgres-to-a-new-version/

This guide assumes that you recently run brew upgrade postgresql and discovered to your dismay that you accidentally bumped from one major version to another: say 9.3.x to 9.4.x. Yes, that is a major version bump in PG land.

First let's check something.

brew info postgresql

The top of what gets printed as a result is the most important:

@Vestride
Vestride / encoding-video.md
Last active November 15, 2024 17:57
Encoding video for the web

Encoding Video

Installing

Install FFmpeg with homebrew. You'll need to install it with a couple flags for webm and the AAC audio codec.

brew install ffmpeg --with-libvpx --with-libvorbis --with-fdk-aac --with-opus
@henrik
henrik / images_helper.rb
Created February 11, 2015 07:57
Rails image_set_tag_3x helper for srcset.
module ImagesHelper
# Example usage:
#
# image_set_tag_3x "foo_1x.png", alt: "foo"
#
# Will assume there is a 2x and 3x version and provide those automagically.
#
# Based on https://gist.github.com/mrreynolds/4fc71c8d09646567111f
def image_set_tag_3x(source, options = {})
srcset = [ 2, 3 ].map { |num|
@iamnewton
iamnewton / bash-colors.md
Last active November 5, 2024 23:43
The entire table of ANSI color codes.

Regular Colors

Value Color
\e[0;30m Black
\e[0;31m Red
\e[0;32m Green
\e[0;33m Yellow
\e[0;34m Blue
\e[0;35m Purple
@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')