Skip to content

Instantly share code, notes, and snippets.

View 5argon's full-sized avatar
🏠
Coffee shop programmer 24h

Sirawat Pitaksarit 5argon

🏠
Coffee shop programmer 24h
View GitHub Profile
@5argon
5argon / IntToStringLookup.cs
Last active February 8, 2017 07:23
Make int.ToString() faster to a certain number by changing it to int.ToStringLookup(). Avoiding dynamic memory allocation on the stack but uses more memory on the heap. Use the python program to generate a new lookup array.
public static class IntToStringLookup {
/*
A Python program for you!
import sys
import math
k = 0
@5argon
5argon / randomBase32.sql
Last active April 8, 2020 09:50
Create a PostgreSQL function that generates a random a Base32 string. Note that it might not be compatible with 8-bit ASCII under certain length because it maps each 5 bits to one Base32 character, so multiples of 8 will work. (8 5-bit Base32 characters = 40-bit = 5 8-bit ASCII characters) (Adapted from : http://stackoverflow.com/questions/39707…
CREATE OR REPLACE FUNCTION yourschema.randomBase32(length integer)
RETURNS text AS $$
declare
chars text[] := '{2,3,4,5,6,7,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z}';
result text := '';
i integer := 0;
begin
if length < 0 then
raise exception 'Given length cannot be less than 0';
end if;
@5argon
5argon / srvport.sh
Last active February 20, 2017 02:20
Get an SRV record's port number + target from a URL. (OSX/Linux, or maybe Windows if you have grep) Separated by a whitespace.
URL=$1
nslookup -type=SRV $URL | grep -Eo "service.*" | grep -Eo "[0-9]*[ ][^ ]*$"
@5argon
5argon / GoogleDocsFormatBasic.gs
Created May 22, 2017 11:10
How to format an entire document using RegEx in Google Docs add-on. It will bold my name in string like "5argon : Hello World!"
function formatInkVN() {
var body = DocumentApp.getActiveDocument().getBody();
//all text!
var allText = body.editAsText();
var regexString = "^.*[ ]:[ ]";
var rangeElement = allText.findText(regexString);
while (rangeElement != null) {
var matchedText = rangeElement.getElement().asText();
@5argon
5argon / GoogleDocsBoldAll.gs
Created May 22, 2017 11:12
Google Docs add-ons script to bold everything.
/**
* @OnlyCurrentDoc
*
* The above comment directs Apps Script to limit the scope of file
* access for this add-on. It specifies that this add-on will only
* attempt to read or modify the files in which the add-on is used,
* and not all of the user’s files. The authorization request message
* presented to users will reflect this limited scope.
*/
@5argon
5argon / GoogleDocsHighlighter.gs
Created May 22, 2017 12:08
Highlight a character name (5argon : Hello world!) or any lines that begin with # sign. Each character get different colors via the function at the bottom.
/**
* @OnlyCurrentDoc
*
* The above comment directs Apps Script to limit the scope of file
* access for this add-on. It specifies that this add-on will only
* attempt to read or modify the files in which the add-on is used,
* and not all of the user's files. The authorization request message
* presented to users will reflect this limited scope.
*/
@5argon
5argon / SharpZibLibTest.cs
Last active June 12, 2017 18:04
Compress, decompress example/benchmark test.
using UnityEngine;
using System.Collections;
using System.IO;
using System;
using System.Diagnostics;
using System.Text;
using System.Runtime.Serialization.Formatters.Binary;
using System.Security.Cryptography;
using ICSharpCode.SharpZipLib.Core;
@5argon
5argon / FirebaseUnityStudy.cs
Created August 7, 2017 15:01
Study the behavior of Unity Firebase API. Run this one by one so it exits play mode in between tests, clearing everything out as much as possible.
#if UNITY_EDITOR
using System.Collections;
using UnityEngine;
using UnityEngine.TestTools;
using System.Collections.Generic;
using NUnit.Framework;
using Firebase;
@5argon
5argon / LerpTest.cs
Created November 16, 2017 09:54
You can use ref and your own Lerp function to beat the performance of Vector3.LerpUnclamped (Vector3.Lerp is slower than Unclamped ones)
using UnityEngine;
using UnityEditor;
using NUnit.Framework;
using System.Collections.Generic;
using System.Diagnostics;
public class TestMisc {
delegate Vector3 CustomLerp(Vector3 v1, Vector3 v2, float lerp);
delegate void CustomLerpRef(ref Vector3 v1, Vector3 v2, float lerp);
@5argon
5argon / GoogleSpreadsheetUnity.cs
Created May 2, 2018 15:13
How to get Google Spreadsheet data to Unity. Put Google Api + Auth + Sheets .dll into your project. Then put .p12 service account file somewhere in Assets.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Sheets.v4;
using Google.Apis.Sheets.v4.Data;
using Google.Apis.Services;