Skip to content

Instantly share code, notes, and snippets.

require "bundler/inline"
require "logger"
gemfile do
gem "graphql", "1.12.19"
gem "graphql-pro", "1.20.1"
gem "redis"
end
# Here's an example of caching parsed AST documents for persisted queries.
@such
such / cursor.rb
Created July 25, 2022 15:26
Bad handling of invalid cursor
# frozen_string_literal: true
require 'bundler/inline'
require 'logger'
gemfile do
gem 'graphql', '2.0.12'
gem 'graphql-pro', '1.22.2'
gem 'activerecord', '7.0.2.4'
@such
such / through_association_preloader.rb
Last active July 7, 2022 13:51
Rails bug reproduction:
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
gem "activerecord", "7.0.2.4"
gem "sqlite3"
end
// in the Context provider:
const interval = setInterval(() => setNow(new Date()), 1000);
// becomes:
const interval = setInterval(() => setNow(moment()), 1000);
// in the Component:
return intervalToDuration({ start: date, end: now });
// becomes:
return moment.duration(now.diff(date)).format('HH:mm:ss');
export function Timer({ date }) {
const { now } = useContext(TickerContext);
return intervalToDuration({ start: date, end: now });
};
export const TickerContext = React.createContext(null);
export function TickerProvider({ children }) {
const [now, setNow] = useState(new Date());
useEffect(() => {
const interval = setInterval(() => setNow(new Date()), 1000);
return () => clearInterval(interval);
}, []);
Moment.pooledTimer = setInterval(() => {
Moment.pooledElements.forEach((element) => {
if (element.props.interval !== 0) {
element.update();
}
});
}, interval);
setTimer = () => {
const { interval } = this.props;
this.clearTimer();
if (!Moment.pooledTimer && interval !== 0) {
this.timer = setInterval(() => {
this.update(this.props);
}, interval);
}
};
<Moment date={date} interval={1000} format="HH:mm:ss" durationFromNow />
setInterval(() => {
document.getElementById('my-countdown').textContent = new Date();
}, 1000)