- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
void input (char inpt [64])
{
for (;;)
{
int i(0);
cin >> inpt;
i ++;
if (inpt[i] == '\n')
inpt[i] = '\0';break;
}
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+55
void input (char inpt [64])
{
for (;;)
{
int i(0);
cin >> inpt;
i ++;
if (inpt[i] == '\n')
inpt[i] = '\0';break;
}
}
+156
<?php
class view {
protected $dir; //templates directory
protected $lang; //language
protected $authorized;
protected $user;
protected function getCache($template) {
//return false; //uncomment for developing
if (!isset($_SESSION['cache_' . $template])) return false;
return $_SESSION['cache_' . $template];
}
protected function addCache($template, $content) {
$_SESSION['cache_' . $template] = $content;
}
public function __construct($dir, localization $lang, user $user) {
$this->dir = $dir;
$this->authorized = (bool) $user->authorized;
$this->user = $user;
$this->lang = $lang;
}
public function invoke($template, $params = [], $return = false, $quests = []) { //can be called w/o params
$filename = ROOT . '/' . $this->dir . '/tpl/' . $template . '.tpl';
$lang = $this->lang->getData();
$content = $this->getCache($template);
if (!$content) {
$f = fopen($filename, 'a+');
$content = fread($f, (filesize($filename) > 0 ? filesize($filename) : 1));
$this->addCache($template, $content);
}
foreach ($params as $key => $value) {
$content = str_ireplace('{{' . $key . '}}', $value, $content);
}
preg_match_all("@{{:([a-z0-9_]+?)}}@sui", $content, $localization);
$localization = $localization[1];
foreach ($localization as $value) {
$content = str_ireplace('{{:' . $value . '}}', $lang[$value], $content);
} //applying lang
foreach ($quests as $key => $value) {
preg_match_all("@{\?$key=$value\?}(((?!{\?.+\?}).)*?){\?\?}@sui", $content, $matches);
while (!empty($matches[0])) {
$content = str_replace($matches[0][0], $matches[1][0], $content);
preg_match_all("@{\?$key=$value\?}(((?!{\?.+\?}).)*?){\?\?}@sui", $content, $matches);
}
preg_match_all("@{\?$key=((?!$value).+?)\?}(((?!{\?.+\?}).)*?){\?\?}@sui", $content, $matches);
while (!empty($matches[0])) {
$content = str_replace($matches[0][0], "", $content);
preg_match_all("@{\?$key=((?!$value).+?)\?}(((?!{\?.+\?}).)*?){\?\?}@sui", $content, $matches);
}
}
preg_match_all("@{\?access=([a-z0-9]+?)\?}(((?!{\?.+\?}).)*?){\?\?}@sui", $content, $perms);
while (!empty($perms[0])) {
foreach ($perms[1] as $value) {
if ($this->user->canAccess($value))
$content = preg_replace("@{\?access=$value\?}(((?!{\?.+\?}).)*?){\?\?}@sui", "$1", $content);
else $content = preg_replace("@{\?access=$value\?}(((?!{\?.+\?}).)*?){\?\?}@sui", "", $content);
}
preg_match_all("@{\?access=([a-z0-9]+?)\?}(((?!{\?.+\?}).)*?){\?\?}@sui", $content, $perms);
}
$content = preg_replace("@{\?authorized=((?!" . (int) $this->authorized . ").+?)\?}(.+?){\?\?}@sui", "", $content);
$content = preg_replace("@{\?authorized=" . (int) $this->authorized . "\?}(.+?){\?\?}@sui", "$1", $content);
$content = preg_replace("@{\?(.+?)\?}(.+?){\?\?}@sui", "", $content);
$content = str_ireplace('{{DIR}}', '/' . $this->dir, $content); //replacing DIR param
$content = str_ireplace('{{URI}}', urlencode(other::filter($_SERVER['REQUEST_URI'])), $content); //replacing URI param
$content = str_ireplace('{{HTTP_HOST}}', $_SERVER['HTTP_HOST'], $content); //replacing HTTP_HOST param
$content = preg_replace("@{\?((.+?)|(.+?){0})\?}@sui", "", $content);
if (!$return) echo $content;
return $content;
}
}
?>
Мой шаблонизатор. Детям и беременным женщинам не смотреть.
+156
<?php
class ACL
{
var $perms = array(); // Массив : Содержит привилегия текущего пользователя
var $userID = 0; // Целое число : Содержит ID текущего пользователя
var $userRoles = array(); // Массив : Содержат роли текущего пользователя
function __constructor($userID = '')
{
if ($userID != '')
{
$this->userID = floatval($userID);
} else {
$this->userID = floatval($_SESSION['userID']);
}
$this->userRoles = $this->getUserRoles('ids');
$this->buildACL();
}
function ACL($userID='')
{
$this->__constructor($userID);
}
?>
Конструктор
__constructor() предназначен для того, чтобы инициализировать объект при создании экземпляра класса ACL. Он вызывается автоматически после вот этой записи: new ACL();
Не сразу понял, что логика тут есть, но какая-то кривая
+140
type func = function (x : real) : real;
const
eps = 0.0000003;
pi = 3.14159265358979;
function Integral (f : func; a, b : real) : real;
var center : real;
begin
center := (a + b) / 2;
if abs(b - a) < eps then
Integral := f(center) * (b - a)
else Integral := Integral(f, a, center) +
Integral(f, center, b);
end;
function myFunc(x : real) : real;
begin
myFunc := cos(x) / x;
end;
begin
writeln(Integral(myFunc, pi/2, pi));
readln;
end.
Толи я дурачек, толи автор кода - школьник....
+71
protected boolean valid_move(int from, int to, int aBoard[], int colorfor) {
if(plainType(colorfor) == userColor) {
return (to>=0 && to<=35 && from >=0 && from<=35 && plainType(aBoard[from])==colorfor && aBoard[to]==emptyType
&& ((from-to == 4 || from-to==5)
|| ((from-to == 10 && plainType(aBoard[from-5])==oppositeType(colorfor))
|| (from-to == 8 && plainType(aBoard[from-4])==oppositeType(colorfor)))
|| (aBoard[from]==kingType(colorfor)
&& ((to-from == 4 || to-from==5)
|| ((to-from == 10 && plainType(aBoard[from+5])==oppositeType(colorfor))
|| (to-from == 8 && plainType(aBoard[from+4])==oppositeType(colorfor)))))));
}
else {
return (to>=0 && to<=35 && from >=0 && from<=35 && plainType(aBoard[from])==colorfor && aBoard[to]==emptyType
&& ((to-from == 4 || to-from==5)
|| ((to-from == 10 && plainType(aBoard[from+5])==oppositeType(colorfor))
|| (to-from == 8 && plainType(aBoard[from+4])==oppositeType(colorfor)))
|| (aBoard[from]==kingType(colorfor)
&& ((from-to == 4 || from-to==5)
|| ((from-to == 10 && plainType(aBoard[from-5])==oppositeType(colorfor))
|| (from-to == 8 && plainType(aBoard[from-4])==oppositeType(colorfor))))))); // =)))))
}
}
https://github.com/haiming020/BBS-AKB48/blob/master/src/Checkers.java
+139
struct Counter{
static int k;
Counter(){ k++; }
~Counter() { k--; }
};
int Counter::k = 0;
#define LOL(x) {string s = #x; Counter c##x; cout<<s.substr(0,1+s.find('['))<<Counter::k<<"]="<<x<<'\n'; }
+145
function myscandir($dir){
if(!file_exists($dir)){
return false;
}
$list = scandir($dir);
unset($list[0],$list[1]);
return array_values($list);
}
+155
function generateSession()
{
$chars = "qazxswedcvfrtgbnhyujmkiolp1234567890QAZXSWEDCVFRTGBNHYUJMKIOLP";
$max = rand(20, 32);
$size = StrLen($chars) - 1;
$sessionID = null;
while ($max--)
$sessionID .= $chars[rand(0, $size)];
return $sessionID;
}
+144
while (1) { // Не все знают логические значения
...
}
for (;;) // Ещё хуже
{ ... }
+135
void SoundService::stop(){
if (mOutputMixObj != NULL) {
(*mOutputMixObj)->Destroy(mOutputMixObj);
mOutputMixObj = NULL;
}
if(mEngineObj != NULL){
(*mEngineObj)->Destroy(mEngineObj);
mEngineObj = NULL; mEngine = NULL;
}
}
Случайно нашёл в книге по Android NDK, открытой на случайной странице.