- 1
enum Bool {True = 0, False = (!True)};
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+184
enum Bool {True = 0, False = (!True)};
Автор: Константин с trinity-core.ru
+73
int[] indexes = list.getSelectedIndices();
if (indexes.length == 0) {
indexes = getAllIndexes();
}
if (indexes.length == 0) {
return false;
}
индуссы атакуют
+170
// convert ',' to '.'
public static function ConvertDecimal($num) {
$num = preg_replace('/,/i', '.', $num);
//check if is number after convertion
if (is_numeric($num))
return $num;
return false;
}
у автора было суровое детство
+76
class PseudoVamp {
public int num;
public boolean truevamp = false;
public int x;
public int y;
public int n1;
public int n2;
public int n3;
public int n4;
void breaknsort() {
n1 = num % 10;
n2 = num / 10 % 10;
n3 = num / 100 % 10;
n4 = num / 1000;
int tmp;
for (int i = 0; i < 4; i++) {
if (n1 > n2) {
tmp = n1;
n1 = n2;
n2 = tmp;
}
if (n2 > n3) {
tmp = n2;
n2 = n3;
n3 = tmp;
}
if (n3 > n4) {
tmp = n3;
n3 = n4;
n4 = tmp;
}
}
}
public PseudoVamp(int a, int b) {
x = a;
y = b;
num = x * y;
breaknsort();
}
}
public class Test {
static void checkvamp(PseudoVamp vamp) {
int x1 = vamp.x % 10;
int x2 = vamp.x / 10;
int y1 = vamp.y % 10;
int y2 = vamp.y / 10;
int tmp;
for (int i = 0; i < 4; i++) {
if (x1 > x2) {
tmp = x1;
x1 = x2;
x2 = tmp;
}
if (x2 > y1) {
tmp = x2;
x2 = y1;
y1 = tmp;
}
if (y1 > y2) {
tmp = y1;
y1 = y2;
y2 = tmp;
}
}
if (vamp.n1 == x1 && vamp.n2 == x2 && vamp.n3 == y1 && vamp.n4 == y2)
vamp.truevamp = true;
}
public static void main(String[] args) {
for (int i = 11; i < 100; i++) {
for (int j = 11; j < 100; j++) {
PseudoVamp v = new PseudoVamp(i, j);
if (v.num < 1000)
continue;
if (v.num > 9999)
return;
checkvamp(v);
if (v.truevamp)
System.out.println(v.x + " * " + v.y + " = " + v.num);
}
}
}
}
A vampire number has an even number of digits and is formed by multiplying a pair of numbers containing half the number of digits of the result. The digits are taken from the original number in any order. Pairs of trailing zeroes are not allowed. Examples include:
1260 = 21 * 60
1827 = 21 * 87
2187 = 27 * 81
Write a program that finds all the 4-digit vampire numbers.
w/o using of arrays.
+139
char *reg = data;
char *temp = "blahblah is ";
strcat(temp,(const char*)"reg[4]");
Как оказывается на Си можно конкатенировать строки
−89
#weather.pyw
from urllib import request
from tkinter import *
import tkinter
import threading
from threading import *
import time
i = 0
active = True
def timerTick( toSleep ):
global active
while active:
refreshCall(0)
time.sleep(toSleep)
def refreshCall(event):
t = Thread(target = refresh)
t.start()
def refresh(*event):
global i
ref['text'] = str(i)
i+=1
r = request
page = str(r.urlopen('http://realmeteo.ru/moscow/1/current/').read())
temperature = page.split('</tr><tr id="num_data"><td>')[1].split(' ')[0]
pressure = page.split(' </td><td>')[1].split(' ')[0]
wind = page.split('<tr id="num_data"><td></td><td>')[1].split(' ')[0]
dest = page.split('<param name="movie" value="/.swf/wind_dir/')[1].split('.swf')[0]
destination = ''
for c in dest:
if c is dest[-1]:
destination += {'N':'Север','S':'Юг','W':'Запад','E':'Восток'}[c]
else:
destination += {'N':'Северо-','S':'Юго-','W':'Западо-','E':'Востоко-'}[c]
#print( temperature, pressure, wind, destination )
l1['text'] = 'Температура: '+temperature
l2['text'] = 'Давление : '+pressure
l3['text'] = 'Сила ветра : '+wind
l4['text'] = 'Направление: '+destination
r = request
page = str(r.urlopen('http://realmeteo.ru/moscow/1/current/').read())
temperature = page.split('</tr><tr id="num_data"><td>')[1].split(' ')[0]
pressure = page.split(' </td><td>')[1].split(' ')[0]
wind = page.split('<tr id="num_data"><td></td><td>')[1].split(' ')[0]
dest = page.split('<param name="movie" value="/.swf/wind_dir/')[1].split('.swf')[0]
destination = ''
for c in dest:
if c is dest[-1]:
destination += {'N':'Север','S':'Юг','W':'Запад','E':'Восток'}[c]
else:
destination += {'N':'Северо-','S':'Юго-','W':'Западо-','E':'Востоко-'}[c]
form = tkinter.Tk()
l1 = Label(form,text='Температура: '+temperature,justify='left'); l1.pack()
l2 = Label(form,text='Давление : '+pressure,justify='left'); l2.pack()
l3 = Label(form,text='Сила ветра : '+wind,justify='left'); l3.pack()
l4 = Label(form,text='Направление: '+destination,justify='left'); l4.pack()
ref = Button(form, text = 'Обновить'); ref.pack()
ref.bind('<Button-1>',refreshCall)
timerThread = Thread(target = timerTick, args=(5,))
timerThread.start()
form.mainloop()
active = False
Угадайте, с какого языка пересел автор. (не пэхапэ)
−99
# разбираюсь с питоном, может растолкуете почему так
>>> z = [lambda: i for i in [1,2,3]]
# почему вот такой результат?
>>> z[0](), z[1](), z[2]()
(3, 3, 3)
# каждый элемент списка - отдельная функция
>>> z[0] == z[1], z[0] is z[1]
(False, False)
# вот таким образом выходит правильно.
>>> z = [lambda: 1, lambda: 2, lambda:3]
>>> z[0](), z[1](), z[2]()
(1, 2, 3)
Автор - я. Меня действительно интересует, почему так происходит.
+163
$firstName = $_POST['firstname'];
$secondName=$_POST['secondname'];
$email = $_POST['email'];
$query="insert into sportsmans values('$secondName','$firstName','$email',null)";
$conn = mysql_connect('localhost','root','VCh3005');
mysql_select_db('Competition');
mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER SET 'utf8'");
mysql_query($query);
mysql_error();
mysql_close();
Классика...
+170
[](){}();
Поздравляю с новым стандартом, товарищи!
−175
if request.path == '/':
thread_list = ThreadBlock.objects.all()
else:
thread_nomer = re.search( r'/\d*/', request.path ).group()[1:-1]
thread_list = ThreadBlock.objects.filter(id=int(thread_nomer))
Бидон, джанга, уеб.