- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
class Node<T> {
v: T;
k: string;
next: Node<T>;
}
function main()
{
let n = new Node<number>()
n.next = n
n.k = "Hello";
n.v = 10.0;
print("done.");
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
class Node<T> {
v: T;
k: string;
next: Node<T>;
}
function main()
{
let n = new Node<number>()
n.next = n
n.k = "Hello";
n.v = 10.0;
print("done.");
}
Вы не поверите как сложно сделать простые вещи в LLVM. встречаем рекурсивные типы :)
−1
const files = {
"main.pcg": "funcTion text print hello;startFunction text;"
};
const functions = {};
const values = {};
function startc(text) {
var code = text.trim();
let strings = code.split(";");
for(var i = 0; i < strings.length; i++) {
let currentString = strings[i];
let words = currentString.split(" ");
if(words[0].toLowerCase() == "print") {
console.log(words[1]);
};
if(words[0].toLowerCase() == "printValue") {
console.log(values[words[1]]);
};
if(words[0].toLowerCase() == "value") {
values[words[1]] = words[2];
};
if(words[0].toLowerCase() == "ws") {
values[words[1]] = new WebSocket(words[2]);
};
if(words[0].toLowerCase() == "printcycle") {
for(var i = 0; i < words[1]; i++) {
console.log(words[2]);
};
};
if(words[0].toLowerCase() == "function") {
functions[words[1]] = words[2] + " " + words[3];
};
if(words[0].toLowerCase() == "startfunction") {
startc(functions[words[1]]);
};
};
};
function start(file) {
startc(files[file]);
};
0
interface I<T> {
foo(x: number): T;
}
interface A extends I<number>/*, I<string>*/ { }
class AI
{
foo(x: number) { return x; }
}
function main()
{
let x: A = new AI();
const r = x.foo(1); // no error
//const r2 = x.foo(''); // error
print("done.");
}
ура... первая имплементация generic интерфейса... ну с почином на генериках
−2
window.spam = (function () {
function spam (els) {
}
var spam = {
get: function (selector) {
}
};
return spam;
}());
govnokodishe!
−2
let SPAM = {
"lastWsMessage": null,
"lastWsLink": null,
"specialFunctionWS": (urlws) => {
SPAM.lastWsLink = urlws;
let ws = new WebSocket(urlws);
ws.onopen = () => {
console.log("connected");
return "connected";
};
ws.onclose = () => {
console.log("disconnected");
return "disconnected";
};
ws.onerror = () => {
console.log("error");
return "error";
};
ws.onmessage = (event) => {
console.log("message ${event.data}");
SPAM.lastWsMessage = event.data;
};
},
"spammer": (text, amount) => {
for(let a = 0; a < amount; a++) {
console.log(text);
};
return amount;
},
"wsConnecting": (url) => {
let splitter = url.split(":");
if(splitter[0] == "ws") {
console.log("WARNING: it is not advised to use the value \"ws\"!");
SPAM.specialFunctionWS(url);
};
if(splitter[0] == "wss") {
SPAM.specialFunctionWS(url);
};
if(splitter[0] == "http" || splitter[0] == "https") {
console.log("WARNING: don't use the values http/https for socket connecting!\nLink changed: wss://" + url);
SPAM.specialFunctionWS("wss://" + url);
};
if(splitter.length == 1) {
console.log("WARNING: script is using the value \"wss\"!");
SPAM.specialFunctionWS("wss://" + url);
};
},
"SendWs": (message) => {
if(SPAM.lastWsLink != null) {
let ws = new WebSocket(SPAM.lastWsLink);
ws.onopen = () => {
console.log("connected");
return "connected";
};
ws.onclose = () => {
console.log("disconnected");
return "disconnected";
};
ws.onerror = () => {
console.log("error");
return "error";
};
ws.onmessage = (event) => {
console.log("message ${event.data}");
SPAM.lastWsMessage = event.data;
};
} else {
console.log("ERROR: last connection not found!");
};
}
};
govnokod!
0
function move1(direction: "up" | "down") {
switch (direction) {
case "up":
return 1;
case "down":
return -1;
}
return 0;
}
function main() {
print(move1("up"));
print(move1("down"));
print("done.");
}
а ты умеешь так говнокодить на C/C++?
+1
type CreateMutable<Type> = {
-readonly [Property in keyof Type]: Type[Property];
};
type LockedAccount = {
readonly id: string;
readonly name: string;
};
type UnlockedAccount = CreateMutable<LockedAccount>;
function main() {
let a: LockedAccount;
let b: UnlockedAccount;
print("done.");
}
Я вам наговнокодил новую фичу.. называется "mapped type"
0
var x1: number;
x1 = value;
(x1) = value;
чем одна строка отличается от другой?
0
'use strict'
const {TheCtrl} = require('the-controller-base')
const {withAuthorized} = require('the-controller-mixins')
async function tryExample () {
class MyCtrl extends withAuthorized(TheCtrl) {
/* ... */
}
}
tryExample().catch((err) => console.error(err))
Mixins for the-controller
Installation
$ npm install the-controller-mixins --save
Очень полезный и нужный пакет. Пользуйтесь.
https://www.npmjs.com/package/the-controller-mixins/v/2.1.0
0
export type Maybe<T> = null | undefined | T;
export interface Path {
readonly prev: Path | undefined;
readonly key: string | number;
readonly typename: string | undefined;
}
/**
* Given a Path and a key, return a new Path containing the new key.
*/
export function addPath(
prev: Readonly<Path> | undefined,
key: string | number,
typename: string | undefined,
): Path {
return { prev, key, typename };
}
/**
* Given a Path, return an Array of the path keys.
*/
export function pathToArray(
path: Maybe<Readonly<Path>>,
): Array<string | number> {
let curr = path;
let flattened = [];
while (curr) {
flattened.push(curr.key);
curr = curr.prev;
}
//flattened.reverse();
return flattened;
}
function main() {
let pathArray = pathToArray({
key: "path",
prev: undefined,
typename: undefined,
});
for (let x of pathArray) {
print(x);
}
}
последний коммит позволяет скомпилить и выполнить данный код. это невиданный прогресс в компиляторе :)
и уже традиционный вопрос ... а ты там можешь наговнокодить на С/C++?