- 1
ok = r.nextInt(prob) <= prob
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+134
ok = r.nextInt(prob) <= prob
рассчитываем вероятность события...
+147
\\Editing source code? CHEATER! CHEATER!
$ps =100
$time = $ps + $time
echo $time
\\The end.
Я один нашёл ошибку?
+130
Java programming class.
A boy and a girl were sitting in a Java programming class together. He reached over and grabbed her breast. She said: "Hey, that's private". He looked confused and said: "I thought we were in the same class"
Оффтоп, ржака, ебмп.
+160
$result = (string)(int)false;
+118
f g l = hylo l (.) (\n -> (g, n-1)) (==0)
Этот пример использует hylomorphism.
Композируем функцию типа (.) g(l) пока не наступит n==0
−91
def dubliSert(): #Проверка дублей Сертификата
dsn = cx_Oracle.makedsn(ip, 1521, '###' )
db = cx_Oracle.connect(LOGIN, PASSWORD, dsn)
f1 = open("text1.txt")
x = f1.readline()
x1 = f1.readline()
x2 = f1.readline()
x3 = f1.readline()
x4 = f1.readline()
x5 = f1.readline()
x6 = f1.readline()
x7 = f1.readline()
x8 = f1.readline()
x9 = f1.readline()
x10 = f1.readline()
x11 = f1.readline()
x12 = f1.readline()
x13 = f1.readline()
x14 = f1.readline()
x15 = f1.readline()
x16 = f1.readline()
x17 = f1.readline()
x18 = f1.readline()
x19 = f1.readline()
x20 = f1.readline()
#x20 = x20.decode("utf-8")
x20 = x20[:-1]
x20 = x20.replace(' ','')
x20 = int(x20, 16)
#print x20
f1.close()
cu = my_cursor=db.cursor()
cu.execute((u"select * from {} where dscertificate_serial like '{}'").format(TABLE, x20))
No comments
+154
var setLeadingZero = function(val) {
if (val.toString().length == 1)
return '0' + val;
else
return val;
}
"Но работает же"
+131
xlApp = new Excel.Application();
try
{
xlApp.Workbooks.Add(Type.Missing);
xlApp.Interactive = false;
xlApp.EnableEvents = false;
xlSheet = (Excel.Worksheet)xlApp.Sheets[1];
xlSheet.Name = "Данные";
DataTable dt = GetData();
int collInd = 0;
int rowInd = 0;
string data = "";
for (int i = 0; i < dt.Columns.Count; i++)
{
data = dt.Columns[i].ColumnName.ToString();
xlSheet.Cells[1, i + 1] = data;
xlSheetRange = xlSheet.get_Range("A1:Z1", Type.Missing);
xlSheetRange.WrapText = true;
xlSheetRange.Font.Bold = true;
}
for (rowInd = 0; rowInd < dt.Rows.Count; rowInd++)
{
for (collInd = 0; collInd < dt.Columns.Count; collInd++)
{
data = dt.Rows[rowInd].ItemArray[collInd].ToString();
xlSheet.Cells[rowInd + 2, collInd + 1] = data;
}
}
xlSheetRange = xlSheet.UsedRange;
xlSheetRange.Columns.AutoFit();
xlSheetRange.Rows.AutoFit();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
xlApp.Visible = true;
xlApp.Interactive = true;
xlApp.ScreenUpdating = true;
xlApp.UserControl = true;
releaseObject(xlSheetRange);
releaseObject(xlSheet);
releaseObject(xlApp);
}
+65
Graphics2D g = ...;
String str = "Some string";
FontRenderContext frc = g.getFontRenderContext();
double height = g.getFont().createGlyphVector(frc, str).getPixelBounds(null, 0, 0).getHeight();
Мне нужно было узнать точную высоту строки, которую я рисую на объекте Image. Спасибо stackoverflow за то, что он есть, по-моему, до этого способа просто невозможно догадаться, даже копая документацию, за несколько часов...
+152
$manufacturer_id = JRequest::getInt('manufacturer_id');
$label_id = JRequest::getInt('label_id');
$vendor_id = JRequest::getInt('vendor_id');
$view_name = "cart";
$view_config = array("template_path"=>JPATH_COMPONENT."/templates/".$jshopConfig->template."/".$view_name);
$view = $this->getView($view_name, getDocumentType(), '', $view_config);
if ($category->category_template=="") $category->category_template="default";
$view->setLayout("category_".$category->category_template);
$jshopConfig->count_products_to_page = $category->products_page;
$context = "jshoping.list.front.product";
$contextfilter = "jshoping.list.front.product.cat.".$category_id;
$orderby = $mainframe->getUserStateFromRequest( $context.'orderby', 'orderby', $jshopConfig->product_sorting_direction, 'int');
$order = $mainframe->getUserStateFromRequest( $context.'order', 'order', $jshopConfig->product_sorting, 'int');
$limit = $mainframe->getUserStateFromRequest( $context.'limit', 'limit', $category->products_page, 'int');
if (!$limit) $limit = $category->products_page;
$limitstart = JRequest::getInt('limitstart');
$orderbyq = getQuerySortDirection($order, $orderby);
$image_sort_dir = getImgSortDirection($order, $orderby);
$field_order = $jshopConfig->sorting_products_field_select[$order];
$filters = getBuildFilterListProduct($contextfilter, array("categorys"));
$orderfield = $jshopConfig->category_sorting==1 ? "ordering" : "name";
$sub_categories = $category->getChildCategories($orderfield, 'asc', $publish = 1);
$dispatcher->trigger( 'onBeforeDisplayCategory', array(&$category, &$sub_categories) );
if ($category->meta_title=="") $category->meta_title = $category->name;
setMetaData($category->meta_title, $category->meta_keyword, $category->meta_description);
$total = $category->getCountProducts($filters);
$action = xhtmlUrl($_SERVER['REQUEST_URI']);
$dispatcher->trigger('onBeforeFixLimitstartDisplayProductList', array(&$limitstart, &$total, 'category'));
if ($limitstart>=$total) $limitstart = 0;
$products = $category->getProducts($filters, $field_order, $orderbyq, $limitstart, $limit);
addLinkToProducts($products, $category_id);
jimport('joomla.html.pagination');
$pagination = new JPagination($total, $limitstart, $limit);
$pagenav = $pagination->getPagesLinks();
foreach($jshopConfig->sorting_products_name_select as $key=>$value){
$sorts[] = JHTML::_('select.option', $key, $value, 'sort_id', 'sort_value' );
}
insertValueInArray($category->products_page, $jshopConfig->count_product_select); //insert category count
foreach ($jshopConfig->count_product_select as $key => $value){
$product_count[] = JHTML::_('select.option',$key, $value, 'count_id', 'count_value' );
}
$sorting_sel = JHTML::_('select.genericlist', $sorts, 'order', 'class = "inputbox" size = "1" onchange = "submitListProductFilters()"','sort_id', 'sort_value', $order );
$product_count_sel = JHTML::_('select.genericlist', $product_count, 'limit', 'class = "inputbox" size = "1" onchange = "submitListProductFilters()"','count_id', 'count_value', $limit );
$_review = JTable::getInstance('review', 'jshop');
$allow_review = $_review->getAllowReview();
if (!$category->category_ordertype) $category->category_ordertype = 1;
$manufacuturers_sel = '';
if ($jshopConfig->show_product_list_filters){
$filter_manufactures = $category->getManufacturers();
$first_manufacturer = array();
$first_manufacturer[] = JHTML::_('select.option', 0, _JSHOP_ALL, 'id', 'name');
if (isset($filters['manufacturers'][0])){
$active_manufacturer = $filters['manufacturers'][0];
}else{
$active_manufacturer = 0;
}
$manufacuturers_sel = JHTML::_('select.genericlist', array_merge($first_manufacturer, $filter_manufactures), 'manufacturers[]', 'class = "inputbox" onchange = "submitListProductFilters()"','id', 'name', $active_manufacturer);
}
$display_list_products = (count($products)>0 || willBeUseFilter($filters));
$dispatcher->trigger('onBeforeDisplayProductList', array(&$products));
$view->assign('config', $jshopConfig);
$view->assign('template_block_list_product', "cart/list_products.php");
$view->assign('template_block_form_filter', "cart/form_filters.php");
$view->assign('template_block_pagination', "cart/block_pagination.php");
$view->assign('path_image_sorting_dir', $jshopConfig->live_path.'images/'.$image_sort_dir);
$view->assign('filter_show_category', 0);
$view->assign('display_pagination', $pagenav!="");
$view->assign('rows', $products);
$view->assign('count_product_to_row', $category->products_row);
$view->assign('filters', $filters);
$view->assign('display_list_products', $display_list_products);
$view->assign('shippinginfo', SEFLink($jshopConfig->shippinginfourl,1));
$view->display();
Все это (пришлось еще отрезать строк 30) нужно таскать за собой для вывода списка товаров в нестандартном месте. При этом оно лежит в контроллере.
Полный код: http://pastebin.com/jTj83ZpE
(joomshopping)