- 1
movie_data["genres"][i]["ru"].lower().encode("utf-8").decode("utf-8")
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−86
movie_data["genres"][i]["ru"].lower().encode("utf-8").decode("utf-8")
Хм...
+72
public abstract class SomeActivity extends Activity implements SomeEventListener {
@Override
protected void onResume() {
super.onResume();
application.addSomeListener(this);
}
@Override
protected void onPause() {
application.removeSomeListener(this);
super.onPause();
}
В дополнение к #11379
Вопрос пользователю нужно задать поверх любой нашей активити...
+59
while (($i <= $additional_limit) && ($i < $available_spaces)) {
$i++;
}
в недрах плагина к wordpress. Прям по-другому минимум двух чисел не найти
+69
public abstract class SomeActivity extends Activity implements SomeEventListener {
private volatile Integer someEventAnswer;
@Override
public Integer onSomeEvent(final Collection<String> someData) {
final CountDownLatch latch = new CountDownLatch(1);
runOnUiThread(new Runnable() {
@Override
public void run() {
showSomeDialog(someData, latch);
}
});
try {
latch.await();
} catch (InterruptedException ignored) {
}
Integer ret = someEventAnswer;
someEventAnswer = null;
return ret;
}
private void showSomeDialog(final Collection<String> someData, final CountDownLatch latch) {
String[] items = someData.toArray(new String[someData.size()]);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Select some data");
builder.setItems(items, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
someEventAnswer = which;
latch.countDown();
}
});
Dialog dialog = builder.create();
dialog.setOwnerActivity(this);
dialog.show();
}
Android API Level 8
Суть: из фонового потока задать вопрос пользователю
+102
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if ((Edit1.Text <> '') or (Edit4.Text <> '')) then
begin
Button1.Enabled:=true;
end;
if ((Edit1.Text = '') or (Edit4.Text = '')) then
begin
Button1.Enabled:=false;
end;
end;
Таким образом настоящий ветеран говнокода защищает свое детище от "кривых" рук.
+16
template<typename T1, typename T2, size_t OFFSET = 8>
struct EnumMult
{
template<T1 t1, T2 t2>
struct Static
{
static const size_t V = (t1 << OFFSET) | t2;
};
static size_t Dynamic(T1 t1, T2 t2)
{
return (t1 << OFFSET) | t2;
}
};
// example
#include <iostream>
enum Suit
{
SPADES,
CLUBS,
DIAMONDS,
HEARTS
};
enum Value
{
SEVEN,
EIGHT,
NINE,
TEN,
JACK,
QUEEN,
KING,
ACE
};
int main()
{
typedef EnumMult<Suit, Value> CardMult;
switch (CardMult::Dynamic(CLUBS, SEVEN))
{
case CardMult::Static<SPADES, ACE>::V:
std::cout << "ACE OF SPADES";
break;
case CardMult::Static<CLUBS, SEVEN>::V:
std::cout << "HOOK";
break;
default:
std::cout << "NOTHING SPECIAL";
}
std::cout << std::endl;
return 0;
}
Понадобилось обработать два enum'а конструкцией switch-case, подумал, что было бы круто сделать квадратный свитч-кейс, но пришла и другая идиотская идея: шаблон для декартова умножения двух енумов. Заранее извините, если паттерн известный.
−122
exec @res = dbo.p_bis_prepaid_diagnostic @tar_addr, @req_dubug_info output
if (@res = 0)
set @res = 1
else
set @res = 0
+121
#include "uni.h"
int getopt_long(int argc, char *const argv[],const char *optstring,const struct option *longopts, int *longindex);
int getopt__long_only(int argc, char *const argv[],const char *optstring,const struct option *longopts, int *longindex);
int chown(const char *path, uid_t owner, gid_t group);
uid_t getuid(void);
int mkdir(const char *pathname, mode_t mode);
gid_t getgid(void);
char *dirname;
mode_t perm;
uid_t owner;
gid_t group;
int main(int argc,char **argv){
owner=getuid();
group=getgid();
perm=0600;
char *pEnd;
char *dirname=(char*)malloc(16);
if(dirname==NULL){fprintf(stderr, "out of memory!\n");return -1;}
memset( dirname,'\0',16);
strcat(dirname,argv[argc-1]);
struct option longopts[] = {
{ "mode", required_argument, NULL, 'm' },
{ "parents", NULL, NULL, 'p'},
{ "verbose", required_argument, NULL, 'v'},
{ "context", required_argument, NULL, 'c'},
{ "help", NULL, NULL, 'h'},
{ "version", NULL, NULL, 'r'},
{ 0, 0, 0, 0 }
};
char c;
while((c=getopt_long(argc,argv,"m:p:v:c:r:h",longopts,NULL)) != -1) {
switch (c) {
case 'm':
perm=strtol(optarg,&pEnd,8);
printf("%s\n",pEnd);
break;
case 'p':
if(rmdir(dirname)<0){
fprintf(stderr, "don't manage to delete folder!\n");return -1;
}
break;
case 'v':
if(mkdir(dirname,perm)<0){
fprintf(stderr, "mkdir: cannot create directory `%s`: file exists\n",dirname);return -1;
} else {
printf("mkdir: created directory `%s`\n",dirname);
return 0;
}
break;
case 'c':
break;
case 'h':
printf("Usage: mkdir [OPTION]... DIRECTORY...\n");
printf("Create the DIRECTORY(ies), if they do not already exist.\n");
printf("\n");
printf("Mandatory arguments to long options are mandatory for short options too.\n");
printf(" -m, --mode=MODE set file mode (as in chmod), not a=rwx - umask\n");
printf(" -p, --parents no error if existing, make parent directories as needed\n");
printf(" -v, --verbose print a message for each created directory\n");
printf(" -Z, --context=CTX set the SELinux security context of each created\n");
printf(" directory to CTX\n");
printf(" --help display this help and exit\n");
printf(" --version output version information and exit\n");
printf("\tAuthor AliceGoth\n");
return 0;
break;
case 'r':
printf("\tMy own mkdir\n");
printf("\tVersion 1.0\n");
printf("\tAuthor AliceGoth\n");
printf("\tEmail [email protected]\n");
break;
case 1:
Мой mkdir
+126
#include "uni.h"
#include "xreadlink.h"
int process(char *dir);
char *cd;
char *scd;
struct stat st1;
ino_t cino;
dev_t cdev;
int main(){
cd = (char *)malloc(160+1);
if(cd==NULL){
perror("Not enough memory");
return -1;
}
scd = (char *)malloc(1600+1);
if(scd==NULL){
perror("Not enough memory");
return -1;
}
memset(cd,'\0',1601);
memset(scd,'\0',1601);
strcat(scd,".");
if(lstat(scd,&st1)==-1){
perror("stat");
exit(EXIT_FAILURE);
};
cino = st1.st_ino;
cdev = st1.st_rdev;
//printf("inode %lu cdev %llu\n",cino,cdev);
process(scd);
return 0;
};
int process(char *dir){
DIR *dp;
struct dirent *ent;
ino_t lino;
dev_t ldev;
ino_t lino2;
dev_t ldev2;
int cnt=0;
char *mydir=(char*)malloc(1600);
char *mydir2=(char*)malloc(1600);
char **fpwd=(char**)malloc(160);
for(int i=0;i<=160;i++){
*(fpwd+i)=(char*)malloc(1600);
if(*(fpwd+i)==NULL){perror("Not sufficient memory");
return -1;
}
}
if(mydir==NULL)return -1;
if(*fpwd==NULL)return -1;
strcpy(mydir,dir);
strcpy(mydir2,dir);
struct stat lstt;
struct stat lstt2;
struct stat stt;
while(lino!=lino2 || ldev!=ldev2){
if(lstat(mydir,&lstt)==-1){
perror("not sufficient memory");
return -1;
}
strcat(mydir2,"/..");
if(lstat(mydir2,&lstt2)==-1){
perror("not sufficient memory");
return -1;
}
//printf("yes\n");
lino=lstt.st_ino;
ldev=lstt.st_rdev;
lino2=lstt2.st_ino;
ldev2=lstt2.st_rdev;
if ((dp = opendir(mydir2)) == NULL) {
fprintf(stderr, "%s: cannot open for reading: %s\n", dir, strerror(errno));
return 1;
}
if(lstat(mydir2,&stt)==-1){
perror("not sufficient memory");
return -1;
}
//if(chdir("/")<0){perror("chdir");return -1;};
while ((ent = readdir(dp)) != NULL){
if(ent->d_ino==lino && strcmp(ent->d_name,".")!=0 && strcmp(ent->d_name,"..")!=0 && stt.st_rdev==ldev){
//printf("%8ld %s\n", ent->d_ino, ent->d_name);
strcat(fpwd[cnt++],ent->d_name);
}
}
if (closedir(dp) != 0) {
fprintf(stderr, "%s: closedir: %s\n", dir, strerror(errno));
return 1;
}
//printf("mydir %s inode %lu cdev %llu inode %lu cdev %llu\n",mydir,lino,ldev,lino2,ldev2);
strcat(mydir,"/..");
strcpy(mydir2,mydir);
}
Поиск текущего каталога в дереве каталогов.
+133
if ((textBox1.Text == textBox2.Text) | (textBox1.Text == textBox3.Text) | (textBox1.Text == textBox4.Text) | (textBox1.Text == textBox7.Text) |
(textBox2.Text == textBox1.Text) | (textBox2.Text == textBox3.Text) | (textBox2.Text == textBox5.Text) | (textBox2.Text == textBox8.Text) |
(textBox3.Text == textBox1.Text) | (textBox3.Text == textBox2.Text) | (textBox3.Text == textBox6.Text) | (textBox3.Text == textBox9.Text) |
(textBox4.Text == textBox5.Text) | (textBox4.Text == textBox6.Text) | (textBox4.Text == textBox1.Text) | (textBox4.Text == textBox7.Text) |
(textBox5.Text == textBox4.Text) | (textBox5.Text == textBox6.Text) | (textBox5.Text == textBox2.Text) | (textBox5.Text == textBox8.Text) |
(textBox6.Text == textBox4.Text) | (textBox6.Text == textBox5.Text) | (textBox6.Text == textBox3.Text) | (textBox6.Text == textBox9.Text) |
(textBox7.Text == textBox8.Text) | (textBox7.Text == textBox9.Text) | (textBox7.Text == textBox1.Text) | (textBox7.Text == textBox4.Text) |
(textBox8.Text == textBox7.Text) | (textBox8.Text == textBox9.Text) | (textBox8.Text == textBox2.Text) | (textBox8.Text == textBox5.Text) |
(textBox9.Text == textBox7.Text) | (textBox9.Text == textBox8.Text) | (textBox9.Text == textBox3.Text) | (textBox9.Text == textBox6.Text)) ;
else
}
label1.Visible = true;
label2.Visible = true;
}
Это эпик.