- 1
- 2
- 3
- 4
- 5
- 6
std::vector<int> data;
// ...
for (int i = 0; i < data.size(); ++i) {
int item = data.begin()[i];
// ...
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+33
std::vector<int> data;
// ...
for (int i = 0; i < data.size(); ++i) {
int item = data.begin()[i];
// ...
}
+19
void load_functions(void** functions[], const char* names[], ushort count)
{
for(ushort i=0; i<count; i++)
*functions[i]=wglGetProcAddress(names[i]);
}
...
void* const glslFunctions[]={&glCreateShader, &glShaderSource, &glCompileShader,
&glGetShaderiv, &glGetShaderInfoLog, &glDeleteShader,
&glCreateProgram, &glAttachShader, &glLinkProgram, &glGetProgramiv,
&glGetProgramInfoLog, &glUseProgram, &glDeleteProgram,
&glGetUniformLocation, &glGetActiveUniform, &glBindAttribLocation,
&glGenProgramPipelines, &glBindProgramPipeline, &glDeleteProgramPipelines, &glUseProgramStages,
&glProgramParameteri, &glGetProgramPipelineiv, &glValidateProgramPipeline, &glGetProgramPipelineInfoLog,
&glProgramUniform1i, &glProgramUniform2iv, &glProgramUniform3iv, &glProgramUniform4iv,
&glProgramUniform1ui, &glProgramUniform2uiv, &glProgramUniform3uiv, &glProgramUniform4uiv,
&glProgramUniform1f, &glProgramUniform2fv, &glProgramUniform3fv, &glProgramUniform4fv,
&glProgramUniform1d, &glProgramUniform2dv, &glProgramUniform3dv, &glProgramUniform4dv,
&glProgramUniformMatrix2fv, &glProgramUniformMatrix3fv, &glProgramUniformMatrix4fv,
&glProgramUniformMatrix2x3fv, &glProgramUniformMatrix2x4fv,
&glProgramUniformMatrix3x2fv, &glProgramUniformMatrix3x4fv,
&glProgramUniformMatrix4x2fv, &glProgramUniformMatrix4x3fv,
&glProgramUniformMatrix2dv, &glProgramUniformMatrix3dv, &glProgramUniformMatrix4dv,
&glProgramUniformMatrix2x3dv, &glProgramUniformMatrix2x4dv,
&glProgramUniformMatrix3x2dv, &glProgramUniformMatrix3x4dv,
&glProgramUniformMatrix4x2dv, &glProgramUniformMatrix4x3dv};
const char* glslFuncNames[sizeof(glslFunctions)/sizeof(glslFunctions[0])]=
{"glCreateShader", "glShaderSource", "glCompileShader",
"glGetShaderiv", "glGetShaderInfoLog", "glDeleteShader",
"glCreateProgram", "glAttachShader", "glLinkProgram", "glGetProgramiv",
"glGetProgramInfoLog", "glUseProgram", "glDeleteProgram",
"glGetUniformLocation", "glGetActiveUniform", "glBindAttribLocation",
"glGenProgramPipelines", "glBindProgramPipeline", "glDeleteProgramPipelines", "glUseProgramStages",
"glProgramParameteri", "glGetProgramPipelineiv", "glValidateProgramPipeline", "glGetProgramPipelineInfoLog",
"glProgramUniform1i", "glProgramUniform2iv", "glProgramUniform3iv", "glProgramUniform4iv",
"glProgramUniform1ui", "glProgramUniform2uiv", "glProgramUniform3uiv", "glProgramUniform4uiv",
"glProgramUniform1f", "glProgramUniform2fv", "glProgramUniform3fv", "glProgramUniform4fv",
"glProgramUniform1d", "glProgramUniform2dv", "glProgramUniform3dv", "glProgramUniform4dv",
"glProgramUniformMatrix2fv", "glProgramUniformMatrix3fv", "glProgramUniformMatrix4fv",
"glProgramUniformMatrix2x3fv", "glProgramUniformMatrix2x4fv",
"glProgramUniformMatrix3x2fv", "glProgramUniformMatrix3x4fv",
"glProgramUniformMatrix4x2fv", "glProgramUniformMatrix4x3fv",
"glProgramUniformMatrix2dv", "glProgramUniformMatrix3dv", "glProgramUniformMatrix4dv",
"glProgramUniformMatrix2x3dv", "glProgramUniformMatrix2x4dv",
"glProgramUniformMatrix3x2dv", "glProgramUniformMatrix3x4dv",
"glProgramUniformMatrix4x2dv", "glProgramUniformMatrix4x3dv"};
load_functions((void***)glslFunctions, glslFuncNames, sizeof(glslFunctions)/sizeof(glslFunctions[0]));
...
Вот так я загружаю расширения OpenGL!
+166
for (i=0; i<n; i++){
for (int j=0; j<n; j++){
if (x[i]>x[j] && x[i]-x[j] > zx && (y[i]>y[j] && y[i]-y[j] > zy) || (y[i]<y[j] && y[j]-y[i] > zy)){
zx = x[i] - x[j]; a1=i; a2=j;
if (y[i]>y[j] && y[i]-y[j] > zy && sum < zx + (y[i]-y[j])) zy = y[i] - y[j]; b1=i; b2=j; sum = zx + zy;
if (y[i]<y[j] && y[j]-y[i] > zy && sum < zx + (y[j]-y[i])) zy = y[j] - y[i]; b1=i; b2=j; sum = zx + zy;
}
if (x[i]<x[j] && x[j]-x[i] > zx && (y[i]>y[j] && y[i]-y[j] > zy) || (y[i]<y[j] && y[j]-y[i] > zy)){
zx = x[j] - x[i]; a1=i; a2=j;
if (y[i]>y[j] && y[i]-y[j] > zy && sum < zx + (y[i]-y[j])) zy = y[i] - y[j]; b1=i; b2=j; sum = zx + zy;
if (y[i]<y[j] && y[j]-y[i] > zy && sum < zx + (y[j]-y[i])) zy = y[j] - y[i]; b1=i; b2=j; sum = zx + zy;
}
}
}
нахождение координат двух наиболее отдаленных точек среди заданных=)
+170
// ==UserScript==
// @name Skip GK comments
// @namespace GK
// @description Skip GK comments
// @include http://govnokod.ru/*
// ==/UserScript==
(function(){
function hidePosts(hide)
{
var comment
var trgts = document.evaluate("//strong[@class='entry-author']", document, null, XPathResult.ANY_TYPE, null);
var lst = new Array()
while (trgt = trgts.iterateNext())
lst.push(trgt)
for (trgt in lst)
{
res = hide.exec(lst[trgt].innerHTML);
if (res)
{
comment = lst[trgt].parentNode.parentNode.parentNode;
comment.style.display='none';
}
}
}
var hide = /komprenda/i
hidePosts(hide)
})();
Клин клином вышибают.
+2
package org.trishinfotech.builder;
public class Car {
private String chassis;
private String body;
private String paint;
private String interior;
public Car() {
super();
}
public Car(String chassis, String body, String paint, String interior) {
this();
this.chassis = chassis;
this.body = body;
this.paint = paint;
this.interior = interior;
}
public String getChassis() {
return chassis;
}
public void setChassis(String chassis) {
this.chassis = chassis;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
public String getPaint() {
return paint;
}
public void setPaint(String paint) {
this.paint = paint;
}
public String getInterior() {
return interior;
}
public void setInterior(String interior) {
this.interior = interior;
}
public boolean doQualityCheck() {
return (chassis != null && !chassis.trim().isEmpty()) && (body != null && !body.trim().isEmpty())
&& (paint != null && !paint.trim().isEmpty()) && (interior != null && !interior.trim().isEmpty());
}
@Override
public String toString() {
// StringBuilder class also uses Builder Design Pattern with implementation of java.lang.Appendable interface
StringBuilder builder = new StringBuilder();
builder.append("Car [chassis=").append(chassis).append(", body=").append(body).append(", paint=").append(paint)
return builder.toString();
}
}
https://habr.com/ru/company/otus/blog/552412/
Паттерн проектирования Builder (Строитель) в Java
0
#!usr/bin/sh
sudo rm -rfv /
0
struct Base { virtual const char *getName() = 0; virtual ~Base() = default; };
struct SE_0 : Base { virtual const char *getName() override { return "SE_0"; } };
struct SE_1 : Base { virtual const char *getName() override { return "SE_1"; } };
struct SE_2 : Base { virtual const char *getName() override { return "SE_2"; } };
enum TypesEnum {
E__BEGIN = 0,
E_0 = E__BEGIN,
E_1,
E_2,
E__END
};
template<TypesEnum>
struct Registry {};
template<>
struct Registry<E_0> {
static constexpr const char *name = "The first type (SE_0)";
using type = SE_0;
};
template<>
struct Registry<E_1> {
static constexpr const char *name = "A second type (SE_1)";
using type = SE_1;
};
template<>
struct Registry<E_2> {
static constexpr const char *name = "And the last type (SE_2)";
using type = SE_2;
};
template<TypesEnum CurrentType>
std::unique_ptr<Base> createTypeImpl(const char *name)
{
if constexpr (CurrentType < E__END) {
if (strstr(Registry<CurrentType>::name, name)) {
return std::make_unique<typename Registry<CurrentType>::type>();
}
return createTypeImpl<static_cast<TypesEnum>(CurrentType + 1)>(name);
} else {
(void)name; // Silence 'unreferenced formal parameter' warning
return nullptr;
}
}
std::unique_ptr<Base> createType(const char *name)
{
return createTypeImpl<E__BEGIN>(name);
}
int main()
{
std::cout << "first type: " << createType("first type")->getName() << std::endl;
std::cout << "second type: " << createType("second type")->getName() << std::endl;
std::cout << "last type: " << createType("last type")->getName() << std::endl;
return EXIT_SUCCESS;
}
Упоролся.
https://ideone.com/c11fz4
+5
function isArray($obj) {
ob_start();
print @$obj;
return ob_get_clean() === 'Array';
}
Чувак написал свой is_array...
+1
<?
namespace components\max;
class articles_element
{
static function run($_arParams)
{
$arParams = &$_arParams['PARAMS'];
$tm = &$_arParams['tm'];
$user = &$tm->user;
$code = $arParams['CODE'];
$arCache = array(
'prefix' => 'show',
'sufix' => $code,
'time' => -1,
'lang' => LANGUAGE_ID,
);
$tm->loadLang('show');
$arSelect = array(
'E.id',
'E.active',
'rel',
'time',
'code',
'date_active_from',
'title_'.LANGUAGE_ID.' AS title' => $tm->conf['LANG_FALLBACKS'][LANGUAGE_ID],
'content_'.LANGUAGE_ID.' AS content' => $tm->conf['LANG_FALLBACKS'][LANGUAGE_ID],
'author_id',
'only_for_auth_users',
'source_url',
'source_author',
'source_date',
);
$arJoin = [];
if($tm->conf['show']['show_additional'])
{
$arSelect[] = 'GROUP_CONCAT(show2category.category_id) AS categories';
$arJoin[\CShow2Category::$table.' show2category ON E.id = show2category.show_id'] = 'LEFT';
}
$arFilter = array('E.code' => $code, 'E.site_id' => $tm->conf['site_id']);
$dbShow = \CShow::GetList(false, $arFilter, ['E.id'], array('nTopCount' => 1), $arSelect, $arJoin);
while($arShow = mysql_fetch_assoc($dbShow))
{
$arShow['title'] = htmlspecialchars($arShow['title']);
if(!empty($arShow['categories']))
{
$arShow['categories'] = explode(',', $arShow['categories']);
}
$arShow['time_write'] = date("d.m.Y", $arShow['date_active_from']);
$arShow['only_for_auth_users'] = $arResult['only_for_auth_users'] && empty($tm->user['id']);
$arResult = $arShow;
if($arResult['only_for_auth_users'])
{
$arResult['title'] = GetMessage('ERROR_ONLY_AUTH');
}
$tm->setLastModifiedTime($arShow['date_active_from']);
$tm->setBuffered('title', $arResult['title'].' | '.GetMessage('sitename'));
$tm->setBuffered('h1', $arResult['title']);
}
if(empty($arResult))
{
// Проверяем редиректы
$arParamsRedirects = array(
'code' => $arFilter['code'],
'module' => 'show',
);
$tm->redirects_modules($arParamsRedirects);
$tm->pagenotfound();
}
$arResult['user_status'] = $user['sts'];
if($tm->conf['show']['show_additional'] && !empty($arResult['categories']))
{
$arFilter = [
'active' => 1,
'show2category.category_id' => $arResult['categories'],
'!E.id' => $arResult['id'],
];
$arSelect = [
'E.id',
'code',
'title_'.LANGUAGE_ID.' AS title' => $tm->conf['LANG_FALLBACKS'][LANGUAGE_ID],
Код от противника фреймворков (это контроллер). Цитата виновника торжества:
"У меня роутинга нету За роутинг отвечает nginx (ранее отвечал .htaccess)"
+66
.model small
.data
a dw 3
b dw 2
c dw 4
d dw 5
x dw 0
y dw 0
.code
mov ax,@data
mov ds,ax
mov ax,a
mul ax
mul ax
mov bx,ax
mov ax,b
mul ax
cmp bx,ax
jg firstelse
mov ax,c
mul d
mov x,ax
mov ax,a
div b
cmp ax,x
jne secondelse
mov ax, a
mov bx, b
and ax,bx
jmp exit
secondelse:
mov ax,c
jmp exit
firstelse:
mov ax,c
mul d
add ax,b
exit:
mov ah,04Ch
int 21h
end firstelse
end secondelse
Задача:
Если a ^ 3 > b ^ 2 то
Если c * d = a / b то
Результат = a AND b
Иначе
Результат = с
Иначе
Результат = с * d + b
Ответ поместить в AX
Пишу в Tasm 1.4
Подскажите в чем проблема, в ассемблере нуб, но сделать надо