Skip to content

Instantly share code, notes, and snippets.

View psksvp's full-sized avatar
⛩️
Working from home

Pongsak Suvanpong psksvp

⛩️
Working from home
  • The Land Down Under
View GitHub Profile
// pairup a seq
// psksvp@gmail.com
object Pairup
{
def main(args: Array[String]): Unit =
{
println("hello")
val a = List(1, 2, 3, 4, 5, 6) //even
val b = pairup(a)
@psksvp
psksvp / Array+Combinatorial.swift
Last active August 20, 2020 02:50
swift array extension that deals with generating combinations and permutations
/**
translate from Scala by psksvp@gmail.com
http://vkostyukov.ru/posts/combinatorial-algorithms-in-scala/
*/
extension Collection
{
func combinations(_ n: Int) -> [[Element]]
{
guard self.count > 0 else {return [[Element]]()}
guard n <= self.count else {return [[Element]]()}
@psksvp
psksvp / approximateFraction.swift
Last active July 22, 2020 03:02
Find rational approximation to given real number
// approximate the fraction of a real
// Created by psksvp on 22/7/20.
print(approximateFraction(0.5))
print(approximateFraction(0.5454))
print(approximateFraction(0.75))
print(approximateFraction(0.333333))
print(approximateFraction(0.888888888888))
print(approximateFraction(0.0123456789))
@psksvp
psksvp / renameXcode.makefile
Last active January 26, 2020 04:37
Rename Xcode project (11.3.1 (11C504))
I put in the make file from https://stackoverflow.com/questions/33370175/how-do-i-completely-rename-an-xcode-project-i-e-inclusive-of-folders
It was originally written by https://stackoverflow.com/users/7641654/pietro-basso
__USE AT YOUR OWN RISK, ALWAYS BACK UP before doing this. You must read the post before using this.__
The makefile needs `ack` and `rename` which can be install with `brew install ack rename`
put this file the project directory then run `make -f renameXcode.makefile OLD_NAME="oldname" NEW_NAME="newname"`
@psksvp
psksvp / gist:bb84c28bee8753f4d0af791d79bf281d
Last active January 11, 2020 13:09
int index of Swift String
public extension String
{
func intIndex(of s: String) -> Int?
{
if let r = self.range(of: s)
{
return self.distance(from: self.startIndex, to: r.lowerBound)
}
else
{
@psksvp
psksvp / gist:9f931dc171be90298383823bf6138b9c
Created January 10, 2020 09:44
fix screen brightness cannot be adjusted probelm on 2103 iMac with Ubuntu 18.10
open the file */etc/default/grub* with a text editor with sudo
change the line
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
to
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash acpi_backlight=vendor"
saved, then run