Skip to content

Instantly share code, notes, and snippets.

View urain39's full-sized avatar
🐌
Loading...

μrainЗ⑨ urain39

🐌
Loading...
  • Garyton University
  • Mercury
View GitHub Profile
@urain39
urain39 / JSONType.ts
Created January 27, 2021 16:06
JSON Type annotation for TypeScript.
interface IMap<V> {
[key: string]: V | V[];
[index: number]: V | V[];
}
type JSONPrimitiveType = number | string | boolean | null;
interface JSONObjectType extends IMap<JSONPrimitiveType | JSONObjectType> {};
interface JSONArrayType extends Array<JSONPrimitiveType | JSONObjectType | JSONArrayType> {};
@urain39
urain39 / count.js
Created May 9, 2020 13:59
Python-like substring count method for JavaScript String prototype.
String.prototype.count = function(substring) {
var i = -1,
count = 0;
if (substring)
while ((i = this.indexOf(substring, i + 1)) !== -1)
count++;
else
count = this.length + 1;
return count;
}
if (typeof String.prototype.format !== "function") {
String.prototype.format = function (mappable, filter) {
var self = this;
return self.replace(/\{([0-9A-Za-z_$]+)\}/g, filter ?
function(_, key) { return filter(mappable[key]); }
:
function(_, key) { return mappable[key]; }
);
};
}
from sys import stdin
from random import randrange
def yes_or_no(n, cnt):
return randrange(0, cnt) < n
def fire():
return yes_or_no(1, 6)
def main():
def generate_urls(elems, attr="href"):
"""
@param elems: list
@param attr: str
@description generator to generate urls of elements
"""
for elem in elems:
if getattr(elem, "attrib", None):
url = elem.attrib.get(attr)
@urain39
urain39 / figlet.sh
Created January 27, 2018 16:05
figlet ASCII font to shell or other script.
figlet $@ | sed -n -e 's/\\/\\\\/g;s/`/\\`/g;p' \
| awk '{ printf "echo \"%s\";\n", $0 }'