Skip to content

Instantly share code, notes, and snippets.

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?
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
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
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";
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'
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]
type
MessageKind = enum
MessageQuit,
MessageLog
Message = object
case kind: MessageKind
of MessageLog:
msg: string
of MessageQuit: nil
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
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;
}
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"});
}