- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
#include <stdio.h>
int main()
{
void say_hello()
{
puts("Hello govnokod!");
}
say_hello();
return 0;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+113
#include <stdio.h>
int main()
{
void say_hello()
{
puts("Hello govnokod!");
}
say_hello();
return 0;
}
http://ideone.com/QZipp
+156
var renderHours = function(s){
var html = '<ul>';
var json = Ext.decode(s);
for(i in json)
if(typeof json[i].from_d != 'undefined')
html += '<li>с <b>'
+ hours[json[i].from_d][1]
+ '</b> - по <b>'
+ hours[json[i].to_d][1]
+ '</b> ('
+ json[i].from_h +':'+ json[i].from_m +'-'
+json[i].to_h +':'+ json[i].to_m +')</li>';
return html+'</ul>';
};
Вот такое попалось
+56
<html>
<head>
<style>
body{
background-color: #3366CC; /* Цвет фона веб-страницы */
}
</style>
</head>
<body>
<?php
/*error_reporting(E_ALL);*/
class Mirror{
public $sizeX;
public $sizeY;
public $filenameI;
public $filenameO;
public $red;
public $green;
public $blue;
public $alpha;
function __construct($f){
$this->filenameI=$f.".png";
$this->filenameO=$f."2.png";
$size=getimagesize($this->filenameI);
$this->sizeX=$size[0];
$this->sizeY=$size[1];
}
function saveImg(){
if(!file_exists($this->filenameO)){
$xx=$this->sizeX;
$yy=($this->sizeY)*2;
$im = imagecreatetruecolor($xx, $yy);
imageAlphaBlending($im, false);
imageSaveAlpha($im, true);
for($x=0;$x<$xx;$x++){
for($y=0;$y<$yy;$y++){
$r=$this->red[$x][$y];
$g=$this->green[$x][$y];
$b=$this->blue[$x][$y];
$alph=$this->alpha[$x][$y];
$color=ImageColorAllocateAlpha($im, $r, $g, $b, $alph);
imagesetpixel($im, $x, $y, $color);
}
}
imagepng($im, $this->filenameO);
imagedestroy($im);
}
echo "<img src=\"".$this->filenameI."\" /><hr>\n";
echo "<img src=\"".$this->filenameO."\" /><br>\n";
}
function loadImg(){
$im = imagecreatefrompng($this->filenameI);
for($x=0;$x<$this->sizeX;$x++){
for($y=0;$y<$this->sizeY;$y++){
$rgb = imagecolorat($im, $x, $y);
$color=imagecolorsforindex($im, $rgb);
$this->red[$x][$y]=$color['red'];
$this->green[$x][$y]=$color['green'];
$this->blue[$x][$y]=$color['blue'];
$this->alpha[$x][$y]=$color['alpha'];
}
}
imagedestroy($im);
}
function createMirror(){
if(!file_exists($this->filenameO)){
$yy=($this->sizeY*2);
for($x=0;$x<$this->sizeX;$x++){
$alph=0;
for($y=$this->sizeY;$y<$yy;$y++){
if($alph<126){
$alph++;
}
$this->red[$x][$y]=$this->red[$x][$this->sizeY-($y-$this->sizeY)-1];
$this->green[$x][$y]=$this->green[$x][$this->sizeY-($y-$this->sizeY)-1];
$this->blue[$x][$y]=$this->blue[$x][$this->sizeY-($y-$this->sizeY)-1];
$this->alpha[$x][$y]=$alph+$this->alpha[$x][$this->sizeY-($y-$this->sizeY)-1];
if($this->alpha[$x][$y]>127) $this->alpha[$x][$y]=127;
}
}
}
}
}
$filename="alpha";
$mirror=new Mirror($filename);
$mirror->loadImg();
$mirror->createMirror();
$mirror->saveImg();
?>
</body>
</html>
Делал для одного сайта зеркальное отражение картинки (photoshop использовать не умеем-с). Почему-то сервер часто падал.
Как оно работает, можно посмотреть здесь http://xcont.com/perc/newperceptron/cell/mirror.php
+99
// Получение имени выполняемого метода, вызывать можно только из Published-методов класса.
// Для обычных методов: FindClassMethodNames(ClassType()), для статических методов FindClassMethodNames(self).
{$optimization OFF}
function FindClassMethodNames(obj: TClass): string;
var _AdrPtr: Pointer;
begin
asm
mov eax, obj
mov edx, dword ptr [esp + 272]
push ebx
push esi
push edi
push $7FFFFFFF
xor edi, edi
jmp @@haveVMT
@@outer:
mov eax, dword ptr [eax]
@@haveVMT:
mov esi, dword ptr [eax].vmtMethodTable
test esi, esi
je @@parent
movzx ecx, word ptr [esi]
add esi, 2
@@inner:
pop ebx
push edx
sub edx, dword ptr [esi + 2]
jl @@no1
cmp edx, ebx
jg @@no1
mov ebx, edx
mov edx, dword ptr [esi + 2]
mov edi, edx
@@no1:
pop edx
push ebx
movzx ebx, word ptr [esi]
add esi, ebx
dec ecx
jnz @@inner
@@parent:
mov eax, dword ptr [eax].vmtParent
test eax, eax
jne @@outer
mov _AdrPtr, edi
pop edi
pop esi
pop ebx
end;
Result := obj.MethodName(_AdrPtr);
end;
{$optimization ON}
// пример использования
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(FindClassMethodNames(ClassType()));
end;
А есть нормальный способ получить имя выполняемого метода, и строку кода заодно?
+155
element.data('selected') ? element.show() : $.noop();
Либо человек из ассемблера пришел, либо "IF" сильно ему по жизни насолил.
+124
http://habrahabr.ru/post/147484/
Я просто оставлю это здесь.
+141
int main()
{
int i = 0;
goto A;
for (;i<3; ++i)
L:{
{
int x;
x += i;
if (0) { A: x = 0; goto B; }
printf("X: %d ",x);
}
{
int y;
y -= i;
if (0) { B: y = 10; goto L; }
printf("Y: %d\n",y);
}
}
}
Отсюда: http://rsdn.ru/forum/cpp/4812647.flat.aspx Автор походу уверен в гениальности кода.
+24
Fixed f = 0.2;
f = std::abs(f);
std::cout << (float)f;
Угадайте, чему будет равно f?
Fixed - тип из той же библиотеки, что и в http://govnokod.ru/11294
+129
return GetByteArray((Object)obj);
На всякий случай.
+119
/**
* Imbues the given {@link Font} with support for fallback fonts,
* needed to display CJK characters in fonts that do not support them.
*
* This is an ugly mess that depends on internal Sun APIs. Use sparingly!
*
* @param font the font
* @return the composite font UI resource
*/
public static FontUIResource getCompositeFontUIResource(final Font font) {
try {
Class<?> klass;
try {
// Java 7
klass = Class.forName("sun.font.FontUtilities");
} catch (final ClassNotFoundException e) {
// Java 6
klass = Class.forName("sun.font.FontManager");
}
// Invoke static method that wraps the font
val method = klass.getMethod("getCompositeFontUIResource", Font.class);
return (FontUIResource) method.invoke(null, font);
} catch (final ClassNotFoundException e) {
// Long block of catches that cannot happen on a Sun JRE
throw new AssertionError(e);
} catch (final IllegalAccessException e) {
throw new AssertionError(e);
} catch (final IllegalArgumentException e) {
throw new AssertionError(e);
} catch (final InvocationTargetException e) {
throw new AssertionError(e);
} catch (final NoSuchMethodException e) {
throw new AssertionError(e);
} catch (final SecurityException e) {
throw new AssertionError(e);
}
}