Skip to content

Instantly share code, notes, and snippets.

Avatar
💻
({oscar, coffee}) => code

Oscar Tong m0o0scar

💻
({oscar, coffee}) => code
  • Base Reality
View GitHub Profile
@m0o0scar
m0o0scar / index.html
Created Jul 1, 2021
Prevent google.com from crashing Electron v13
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'">
<meta http-equiv="X-Content-Security-Policy" content="default-src 'self'; script-src 'self'">
<title>Hello World!</title>
</head>
<body>
@m0o0scar
m0o0scar / index.html
Created Jun 8, 2021
iPhone 12 HDR video overexposed issue
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
</head>
<body>
<h1>iPhone 12 HDR Video Test</h1>
<video controls autoplay width="600">
@m0o0scar
m0o0scar / isSupportFontFamily.js
Created Feb 27, 2018
用JS检测用户是否安装某font-family字体
View isSupportFontFamily.js
//原文及原理请见:http://www.zhangxinxu.com/wordpress/2018/02/js-detect-suppot-font-family/
var isSupportFontFamily=function(f){if(typeof f!="string"){return false}var h="Arial";if(f.toLowerCase()==h.toLowerCase()){return true}var e="a";var d=100;var a=100,i=100;var c=document.createElement("canvas");var b=c.getContext("2d");c.width=a;c.height=i;b.textAlign="center";b.fillStyle="black";b.textBaseline="middle";var g=function(j){b.clearRect(0,0,a,i);b.font=d+"px "+j+", "+h;b.fillText(e,a/2,i/2);var k=b.getImageData(0,0,a,i).data;return[].slice.call(k).filter(function(l){return l!=0})};return g(h).join("")!==g(f).join("")};
@m0o0scar
m0o0scar / DistanceCalculator.cs
Last active Nov 16, 2017
Simple way to calculate closest distance to a cube surface
View DistanceCalculator.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DistanceCalculator : MonoBehaviour {
public GameObject[] targets;
void Update () {
foreach(GameObject target in targets) {
@m0o0scar
m0o0scar / uuid.js
Last active Nov 16, 2017
Generate UUID
View uuid.js
//generate an uuid with specify length
function uuid(length=26) {
let len = Math.min(length, 50)/2;
return Math.random().toString(36).substring(2, 2+Math.floor(len)) +
Math.random().toString(36).substring(2, 2+Math.ceil(len));
}
@m0o0scar
m0o0scar / Microphone.cs
Last active Nov 16, 2017
Unity To Playback A Microphone Input In Real Time
View Microphone.cs
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(AudioSource))]
public class Microphone : MonoBehaviour {
AudioSource source;
void Start () {
if(Microphone.devices.Length > 0) {