Skip to content

Instantly share code, notes, and snippets.

View kaizhu256's full-sized avatar

kai zhu kaizhu256

View GitHub Profile
@kaizhu256
kaizhu256 / demo.sinefit.sql
Last active April 17, 2024 07:09
demo.sinefit.sql
-- table - __data1 - insert
DROP TABLE IF EXISTS __data1;
CREATE TABLE __data1 AS
SELECT
tt,
SIN(tt) AS yy
FROM (
SELECT
value * 1.0 / (2 * 3.14) AS tt
FROM GENERATE_SERIES(0, 256)
@kaizhu256
kaizhu256 / cosfit
Created August 3, 2023 22:02
gauss-newton cosine fit pseudo code
aa = SQRT(SUM((yy - avg)^2) * 2.0 / nn)
cos = cosine(pp + ww*tt)
sin = sine(pp + ww*tt)
rr = (cos - yy) * (cos - yy)
hh1 = SUM( sin*sin - rr*cos )
hh2 = SUM(tt * (sin*sin - rr*cos))
hh3 = SUM(tt*tt * (sin*sin - rr*cos))
gg1 = SUM( rr * sin)
gg2 = SUM(tt * rr * sin)
inv = 1 / (hh1*hh3 - hh2*hh2)
@kaizhu256
kaizhu256 / statistics-distributions.js
Last active March 19, 2023 00:49 — forked from benrasmusen/statistics-distributions.js
JavaScript library for calculating critical values and upper probabilities of common statistical distributions
/*
* NAME
*
* statistics-distributions.js - JavaScript library for calculating
* critical values and upper probabilities of common statistical
* distributions
*
* SYNOPSIS
*
*
@kaizhu256
kaizhu256 / globExclude.mjs
Last active February 19, 2023 22:22
This gist file demos a performant, self-contained function "globExclude()", which batch-globs <pathnameList> in a single pass, with given filters <excludeList>, <includeList>.
/*jslint beta, node*/
// This gist file demos a performant, self-contained function "globExclude()",
// which batch-globs <pathnameList> in a single pass,
// with given filters <excludeList>, <includeList>.
//
// Could be useful if you need to glob thousands of files for test-coverage,
// or other purposes.
// Example usage
@kaizhu256
kaizhu256 / CalcNaturalBreaks.cpp
Last active November 11, 2021 01:56
This page contains C++ code of a O(k×n×log(n)) method for the classification of an array of numeric values such that the variance per class is minimal, known as a Fisher's Natural Breaks Classification
/*
copyright
This code is written by Maarten Hilferink, © Object Vision BV, and is provided
under GNU GPL v3.0 license
https://www.geodms.nl/CalcNaturalBreaks
This page contains C++ code of a O(k×n×log(n)) method for the classification of
an array of numeric values such that the variance per class is minimal, known as
a Fisher's Natural Breaks Classification. This algorithm is an improvement of
@kaizhu256
kaizhu256 / vfp.memo.to.csv.prg
Created September 21, 2021 15:33
Export memo fields with other field types to a text file with Visual FoxPro
* https://docs.microsoft.com/en-us/previous-versions/troubleshoot/visualstudio/foxpro/export-record-memo-fields
CLOSE ALL
CLEAR ALL
lcFieldString = ''
lcMemo = ''
USE GETFILE('dbf', 'Select DBF') && Prompts for table to be used.
////////////////////////////////////////////////////////////////
//
// http://www.planetquantum.com/Tables/StudentT.txt
//
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
//
// Critical Values of Student's t Distribution
// One sided test Prob(t<=c) == p
@kaizhu256
kaizhu256 / sqlite3_auto_extension.md
Created August 8, 2021 15:04
[sqlite] Example Showing ACTUAL Use of sqlite3_auto_extension()

[sqlite] Example Showing ACTUAL Use of sqlite3_auto_extension() Steve and Amy Tue, 07 Jun 2011 05:53:21 -0700

Would someone, please, show me an example (several actual, successive lines of code) in C (or C++) showing a proper use of

sqlite3_auto_extension()? I have searched the web looking for examples, but there are none that I can tell. I have also, to the best of my understanding, readhttp://www.sqlite.org/c3ref/auto_extension.html numerous times and I have had no success. I am trying to use SQLite with extensionfunctions.c, but

@kaizhu256
kaizhu256 / lib.jslint.js
Created May 11, 2021 21:55
standalone jslint program runnable with nodejs
#!/usr/bin/env node
/*
shRawLibFetch
{
"fetchList": [
{
"url": "https://github.com/douglascrockford/JSLint/blob/bca8b225a376352899d634442802b241fee8b97b/jslint.js"
}
]
}
@kaizhu256
kaizhu256 / jsonRowListFromcsv.js
Created December 21, 2020 21:12
convert json list-of-list or list-of-dict to csv
function jsonRowListFromCsv({
csv
}) {
/*
* this function will convert <csv>-text to json list-of-list
*/
/*
https://tools.ietf.org/html/rfc4180#section-2
Definition of the CSV Format
While there are various specifications and implementations for the