Search This Blog

2021/02/27

Use timer to auto save game data | Godot Engine

 func _ready():

# Timers don't work unless they are in the tree

var timer = Timer.new()

timer.set_wait_time(1)

timer.connect("timeout", self, "_on_Timer_timeout")

timer.set_autostart(true)

self.add_child(timer)


func _on_Timer_timeout():

# autosave func

save_game()

2021/01/17

牛顿迭代法求根号的值

例:求根号2等于多少。随意猜测为4,用牛顿迭代法

(4+2/4)/2=2.25

(2.25+2/2.25)/2=1.56944...

(1.56944...+2/1.56944...)/2=1.42189...

(1.42189...+2/1.42189...)/2=1.41423...

......

2020/08/20

Check if data in table is duplicated

Sub check()

Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("History")

Dim ws2 As Worksheet
Set ws2 = ThisWorkbook.Worksheets("Result")

Dim i As Long, j As Integer, k As Integer

i = 2
j = 0
k = 1

Do While ws.Cells(i, 3).Value <> ""
If ws.Cells(i, 3).Value = ws.Cells(i - 1, 3).Value Then
j = j + 1

Else

j = 0

End If

If j > 1 Then
ws2.Cells(k, 1).Value = ws.Cells(i, 3).Value
k = k + 1
End If
i = i + 1
Loop

Sheets("Result").Select
Columns("A:A").Select

' delete duplicate data
ActiveSheet.Range("$A$1:$A$5000").RemoveDuplicates Columns:=1, Header:=xlNo

MsgBox "End"



End Sub

2020/07/03

Create array in PowerShell

$hashArray = @{}

If($hashArray[$key] -eq $null) {
$hashArray.add("$key", @{
"key1" = "value"
"key2" = "value"
"key3" = "value"
}
)
}
$hashArray[$key]["key1"]

2020/05/27

Proxy and login sample | PowerShell

# proxy
# password must be secure string
$password = "yourPassword" | ConvertTo-SecureString -AsPlainText -Force
$proxyCred = New-Object System.Management.Automation.PsCredential("$uname@domain.tld", $password)
$proxyUrl = "your proxy url"
$proxy = New-Object System.Net.WebProxy $proxyUrl
$proxy.Credentials = $proxyCred
[System.Net.WebRequest]::DefaultWebProxy = $proxy
Write-Host("Proxy setting")

# login
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;
$browser = New-Object System.Net.WebClient
$browser.Proxy.Credentials = $proxyCred

$loginUrl = "login url"
$loginPassword= "yourLoginPassword" |ConvertTo-SecureString -AsPlainText -Force
$BSTR = [Sysrem.Runtime.InteropServices.Marshal]::SecureStringToBSTR($loginPassword)
$unsecurePassword = [System.Rutime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
$postParams = @{
  username = "username"
  password = $unsecurePassword
}

$Auth = Invoke-RestMethod -Uri $loginUrl -Method POST -Body $postParams
# $result = Invoke-RestMethod -Uri $loginUrl -Method GET -Headers $headers