- 1
1/-0 == 42
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+141
1/-0 == 42
Внезапно.
+121
This awesome yet simple and pragmatic PHP library performs an addition of two numbers.
In early stages of Internet, developers were forced to work with poor, dry, functional, horrific languages. Everything had to be done through austere functions and operators. There was no objects. No interfaces. No dependency injection.
For example, to make something as simple as an addition, our dads had to write: 1+1. Yeah, really.
Hopefuly now, we have PHP 5.3 and its solid OOP implementation. SimplePHPEasyPlus lets you make this addition in a more fashionable way, using real OOP. It is fast, simple, flexible and tested. To add 1 to 1, all you have to do is:
use SimplePHPEasyPlus\Number\NumberCollection;
use SimplePHPEasyPlus\Number\SimpleNumber;
use SimplePHPEasyPlus\Number\CollectionItemNumberProxy;
use SimplePHPEasyPlus\Parser\SimpleNumberStringParser;
use SimplePHPEasyPlus\Iterator\CallbackIterator;
use SimplePHPEasyPlus\Operator\AdditionOperator;
use SimplePHPEasyPlus\Operation\ArithmeticOperation;
use SimplePHPEasyPlus\Operation\OperationStream;
use SimplePHPEasyPlus\Engine;
use SimplePHPEasyPlus\Calcul\Calcul;
use SimplePHPEasyPlus\Calcul\CalculRunner;
$numberCollection = new NumberCollection();
$numberParser = new SimpleNumberStringParser();
$firstParsedNumber = $numberParser->parse('1');
$firstNumber = new SimpleNumber($firstParsedNumber);
$firstNumberProxy = new CollectionItemNumberProxy($firstNumber);
$numberCollection->add($firstNumberProxy);
$secondParsedNumber = $numberParser->parse('1');
$secondNumber = new SimpleNumber($secondParsedNumber);
$secondNumberProxy = new CollectionItemNumberProxy($secondNumber);
$numberCollection->add($secondNumberProxy);
$addition = new AdditionOperator('SimplePHPEasyPlus\Number\SimpleNumber');
$operation = new ArithmeticOperation($addition);
$engine = new Engine($operation);
$calcul = new Calcul($engine, $numberCollection);
$runner = new CalculRunner();
$runner->run($calcul);
$result = $calcul->getResult();
$numericResult = $result->getValue(); // 2
This library is now available for production purposes. Enjoy!
[КО]Складывает 2 числа[/КО]
+127
val arr = new Array[Int](3)
val arr2 = arr
arr(0) = 100
arr(1) = 200
arr(2) = 300
//arr2 == Array(100, 200, 300)
Не говнокод конечно, хотя как посмотреть.
Это нормально, учитывая, что val предполагает неизменяемость значения, или в данном случае считается, что только присвоить новое значение нельзя, а изменять внутреннюю структуру массива можно как захочешь?
Ведь наже в C++ нельзя изменить значения const std::vector.
+51
#101 Check PHP configuration in console
$ php -r "phpinfo\(\);"
Вот такой скрипт нашёл в дебрях локального битрикса под NDA.
+50
public function getFilename($filename) {
$string = ereg_replace("ж", "zh", $filename);
$string = ereg_replace("ё","yo",$string);
$string = ereg_replace("и", "i",$string);
......
$string = ereg_replace("Т","T",$string);
$string = ereg_replace("Б","B",$string);
$string = ereg_replace(" ","_",$string);
$filename = preg_replace("/[^\w\.\-_]/","",$string);
return strtolower($filename);
}
+6
template <typename T, size_t rows, size_t cols>
class Matrix {
public:
Matrix() :
m_matrix(reinterpret_cast<T*>(new char[sizeof(T) * rows * cols]))
{
memset(m_matrix, 0, sizeof(T) * rows * cols);
new (m_matrix) T[rows * cols];
if ( rows == cols ) {
for ( size_t i = 0; i < rows; i++ )
m_matrix[i * cols + i] = 1; // FIXME: this is hack
}
}
// ...
private:
T *m_matrix;
};
Из прошлого куска.
Инициализируем память нулями. А вдруг тип скалярный? :)
+10
template <typename T, size_t rows, size_t cols>
class Matrix {
public:
Matrix() :
m_matrix(new T[rows * cols])
{
// Make identity matrix, if possible
if ( rows == cols ) {
for ( size_t i = 0; i < rows; i++ )
m_matrix[i * cols + i] = 1; // FIXME: this is hack
}
}
// ...
Matrix<T, rows, cols>& operator =(Matrix<T, rows, cols> &&other) {
if ( this != &other ) {
delete [] m_matrix;
m_matrix = other.m_matrix;
other.m_matrix = new T[cols * rows];
other = static_cast<const Matrix&>(Matrix());
}
return *this;
}
// ...
};
Издержки move construtor :)
Прошу внимания к строчкам 19-23
+14
int main(){(([](){})());}
preview.tinyurl.com/blrtfuo
ideone.com/BXrXDR
Или еще чуть веселее:
ideone.com/C425yo
−127
#!/bin/bash
set -e
KEHU_FILE=kehu_ruikemei
echo "*************"
echo "rm logo_linux_clut224"
echo "*************"
find drivers/video/logo/ -name logo_linux_clut224.o -exec rm -f {} \;
find drivers/video/logo/ -name logo_linux_clut224.c -exec rm -f {} \;
find drivers/video/logo/ -name logo_linux_clut224.ppm -exec rm -f {} \;
echo "***********************"
echo "copy logo_linux_clut224.ppm"
echo "***********************"
cp $KEHU_FILE/logo_linux_clut224.ppm drivers/video/logo/
echo "***********************"
echo "make kernel.img"
echo "***********************"
make kernel.img -j4
echo "***********************"
echo "return origin files"
echo "***********************"
find drivers/video/logo/ -name logo_linux_clut224.o -exec rm -f {} \;
find drivers/video/logo/ -name logo_linux_clut224.c -exec rm -f {} \;
git checkout -- drivers/video/logo/logo_linux_clut224.ppm
echo "return origin files success!!!"
Скрипт в корне исходников ядра linux для Rockchip RK3066.
+107
// define types
const int FB2 = 0;
const int TXT = 1;
// private
private int Type;
…
// class methods
public CVBook(string path, string type) {
switch(type)
{
case "fb2":
{
Type = 0;
}
break;
case "txt":
{
Type = 1;
}
break;
default:
{
throw new Exception("Unknown Book Format");
}
}
…
switch (Type) {
case FB2: { … }
case TXT: { … }
default:
{
throw new Exception("Unknown Book Format");
}
}
}
}
Парсер книг, все в одном методе.