Skip to content

Instantly share code, notes, and snippets.

🏠
Coffee shop programmer 24h

Sirawat Pitaksarit 5argon

🏠
Coffee shop programmer 24h
Block or report user

Report or block 5argon

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@5argon
5argon / IntToStringLookup.cs
Last active Feb 8, 2017
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.
View IntToStringLookup.cs
public static class IntToStringLookup {
/*
A Python program for you!
import sys
import math
k = 0
@5argon
5argon / randomBase32.sql
Last active Feb 17, 2017
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…
View randomBase32.sql
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 Feb 20, 2017
Get an SRV record's port number + target from a URL. (OSX/Linux, or maybe Windows if you have grep) Separated by a whitespace.
View srvport.sh
URL=$1
nslookup -type=SRV $URL | grep -Eo "service.*" | grep -Eo "[0-9]*[ ][^ ]*$"
@5argon
5argon / GoogleDocsFormatBasic.gs
Created May 22, 2017
How to format an entire document using RegEx in Google Docs add-on. It will bold my name in string like "5argon : Hello World!"
View GoogleDocsFormatBasic.gs
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
Google Docs add-ons script to bold everything.
View GoogleDocsBoldAll.gs
/**
* @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
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.
View GoogleDocsHighlighter.gs
/**
* @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 Jun 12, 2017
Compress, decompress example/benchmark test.
View SharpZibLibTest.cs
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 Aug 7, 2017
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.
View FirebaseUnityStudy.cs
#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 Nov 16, 2017
You can use ref and your own Lerp function to beat the performance of Vector3.LerpUnclamped (Vector3.Lerp is slower than Unclamped ones)
View LerpTest.cs
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
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.
View GoogleSpreadsheetUnity.cs
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;
You can’t perform that action at this time.