- 1
- 2
- 3
- 4
- 5
if ([_categories count] != 0) {
for (NSString *item in _categories) {
[path appendFormat:@"categories/%@/", item];
}
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−113
if ([_categories count] != 0) {
for (NSString *item in _categories) {
[path appendFormat:@"categories/%@/", item];
}
}
Случайно обнаружил у себя :)
+36
#include <iostream>
int main()
{
system("calc");
}
Калькулятор на C++? Да пожалуйста.
+24
template <typename IdType, class Tag>
class id {
public:
typedef IdType value_type;
explicit id(value_type val)
: value(val)
{}
bool operator==(id rhs)
{
return rhs.value == value;
}
bool operator!=(id rhs)
{
return rhs.value != value;
}
value_type value;
};
#define HASKELL_NEWTYPE(type_name, value_type) struct __##type_name##_tag__ {}; \
typedef ::id<value_type, __##type_name##_tag__> type_name
Когда newtype нет, но очень хочется.
http://ideone.com/VRu56j
Простите за синтетику
+15
/**
* @brief Serializer generic interface.
*/
template<typename ValueType>
struct serializer
{
/**
* @brief Parses value from raw bytes.
* @param from byte buffer parse value from
*/
static ValueType parse(uint8_t *from);
/**
* @brief Writes value to raw byte buffer.
* @param value value to write
* @param dest destination buffer
*/
static void write(ValueType value, uint8_t *dest);
};
template<>
struct serializer<uint8_t>
{
static uint8_t parse(uint8_t *from)
{
return *from;
}
static void write(const uint8_t value, uint8_t *to)
{
*to = value;
}
};
template<>
struct serializer<uint16_t>
{
static uint16_t parse(uint8_t *from)
{
return (uint16_t)from[0] << 8 | from[1];
}
static void write(const uint16_t value, uint8_t *to)
{
to[0] = (value >> 8);
to[1] = value & 0xff;
}
};
template<>
struct serializer<uint32_t>
{
static uint32_t parse(uint8_t *from)
{
return from[0] << 24 | from[1] << 16 | from[2] << 8 | from[3];
}
static void write(const uint32_t value, uint8_t *to)
{
serializer<uint16_t>::write(value >> 16, to);
serializer<uint16_t>::write(value & 0xffff, to + 2);
}
};
template<>
struct serializer<uint64_t>
{
static uint64_t parse(uint8_t *from)
{
const uint32_t high = serializer<uint32_t>::parse(from);
const uint32_t low = serializer<uint32_t>::parse(from + 4);
return ((uint64_t) high << 32) | low;
}
static void write(const uint64_t value, uint8_t *to)
{
serializer<uint32_t>::write(value >> 32, to);
serializer<uint32_t>::write(value & 0xffffffff, to + 4);
}
};
Тут поднялась тема неуместного битолюбства... Решил поделиться одним из моих первых крестОпусов.
"кроссплатформенный hton(sl)".
+43
function Podergatsya($i)
{
$i++;
$i--;
return $i;
}
Индусская CMS
+137
void riffoser_track_writeriff(struct riffoser_track * track,char * filename,riffoser_samplerate_t samplerate,riffoser_bitspersample_t bitspersample) {
FILE * fp;
unsigned long i1,i2,i3,i4,i5,i6,fpi;
unsigned char c1,bytespersample;
unsigned char * skipbuf;
float fret,val;
long ival;
unsigned char nomorewaves;
riffoser_channel_t chan;
bytespersample=bitspersample/8;
fp=fopen(filename,"wb");
i1=track->channels*samplerate*bytespersample*track->length;
i2=4+24+8+i1+(i1%2>0?1:0);
riffoser_writestr("RIFF");
riffoser_writeint(4,4+24+8+i1+(i1%2>0?1:0));
riffoser_writestr("WAVEfmt ");
riffoser_writeint(4,16);
riffoser_writeint(2,1);
riffoser_writeint(2,track->channels);
riffoser_writeint(4,samplerate);
riffoser_writeint(4,bytespersample*track->channels*samplerate);
riffoser_writeint(2,bytespersample*track->channels);
riffoser_writeint(2,bytespersample*8);
riffoser_writestr("data");
riffoser_writeint(4,i1);
if (i1%2>0)
riffoser_writeint(1,0);
i1=0;
i3=track->waves_count;
i6=0;
nomorewaves=0;
while (1) {
chan=i1%track->channels;
if (i3==track->waves_count&&!nomorewaves) {
i5=i1;
0&&printf("%lu: finding nearest wave...\n",i1);
for (i2=0;i2<track->waves_count;i2++){
if ((track->wavestates[i2]->state==RIFFOSER_WAVESTATE_IDLE)&&(((i3==track->waves_count))||(RIFFOSER_RENDER___FROM(track->wavestates[i2])<=i5))&&(RIFFOSER_RENDER___FROM(track->wavestates[i2])>=i6)) {
0&&printf("%lu: found wave %lu with from %f\n",i1,i2,RIFFOSER_RENDER___FROM(track->wavestates[i2]));
i3=i2;
i5=RIFFOSER_RENDER___FROM(track->wavestates[i2]);
}
else {
0&&printf("%lu: skipping wave %lu\n",i1,i2);
}
}
if (i3!=track->waves_count)
0&&printf("next wave will be %lu at %f\n",i3,RIFFOSER_RENDER___FROM(track->wavestates[i3]));
else nomorewaves=1;
}
c1=0;
val=0;
for (i2=0;i2<track->waves_count;i2++){
if (track->wavestates[i2]->state==RIFFOSER_WAVESTATE_RENDERING) {
if (RIFFOSER_RENDER___TO(track->wavestates[i2])<i1) {
track->wavestates[i2]->state=RIFFOSER_WAVESTATE_FINISHED;
0&&printf("%lu: wave %lu finished\n",i1,i2);
} else {
if (track->wavestates[i2]->channel==chan) {
// printf("correct channel\n");
track->wavestates[i2]->samplenum++;
if (track->wavestates[i2]->samplenum>RIFFOSER_RENDER___WSC(track->waves[i2]))
track->wavestates[i2]->samplenum-=RIFFOSER_RENDER___WSC(track->waves[i2]);
0&&printf("%lu: rendering wave %lu (%f-%f), samplenum is %f (%f%%)\n",i1,i2,RIFFOSER_RENDER___FROM(track->wavestates[i2]),RIFFOSER_RENDER___TO(track->wavestates[i2]),track->wavestates[i2]->samplenum,RIFFOSER_RENDER___WPP(track->waves[i2],track->wavestates[i2]->samplenum));
RIFFOSER_WAVE_FUNC(track->waves[i2],RIFFOSER_RENDER___WPP(track->waves[i2],track->wavestates[i2]->samplenum));
fret=fret*track->waves[i2]->amplitude/200;
// replace for now
val=fret;
}
else {
// printf("wrong channel ( %u / %u )\n",track->wavestates[i2]->channel,chan);
}
c1=1;
}
}
}
if (bytespersample==1) {
ival=round(val*2.56)-128;
if (ival>127)
ival=127;
}
else if (bytespersample==2) {
ival=round(val*655.36);
if (ival>65535)
ival=65535;
}
else if (bytespersample==4) {
ival=round(val*42949672.96);
if (ival>4294967295)
ival=4294967295;
}
riffoser_writeint(bytespersample,ival);
if (c1==0) {
if (i3!=track->waves_count) {
0&&printf("%lu: warping to position %lu\n",i1,i5);
i4=(i5-i1)*bytespersample;
skipbuf=malloc(i4);
memset(skipbuf,0,i4);
riffoser_writebuf(i4,skipbuf);
Полная версия - https://github.com/anon4ik/riffoser/blob/master/libriffoser.c
+128
[Record] variant ItemPatternMatched: PatternMatchedBase, IPatternMatched
_matchByLexemeValue:option[string]
public Match(source:SourceLexemes, namedLinkDictionary:NamedLinkDictionary):MatchResult
match(source)
|[] => MatchResult.EndOfLexemes(source, namedLinkDictionary)
|lexeme_::lexemes_=> def updatedNamedLinkDictionary = updateNamedLinkDictionary(lexeme_::[], namedLinkDictionary);
def failure = MatchResult.Failure(source, namedLinkDictionary);
def success = MatchResult.Success(lexemes_, updatedNamedLinkDictionary);
match(_matchByLexemeValue)
|None | Some(lexemeValue_) when (lexemeValue_==lexeme_._value) =>
match(this, lexeme_._type)
|(Symbol, SourceLexeme.Type.Symbol) | (Identificator, SourceLexeme.Type.Identificator) | (Number, SourceLexeme.Type.Number) =>
success
|_ =>
failure
|_ =>
failure
|Symbol
|Identificator
|Number
Начальник, посмотрев на код, сказал, что NemerleGovno. Я не знаю, что ему ответить?
+72
if("all".equalsIgnoreCase(lvl)) {
setLevel(SimpleLog.LOG_LEVEL_ALL);
} else if("trace".equalsIgnoreCase(lvl)) {
setLevel(SimpleLog.LOG_LEVEL_TRACE);
} else if("debug".equalsIgnoreCase(lvl)) {
setLevel(SimpleLog.LOG_LEVEL_DEBUG);
} else if("info".equalsIgnoreCase(lvl)) {
setLevel(SimpleLog.LOG_LEVEL_INFO);
} else if("warn".equalsIgnoreCase(lvl)) {
setLevel(SimpleLog.LOG_LEVEL_WARN);
} else if("error".equalsIgnoreCase(lvl)) {
setLevel(SimpleLog.LOG_LEVEL_ERROR);
} else if("fatal".equalsIgnoreCase(lvl)) {
setLevel(SimpleLog.LOG_LEVEL_FATAL);
} else if("off".equalsIgnoreCase(lvl)) {
setLevel(SimpleLog.LOG_LEVEL_OFF);
}
Внутренности конструктора org.apache.commons.logging.impl.SimpleLo g
+137
static /*public*/ string GenerateRandomJpegName()
{
return GenerateRandomString() + ".jpg";
}
static string GenerateRandomString()
{
bool UseSigns = true;
bool UseUpperLetters = true;
bool UseLetters = true;
int Length;
NewLabel:
try
{
Length = new Random(DateTime.Now.Millisecond - DateTime.Now.Second + new Random(DateTime.Now.Millisecond).Next(0, 100) / new Random(DateTime.Now.Millisecond - DateTime.Now.Second).Next(0, 10)).Next(0, 100);
}
catch { goto NewLabel; }
string result = "C:/";
try
{
int Seed = 0;
char[] letters = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
char[] signs = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
List<char> keyWords = new List<char>();
List<char> upperLetters = new List<char>();
foreach (char c in letters)
upperLetters.Add(Convert.ToChar(c.ToString().ToUpper()));
if (UseLetters)
foreach (char c in letters)
keyWords.Add(c);
if (UseSigns)
foreach (char c in signs)
keyWords.Add(c);
if (UseUpperLetters)
foreach (char c in upperLetters)
keyWords.Add(c);
int MaxValue = keyWords.Count;
for (int i = 0; i <= Length; i++)
{
try
{
Random mainrand = new Random(Seed);
char RandChar = keyWords[mainrand.Next(0, MaxValue)];
result += RandChar;
Seed += DateTime.Now.Millisecond + Seed - new Random().Next(10) + new Random(DateTime.Now.Millisecond + 800 * 989 / 3).Next(10);
}
catch { continue; }
}
}
catch { }
return result;
}
Вместо одного вызова Path.GetRandomFileName
+79
List<String> list;
....
Long num = Long.parseLong( "" + list.size() );
Самый оригинальный способ конвертации int в Long, кот. встречал в проекте )