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
class Module | |
def stateful(*args) | |
state_name = self.name | |
state_var_name = "@#{state_name}".to_sym | |
args_var_sym = "@args".to_sym | |
tmp_var_arr_name = "@_#{state_name}_tmp_vars".to_sym | |
set_tmp_var = ->(to, key, name, value) { | |
tmp_var_arr = to.instance_variable_get(tmp_var_arr_name) | |
if tmp_var_arr.nil? |
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
require "http/client" | |
username = "username" | |
password = "password" | |
client = HTTP::Client.new "https://mycompany.atlassian.net", port=443, tls=true | |
client.basic_auth username, password | |
headers = HTTP::Headers{} of String => Array(String) | |
headers["Content-Type"] = "application/json" | |
response = client.get("/rest/api/2/issue/test-issue") | |
puts response.pretty_inspect |
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 myutils | |
proc preRun(): int = | |
#...sets up the environment with globals and whatnot... | |
discard | |
proc initHandler(idx: int, vargs: seq[string], env: HandleEnvironment): int {.gcsafe.} = | |
#...code stuff... | |
discard | |
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
my $filename = 'test.js'; | |
my $grep-filename = filename($filename).comb.map({ '.*' ~ do $^a eq '.' ?? '\\.' !! $^a }).join ~ '.*\\.' ~ $filename.IO.extension ~ '$'; | |
if not $grep-filename.starts-with('.*') { | |
$grep-filename = '.*' ~ $grep-filename; | |
} | |
$grep-filename.say; | |
my $grep-regex = /:i <$grep-filename>/; | |
# Paths are anonymized to just have magic variables in them. | |
my $src-path = "$SOURCE-PATH"; | |
my $dst-path = "$DEST-PATH"; |
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
my $filename = 'test.ftl'; | |
my $grep-filename = $filename.split('.')[0 ..^ *-1] # Get the filename part: foo.bar.ftl -> (foo bar) | |
.join('') # Make it a string: (foo bar) -> 'foobar' | |
.split('') # Make it a list: 'foo' -> ( f o o ) | |
.map({ '.*' ~ $^a })[1 .. *] # Add regex wildcards and remove extraneous string: ( f o o ) -> (.*f .*o .*o .*) | |
.join('') # Turn it back into a string: (.*f .*o .*o .*) -> '.*f.*o.*o.*' | |
~ $filename.split('.')[*-1]; # Add the file ending back in: '.*f.*o.*o.*.ftl' |
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
template logChan: expr = channels[2][] | |
template log(msg: string) = | |
# line 86 is the below line. | |
logChan.send(Message(kind: MessageLog, msg: msg, newline: false, level: LevelNone)) | |
proc playerThreadFunc(channels: ThreadArg) {.thread.} = | |
let rooms = initRooms() | |
var currentRoom = rooms[startRoomName] |
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
type | |
MessageKind = enum | |
MessageQuit, | |
MessageLog | |
Message = object | |
case kind: MessageKind | |
of MessageLog: | |
msg: string | |
of MessageQuit: nil |
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
from hashes import THash | |
proc hash(direction: Direction): THash = | |
return hash(ord(direction)) | |
main.nim(25, 15) Error: type mismatch: got (range 0..7(int)) | |
but expected one of: | |
main.hash(direction: Direction): THash |
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
use std::fmt::{Show, Formatter, FormatError}; | |
use std::collections::HashMap; | |
use std::collections::hashmap::{Entry, Vacant, Occupied}; | |
trait HasInventory { | |
fn getInventory<'s>(&'s self) -> &'s mut Inventory; | |
fn addToInventory(&self, item: &Item); | |
fn removeFromInventory(&self, itemName: &str) -> bool; | |
} |
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
var game; | |
var create = function() { | |
var x = game.width / 2.0 - 64 / 2.0; | |
var y = game.height / 2.0 - 64 / 2.0; | |
game.add.text(x, y, "ず", {font: "64px arial", fill: "#FFF"}); | |
// OR | |
// game.add.text(x, y, "ぽ", {font: "64px arial", fill: "#FFF"}); | |
} |
NewerOlder