- 1
- 2
- 3
- 4
- 5
- 6
- 7
function printVar($var) {
ob_start();
print_r($var);
$var = ob_get_contents();
ob_end_clean();
return $var;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+157
function printVar($var) {
ob_start();
print_r($var);
$var = ob_get_contents();
ob_end_clean();
return $var;
}
Вдруг версия php < 4.2.0? :)
Найдено в фреймворке DoPHP
+118
string s=textBox1.Text,d="";
if (s.lenght > 0)
for (int i = 0; i < s.lenght- 1; i++)
d += s[i];
Код, присланный товарищем мне на проверку. Смех и грех - этот человек учится на третьем курсе политеха на специальности ИТ.
+128
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
int x = Convert.ToInt32(comboBox1.Text);
switch (x)
{
case 2: textBox1.Visible=true;
textBox2.Visible = true;
textBox3.Visible = false;
textBox4.Visible = false;
textBox5.Visible = false;
textBox6.Visible = false;
textBox7.Visible = false;
textBox8.Visible = false;
textBox9.Visible = false;
textBox10.Visible = false;
break;
case 3:
textBox1.Visible = true;
textBox2.Visible = true;
textBox3.Visible = true;
textBox4.Visible = false;
textBox5.Visible = false;
textBox6.Visible = false;
textBox7.Visible = false;
textBox8.Visible = false;
textBox9.Visible = false;
textBox10.Visible = false;
break;
//и так до 10
//...
private void button1_Click(object sender, EventArgs e)
{
double p1 = 1 / Convert.ToDouble(textBox1.Text);
double p2 = 1 / Convert.ToDouble(textBox2.Text);
double p3 = 1 / Convert.ToDouble(textBox3.Text);
double p4 = 1 / Convert.ToDouble(textBox4.Text);
double p5 = 1 / Convert.ToDouble(textBox5.Text);
double p6 = 1 / Convert.ToDouble(textBox6.Text);
double p7 = 1 / Convert.ToDouble(textBox7.Text);
double p8 = 1 / Convert.ToDouble(textBox8.Text);
double p9 = 1 / Convert.ToDouble(textBox9.Text);
double p10 = 1 / Convert.ToDouble(textBox10.Text);
double inv;
int x = Convert.ToInt32(comboBox1.Text);
switch (x)
{
case 2:
inv=(1/p1+1/p2);
break;
case 3:
inv = ((1 / p1) + (1 / p2)+(1/p3));
break;
case 4:
inv = ((1 / p1) + (1 / p2) + (1 / p3)+(1/p4));
break;
case 5:
inv = ((1 / p1) + (1 / p2) + (1 / p3) + (1 / p4)+(1/p5));
break;
case 6:
inv = ((1 / p1) + (1 / p2) + (1 / p3) + (1 / p4) + (1 / p5)+(1/p6));
break;
case 7:
inv = ((1 / p1) + (1 / p2) + (1 / p3) + (1 / p4) + (1 / p5) + (1 / p6) + (1 / p7));
break;
case 8:
inv = ((1 / p1) + (1 / p2) + (1 / p3) + (1 / p4) + (1 / p5) + (1 / p6) + (1 / p7) + (1 / p8));
break;
case 9:
inv = ((1 / p1) + (1 / p2) + (1 / p3) + (1 / p4) + (1 / p5) + (1 / p6) + (1 / p7) + (1 / p8) + (1 / p9));
break;
case 10:
inv = ((1 / p1) + (1 / p2) + (1 / p3) + (1 / p4) + (1 / p5) + (1 / p6) + (1 / p7) + (1 / p8) + (1 / p9) + (1 / p10));
break;
double rez = 1 / inv;
textBox11.Text = Convert.ToString(rez);
}
}
+149
$message = array(
'Message from blablabla',
'',
'Name: '.$_POST['name'],
'Title: '.$_POST['title'],
'City, State: '.$_POST['city'],
'Enrollment: '.$_POST['enrol'],
'Email: '.$_POST['email'],
'Phone: '.$_POST['phone'],
);
$body = implode('<br>',$message);
Чувак, вроде опытный программист, в 2006 году написал сие произведение искусства:
+75
private void configComponents(/* params */) throws MyException {
String err_msg = null;
try {
// some code here...
return;
} catch (ComponentConfigurationException e) {
err_msg = e.getMessage();
} catch (MyException e) {
err_msg = e.getMessage();
} catch (Exception e) {
err_msg = setupProcessErrorMessage;
}
throw new MyException(err_msg);
}
А rethrowing у нас уже не в почете. Правильно контрагаить ретурном из трай-секции и выбросом исключения, если трай-секция не дожила до ретурна.
+169
function ValidateIPAdress($value){
if (preg_match('/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $value)){
return true;
}
return false;
}
if( ValidateIPAdress("192.168.0.1") )
echo("This is an IPAdress");
else
echo("This is not an IPAdress");
Функция проверки IP адреса.
−183
def validate_line(line):
if len(line) <= 2: return False
if line[0] == '""': return False
if line[0] == "''": return False
if line[0] == '+!': return False
if line[0] == '-?': return False
if line[0] == '- (': return False
if line[0] == '-(': return False
if line[0] == '-)': return False
if line[0] == '-6a': return False
if line[0] == '-6a )': return False
if line[0] == '-a': return False
if line[0] == '-aa': return False
if line[0] == '-:': return False
if line[0] == ':': return False
if line[0][0] == '#': return False
if line[0][0] == "'": return False
if line[0][0] == '&': return False
if line[0][0] == '(': return False
return True
Жил был один маленький портальчик одной немаленькой компании. Портал внутренний, пользовался секретамками, манагерами и прочим планктоном. С задачей своей справлялся, не глючил и вообще проблем не приносил. И вот задумали в него добавить пару "фишек". А писался он давно, программиста уже не найти. Полезли в код, а там ... В общем вот; ВЕСЬ код написан в так вот стиле...
+162
/**
* Test to see if the cache storage is available.
*
* @static
* @access public
* @return boolean True on success, false otherwise.
*/
function test()
{
return true;
}
Описание метода в коментах.
Joomfish
+154
__int64 timestamp;
// Get nanoseconds since 1601
timestamp = rand() + (((__int64)rand()) << 32);
timestamp /= 100;
очень вольная работа со временем...
+114
[Serializable()]
public class Vendor
{
#region Constructors
public Vendor(long vendorID)
{
LoadData(vendorID);
}
internal Vendor(Vendor argVendor)
{
if (argVendor != null)
{
this.ID = argVendor.ID;
this.VendorName = argVendor.VendorName;
this.Account = argVendor.VendorAccount;
this.EIN = argVendor.VendorEIN;
this.Address = argVendor.VendorAddress;
this.City = argVendor.VendorCity;
this.State = argVendor.VendorState;
this.PostalCode = argVendor.VendorZip;
this.Phone = argVendor.VendorPhone;
this.ContactName = argVendor.VendorContact;
this.VendorCode = argVendor.VendorCode;
this.Country = argVendor.VendorCountry;
this.FaxNumber = argVendor.VendorFax;
this.Email = argVendor.Email;
}
}
#endregion
public void LoadData(long vendorID)
{
POMRepositoryDataClassesDataContext db = new POMRepositoryDataClassesDataContext();
var ven = (from v in db.Vendors
where v.ID == vendorID
select v).SingleOrDefault();
if (ven != null)
{
populateMe(ven);
}
}
public void LoadDataByVendorCode(string argVendorCode)
{
POMRepositoryDataClassesDataContext db = new POMRepositoryDataClassesDataContext();
var ven = (from v in db.Vendors
where v.VendorCode == argVendorCode
select v).Take(1).SingleOrDefault();
if (ven != null)
{
populateMe(ven);
}
}
private void populateMe(Vendor ven)
{
this.ID = ven.ID;
this.VendorName = ven.VendorName;
this.Account = ven.VendorAccount;
this.EIN = ven.VendorEIN;
this.Address = ven.VendorAddress;
this.City = ven.VendorCity;
this.State = ven.VendorState;
this.PostalCode = ven.VendorZip;
this.Phone = ven.VendorPhone;
this.ContactName = ven.VendorContact;
this.VendorCode = ven.VendorCode;
this.Country = ven.VendorCountry;
this.FaxNumber = ven.VendorFax;
this.Email = ven.Email;
}
}
No comments!!!