Skip to content

Instantly share code, notes, and snippets.

View thc282's full-sized avatar
🎮
Gaming Student

thc282

🎮
Gaming Student
View GitHub Profile
@thc282
thc282 / CustomTextField.kt
Last active April 13, 2024 18:22
JetPack Compose Customize TextField + Error Message (Fix Text cutting when height is small) [Default style = OutlinedTextField] <Android>
var email by remember { mutableStateOf("") }
var isEmailValid by remember { mutableStateOf(false) }
//Calling the function
CustomOutlinedTextField(
value = email,
onValueChange = {
email = it
isEmailValid = isValidEmail(it)
},
@thc282
thc282 / FixScreenScale.html
Created April 19, 2024 21:12
Fix HTML fit screen
<!--add this into <head> part -->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
@thc282
thc282 / Json2CSV.js
Last active July 18, 2024 10:02
Convert Json to CSV format & popout form
//Convert to csv
downloadCSVFromJson = (filename, arrayOfJson) => {
// convert JSON to CSV
const replacer = (key, value) => value === null ? '' : value // specify how you want to handle null values here
const header = Object.keys(arrayOfJson[0])
let csv = arrayOfJson.map(row => header.map(fieldName =>
JSON.stringify(row[fieldName], replacer)).join(','))
csv.unshift(header.join(','))
csv = csv.join('\r\n')
@thc282
thc282 / WindowOpen.js
Last active April 22, 2024 16:15
window.open with android / IOS
//Get the device type
let system = navigator.userAgent
let isAndroid = system.indexOf('Android') > -1 || system.indexOf('Adr') > -1 // android终端
let isiOS = !!system.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/) //ios终端
let Androidurl = "https://www.androidurl.com"
let Appleurl = "https://www.Appleurl.com"
// Open the Google Maps link in a new tab
var newWindow = window.open('', '_blank') // Noted: this window.open() must be call outside the async, since safari blocked .open() inside any async function
@thc282
thc282 / ExecutionPolicyFix.md
Last active June 25, 2024 02:34
fix ps1 cannot be loaded because running scripts is disabled on this system

To fix the ExecutionPolicy

ps1 cannot be loaded because running scripts is disabled on this system

Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope CurrentUser

@thc282
thc282 / interpolation.md
Last active June 25, 2024 09:26
the code to calculate the interpolation

1. First calculate the speed

speed = (currentTime - startTime) / (endTime - startTime)

frame = Date.now()
const speed = (frame - positions[0].frame) / (positions[0 + delay].frame - positions[1 + delay].frame);
  • The interpolation factor speed represents the position between the two most recent positions in the positions array.
  • frame is the current frame of the game.
  • positions[0].frame is the frame of the most recent position in the positions array.
  • positions[0 + delay].frame and positions[1 + delay].frame are the frames of the two most recent positions, with a delay offset.
@thc282
thc282 / canvasCapture.md
Last active August 21, 2024 08:52
canvas capture (three js)

⚠⚠⚠⚠⚠this must be set when new a renderer object⚠⚠⚠⚠⚠
{preserveDrawingBuffer: true}

//⚠⚠⚠⚠⚠this must be set when new a renderer object⚠⚠⚠⚠⚠
//{preserveDrawingBuffer: true}
const renderer = new THREE.WebGLRenderer({preserveDrawingBuffer: true});
//set a id for getting the canvas
renderer.domElement.id = 'screenshot';