- 1
BLOG_BLOG_BLOG_NO_BLOG
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+184
BLOG_BLOG_BLOG_NO_BLOG
Константа в 1C-Bitrix.
Баден-Баден отдыхает.
+115
columnDomain.Visible =
(grid.MainView.RowCount >
0
&&
!String.IsNullOrEmpty(
((ListItem)
grid.MainView.
GetRow(0)).Domain)
&&
((ListItem)
grid.MainView.GetRow(0))
.Domain !=
((ListItem)
grid.MainView.GetRow(0))
.DisplayName);
Это реальное форматирование кода, очевидно сделанное для удобства чтения на узком и высокои мониторе :) И такого многие и многие экраны
−103
public static function trimExtraLineBreaks(string:String):String
{
var trimmedString:String = string;
for(var i:int = 0; i < 20; i++)
{
trimmedString = trimmedString.replace(new RegExp("\r\r","g"),"\r");
trimmedString = trimmedString.replace(new RegExp("\r\n","g"),"\r");
trimmedString = trimmedString.replace(new RegExp("\n\n","g"),"\n");
trimmedString = trimmedString.replace(new RegExp("\n\r","g"),"\n");
trimmedString = trimmedString.replace(new RegExp("\n ","g"),"\n");
trimmedString = trimmedString.replace(new RegExp("\r ","g"),"\n");
trimmedString = trimmedString.replace(new RegExp(" \n","g"),"\n");
trimmedString = trimmedString.replace(new RegExp(" \r","g"),"\n");
}
return trimmedString;
}
Натолкнулся на просторах github'а во время поиска чего-то там... Ей богу сразу забыл, что искал.
+151
<?php
function test_menu() {
// $menu['test'] = array(
// 'page callback' => 'test_page',
// 'access callback' => TRUE,
// );
$menu['test/%user_uid_optional'] = array(
'page callback' => 'test_view',
'page arguments' => array(1),
'access callback' => 'test_access',
'access arguments' => array(1),
);
$menu['test/%user/view'] = array(
'title' => 'View',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$menu['test/%user/edit'] = array(
'title' => 'Edit',
'page callback' => 'test_edit',
'page arguments' => array(1),
'access callback' => 'test_access',
'access arguments' => array(1),
'type' => MENU_LOCAL_TASK,
);
return $menu;
}
function test_page() {
global $user;
if ($user->uid) {
menu_set_active_item("test/$user->uid");
return menu_execute_active_handler();
}
else {
drupal_goto('user/login');
}
}
function test_view($account) {
module_load_include('pages.inc', 'user');
return user_view($account);
}
function test_edit($account) {
module_load_include('pages.inc', 'user');
return user_edit($account);
}
function test_access($account) {
dpm($account);
return TRUE;
}
+127
[code=Си]
switch(n)
case 1:
{
/* code1 */
/* fallthrough */
case 2:
/* code 2 */
}
[/code]
Все имена и явки изменены!
Сцуко, работает. Щас в стандарт полезу, интересно же! Обвиняют меня, я киваю на издержки мержа. Но смешно.
+167
float ArenaTeam::GetChanceAgainst(uint32 own_rating, uint32 enemy_rating)
{
// returns the chance to win against a team with the given rating, used in the rating adjustment calculation
// ELO system
// return 1.0f/(1.0f+exp(log(10.0f)*(float)((float)enemy_rating - (float)own_rating)/400.0f));
float a,b;
a = own_rating;
b = enemy_rating;
if(a<1800 && b<1800) return 16;
if(a>=1800 && a<2000 && b<2000 || b>=1800 && b<2000 && a<2000) return 15;
if(a>=2200 && b>=2200) return 15;
if(a>b){
if(a>=2000 && a<2100 && b>=2100 && b<2200) return 17;
if(a>=2000 && a<=2100 && b>=2200) return 18;
if(b>=2000 && b<2100 && a>=2200) return 9;
if(a>=2000 && a<2100 && b>=2000 && b<2100) return 15;
if(a>=2100 && a<2200 && b>=2100 && b<2200) return 15;
if(a>=2100 && a<2200 && b>=2200) return 16;
if(b>=2100 && b<2200 && a>=2200) return 11;
if (a>=2000 && a<2100 && b >=1850) return 10;
if (a>=2000 && a<2100 && b <=1850) return 5;
if (a>=2100 && a<=2200 && b >=1950 && b <2000) return 9;
if (a>=2100 && a<=2200 && b >=1900 && b <2000) return 7;
if (a>=2100 && a<=2200 && b >=2000 && b <2100) return 11;
if (a>=2100 && a<2200 && b <=1900 && b >=1750) return 4;
if (a>=2100 && a<2200 && b <1750) return 3;
if (a>=2200 && b >=1950 && b <=2000) return 4;
if (a>=2200 && b <=1950 && b>=1800) return 2;
if (a>=2200 && b <=1850) return 1;
if(a>=1500 && a<1600 && b >=2200) return 31;
if(a>=1500 && a<1600 && b>=2000 && b <2100) return 28;
if(a>=1500 && a<1600 && b>=2100 && b<2200) return 29;
if(a>=1500 && a<1600 && b>=2100 && b>2200) return 31;
if (a>=1900 && a<2000 && b>=2000 && b<= 2075) return 18;
if (a>=1900 && a<2000 && b>=2075 && b<= 2150) return 24;
if (a>=1900 && a<2000 && b>=2150 && b<= 2200) return 25;
if (a>=1900 && a<2000 && b>=2150 && b> 2200) return 27;
if (a>=1800 && a<1900 && b>=2000 && b<= 2075) return 22;
if (a>=1800 && a<1900 && b>=2075 && b<= 2150) return 27;
if (a>=1800 && a<1900 && b>=2150 && b<= 2200) return 29;
if (a>=1800 && a<1900 && b>=2150 && b> 2200) return 30;
if (a>=1600 && a<1800 && b>=2000 && b<= 2075) return 22;
if (a>=1600 && a<1800 && b>=2075 && b<= 2150) return 28;
if (a>=1600 && a<1800 && b>=2150 && b<= 2200) return 29;
if (a>=1600 && a<1800 && b>=2150 && b> 2200) return 30;
if(a<1500 & b>=2000) return 31;
}else{
// same just b instead of a and a instead of b
}
}
New developer for wow server ;) Best part is the cast to floats at start imo
+160
<?php
class security extends engine{
var $temp=array();
function getUserId(){
$hash=explode('::',$_COOKIE['site_hash']);
$id=$hash[0];
return $id;
}
function getUserSecurityAccess($id){
if(is_numeric($id)){
$id=rawurlencode($id);
$conn_id=mysql_connect('host','user','passwd');
mysql_select_db('database');
$q=mysql_query("SELECT groupid FROM `users`
WHERE id='".$id."'",$conn_id);
if($q){
if(mysql_numrows($q)!=0){
$result=@mysql_fetch_assoc($q);
return $result['group_id'];
}else{
return -1;
}
}else{
return -1;
}
mysql_close($conn_id);
}else{
return -1;
}
}
function checkUserPermission($module,$act){
#return true;
$this->temp=array();
$this->temp['_result']=0;
$this->temp['_uid']=explode('::',$_COOKIE['site_hash']);
$this->temp['_uid']=$this->temp['_uid'][0];
$this->temp['_gid']=$this->getUserSecurityAccess($this->temp['_uid']);
$this->temp['_conn_id']=mysql_connect('host','user','passwd');
mysql_select_db('database');
$this->temp['_q1']=mysql_query('SELECT perms'
.'FROM `secure_groups`'
.'WHERE id='.$this->temp['_gid']);
$this->temp['_access_stamp']=mysql_fetch_assoc($this->temp['_q1']);
$this->temp['_access_stamp']=$this->temp['_access_stamp']['perms'];
$this->temp['_access_stamp']=explode(';',$this->temp['_access_stamp']);
$this->temp['_access_stamp']=array_slice($this->temp['_access_stamp'],0,-1);
foreach($this->temp['_access_stamp'] as $this->temp['v']){
$this->temp['_mod_access']=explode(':',$this->temp['v']);
$this->temp['_mod_indefier']=$this->temp['_mod_access'][0];
if($this->temp['_mod_indefier']==$module){
$this->temp['_perms']=explode(',',$this->temp['_mod_access'][1]);
switch($act){
case 'r':
$this->temp['_result']=($this->temp['_perms'][0]==1)? 1:0;
break;
case 'w':
$this->temp['_result']=($this->temp['_perms'][1]==1)? 1:0;
break;
}
break;
}
}
mysql_close($conn_id);
return $this->temp['_result'];
}
}
?>
Понравилось окончание статьи
"Надеюсь, что мы скоро встретимся...
Кто хочет почитать остальные мои статьи - прошу на http://e-code.tnt43.com.
С уважением Карпенко Кирилл, глава IT-отдела ИНПП. "
+122
<?php require_once "db_config.php";
class db extends db_config {
private $connection;
function __construct(){
$this->open_connection();
// echo "Соединение установлено ";
}
private function open_connection(){
$this->connection=mysql_connect($this->DB_HOST,$this->DB_USER,$this->DB_PASS);
if (!$this-connection){
die("Соедитение с базой данных не установлено: ".mysql_error());
} else {
$db_select=mysql_select_db($this->DB_NAME);
if (!$db_select){
die("База данных не определена: ".mysql_error());
}
}
mysql_query("set names utf8")or die("set name utf8 failed");
mysql_query("set lc_time_names=ru_RU");
}
public function sql($query){
$result=mysql_query($query,$this->connection);
if (!result){
die("Запрос не выполнен: ".mysql_error());
}
return $result;
}
}
$db = new db();?>
Типа сингелтон
+154
function(&(*(--Iter)++);
Вот как надо использовать итератор...
+159
<?
if(($socle == 1302 || $socle == 2723 || $socle == 2723 || $socle == 211) && ($power == 1816 || $power = 1296 || $power = 2741 || $power = 2741 || $power = 216 || $power = 1854))//G9 40W
{echo '<br/><a href="/catalog/?id=1§ion=2163&dep=12">Купить лампочку: цоколь G9, мощность 40W</a>';}
else if(($socle == 1324 || $socle == 2964 || $socle == 212) && ($power == 1826 || $power == 2942 || $power == 1325 || $power == 1861 || $power == 217 || $power == 1734))//GU10 50W
{echo '<br/><a href="/catalog/?id=2§ion=2163&dep=12">Купить лампочку: цоколь GU10, мощность 50W</a>';}
else if(($socle == 2855 || $socle == 1294 || $socle == 2733 || $socle == 1883 || $socle == 1721) && ($power == 1816 || $power = 1296 || $power = 2741 || $power = 2741 || $power = 216 || $power = 1854))//E14 40W
{
echo '<br/><a href="/catalog/?id=3§ion=2163&dep=12">Купить лампочку: цоколь E14, мощность 40W</a><br/>';
echo '<br/><a href="/catalog/?id=4§ion=4212&dep=12">Купить энергосберегающую лампочку: цоколь E14, мощность 7W</a>';
}
else if(($socle == 2748 || $socle == 1305 || $socle == 3051 || $socle == 203 || $socle == 1724) && ($power == 1816 || $power = 1296 || $power = 2741 || $power = 2741 || $power = 216 || $power = 1854))//E27 40W
{
echo '<br/><a href="/catalog/?id=5§ion=2162&dep=12">Купить лампочку: цоколь E27, мощность 40W</a><br/>';
echo '<br/><a href="/catalog/?id=6§ion=4212&dep=12">Купить энергосберегающую лампочку: цоколь E27, мощность 11W</a>';
}
else if(($socle == 2748 || $socle == 1305 || $socle == 3051 || $socle == 203 || $socle == 1724) && ($power == 1919 || $power = 1817 || $power = 5163 || $power = 1306 || $power = 2727 || $power = 205 || $power = 3052 || $power = 1850))//E27 60W
{
echo '<br/><a href="/catalog/?id=7§ion=2162&dep=12">Купить лампочку: цоколь E27, мощность 60W</a><br/>';
echo '<br/><a href="/catalog/?id=8§ion=4212&dep=12">Купить энергосберегающую лампочку: цоколь E27, мощность 11W</a>';
}
else if(($socle == 2748 || $socle == 1305 || $socle == 3051 || $socle == 203 || $socle == 1724) && ($power == 1919 || $power = 1817 || $power = 5163 || $power = 1306 || $power = 2727 || $power = 205 || $power = 3052 || $power = 1850))//E27 60W
{
echo '<br/><a href="/catalog/?id=9§ion=2162&dep=12">Купить лампочку: цоколь E27, мощность 60W</a><br/>';
echo '<br/><a href="/catalog/?id=10§ion=4212&dep=12">Купить энергосберегающую лампочку: цоколь E27, мощность 11W</a>';
}
?>
Говнокодеры не спят, они какают и какают :))))
Учитесь, как надо давать покупателю возможность выбрать подходящую лампочку)