- 1
Тем временем, в Яунде двадцать четыре градуса тепла.
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
Тем временем, в Яунде двадцать четыре градуса тепла.
+4
def do_creaprim(self, mesh, objname, addondir):
global message
objname = objname.replace(".", "")
objname = objname.replace(" ", "_")
bm = bmesh.new()
bm.from_mesh(mesh)
try:
txt = bpy.data.texts[str.lower("add_mesh_" + objname) + ".py"]
txt.clear()
except:
txt = bpy.data.texts.new("add_mesh_" + str.lower(objname) + ".py")
strlist = []
strlist.append("bl_info = {\n")
strlist.append("\"name\": \"" + objname + "\", \n")
strlist.append("\"author\": \"Gert De Roost\",\n")
strlist.append("\"version\": (1, 0, 0),\n")
strlist.append("\"blender\": (2, 65, 0),\n")
strlist.append("\"location\": \"Add > Mesh\",\n")
strlist.append("\"description\": \"Create " + objname + " primitive.\",\n")
strlist.append("\"warning\": \"\",\n")
strlist.append("\"wiki_url\": \"\",\n")
strlist.append("\"tracker_url\": \"\",\n")
strlist.append("\"category\": \"Add Mesh\"}\n")
strlist.append("\n")
strlist.append("\n")
strlist.append("if \"bpy\" in locals():\n")
strlist.append(" import imp\n")
strlist.append("\n")
strlist.append("\n")
strlist.append("import bpy\n")
strlist.append("import bmesh\n")
strlist.append("import math\n")
strlist.append("from mathutils import *\n")
strlist.append("\n")
strlist.append("\n")
strlist.append("\n")
strlist.append("\n")
strlist.append("class " + objname + "(bpy.types.Operator):\n")
strlist.append(" bl_idname = \"mesh." + str.lower(objname) + "\"\n")
strlist.append(" bl_label = \"" + objname + "\"\n")
strlist.append(" bl_options = {\'REGISTER\', \'UNDO\'}\n")
strlist.append(" bl_description = \"add " + objname + " primitive\"\n")
strlist.append("\n")
strlist.append(" def invoke(self, context, event):\n")
strlist.append("\n")
strlist.append(" mesh = bpy.data.meshes.new(name=\"" + objname + "\")\n")
strlist.append(" obj = bpy.data.objects.new(name=\"" + objname + "\", object_data=mesh)\n")
strlist.append(" scene = bpy.context.scene\n")
strlist.append(" scene.objects.link(obj)\n")
strlist.append(" obj.location = scene.cursor_location\n")
strlist.append(" bm = bmesh.new()\n")
strlist.append(" bm.from_mesh(mesh)\n")
strlist.append("\n")
strlist.append(" idxlist = []\n")
posn = 0
strlist.append(" vertlist = [")
for v in bm.verts:
if posn > 0:
strlist.append(", ")
posn += 1
strlist.append(str(v.co[:]))
strlist.append("]\n")
strlist.append(" for co in vertlist:\n")
strlist.append(" v = bm.verts.new(co)\n")
strlist.append(" bm.verts.index_update()\n")
strlist.append(" idxlist.append(v.index)\n")
posn = 0
strlist.append(" edgelist = [")
for e in bm.edges:
if posn > 0:
strlist.append(", ")
posn += 1
strlist.append("[" + str(e.verts[0].index) + ", " + str(e.verts[1].index) + "]")
strlist.append("]\n")
strlist.append(" for verts in edgelist:\n")
strlist.append(" try:\n")
strlist.append(" bm.edges.new((bm.verts[verts[0]], bm.verts[verts[1]]))\n")
strlist.append(" except:\n")
strlist.append(" pass\n")
posn1 = 0
strlist.append(" facelist = [(")
for f in bm.faces:
if posn1 > 0:
strlist.append(", (")
posn1 += 1
posn2 = 0
for v in f.verts:
if posn2 > 0:
strlist.append(", ")
strlist.append(str(v.index))
posn2 += 1
strlist.append(")")
strlist.append("]\n")
strlist.append(" bm.verts.ensure_lookup_table()\n")
strlist.append(" for verts in facelist:\n")
Залил вам отборного
0
create or replace function TO_NUMBER_EX (sNumber in varchar2) return number is
---------------------------------------------------------------------
-- Преобразование строки в число с разными символами разделителями
---------------------------------------------------------------------
iRet number(12,3) :=0;
cReplSgn char(1);
cToReplSgn char(1);
begin
begin
iRet := to_number(sNumber);
exception
when OTHERS then
iRet := null;
end;
if iRet is null then
begin
if instr(sNumber,'.') > 0 then
cReplSgn := '.';
cToReplSgn := ',';
else
cReplSgn := ',';
cToReplSgn := '.';
end if;
iRet := to_number(replace(sNumber,cReplSgn,cToReplSgn));
exception
when OTHERS then
iRet := null;
end;
end if;
return(nvl(iRet,0));
end TO_NUMBER_EX;
PL/SQL
велосипедно-костыльное программирование с неожиданными значениями по умолчанию
0
#include <iostream>
#include <string>
int main()
{
std::cout << "Купи слона!" << std::endl;
while(true)
{
std::string temp;
std::getline(std::cin, temp);
std::printf("Все говорят: \"%s\", а ты купи слона!\n", temp.c_str());
}
}
Когда не любишь 1c.
0
public bool isUnderpayment(double paymentValue)
{
if (paymentValue > 0)
return true;
return false;
}
Пятница, смеркалось.
−1
[color=green][s][u][b][size=20]ДАВАЙТЕ ФЛУДИТЬ И ТРОЛЛИТЬ[/size][/color][/b][/u][/s]
ДАВАЙТЕ ФЛУДИТЬ И ТРОЛЛИТЬ
−1
TServerThread = class(TThread)
private
procedure DoReadData;
protected
ThreadOwner: TIPCServer;
procedure Execute; override;
constructor Create(AThreadOwner: TIPCServer);
destructor Destroy; override;
public
end;
Мы кодили, кодили и наконец накодили!
0
<!DOCTYPE html>
<html>
<head>
<?php
$filename = 'mes.txt';
$count = "count.txt";
$count_file = fopen($count, "r");
$handle = fopen($filename, "rb");
date_default_timezone_set('Europe/Moscow');
$contents = file_get_contents($filename);
$contents2=nl2br($contents);
$password=htmlspecialchars($_POST["pass"]);
if($password=='dfhsdhf' || $password=='eeeeeer')
{
}
else
{
echo '403';
exit;
}
if( isset( $_POST['obn'] ) )
{
fclose($count_file);
$count_file = fopen($count, "w");
fwrite($count_file, '0');
echo "Обнулено";
$date = date("Y-m-d H:i:s");
$date_file = fopen("date.txt", "w");
fwrite($date_file, "$date");
}
?>
<title>Admin panel</title>
</head>
<body>
<h1>Начиная с <div id=date><?php echo file_get_contents("date.txt") ?></div> сайте было <div id=count><?php echo file_get_contents("count.txt") ?></div> людей</h1>
<p><?php if ($password == 'dfhsdhf')
echo "$contents2";
?>
</p>
<br>
<?php if ($password != 'dfhsdhf')
exit;
?>
<form method="POST">
<p>Введите код подтверждения</p>
<input type="password" name="pass">
<input type="submit" name="obn" value="Обнулить" />
</form>
</body>
</html>
Лучшая админка на php
+2
if hasattr(query, "items"):
query = query.items()
else:
# It's a bother at times that strings and string-like objects are
# sequences.
try:
# non-sequence items should not work with len()
# non-empty strings will fail this
if len(query) and not isinstance(query[0], tuple):
raise TypeError
# Zero-length sequences of all types will get here and succeed,
# but that's a minor nit. Since the original implementation
# allowed empty dicts that type of behavior probably should be
# preserved for consistency
except TypeError:
ty, va, tb = sys.exc_info()
raise TypeError("not a valid non-string sequence "
"or mapping object").with_traceback(tb)
https://github.com/python/cpython/blob/master/Lib/urllib/parse.py#L848
Зачем генерировать TypeError, а потом ее ловить и снова кидать?
0
void DrawLine(Vec2Si32 a, Vec2Si32 b, Rgba color_a, Rgba color_b) { // https://pastebin.com/p26FvZdd
Vec2Si32 ab = b - a;
Vec2Si32 abs_ab(std::abs(ab.x), std::abs(ab.y));
if (abs_ab.x >= abs_ab.y) {
if (a.x > b.x) {
DrawLine(b, a, color_b, color_a);
} else {
Sprite back = GetEngine()->GetBackbuffer();
Vec2Si32 back_size = back.Size();
if (ab.x == 0) {
if (a.x >= 0 && a.x < back_size.x &&
a.y >= 0 && a.y < back_size.y) {
back.RgbaData()[a.x + a.y * back.StridePixels()] = color_a;
}
return;
}
Si32 x1 = std::max(0, a.x);
Si32 x2 = std::min(back_size.x - 1, b.x);
Si32 y1 = a.y + ab.y * (x1 - a.x) / ab.x;
Si32 y2 = a.y + ab.y * (x2 - a.x) / ab.x;
if (y1 < 0) {
if (y2 < 0) {
return;
}
// lower left -> upper right
y1 = 0;
x1 = a.x + ab.x * (y1 - a.y) / ab.y;
x1 = std::max(0, x1);
} else if (y1 >= back_size.y) {
if (y2 >= back_size.y) {
return;
}
// upper left -> lower right
y1 = back_size.y - 1;
x1 = a.x + ab.x * (y1 - a.y) / ab.y;
x1 = std::max(0, x1);
}
if (y2 < 0) {
// upper left -> lower right
y2 = 0;
x2 = a.x + ab.x * (y2 - a.y) / ab.y;
x2 = std::min(back_size.x - 1, x2);
} else if (y2 >= back_size.y) {
// lower left -> upper right
y2 = back_size.y - 1;
x2 = a.x + ab.x * (y2 - a.y) / ab.y;
x2 = std::min(back_size.x - 1, x2);
}
Vec4Si32 rgba_a(static_cast<Si32>(color_a.r),static_cast<Si32>(color_a.g),static_cast<Si32>(color_a.b),static_cast<Si32>(color_a.a));
Vec4Si32 rgba_b(static_cast<Si32>(color_b.r),static_cast<Si32>(color_b.g),static_cast<Si32>(color_b.b),static_cast<Si32>(color_b.a));
Vec4Si32 rgba_ab = rgba_b - rgba_a;
Vec4Si32 rgba_1 = rgba_a + rgba_ab * (x1 - a.x) / ab.x;
Vec4Si32 rgba_2 = rgba_a + rgba_ab * (x2 - a.x) / ab.x;
Vec4Si32 rgba_12 = rgba_2 - rgba_1;
if (x2 <= x1) {
if (x2 == x1) {
Rgba color(rgba_1.x, rgba_1.y, rgba_1.z, rgba_1.w);
back.RgbaData()[x1 + y1 * back.StridePixels()] = color;
}
return;
}
Vec4Si32 rgba_16 = rgba_1 * 65536;
Vec4Si32 rgba_12_16 = rgba_12 * 65536;
Vec4Si32 rgba_12_16_step = rgba_12_16 / (x2 - x1);
Si32 y_16 = y1 * 65536;
Si32 y12_16_step = ((y2 - y1) * 65536) / (x2 - x1);
Si32 stride = back.StridePixels();
for (Si32 x = x1; x <= x2; ++x) {
Rgba color(rgba_16.x >> 16,rgba_16.y >> 16,rgba_16.z >> 16,rgba_16.w >> 16);
back.RgbaData()[x + (y_16 >> 16) * stride] = color;
rgba_16 += rgba_12_16_step;
y_16 += y12_16_step;
}
}
} else { // тут почти тоже самое
if (a.y > b.y) {
DrawLine(b, a, color_b, color_a);
} else {
Sprite back = GetEngine()->GetBackbuffer();
Vec2Si32 back_size = back.Size();
if (ab.y == 0) {
if (a.y >= 0 && a.y < back_size.y && a.x >= 0 && a.x < back_size.x) {
back.RgbaData()[a.x + a.y * back.StridePixels()] = color_a;
}
return;
}
Si32 y1 = std::max(0, a.y);
Si32 y2 = std::min(back_size.y - 1, b.y);
Si32 x1 = a.x + ab.x * (y1 - a.y) / ab.y;
Si32 x2 = a.x + ab.x * (y2 - a.y) / ab.y;
if (x1 < 0) {
if (x2 < 0) {
return;
}
// lower left -> upper right
x1 = 0;
y1 = a.y + ab.y * (x1 - a.x) / ab.x;
y1 = std::max(0, y1);
} else if (x1 >= back_size.x) {
if (x2 >= back_size.x) {
Взято отсюда https://github.com/FrostyMorning/arctic/blob/master/engine/easy.cpp
https://pastebin.com/p26FvZdd