- 1
- 2
- 3
- 4
- 5
// добавляем новые ссылки
for i := 0 to ATags.Count - 1 do
begin
// так мне кажется лучше
Application.ProcessMessages;
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−1
// добавляем новые ссылки
for i := 0 to ATags.Count - 1 do
begin
// так мне кажется лучше
Application.ProcessMessages;
кому или чему лучше кроме тебя, автор ?
+1
_RE_DESCRIPTION_TAG_OPEN = re.compile(r'<p\s+class="description">'.encode('utf-8'))
_RE_DESCRIPTION_TAG_CLOSE = re.compile(r'</p>\s*<p\s+class="author">'.encode('utf-8'))
def replace_description_tag(content, new_tag):
content = _RE_DESCRIPTION_TAG_OPEN .sub(f'<{new_tag} class="description">'.encode('utf-8'), content)
return _RE_DESCRIPTION_TAG_CLOSE.sub(f'</{new_tag}><p class="author">'.encode('utf-8'), content)
Парсить HTML регулярками — нельзя. Но если HTML невалидный — то можно!
А дело в том, что ГК генерирует говно, которое пришлось фиксить таким вот диким образом, см. https://govnokod.ru/26373#comment522056.
+4
final Optional<Customer> customer = Optional.ofNullable(customerId)
.map(custId -> customerService.getById(custId)
.map(cust -> Optional.of(cust))
.orElseThrow(() -> new NoSuchCustomerException(custId)))
.orElse(Optional.empty());
Попытка функционального программирования, когда в язык добавили монаду Optional, но не добавили монаду Try.
−1
- $pending = $this->$tag['callback']($open['data'], $open['option']);
+ $pending = $this->{$tag['callback']}($open['data'], $open['option']);
Копаюсь в сорцах говнокода.
В PHP 7 поменяли приоритет, пол часа не мог понять что за хуйня.
+139
class MainClass
{
public static char[,] titato = new char[3, 3] { { ' ', ' ', ' ' }, { ' ', ' ', ' ' }, { ' ', ' ', ' ' } };
static bool CheckWin(char s)
{
if ((titato[0, 0] == titato[1, 1] & titato[1, 1] == titato[2, 2] & titato[0, 0] != ' ') ||
(titato[0, 1] == titato[0, 2] & titato[0, 2] == titato[0, 0] & titato[0, 1] != ' ') ||
(titato[1, 1] == titato[1, 2] & titato[1, 2] == titato[1, 0] & titato[1, 1] != ' ') ||
(titato[2, 1] == titato[2, 2] & titato[2, 2] == titato[2, 0] & titato[2, 1] != ' ') ||
(titato[1, 0] == titato[2, 0] & titato[2, 0] == titato[0, 0] & titato[1, 0] != ' ') ||
(titato[1, 1] == titato[2, 1] & titato[2, 1] == titato[0, 1] & titato[1, 1] != ' ') ||
(titato[1, 2] == titato[2, 2] & titato[2, 2] == titato[0, 2] & titato[1, 2] != ' ') ||
(titato[2, 0] == titato[1, 1] & titato[1, 1] == titato[0, 2] & titato[2, 0] != ' '))
{
return true;
}
return false;
}
public static void PrintTicTacToe(char s)
{
Console.Clear();
Console.Write(" ");
Console.BackgroundColor = ConsoleColor.White;
for (int i = 0; i < titato.GetLength(0); i++) {
Console.Write(" {0} ", i);
}
Console.WriteLine();
for (int i = 0; i < titato.GetLength(0); i++) {
Console.BackgroundColor = ConsoleColor.White;
Console.Write("{0}", i);
for (int j = 0; j < titato.GetLength(1); j++) {
Console.BackgroundColor = ConsoleColor.Black;
if (titato[i, j] == 'x') {
Console.ForegroundColor = ConsoleColor.Red;
}
else if (titato[i, j] == 'o') {
Console.ForegroundColor = ConsoleColor.Green;
}
else {
Console.ForegroundColor = ConsoleColor.Black;
}
Console.Write(" {0} ", titato[i, j]);
}
Console.WriteLine();
}
Console.BackgroundColor = ConsoleColor.White;
Console.ForegroundColor = ConsoleColor.Black;
if (CheckWin(s)) {
Console.WriteLine(s + " win!!!");
}
}
public static void PushXO(int i, int j, char s)
{
titato[i, j] = s;
}
public static void Main(string[] args)
{
bool symbolX = true;
char s = 'x';
int i = 0, j = 0;
do {
Console.WriteLine("TIC TAC TOE!");
PrintTicTacToe(s);
if (symbolX == true) {
Console.WriteLine("Ходит Х");
Console.WriteLine("Введите номер столбца а затем введите номер строки:");
s = 'x';
symbolX = false;
}
else {
Console.WriteLine("Ходит О");
Console.WriteLine("Введите номер столбца а затем введите номер строки:");
s = 'o';
symbolX = true;
}
i = int.Parse(Console.ReadLine());
j = int.Parse(Console.ReadLine());
PushXO(j, i, s);
// Console.ReadLine();
PrintTicTacToe(s);
} while (true);
}
Крестики-нолики
+61
<html>
<head>
<title>В Контакте | Страницы юзера</title>
<style type="text/css">
body{
background: black;
color: #D1D1D1;
font-family: "Trebuchet MS", Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 1.2em;
}
div.body{
margin-left: auto;
margin-right: auto;
width: 520px;
}
a{color: #D1D1D1; text-decoration: none;}
a:hover{color: #3e9af2; text-decoration: underline;}
li{white-space: nowrap; list-style: none;}
input{
background: black;
color: #D1D1D1;
border:none;
border-bottom: 1px dotted #D1D1D1;
font-family: "Trebuchet MS", Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 1.2em;
margin-bottom: -2px;
}
</style>
<script type="text/javascript">
<!--//
function set_id(){
var user_id_1 = document.getElementById('user_id').value.replace(/[^\d]/g, "");
var user_id_2 = user_id_1 + '&' + Math.round(Math.random() * 999999);
var user_links = '';
user_links += '<ul>';
user_links += ' <li><a href="http://vkontakte.ru/id' + user_id_1 + '?' + Math.round(Math.random() * 999999) + '" target="_blank">Главная страница</a></li>';
user_links += ' <li>';
user_links += ' <a href="http://vkontakte.ru/wall.php?id=' + user_id_2 + '" target="_blank">Стена</a>';
user_links += ' <ul>';
user_links += ' <li><a href="http://vkontakte.ru/wall.php?act=write&id=' + user_id_2 + '" target="_blank">Оставить сообщение</a></li>';
user_links += ' <li><a href="http://vkontakte.ru/graffiti.php?act=draw&to_id=' + user_id_2 + '" target="_blank">Оставить графити</a></li>';
user_links += ' <li><a href="http://vkontakte.ru/photos.php?to_id=' + user_id_2 + '" target="_blank">Оставить фото</a></li>';
user_links += ' <li><a href="http://vkontakte.ru/video.php?to_id=' + user_id_2 + '" target="_blank">Оставить видио</a></li>';
user_links += ' <li><a href="http://vkontakte.ru/audio.php?to_id=' + user_id_2 + '" target="_blank">Оставить аудио</a></li>';
user_links += ' </ul>';
user_links += ' </li>';
user_links += ' <li><a href="http://vkontakte.ru/mail.php?act=write&to=' + user_id_2 + '" target="_blank">Отправить сообщение</a></li>';
user_links += ' <li><a href="http://vkontakte.ru/friend.php?id=' + user_id_2 + '" target="_blank">Друзья</a></li>';
user_links += ' <li><a href="http://vkontakte.ru/photos.php?id=' + user_id_2 + '" target="_blank">Альбомы</a></li>';
user_links += ' <li><a href="http://vkontakte.ru/photos.php?act=user&id=' + user_id_2 + '" target="_blank">Фото с юзером</a></li>';
user_links += ' <li><a href="http://pda.vkontakte.ru/taggedphotos' + user_id_1 + '" target="_blank">Фото с юзером, если надо посмотреть скрытые фото</a></li>';
user_links += ' <li><a href="http://vkontakte.ru/video.php?id=' + user_id_2 + '" target="_blank">Видeо</a></li>';
user_links += ' <li><a href="http://vkontakte.ru/questions.php?mid=' + user_id_2 + '" target="_blank">Вопросы</a></li>';
user_links += ' <li><a href="http://vkontakte.ru/notes.php?id=' + user_id_2 + '" target="_blank">Заметки</a></li>';
user_links += ' <li><a href="http://vkontakte.ru/apps.php?mid=' + user_id_2 + '" target="_blank">Приложения</a></li>';
user_links += ' <li><a href="http://vkontakte.ru/groups.php?mid=' + user_id_2 + '" target="_blank">Группы</a></li>';
user_links += '</ul>';
document.title = 'В Контакте | Страницы юзера id' + user_id_1;
document.getElementById('user_id').value = user_id_1;
document.getElementById('user_pages').innerHTML = user_links;
}
//-->
</script>
</head>
<body onLoad="set_id()">
<div class="body">
Страницы юзера id<input name="user_id" id="user_id" type="text" value="1" onKeyUp="set_id()" onKeyPress="set_id()" onPaste="set_id()">
<div id="user_pages"></div>
<noscript><p align="center">Ипать))) ... ктож а таком старье сидит)....<br />Включи JavaScript!</p></noscript>
<p align="center">by Dr.Freez</p>
</div>
</body>
</html>
говницо)))
+1
function foo(arg: any) {
if (typeof arg === "string") {
// We know this is a string now.
print(<string>arg);
}
}
function main() {
foo("Hello");
foo(1);
print("done.");
}
я вам новый говнокодец притарабанил.... вот будете как настоящие жабаскриптеры в нативе
0
namespace Ifaces {
interface IFoo {
foo(): number;
bar(x: number): string;
twoArg(x: number, y: number): number;
baz: string;
}
class A implements IFoo {
constructor() {
this.baz = "Q" + "A";
}
foo(): number {
return 12;
}
bar(v: number) {
return v.toString();
}
twoArg(x: number, y: number) {
return x;
}
baz: string;
}
class B extends A {
foo(): number {
return 13;
}
}
function foo(f: IFoo) {
return "" + f.foo() + f.baz + f.bar(42);
}
export function run() {
print("Ifaces.run");
let a = new A();
assert("" + foo(a) + "X" == "12.QA42.X");
assert((a as IFoo).twoArg(1, 2) == 1, "t");
a = new B();
assert("" + foo(a) + "X" == "13.QA42.X", "b");
let q = a as IFoo;
q.baz = "Z";
assert("" + foo(q) + "X" == "13.Z42.X", "x");
print("Ifaces.runDONE");
}
}
function main() {
Ifaces.run();
print("done.");
}
хотел оставить вас в покое. но не смог. Ловите - fields в интерфейсах
+4
def generate_set(max_size, base_images, samples_per_image=100):
assert len(base_images) == CHARS_NUM
input_vec_len = max_size[0] * max_size[1]
output_vec_len = CHARS_NUM
set_size = samples_per_image * CHARS_NUM
x_set = np.empty(shape=(set_size, input_vec_len))
y_set = np.empty(shape=(set_size, output_vec_len))
sample_num = 0
for c, img in base_images.items():
for _ in range(samples_per_image):
x_set[sample_num] = generate_distorted_sample(img)
y_set[sample_num] = char_to_onehot(c)
sample_num += 1
# LOL
rng_state = np.random.get_state()
np.random.shuffle(x_set)
np.random.set_state(rng_state)
np.random.shuffle(y_set)
return x_set, y_set
ТУРЕЛЬ: 1-1 сорцовый кобенный генератор по мотивам: https://govnokod.ru/26434#comment527875.
https://github.com/gost-gk/turel
Принцимп мухи: берём символы русского алфамита с цифрами/пуньктуацией, генерируем из них слегка искажённые картинки, тренируем элементарную модельку —
optimizer = keras.optimizers.Adagrad(learning_rate=0.02)
model = Sequential()
model.add(Dense(units=CHARS_NUM * 2, activation='relu', input_dim=input_vec_len))
model.add(Dense(units=CHARS_NUM, activation='softmax'))
model.compile(loss='categorical_crossentropy',
optimizer=optimizer,
metrics=['accuracy'])
−4
static Singleton * g_pInstance = NULL;
Singleton* Singleton::sharedInstance()
{
if (g_pInstance)
return g_pInstance;
else {
g_pInstance = new Singleton();
if (g_pInstance->init()) {
return g_pInstance;
} else {
delete g_pInstance;
g_pInstance = NULL;
}
return g_pInstance;
}
}
Ещё из жизни синглтонов. Даёшь больше return'ов!