- 1
- 2
- 3
- 4
void IRQHandler(void)
{
...
WaitSemaphore(semH);
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+160
void IRQHandler(void)
{
...
WaitSemaphore(semH);
Из кода для встроенного устройства реального времени.
+164
i = j ? k : l = m;
опять же с форума wasm.ru... пол дня объяснял почему с++ компилятор трактует это выражение как i = j ? k : (l = m), а никак по-другому... не пишите такую чушь никогда)
+161
<?php
//////////....................................
static function Request($module="__global",$action='__global',$route=null){
if(!$route && !empty(self::$route)) $route=self::$route;
else $route=self::setRoute(APP_ModuleContext::getContext());
$action=strtolower($action);
$module=strtolower($module);
$ro=array();
if(!empty($route['allow'][$module])){
$ro=$route['allow'][$module];
$dis=!empty($route['disallow'][$module])?$route['disallow'][$module]:array();
if(!empty($dis) && $dis['__global']===true) return new throw APP_Exceptions_PluginBox("Плагины для модуля '$module' отключены");
if(empty($ro['__global'])) $ro['__global']=array();
if(empty($ro[$action])) $ro[$action]=array();
$ro=array_merge($ro['__global'],$ro[$action]);
if(!empty($ro)){
$ro=array_unique($ro);
if(!empty($dis)){
if(empty($dis['__global'])) $dis['__global']=array();
if(empty($dis[$action])) $dis[$action]=array();
$dis=array_merge($dis['__global'],$dis[$action]);
if(!empty($dis)){
$dis=array_unique($dis);
$ro=array_diff($ro,$dis);
}
}
if(!empty($ro)){
$res=array();
foreach($ro as $plugin){
$res[$plugin]=self::getContents($plugin);
}
return $res;
}else return new throw APP_Exceptions_PluginBox("Все плагины были отключены для '$module - $action'");
}else return new throw APP_Exceptions_PluginBox("Нет плагинов для запроса '$module - $action'");
}
return false;
}
/////////////..........................................
?>
Роутеры роутят
−99
if (((vo.metricId == 3) && ((columnName == "A/c Balance CCY & Amount") || (columnName == "No. of Trades Impacted") ||
(columnName == "Value of Trades") || (columnName == "Facility CCY & Amount") || (columnName == "MTM/ Net Position") ||
(columnName == "Utilisation CCY & Amt"))) ||
((vo.metricId == 5) && (columnName == "Amount")) ||
((vo.metricId == 5) && (columnName == "Balance in Local")) ||
((vo.metricId == 5) && (columnName == "Balance in EUR")) ||
((vo.metricId == 5) && (columnName == "Sub Balance EUR")) ||
((vo.metricId == 5) && (columnName == "Unsub Balance EUR")) ||
((vo.metricId == 5) && (columnName == "PFE EUR")) ||
((vo.metricId == 5) && (columnName == "Provision EUR")) ||
((vo.metricId == 13) && ((columnName == "EUR Net Cost") || (columnName == "Nominal/ Position"))) ||
((vo.metricId == 14) && ((columnName == "CCY Value") || (columnName == "EUR Value"))) ||
((vo.metricId == 15) && ((columnName == "Value") || (columnName == "EUR Value"))) ||
((vo.metricId == 16) && ((columnName == "Value") || (columnName == "EUR Value"))) ||
((vo.metricId == 17) && ((columnName == "Value") || (columnName == "EUR Value"))) ||
((vo.metricId == 18) && ((columnName == "Value") || (columnName == "EUR Value"))) ||
((vo.metricId == 19) && ((columnName == "Value") || (columnName == "EUR Value"))) ||
((vo.metricId == 20) && ((columnName == "Value") || (columnName == "EUR Value"))) ||
((vo.metricId == 21) && ((columnName == "Value") || (columnName == "EUR Value"))) ||
((vo.metricId == 22) && ((columnName == "Value") || (columnName == "EUR Value")))
Королевский IF!
+146
class GridPanel extends JPanel {
protected Point myLocation;
@Override
public Point location() {
return this.myLocation;
}
}
убивал бы за такое.
+158
$arTime = localtime();
//формируем ядро номера заказа, которое будем подцеплять к разным префиксам
$orderNumberCore = str_pad($arTime[4]+1, 2, "0", STR_PAD_LEFT).str_pad($arTime[3], 2, "0", STR_PAD_LEFT).str_pad($arTime[2], 2, "0", STR_PAD_LEFT).str_pad($arTime[1], 2, "0", STR_PAD_LEFT).str_pad($arTime[0], 2, "0", STR_PAD_LEFT);
Формируется номер заказав интернет-магазине из даты/времени. Но при этом не учитывается год.
$orderNumberCore -- это дата в формате dmhis.
+146
protected void displayBoard() {
for (int i = 0; i < this.viewArea.getComponentCount(); i++) {
Component next = this.viewArea.getComponent(i);
next.paint(next.getGraphics());
}
try {
Thread.currentThread();
Thread.sleep(50);
} catch (Exception e) {
}
}
странный код. Особенно не понял строку 7
+166
// 0. original version:
struct Subscriber {
ServiceConfig *services;
};
struct ServiceConfig {
};
// reported problem: as per doc, Customer may have multiple service configurations, yet we can configure only one.
// 1. next "fixed" version, as delivered to the customer:
struct Subscriber {
};
struct ServiceConfig {
Subscriber *subs;
};
// ticket reopened: wtf. changing services for one customer, affects others!!
// 2. next "fixed" version, as delivered to the customer:
struct Subscriber {
ServiceConfig *services;
};
struct ServiceConfig {
};
// ticket reopened: @#$%^& [*BEEP*] @#$%^& [*BEEP*] @#$%^&*
// 3. finally:
struct Subscriber {
};
struct ServiceConfig {
};
struct SubscriberServiceConfig {
Subscriber *subs;
ServiceConfig *services;
};
если бы лично не лицезрел эту переписку (навечно задокументированую в аналах вершн контрол) между нашими разработчиками и консультантами работающими на инсталяции у кастомера, нивжисть бы не поверил что такое даже может иметь место.
самое страшное в этой истории, что консультанты разработчикам с самого начала сказали что в коде данные организованы неправильно по сравнению с тем как данные хранятся в базе.
+163
<?
class Thread {
<...>
function Thread($proc_id) {
$this->db=new ezSQL_mssql(s_login, s_password, s_db_name_threads, s_host);
$this->proc_id=$proc_id;
$this->timeout=500;
$this->last_busy=0;
$this->notactive_num=0;
$query="INSERT INTO threads(proc_id, last_beat) VALUES('".$this->proc_id."','".(time()+60)."');";
$this->db->query($query);
}
static function Create($url,$proc_id) {
$t = new Thread($proc_id);
//### execute thread
//NB!!!
//BE CAREFUL WITH LOG PATHS, IF YOU MISS OR MISSPEL THE PATH, IT IS HARDLY POSSIBLE TO DEBUG
//IF YOU MISSPELL THE PATH YOU CAN FACE THE PROBLEM OF THREADS SIMPLY DO NOT START OR DO NOT LOG WITHOUT ANY NOTIFICATION
//USE YOUR OWN PATHS FOR PHP, LOGS AND COMMAND LINE COMMANDS AD PARAMETERS FOR YOUR SPECIFIC OS, WINDOWS EXAMPLE IS BELOW
//start /B will execute background process in windows, > symbol will store the output of current process into log file
//you can call threads from another server via http request etc.
pclose(popen("start /B \"$proc_id\" C:\php\php.exe D:\wwwroot\\newimport\elko\import_ignitor_thread.php > D:\globalimport\logs\\".$proc_id.".txt $proc_id","r"));
//give some time to start the thread
Sleeper(1000);
return $t;
}
//check is Thread active or not
//check active, busy, last beat etc.
//you can put here your own business logic how thread should be checked for statused etc.
function isActive () {
if($this->state==3){
return false;
}elseif ($this->last_busy==1){
return true;
}
$cur_time=time();
if($cur_time>$this->last_beat){
$result=$this->db->get_var("SELECT last_beat FROM threads WHERE proc_id=".$this->proc_id);
$this->state=$this->db->get_var("SELECT state FROM threads WHERE proc_id=".$this->proc_id);
if($cur_time<$result){
return true;
}
}else{
return true;
}
return true;
}
//check is Thread is busy or not, in order to give a new task/job
//it is similat to the previous procedure
function isBusy() {
//$this->tell("ping"); - this could be implemented in the future
$cur_time=time();
if($cur_time>$this->last_beat or $this->last_busy==0){
$result=$this->db->get_var("SELECT busy FROM threads WHERE proc_id=".$this->proc_id);
$this->last_busy=$result;
if($result==1){
return true;
}else{
return false;
}
}else{
return false;
}
}
//tells a command to the thread
function tell($thought, $params = NULL) {
$param=base64_encode(serialize($params));
$query="INSERT INTO cmd(proc_id, cmd, param) VALUES('".$this->proc_id."','".$thought."','".$param."');";
$this->db->query($query);
}
}
'многопоточность'
+157
<?php
function Sleeper($mSec)
{
// For dummies like me who spent 5 minutes
// wondering why socket_create wasn't defined
if(!function_exists('socket_create')){
die("Please enable extension php_sockets.dll");
}
// So the socket is only created once
static $socket=false;
if($socket===false){
$socket=array(socket_create(AF_INET,SOCK_RAW,0));
}
$pSock=$socket;
// Calc time
$uSex = $mSec * 1000;
// Do the waiting
socket_select($read=NULL,$write=NULL,$pSock,0,$uSex);
// OCD
return true;
}
что бы гк делал без этого чудесного языка..