Skip to content

Instantly share code, notes, and snippets.

Avatar

Satoh, Hiroh cho45

View GitHub Profile
View format-number-with-si-prefix.js
function formatN (n) {
const unitList = ['y', 'z', 'a', 'f', 'p', 'n', 'u', 'm', '', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'];
const zeroIndex = 8;
const nn = n.toExponential(2).split(/e/);
let u = Math.floor(+nn[1] / 3) + zeroIndex;
if (u > unitList.length - 1) {
u = unitList.length - 1;
} else
if (u < 0) {
u = 0;
View NyanCat.pm
=pod
Nyan Cat TAP Formatter
1. Save this file into your PERL5LIB
2. Run prove with option like following:
$ prove --formatter NyanCat
http://www.mattsears.com/articles/2011/11/16/nyan-cat-rspec-formatter
View uneval.js
if (typeof uneval != "function") {
uneval = function (o) {
switch (typeof o) {
case "undefined" : return "(void 0)";
case "boolean" : return String(o);
case "number" : return String(o);
case "string" : return '"' + o.replace(/[^a-z]/gi, function (_) { return '\\u' + (0x10000 + _.charCodeAt(0)).toString(16).slice(1) }) + '"';
case "function" : return "(" + o.toString() + ")";
case "object" :
if (o == null) return "null";
View sine.js
//#!node
const sleep = (n) => new Promise( (resolve) => setTimeout(resolve, n) );
const asciichart = require('asciichart')
const screen = {
clear: function () {
console.log('\x1b[2J');
},
View ITU-T G.227.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View niz-sketch.rb
#!/usr/bin/env ruby
require "hid_api" # gem install hid_api
require "pp"
COMMAND_READ_ALL = 0xf2
COMMAND_VERSION = 0xf9
COMMAND_READ_COUNTER = 0xe3
COMMAND_INITIAL_CALIB = 0xdb
COMMAND_PRESS_CALIB = 0xdd
#COMMAND_WRITE_ALL = 0x00
View size.rb
#!/usr/bin/env ruby
require 'pp'
D = Struct.new(:sec, :size, :name)
target = ARGV.shift
sram = `arm-none-eabi-objdump -t '#{target}'`.chomp.split(/\n/).
select {|l| /\.(bss|data)|vectors/ =~ l }.
View avstack.pl
#!/usr/bin/perl -w
# avstack.pl: AVR stack checker
# Copyright (C) 2013 Daniel Beer <dlbeer@gmail.com>
#
# Permission to use, copy, modify, and/or distribute this software for
# any purpose with or without fee is hereby granted, provided that the
# above copyright notice and this permission notice appear in all
# copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
View signal-processor.js
class SignalProcessor extends AudioWorkletProcessor {
constructor() {
super();
this.buffers = [];
this.port.onmessage = (e) => {
console.log(e, this.buffers);
this.port.postMessage(this.buffers);
// this.buffers.length = 0;
};
}
View Math.js
let a = 0;
for (let i = 0; i < 10000; i++) {
a += Math.sin(i);
a += Math.cos(i);
}
You can’t perform that action at this time.