Skip to content

Instantly share code, notes, and snippets.

View elliotchance's full-sized avatar
🤓
Building awesome stuff with V

Elliot Chance elliotchance

🤓
Building awesome stuff with V
View GitHub Profile
@elliotchance
elliotchance / koi.md
Last active April 10, 2025 02:45
Koi

Koi

Koi is a language that seeks to make many traditional bugs impossible by preventing them at the language level. Each of these are discussed in more detail below.

  1. Prevent all runtime errors. Runtime errors are, by definition, unexpected and either have to be caught and emit and error under a sitution that can't be handled safely or cause the program to blow up.
  2. No garbage collector, but no manual memory management either. It's unsafe to manage memory manully, but we also don't want the overhead of a garbage collector.
  3. Interoperability with C. This is critical to making sure we can use existing libraries and also makes the lanaguage a lot easier if we can offload the lowest level logic to C.
  4. All objects are also interfaces. Any object can be provided for a type if it fits the receiving interface.
  5. First class testing. Language constructs for dealing with tests, assertions, mocks, etc.
@elliotchance
elliotchance / 1.js
Last active March 21, 2023 04:11
Generate list index
// separator is what to put between each link. Examples:
// - New line: '\n'
// - Comma: ', '
// - Pipe: ' | '
const separator = '\n';
// The link for the URL. It must contain a slash at the end.
// You cannot use the [List123] links.
const listURL = 'https://rateyourmusic.com/list/echance/a-state-of-trance-1/';
@elliotchance
elliotchance / 1.js
Created March 19, 2023 21:00
Sort list items by artist/title
let done;
do {
done = true;
Array.from(document.getElementsByClassName('box'))
.sort((a, b) => {
const [x, y] = [a.innerText, b.innerText];
const cmp = x.localeCompare(y);
if (cmp < 0) {
done = false;
document.getElementById(a.id).parentNode.insertBefore(document.getElementById(a.id), document.getElementById(b.id));
@elliotchance
elliotchance / gist:257951d705132134b882258c83297dd6
Created August 28, 2021 17:41
PostgreSQL (ckolkman.vscode-postgres)
ready on 127.0.0.1:3210
connected
query: SELECT current_setting('server_version_num') as ver_num FROM singlerow;
response: vsql.Result{
columns: ['VER_NUM']
rows: [vsql.Row{
offset: 0
data: {'VER_NUM': vsql.Value{
typ: CHARACTER VARYING
f64_value: 0
@elliotchance
elliotchance / compare.go
Last active June 28, 2021 14:16
Compare gedcom files with Go
package main
import (
"fmt"
"github.com/elliotchance/gedcom"
)
func main() {
// 1. Load gedcom files.
leftGedcom, err := gedcom.NewDocumentFromGEDCOMFile("file1.ged")
class DirtyRead(TransactionTest):
def run(self):
result1 = self.client1.fetch_record(id=1)
self.client2.update_record(id=1, name="Joe 2")
result2 = self.client1.fetch_record(id=1)
return result1 != result2
class NonRepeatableRead(TransactionTest):
def run(self):
result1 = self.client1.fetch_record(id=1)
class TransactionTest:
def __init__(self, transaction_type):
self.table = Table()
client = self.table.new_transaction(ReadCommittedTransaction)
client.add_record(id=1, name="Joe")
client.add_record(id=3, name="Jill")
client.commit()
self.client1 = self.table.new_transaction(transaction_type)
self.client2 = self.table.new_transaction(transaction_type)
class SerializableTransaction(RepeatableReadTransaction):
def __init__(self, table, xid):
Transaction.__init__(self, table, xid)
self.existing_xids = self.table.active_xids.copy()
def record_is_visible(self, record):
is_visible = ReadCommittedTransaction.record_is_visible(self, record) \
and record['created_xid'] <= self.xid \
and record['created_xid'] in self.existing_xids
class LockManager:
def __init__(self):
self.locks = []
def add(self, transaction, record_id):
if not self.exists(transaction, record_id):
self.locks.append([transaction, record_id])
def exists(self, transaction, record_id):
return any(lock[0] is transaction and lock[1] == record_id \
class RepeatableReadTransaction(ReadCommittedTransaction):
def record_is_locked(self, record):
return ReadCommittedTransaction.record_is_locked(self, record) or \
self.table.locks.exists(self, record['id'])
def record_is_visible(self, record):
is_visible = ReadCommittedTransaction.record_is_visible(self, record)
if is_visible:
self.table.locks.add(self, record['id'])