Skip to content

Instantly share code, notes, and snippets.

View fsubal's full-sized avatar

fsubal fsubal

View GitHub Profile
@tadd
tadd / git-push
Last active November 11, 2023 05:16
Force not to use `git push -f` but `--force-with-lease`
#!/bin/bash -eu
argv="$(sed -E 's/(^| )-f\b/\1--force-with-lease/g' <<<$@)"
exec git push ${argv}
class JsonSerialize
include ActiveModel::Model
include ActiveModel::Attributes
include ActiveModel::Serializers::JSON
def initialize(attributes)
super()
attributes.each do |key, value|
self.public_send("#{key}=", value)
end
@eric-hemasystems
eric-hemasystems / hash_delegate.rb
Created August 16, 2021 16:43
Rails `delegate to:` for hashes
module HashDelegate
# Like `delegate :foo, to: :bar` only for hashes instead
# of objects. So these are the same:
#
# def foo
# bar[:foo]
# end
#
# hash_delegate :foo, to: :bar
@petamoriken
petamoriken / useResponsive.ts
Last active October 11, 2022 03:41
雑に Responsive Design 用の React Custom Hooks を作ったやつ。
import { useEffect, useMemo, useState } from "react";
/**
* 後続の Iterator Value と合わせた Iterator を返す
* (1, 2, 3) -> ([1, 2], [2, 3], [3, undefined])
*
* @param iterable
*/
function* withNext<T>(iterable: Iterable<T>): IterableIterator<[T, T | undefined]> {
let isStart = true;
@gaearon
gaearon / uselayouteffect-ssr.md
Last active July 7, 2024 18:47
useLayoutEffect and server rendering

If you use server rendering, keep in mind that neither useLayoutEffect nor useEffect can run until the JavaScript is downloaded.

You might see a warning if you try to useLayoutEffect on the server. Here's two common ways to fix it.

Option 1: Convert to useEffect

If this effect isn't important for first render (i.e. if the UI still looks valid before it runs), then useEffect instead.

function MyComponent() {
@fsubal
fsubal / 2019-02-20.als
Created February 20, 2019 11:57
alloy 入門ハンズオン
abstract sig Object {}
sig File extends Object {}
sig Directory extends Object {
children: set Object
}
// singleParent が欠けると => 複数の directory に属する file があらわれる
fact singleParent {
all o : Object | lone children.o
@hashrock
hashrock / svg-drag.js
Last active January 31, 2024 13:22
SVG Drag and Drop with React Hooks
import React from "react";
import ReactDOM from "react-dom";
const Circle = () => {
const [position, setPosition] = React.useState({
x: 100,
y: 100,
active: false,
offset: { }
});
@Jessidhia
Jessidhia / react-scheduler.md
Last active June 11, 2024 10:48
Implementation notes on react's scheduling model as of (shortly before) 16.8.0

Implementation notes on react's scheduling model as of (shortly before) 16.8.0

While the public API intended for users to use is the scheduler package, the reconciler currently does not use scheduler's priority classes internally.

ReactFiberScheduler has its own internal "mini-scheduler" that uses the scheduler package indirectly for its deadline-capable scheduleCallback.

This is kind of a documentation of implementation details that I suppose will be gone by the end of the year, but what can you do.

@ayamflow
ayamflow / gist:b602ab436ac9f05660d9c15190f4fd7b
Created May 9, 2016 19:10
Safari border-radius + overflow: hidden + CSS transform fix
// Add on element with overflow
-webkit-mask-image: -webkit-radial-gradient(white, black);
fizz = function f() {
fizz = function () {
fizz = function () {
fizz = f
return "Fizz"
}
}
}
buzz = function f() {