Skip to content

Instantly share code, notes, and snippets.

@wewindy
wewindy / using_with_expression.sql
Created July 24, 2021 21:50
postgis_sql_example
with temp_result as (
select st_point(1, 2) as test_point
)
select st_asgeojson(test_point) as final_result from temp_result;
@wewindy
wewindy / eclosion.frag
Created June 29, 2021 09:54
边缘羽化片元着色器
uniform sampler2D Tex;
const float size = 0.5;
void main(void)
{
vec2 realSize = vec2(textureSize(Tex, 0));
float ratio = (realSize.x > realSize.y) ? realSize.y/realSize.x : realSize.x/realSize.y;
vec2 texSize = vec2(512., 512.);
vec2 xy = gl_FragCoord.xy;
@wewindy
wewindy / PolylineTrailLinkMaterialProperty.js
Last active June 3, 2021 09:17
Cesium Polyline Trail Material Property
import { Color, defined, Event, Material, Property } from 'cesium'
const PolylineTrailLinkType = 'PolylineTrailLink'
const PolylineTrailLinkSource = /* glsl */`
czm_material czm_getMaterial(czm_materialInput materialInput)
{
czm_material material = czm_getDefaultMaterial(materialInput);
vec2 st = materialInput.st;
@wewindy
wewindy / FileSystemAPI.html
Created May 24, 2021 05:53
异步选择文件或文件夹 API
<button id="btn">ClickMe</button>
<script>
const btn = document.getElementById('btn')
let fileHandle
btn.addEventListener('click', async () => {
[fileHandle] = await window.showOpenFilePicker()
const file = await fileHandle.getFile()
const contents = await file.text()
console.log(contents)
})
@wewindy
wewindy / save.md
Created May 24, 2021 01:49
纯前端保存文件

使用a标签的 click 事件以及 URL.createObjectURL 方法 适合小文件的下载(无后端)

保存二进制文件

const buffer = new Float32Array([1, 2, 3, 4, 5]) // 创建一个类型数组,大小为 20 bytes
// 创建 blob 对象,第一个参数可以放置多个变量,这里放一个就好了
const blob = new Blob([buffer], {
 type: "application/octet-stream"
@wewindy
wewindy / condition-rAF.js
Created March 29, 2021 02:16
能用时间和条件来控制 requestAnimationFrame 的渲染
function main() {
let last = 0
// 上次渲染的值(此处初始化为一个整数)
let lastState = Math.floor(Math.random() * 10)
const canWeRender = function() {
// 这次渲染的值
const currentState = Math.floor(Math.random() * 10)
// 比较二者是否一致,如果一致,则false,否则true
if (currentState === lastState) {
console.log("lastState eq. currentState. Will not render.")
@wewindy
wewindy / friendly-filesize.js
Created March 29, 2021 02:00
return a string that friendly print file size.
function friendlyFileSize(sizeInBytes) {
if(sizeInBytes < 1024) {
return `${sizeInBytes} Bytes`;
} else if(sizeInBytes >= 1024 && sizeInBytes < 1048576) {
return `${(sizeInBytes/1024).toFixed(2)} KB`;
} else if(sizeInBytes >= 1048576) {
return `${(sizeInBytes/1048576).toFixed(2)} MB`;
}
}
@wewindy
wewindy / localForage-demo.js
Last active May 24, 2021 01:28
localForage-demo
import localForage from 'localforage'
// 创建仓库对象,并创建名为 “test” 的 indexeddb 以及 名为 “testidb” 的表
const store = localForage.createInstance({
driver: localForage.INDEXEDDB,
name: "test",
storeName: "testidb"
})
// 设置 key-value
@wewindy
wewindy / jacobi.js
Last active March 18, 2021 18:43
jacobi_alg
import Matrix2 from '../core/mat2.js'
import Matrix3, { transpose, multiply, } from '../core/mat3.js'
/**
* 雅可比迭代法求解实对称矩阵的特征向量、特征值
* @param {Matrix2 | Matrix3} matrix 二维数组,当前支持二维、三维迭代求解
* @returns {Object} 返回一个对象 obj, obj.eigenVectors 是特征向量(二维数组),obj.eigenValues 是特征值(一维数组)
*/
function jacobi(matrix) {
const length = matrix.length === undefined ? matrix.dimensions : matrix.length
@wewindy
wewindy / transpose.js
Created February 25, 2021 11:02
array[][] transpose
/**
* 将矩阵(二维数组形式)转置的高效方法
* @param {Array[][]} arr 二维数组,子数组中元素个数应一致
*/
export function transpose(arr) {
return arr[0].map((_, i) => arr.map(row => row[i]))
}