- 1
- 2
- 3
- 4
- 5
@hands_by_value.each do |hand|
if @hands_by_value.slice(@hands_by_value.index(hand)+1..@hands_by_value.index(@hands_by_value.last)).include?(hand)
@hands_by_value.delete_at(@hands_by_value.index(hand))
end
end
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−104
@hands_by_value.each do |hand|
if @hands_by_value.slice(@hands_by_value.index(hand)+1..@hands_by_value.index(@hands_by_value.last)).include?(hand)
@hands_by_value.delete_at(@hands_by_value.index(hand))
end
end
Рукотворный array.uniq! похоже :)
+113
public string GetNormalImage(int newWidth, int newHeight, string sufix = "normal") {
String[] tmp = _originalImagePath.Split('.');
String newImagePath = "";
for (int i = 0; i < tmp.Length - 1; i++)
{
newImagePath += tmp[i];
newImagePath += "_";
}
newImagePath += sufix + ".";
newImagePath += tmp[tmp.Length - 1];
Image oldImage = Image.FromFile(_originalImagePath);
if (oldImage.Height >= oldImage.Width) {
Image newImage;
newImage = FixedSize(oldImage, newWidth, newHeight);
newImage.Save(newImagePath);
} else {
float heightRatio = (float)newHeight / (float)oldImage.Height;
float widthRatio = (float)newWidth / (float)oldImage.Width;
float bestRatio = 1;
if (heightRatio < widthRatio) {
bestRatio = heightRatio;
} else {
bestRatio = widthRatio;
}
var result = new System.Drawing.Bitmap((int)Math.Round(oldImage.Width * bestRatio), (int)Math.Round(oldImage.Height * bestRatio));
using (var graphics = Graphics.FromImage(result))
{
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.DrawImage(oldImage, new Rectangle(Point.Empty, new Size((int)Math.Round(oldImage.Width * bestRatio), (int)Math.Round(oldImage.Height * bestRatio))));
}
result.Save(newImagePath);
}
return newImagePath;
}
ресайз изображения
+145
<?php
/* {{{ index */
function creative_stat_default()
{
$dtime = urldecode(get_param('dtime', date('d.m.Y-d.m.Y')));
list($begin_t, $end_t) = convert_date_calendar($dtime);
$user = User::get_instance();
$DB = DbSimple::getDb();
$creatives_ids = $user->get_users_ids_by_roles(array('creative'));
// user names
$sql = "
SELECT user_id AS ARRAY_KEY, {$user->sql_case_names} as name
FROM users
WHERE user_id IN (?a)";
$user_names = $DB->select($sql, $creatives_ids);
// tasks all
$sql = "
SELECT to_user_id AS ARRAY_KEY, count(task_id) as tasks_all
FROM creative_tasks
WHERE to_user_id IN (?a) AND dtime BETWEEN ?d AND ?d
GROUP BY to_user_id
";
$tasks = $DB->select($sql, $creatives_ids, $begin_t, $end_t);
// tasks done
$sql = "
SELECT to_user_id AS ARRAY_KEY, count(task_id) as tasks_done
FROM creative_tasks
WHERE to_user_id IN (?a) AND dtime BETWEEN ?d AND ?d AND status_id = ?d
GROUP BY to_user_id
";
$tasks_done = $DB->select($sql, $creatives_ids, $begin_t, $end_t, GOODS_STATUS_ACTIVE);
// goods all
$sql = "
SELECT creatives_id AS ARRAY_KEY, count(good_id) as goods_all
FROM goods
WHERE creatives_id IN (?a) AND date_create BETWEEN ?d AND ?d
GROUP BY creatives_id
";
$goods_all = $DB->select($sql, $creatives_ids, $begin_t, $end_t);
// goods active
$sql = "
SELECT creatives_id AS ARRAY_KEY, count(good_id) as goods_active
FROM goods
WHERE creatives_id IN (?a) AND date_create BETWEEN ?d AND ?d AND status_id = ?d
GROUP BY creatives_id
";
$goods_active = $DB->select($sql, $creatives_ids, $begin_t, $end_t, GOODS_STATUS_ACTIVE);
foreach($creatives_ids as $id) {
$stat[$id] = array_merge(
$user_names[$id],
isset($tasks[$id]) ? $tasks[$id] : array('tasks_all' => 0),
isset($tasks_done[$id]) ? $tasks_done[$id] : array('tasks_done' => 0),
array(
'tasks_not_ready' => (isset($tasks[$id]['tasks_all']) ? $tasks[$id]['tasks_all'] : 0) -
(isset($tasks_done[$id]['tasks_done']) ? $tasks_done[$id]['tasks_done'] : 0)),
isset($goods_all[$id]) ? $goods_all[$id] : array('goods_all' => 0),
isset($goods_active[$id]) ? $goods_active[$id] : array('goods_active' => 0)
);
}
render_tpl('creative/stat/index', array(
'header' => 'Статистика креатива',
'dtime' => $dtime,
'stat' => $stat
), 'creative#stat');
}
/* }}} */
Собираю статистику. Каждый запрос возвращает массив с ключем = id пользователя, дальше это все клеится в один массив для отображения в табличке.
+161
function returnFalse() {
return false;
}
+163
$json = "";
$json .= "{\n";
$json .= "page: $page,\n";
$json .= "total: $total,\n";
$json .= "rows: [";
$rc = false;
while ($row = mysql_fetch_array($result)) {
if ($rc) $json .= ",";
$json .= "\n{";
$json .= "id:'".$row['id']."',";
$json .= "cltr: 'fo',";
$json .= "cell:['";
$json .= $row['secid'];
$json .="','".$row['blasttradedate'];
$json .="','".round($row['bid'],$row['decimals']);
$json .="','".round($row['offer'],$row['decimals']);
$json .="','".round($row['price'],$row['decimals']);
if(round($row['last'],$row['decimals'])) $json .="','".round($row['last'],$row['decimals']);
else $json .="', '";
// и еще много строк в том же духе
}
$json .= "]\n";
$json .= "}";
Сборка JSON по-джедайски
+147
/**
* GetResponse
* For common activation code length must be only 4 or 5 or 7 or 8 chars
*
* From XXX ... or 10
* From YYY ... or 11
*
* @return string
*/
эволюция
+151
<?
if(!defined('Hacking')) { die('Hacking attempt!'); exit;}
$database_user_name="demo";
$database_password="demo";
$database_name="demo";
$display_errors = false;
$AdminEmail="[email protected]";
$bpref="demo";
$domenname="demo";
function connect_db()
{
global $database_user_name, $database_password;
$db=mysql_connect("localhost",$database_user_name,$database_password) or die ("Could not connect");
mysql_query("SET NAMES cp1251") or die("Invalid query: " .mysql_error());
return $db;
}
function db_name()
{
global $database_name;
$db_name=$database_name;
return $db_name;
}
function get_now()
{
$db=connect_db();
$db_name=db_name();
mysql_select_db($db_name,$db);
$sql="select now() as now";
$result=mysql_query($sql,$db);
$myrow=mysql_fetch_array($result);
$now=$myrow["now"];
return $now;
}
function puterror($message)
{
echo("<p>$message</p>");
exit();
}
foreach($_GET as $chexss) {
if((eregi("<[^>]*script[^>]*>", $chexss)) || (eregi("<[^>]*object[^>]*>", $chexss)) ||
(eregi("<[^>]*iframe[^>]*>", $chexss)) || (eregi("<[^>]*applet[^>]*>", $chexss)) ||
(eregi("<[^>]*meta[^>]*>", $chexss)) || (eregi("<[^>]*style[^>]*>", $chexss)) ||
(eregi("<[^>]*form[^>]*>", $chexss)) || (eregi("\([^>][^)]*\)", $chexss)) ||
(eregi("<[^>]*frameset[^>]*>", $chexss)) || (eregi("<[^>]*onmouseover[^>]*>", $chexss)) ||
(eregi("<[^>]*img[^>]*>", $chexss)) || (eregi("\"", $chexss)) || (eregi("'", $chexss))){
die("Попытка ХАКА !");
}
}
$zzzz = html_entity_decode(urldecode($_SERVER['QUERY_STRING']));
if ($zzzz) {
if ((strpos($zzzz, '<') !== false) ||
(strpos($zzzz, '>') !== false) ||
(strpos($zzzz, '"') !== false) ||
(strpos($zzzz, './') !== false) ||
(strpos($zzzz, '../') !== false) ||
(strpos($zzzz, '\'') !== false) ||
(strpos($zzzz, '.pl') !== false) ||
(strpos($zzzz, '.php') !== false))
{
die("Попытка ХАКА !");
}
}
$zamena_b = array( "\x27", "\x22", "\x60", "\t",'\n','\r', '\\', "'","¬","#",";","~","[","]","{","}","=","-","+",")","(","*","&","^","%","$","<",">","?","!",".pl", ".php",'"' );
$_GET = str_replace($zamena_b, '', $_GET);
$_POST = str_replace($zamena_b, '', $_POST);
$_SESSION = str_replace($zamena_b, '', $_SESSION);
$_COOKIE = str_replace($zamena_b, '', $_COOKIE);
$_ENV = str_replace($zamena_b, '', $_ENV);
$_FILES = str_replace($zamena_b, '', $_FILES);
$_REQUEST = str_replace($zamena_b, '', $_REQUEST);
$_SERVER = str_replace($zamena_b, '', $_SERVER);
?>
Просторы интернета богаты... Так вот люди работают с СУБД
+152
$search_string = str_replace('"', '', $search_string);
$search_string = str_replace('+', '%20', $search_string);
//$search_string = preg_replace( '#([[:punct:]])#e', '( isset($punct[\'\1\']) ? $punct[\'\1\'] : \'\')', $search_string );
$search_string = trim($search_string);
$search_string = addslashes(stripslashes(htmlspecialchars(strip_tags(rawurldecode($search_string)))));
Борямся с XSS
+163
#include <stdio.h>
const int (&getArray())[10] {
static int tmp[10] = {1,2,3,4,5,6,7,8,9,10};
return tmp;
}
void foo(const int (&refArr)[10])
{
size_t size = sizeof(refArr); // returns 10*sizeof(int)
printf ("Array size: %d\r\n", size);
}
int main() {
foo(getArray());
printf ("%d", getArray()[0]);
for (size_t i=1; i<sizeof(getArray())/sizeof(getArray()[0]); ++i)
printf (",%d", getArray()[i]);
return 0;
}
http://codepad.org/rPl6b7IS
c++ страшный язык :)
Извращения на тему: http://heifner.blogspot.com/2005/06/c-reference-to-array.html
+146
count:while(1);
goto count;