Skip to content

Instantly share code, notes, and snippets.

FUJI Goro gfx

View GitHub Profile
View generator.ts
function* iterateParams() {
for (const x of ["a", "b", "c"]) {
for (const i of [1, 2, 3]) {
yield { x, i };
}
}
}
for (const p of iterateParams()) {
console.log(p);
View hires-time.c
#include <stdio.h>
#include <sys/time.h>
#include <time.h>
int main() {
printf("gettmeofday:\n");
for (int i = 0; i < 10; i++) {
struct timeval tv1, tv2;
gettimeofday(&tv1, NULL);
gettimeofday(&tv2, NULL);
@gfx
gfx / prog.c
Created Apr 6, 2020
`fread(3)` returns 0 for success. why?
View prog.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
int main() {
char cmdline[256];
char proc_file[256];
snprintf(proc_file, sizeof(proc_file), "/proc/%d/cmdline", getpid());
@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 でソートを指定すべきです。"
You can’t perform that action at this time.