This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
next_xid = 1 | |
active_xids = set() | |
records = [] | |
def new_transaction(): | |
global next_xid | |
next_xid += 1 | |
active_xids.add(next_xid) | |
return Transaction(next_xid) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
str := "abc foo:bar def baz:qux ghi" | |
re := regexp.MustCompile("([a-z]+):([a-z]+)") | |
result := ReplaceAllStringSubmatchFunc(re, str, func(groups []string) string { | |
return groups[1] + "." + groups[2] | |
}) | |
fmt.Printf("'%s'\n", result) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
func BatchStrings(values <-chan string, maxItems int, maxTimeout time.Duration) chan []string { | |
batches := make(chan []string) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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/'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pytest | |
class Game: | |
def __init__(self): | |
self.frames = [[]] | |
self.allow_bonus_roll = False | |
@property | |
def last_frame(self): | |
return self.frames[-1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import re | |
import glob | |
import os | |
files = [] | |
for arg in sys.argv[1:]: | |
if os.path.isdir(arg): | |
arg += "/*.swift" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import time | |
class Person: | |
WAITING = 0 | |
IN_ELEVATOR = 1 | |
DONE = 2 | |
def __init__(self, from_floor, to_floor): | |
self.from_floor = from_floor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"strings" | |
"sync" | |
"time" | |
) | |
type ChannelPerf struct { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf8 -*- | |
from __future__ import print_function | |
class LockManager: | |
def __init__(self): | |
self.locks = [] | |
def add(self, transaction, record_id): | |
if not self.exists(transaction, record_id): |
NewerOlder