- 1
((UIButton*)[[mCellsArray objectAtIndex:indexPath.row]viewWithTag:kSpeakGalleryCellButtonTag]).selected = !((UIButton*)[[mCellsArray objectAtIndex:indexPath.row]viewWithTag:kSpeakGalleryCellButtonTag]).selected;
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−83
((UIButton*)[[mCellsArray objectAtIndex:indexPath.row]viewWithTag:kSpeakGalleryCellButtonTag]).selected = !((UIButton*)[[mCellsArray objectAtIndex:indexPath.row]viewWithTag:kSpeakGalleryCellButtonTag]).selected;
Встречается в проекте раз пять такая конструкция
+128
if (i < 1024) {
...
} else if (i/1024 < 1024) {
...
} else if (i/1048576 < 1024) {
...
} else if (i/1073741824 < 1024) {
...
} else {
return "о$#еть, терабайтный файл!";
}
http://ithappens.ru/story/8200
>Но приложения он пишет отменные
А в упрощение сравнений не может.
+131
#include <stdio.h>
#include <math.h>
void out_bin (unsigned short c){
for (int i = 11; i>=0; i--) {
if ((c & (unsigned short)(1<<i))/(1<<i)==1) printf("1");
else printf("0");
}
printf("\n");
}
int main (){
int a[8]={2,4,5,6,8,9,10,11};
int b[4]={0,1,3,7};
int d=0;
unsigned short int c=0,c1[4]={0,0,0,0};
unsigned char data=165,tdata=176;
for(int i=7;i>=0;i--)
{
if (tdata & 128){
c+=(unsigned short )(1<<a[i]);
}
tdata<<=1;
}
for (int i=0;i<8;i++){
unsigned short b = (unsigned short)((c & (unsigned short)(1<<a[i]))/(1<<a[i])) ;
if(a[i] & 1) c1[0]^=b;
else
if(a[i] & 2) c1[1]^=b ;
else
if(a[i] & 4) c1[2]^=b ;
else
if(a[i] & 8) c1[3]^=b ;
}
for (int i = 0; i < 4; i++) {
if (!c1[i]) {
c|=(unsigned short)(1<<((1<<i)-1));
}
}
printf("Data= ");
out_bin(c);
c ^= 256 ;
if ((((c & 1024)/1024) ^ ((c & 256)/256) ^ ((c & 64)/64) ^ ((c & 16)/16) ^ ((c & 4)/4) ^ ((c & 1)/1) ) !=1 ){
d += 1;
}
if ((((c & 1024)/1024) ^ ((c & 512)/512) ^ ((c & 64)/64) ^ ((c & 32)/32) ^ ((c & 4)/4) ^ ((c & 2)/2) ) !=1 ){
d +=2;
}
if ((((c & 2048)/2048) ^ ((c & 64)/64) ^ ((c & 32)/32) ^ ((c & 16)/16) ^ ((c & 8)/8) ) !=1 ){
d +=4;
}
if ((((c & 2048)/2048) ^ ((c & 1024)/1024) ^ ((c & 512)/512) ^ ((c & 256)/256) ^ ((c & 128)/128) )!=1 ){
d+=8;
}
printf("Spoiled= ");
out_bin(c);
printf("%d",d);
if (d){
c ^=(1<<(d-1));
}
printf("Corrected= ");
out_bin(c);
return 0;
}
Код Хэмминга
+147
if($row['status_id'] != 6){
if($row['assist_type'] == 0){
$row['assist_type'] == 3;
}
...
}
:-|
+110
public partial class ProductForm : Form
{
private delegate bool ProductManipulation();
private static ProductManipulation pmd;
public ProductForm()
{
InitializeComponent();
this.FormClosing += this.ProductForm_Closing;
ProductsLB.DoubleClick += this.ChangeBtn_Click;
ProductsLB.Click += this.LoadProductKey;
pmd = LoadDataToLB;
pmd();
}
...
private void AddBtn_Click(object sender, EventArgs e)
{
pmd -= LoadDataToLB;
pmd += AddProduct + pmd;
pmd += LoadDataToLB;
pmd();
pmd -= AddProduct;
}
...
Обильное делегирование
+142
CREATE TABLE `users` (
нормальные поля типо имя
`ff` text NOT NULL,
`da` char(100) NOT NULL,
Дали мне дампик таблицы... В полях ДА! вот это...
00A00A00000A0A0AA793655265A00AA000000A00 00A000A72540000AA0A00560A000000A9A990000 0000AAA00000104A004010A00A000A0A0A0AA599 135A00A000A0A0000A00000000A4A450000A0AAA 010AAAA000AA9A0000AAAAA0AAA0A000104AA04A AAA000A0000A00000000AAA000A0A00000000A00 0070000AA00A0000000000A0000000A00000A080 900A0000000A00A00000AAA0000A000A00000000 A00000A0A000000000000070000A00000A000000 00A00000000000A000001A1A0000000000000000 0A00000A00000000A00000000A0A0A000A000A00 0000000000000A00AAAA00AAA000A0A00A0000A0 00AAAAA0A0AA0A00A000','01000000000100000 000000001B261000000000000000000000000000 0000000000000000000000000000000000000000 000
−106
def simpleEncrDecr( alphabet, alphabetKey, encrDecrWord, triger) #простой метод одну букву из алфавита заменяет другой
alphabet = alphabet.chars.to_a
alphabetKey = alphabetKey.chars.to_a
encrDecrWord = encrDecrWord.chars.to_a
if triger == 'encryption' then
for i in 0..encrDecrWord.length-1
encrDecrWord[i] = alphabetKey[alphabet.rindex(encrDecrWord[i])]
end
elsif triger == 'decryption'
for i in 0..encrDecrWord.length-1
encrDecrWord[i] = alphabet[alphabetKey.rindex(encrDecrWord[i])]
end
else
p "You is looser! :-)"
end
encrDecrWord.join
end
def manyAlphEncrDecr( alphabet, alpKey, encrDecrWord, triger) #для закодування нужное слово которое будет ключом
alphabet = alphabet.chars.to_a
encrDecrWord = encrDecrWord.chars.to_a
if triger == 'encryption' then
for i in 0..encrDecrWord.length-1
sum = alphabet.rindex(encrDecrWord[i])+alphabet.rindex(alpKey[i])
encrDecrWord[i] = alphabet[sum%alphabet.length]
end
elsif triger == 'decryption'
for i in 0..encrDecrWord.length-1
div = alphabet.rindex(encrDecrWord[i])-alphabet.rindex(alpKey[i])
encrDecrWord[i] = alphabet[div]
end
else
p "You is looser! :-)"
end
encrDecrWord.join
end
def permutationEncrDecr( permKeyNew, encrDecrWord, triger) #меняет местами буквы в соответствии с ключом, 1234 <=> 3241
encrDecrWord = encrDecrWord.chars.to_a
encrDecrWordNew = Array.new
if triger == 'encryption' then
for i in 0..encrDecrWord.length-1
encrDecrWordNew[i] = encrDecrWord[permKeyNew[i]]
end
elsif triger == 'decryption'
for i in 0..encrDecrWord.length-1
encrDecrWordNew[permKeyNew[i]] = encrDecrWord[i]
end
else
p "You is looser! :-)"
end
encrDecrWordNew.join
end
def frequencyAnalysis(textForAnalis) #частотный анализ текста (подсчет букв)
analisHash = Hash.new
for i in 0..textForAnalis.length-1
analisHash[textForAnalis[i]] = 0
end
for i in 0..textForAnalis.length-1
analisHash[textForAnalis[i]] += 1
end
puts "Frequency Analysis - #{analisHash}"
end
p "Alphabet - #{alphabet = ('0'..'z').to_a.join}"
print "Enter words for encryption/decryption:"
wordForEncryped = gets.chomp
print "Type method:\n1-simple\n2-many alphabetic\n3-permutation\n"
method = gets.chomp
case
when method == '1' then
puts "Key for alphabet - #{alphabetKey = alphabet.chars.to_a.shuffle.join}"
puts "Simple Encryped - #{encrypedWord = simpleEncrDecr( alphabet, alphabetKey, wordForEncryped, 'encryption')}"
frequencyAnalysis(encrypedWord)
puts "Simple Decryped - #{simpleEncrDecr( alphabet, alphabetKey, encrypedWord, 'decryption')}"
when method == '2' then
print "Enter word for many alphabetical encryption/decryption:"
wordForManyAlphKey = gets.chomp.chars.to_a
manyAlphKey = Array.new
for i in 0..wordForEncryped.length-1
manyAlphKey[i] = wordForManyAlphKey[i%wordForManyAlphKey.length]
end
puts "Many Alphabetic Encryped - #{encrWordForManyAlph = manyAlphEncrDecr( alphabet, manyAlphKey, wordForEncryped, 'encryption')}"
frequencyAnalysis(encrWordForManyAlph)
puts "Many Alphabetic Decryped - #{manyAlphEncrDecr( alphabet, manyAlphKey, encrWordForManyAlph, 'decryption')}"
when method == '3' then
print 'Please typed key(f.e. 23451):'
permKey = gets.chomp.chars.to_a
lengthForSum = permKey.length
newPermKey = Array.new
for i in 0..wordForEncryped.length-1
lengthForSum += permKey.length if i==lengthForSum
newPermKey[i] = permKey[i%permKey.length].to_i + lengthForSum - permKey.length-1
end
puts "Permutation Encryped - #{encrypedWordForPrem = permutationEncrDecr( newPermKey, wordForEncryped, 'encryption')}"
frequencyAnalysis(encrypedWordForPrem)
puts "Permutation Decryped - #{permutationEncrDecr( newPermKey, encrypedWordForPrem, 'decryption')}"
else p 'Incorect typed'
end
Методьі кодирования
1. простой метод одну букву из алфавита заменяет другой
2. для закодування нужное слово которое будет ключом
3. меняет местами буквы в соответствии с ключом, 1234 <=> 3241
4. частотный анализ текста (подсчет букв)
у каждого метода кроме 4 есть триггер - выбор в каком режиме метод будет работать (кодирование или декодирование)
+65
for (...) {
Comparator<Date> date_comparator = new Comparator<Date>() {
@Override
public int compare(Date s1, Date s2) {
long n1 = s1.getTime();
long n2 = s2.getTime();
if (n1 < n2)
return -1;
else if (n1 > n2)
return 1;
else
return 0;
}
};
Date beforeSaveDate = (Date) beforeSaveParam.getValue();
beforeSaveDate.setSeconds(0);
Date toSaveDate = (Date) toSaveParam.getValue();
comparedValue = date_comparator.compare(beforeSaveDate, toSaveDate);
}
Задача была сравнить две даты, игнорируя при этом секунды.
+167
$zfunctv=0;
if ($zfunctv==1 || $zfunctv==2 || $zfunctv==3 || $zfunctv==4) require_once('function1.php');
if ($zfunctv==2 || $zfunctv==3) require_once('function2.php');
if ($zfunctv==3 || $zfunctv==4) require_once('function3.php');
if ($zfunctv==''){
require_once('function1.php');//Для всех окон
require_once('function2.php');//Для полноразмерных окон
require_once('function3.php');//Для оборудования
require_once('admfunct.php');
}
Какого хрена? Как это работает?! Код коммерческой системы UserSide v2.48
+132
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <time.h>
char a[150],c[150];
int main(int argc, char **argv) {
FILE * tmp;
while(1) {
int b=0,b1=0;
bool A=0;
tmp=fopen(".tmp.txt","r");
fgets(c,150,tmp);
fclose(tmp);
system("rm .tmp.txt");
system("xwininfo -tree -root | grep -i '\\- deadbeef-0.5.1' > .tmp.txt");
tmp=fopen(".tmp.txt","r");
fgets(a,150,tmp);
fclose(tmp);
for(int i=16;i<149;i++) {
c[i-16]=c[i];
a[i-16]=a[i];
if(a[i-16]=='-')
b++;
if(c[i-16]=='-')
b1++;
if(b==2)
a[i-16]=0;
if(b1==2)
c[i-16]=0;
}
for(int j=0;j<(int)strlen(c);j++) {
if (a[j]!=c[j]) A=true;
}
if (A) {
char lamp[]="/usr/bin/purple-remote \"setstatus?status=available&message=";
strcat(lamp,a);
strcat(lamp,"\"");
system(lamp);
}
sleep(5);
}
return 0;
}
Реализация аналога pidgin-musictracker для deadbeef