- 1
- 2
Prelude> [(-1/0),1 .. 1]
[-Infinity,1.0,Infinity,Infinity]
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+136
Prelude> [(-1/0),1 .. 1]
[-Infinity,1.0,Infinity,Infinity]
Целых 2 бесконечности между единицей.
−402
NSParameterAssert(![method isEqualToString:@"GET"] && ![method isEqualToString:@"HEAD"]);
код из afnetworking - американцы поймут что такое GET HEAD)))))))))))))
+158
if ($class_week == 1) {
$current_week = 1;
} else {
$current_week = 1;
}
В одном из гос. проектов нашёл..
+56
if(i%2==0)
{
for(j=int (l);j<n+int (l);j++)
{
A[i][j]=B1[k];
k++;
}
}
else if(i%2!=0)
{
for(j=int (l);j<n+int (l);j++)
{
A[i][j]=B2[k];
k++;
}
}
Когда-то один однокурсник спросил у препода:
- А как добавить код в ИНАЧЕ от ИНАЧЕ.
Что-то подобное увидел и в этом коде.
+135
int log2_floor (unsigned x)
{
#define NIMHTNOE0WNM(n) (((~(x>>n)+1)>>n)&n)
int res, n;
n = NIMHTNOE0WNM(16); res = n; x >>= n;
n = NIMHTNOE0WNM( 8); res |= n; x >>= n;
n = NIMHTNOE0WNM( 4); res |= n; x >>= n;
n = NIMHTNOE0WNM( 2); res |= n; x >>= n;
n = NIMHTNOE0WNM( 1); res |= n;
return res;
}
Кто-то Воррена перечитал.
+49
#include <stdio.h>
#include <math.h>
#include "determinant.h"
double det(double **matrix, int size)
{
if(size==2)
{
return matrix[0][0]*matrix[1][1]-matrix[0][1]*matrix[1][0];
}
else if(size==1)
{
return matrix[0][0];
}
int result = 0;
for(int j=0; j<size; j++)
{
if(matrix[0][j]!=0)
{
result+=matrix[0][j]*(unsigned)pow(-1.f,(unsigned)j)*det(minor(matrix, size, 0, j), size-1);
}
}
return result;
}
double **minor(double **matrix, int size, int str, int col)
{
double **minor=new double *[size-1];
int m_str = 0;
int m_col;
for(int i=0; i<size; i++)
{
if(i!=str)
{
m_col = 0;
minor[m_str]=new double[size-1];
for(int j=0; j<size; j++)
{
if(j!=col)
{
minor[m_str][m_col]=matrix[i][j];
m_col++;
}
}
m_col++;
}
}
return minor;
}
Считаю определитель рекурсией, во время теста в этом сорце вылетает ошибка EXC_BAD_ACCESS(code=1, access=0x8),
после одного прохода рекурсии, с чем это связано? Помогите разобраться :)
−396
@implementation SlideMenuNavigationBar
- (void)layoutSubviews
{
[super layoutSubviews];
for (UIView *aView in self.subviews) {
// Correcting menu toggle button position
if ([[aView.class description] isEqualToString:@"UIButton"] && aView.frame.origin.x < self.frame.size.width/2) {
CGRect frame = aView.frame;
frame.origin.x = 12; // 8 for correlation
frame.origin.y = -1; // 1 for correlation
aView.frame = frame;
}
if (aView.frame.origin.x > self.frame.size.width/2 && !isIPad && ![[aView.class description] isEqualToString:@"ColoredView"]) {
CGRect frame = aView.frame;
frame.origin.x = 260; // 8 for correlation
frame.origin.y = -1; // 1 for correlation
aView.frame = frame;
}
// Correcting back button and right button positions
if ([[aView.class description] isEqualToString:@"_UINavigationBarBackIndicatorView"]) {
CGRect frame = aView.frame;
frame.origin.y = [self.class navigationBarHeight] - kDefaultNavigationBarHeight + 5; // 5 for correlation
aView.frame = frame;
}
if ([[aView.class description] isEqualToString:@"UINavigationButton"]) {
CGRect frame = aView.frame;
frame.origin.y = [self.class navigationBarHeight] - kDefaultNavigationBarHeight + 2; // 2 for correlation
aView.frame = frame;
}
if ([aView isKindOfClass:[NavigationBarButton class]]) {
CGRect frame = aView.frame;
frame.origin.x = 278; // 8 for correlation
frame.origin.y = 6; // 1 for correlation
aView.frame = frame;
}
}
}
@end
фиг знает что думали :D
−91
[Embed(source = "/assets/video_preview/VideoSlideThumb.png")]
public static const VIDEO_PREVIEW: Class;
public static function get videoPreviewBD(): BitmapData
{
var image : Bitmap = new VIDEO_PREVIEW ();
return image.bitmapData.clone();
}
Когда-то давно бытовала такая пословица: What Intel giveth Microsoft taketh away. Но похоже что переходное красное знамя подхватили и в других организациях по-меньше.
+138
public new string ID
{
get
{
return base.ID;
}
set
{
base.ID = value;
}
}
+117
@Override
public void afterPersistenceInit() {
val conn = emProvider.get().unwrap(Connection.class);
try {
log.info("Transaction isolation level: {}", getLevelString(conn.getTransactionIsolation()));
} catch (final SQLException e) {
log.error("Error getting transaction isolation level", e);
}
}
private String getLevelString(final int isolationLevel) {
// Poor man's enums. Use reflection to find a constant with the given value
try {
for (val maybeLevelConstant: Connection.class.getDeclaredFields()) {
if (maybeLevelConstant.getType() == int.class && maybeLevelConstant.getName().startsWith("TRANSACTION_")
&& maybeLevelConstant.getInt(null) == isolationLevel) {
return maybeLevelConstant.getName();
}
}
} catch (final IllegalArgumentException | IllegalAccessException e) {
return "UNKNOWN";
}
return "UNKNOWN";
}
Ищем рефлексией константу с нужным значением. И всё для того, чтобы напечатать её в логе. Вот что крест животворящий отсутствие энумов в legacy API делает.