Skip to content

Instantly share code, notes, and snippets.

FUJI Goro gfx

Block or report user

Report or block gfx

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@gfx
gfx / asroot.pm
Last active Sep 4, 2019
perl -Masroot foo.pl # run it as root
View asroot.pm
# usage: use asroot; # run it as root
package asroot;
use strict;
use warnings;
# TODO: inherits @INC
exec "sudo", $^X, $0, @ARGV if $< != 0;
1;
View webpack.config.js.diff
diff --git a/config/webpack.config.js b/config/webpack.config.js
index 601977b04..63866d814 100644
--- a/config/webpack.config.js
+++ b/config/webpack.config.js
@@ -37,11 +37,16 @@ const publicPath = (() => {
const DAY_MS = 24 * 60 * 60 * 1000;
const ASSET_EXPIRED_TIME_MS = Date.now() - 14 * DAY_MS; // 14 days ago
+// filter core-js modules instead of just using "core-js" to reduce bundle sizes
+const coreJsModules = require("core-js-compat")({
View decode-benchmark.ts
// NOTE: use the last segment of the result CSV
/* eslint-disable no-console */
import { utf8EncodeJs, utf8Count, utf8DecodeJs, utf8DecodeTD } from "../src/utils/utf8";
import { utf8DecodeWasm } from "../src/wasmFunctions";
// @ts-ignore
import Benchmark from "benchmark";
for (const baseStr of ["A"]) {
@gfx
gfx / json-bench.js
Last active Jun 28, 2019
Evaluating JSON.parse vs object literal. cf. https://v8.dev/blog/cost-of-javascript-2019
View json-bench.js
const fs = require("fs");
const assert = require("assert");
const jsonBuffer = fs.readFileSync("./schema.json");
const object = JSON.parse(jsonBuffer.toString());
const jsonParseExpr = `(JSON.parse(${JSON.stringify(JSON.stringify(object))}))`;
const objectLiteralExpr = `(${JSON.stringify(object)})`;
const N = 100;
@gfx
gfx / msgpack-rails-init.rb
Created Jun 25, 2019
Mapping MessagePack timestamp type to ActiveSupport::TimeWithZone
View msgpack-rails-init.rb
# for Rails v5.2 + msgpack-ruby v1.3
MessagePack::DefaultFactory.register_type(
MessagePack::Timestamp::TYPE,
ActiveSupport::TimeWithZone,
packer: -> (time) do
MessagePack::Timestamp.to_msgpack_ext(time.tv_sec, time.tv_nsec)
end,
unpacker: -> (payload) do
tv = MessagePack::Timestamp.from_msgpack_ext(payload)
View MutableBuffer.ts
// Experimental `push(...bytes)`-able buffer
// Unfortunately, it is always slower than Array<number>.
export class MutableBuffer {
private length = 0;
private buffer = new Uint8Array(32);
push(...bytes: ReadonlyArray<number>): void {
const newLength = this.length + bytes.length;
@gfx
gfx / querly.yml
Created Aug 27, 2018
Check Relay connection sort order
View querly.yml
rules:
- id: kibela.connection_type_without_resolver
pattern: "field(:symbol:, _.connection_type, ..., !resolve: _, ...)"
message: "Relay connection に resolver が設定されていません。 AR::Relation に対するconnectionは resolver でソートを指定すべきです。"
@gfx
gfx / findReactChldrenRecursively.ts
Last active Aug 8, 2018
Find react children recursively.
View findReactChldrenRecursively.ts
// usage:
// findChildRecursively(this.props.children, (child) => {
// return React.isValidElement(child) && child.type === "a";
// });
export function findChildRecursively(
children: React.ReactNode | ReadonlyArray<React.ReactNode>,
predicate: (child: React.ReactChild) => boolean,
): boolean {
View countable_object.rb
# frozen_string_literal: true
module Types
class CountableObject < BaseObject
class << self
def define_connection(**args, &block)
super(**args) do
block&.call
# this type must be GraphQL::INT_TYPE (not Integer), may be a bug.
@gfx
gfx / .eslintrc.js
Last active Aug 6, 2019
Kibela's eslint / prettier config files
View .eslintrc.js
module.exports = {
extends: [
// https://eslint.org/docs/rules/
"eslint:recommended",
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/src/configs/recommended.json
"plugin:@typescript-eslint/recommended",
// https://prettier.io/docs/en/eslint.html
"plugin:prettier/recommended",
// https://github.com/yannickcr/eslint-plugin-react
"plugin:react/recommended",
You can’t perform that action at this time.