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 * as fs from "fs"; | |
function raise(msg: string): never { | |
console.error(`Error "${msg}" raised at ${new Date()}`) | |
throw new Error(msg) | |
} | |
function readConfig(configFile: string): string { | |
if (!fs.existsSync(configFile)) | |
raise(`Configuration file ${configFile} missing.`) |
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
{ | |
"workbench.activityBar.visible": true, | |
"editor.lineHeight": 0, | |
"files.autoSave": "onFocusChange", | |
"editor.fontLigatures": true, | |
"editor.smoothScrolling": true, | |
"editor.mouseWheelZoom": true, | |
"workbench.sideBar.location": "right", | |
"editor.autoClosingBrackets": "always", | |
"mocha.files.ignore": [ |
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
public class Parenthesis | |
{ | |
public static int GetClosingParenthesis(string input, int openingPos) | |
{ | |
var counter = 0; | |
var positionFound = -1; | |
for (int i = 0; i < input.Length; i++) | |
{ | |
if (input[i] == '(' && openingPos == i) | |
{ |
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" | |
) | |
func main() { | |
//Declare a pointer of type Human | |
peter := new(Human) | |
//The compile will dereference the pointer to make the call |
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
extension UIColor { | |
convenience init(rgb:UInt, alpha:CGFloat = 1.0) { | |
self.init( | |
red: CGFloat((rgb & 0xFF0000) >> 16) / 255.0, | |
green: CGFloat((rgb & 0x00FF00) >> 8) / 255.0, | |
blue: CGFloat(rgb & 0x0000FF) / 255.0, | |
alpha: CGFloat(alpha) | |
) | |
} | |
} |
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
def deleteNode(node: FrequencyNode): Unit = { | |
node.prev.next = node.next | |
node.next.prev = node.prev | |
node.next= null; node.prev = null | |
} |
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
def access(key: UUID): Int = { | |
val tmp = this.byKey(key) | |
if (tmp == null) { | |
throw new Exception("No such key") | |
} | |
val freq = tmp.parent | |
var nextFreq = freq.next | |
if (nextFreq == this.frequencyHead || nextFreq.value != (freq.value + 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
def insert(key: UUID, value : Int) = { | |
if (this.byKey.contains(key)){ | |
throw new Exception("Key already exists") | |
} | |
val freqNode = this.frequencyHead.next | |
if (freqNode.value != 1){ | |
this.frequencyHead.next = LfuCache.getNewNode(this.frequencyHead, freqNode) | |
this.byKey(key) = LfuItem(this.frequencyHead.next, value, key) | |
this.frequencyHead.next.items += this.byKey(key) |
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
object Time { | |
def time[A](a: => A) = { | |
val now = System.nanoTime | |
val result = a | |
val micros = (System.nanoTime - now) / 1000 | |
println("%d microseconds".format(micros)) | |
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
# Install the following modules: | |
# pip install pyperclip | |
# pip install uuid | |
import uuid | |
import pyperclip | |
pyperclip.copy(str(uuid.uuid1())) | |
# On Windows systems, there is no notion of an “executable mode”. |