- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
struct Bar {};
class Foo {
public:
Bar& bar() const { return *bp; }
private:
Bar b;
Bar * const bp = &b;
};
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+2
struct Bar {};
class Foo {
public:
Bar& bar() const { return *bp; }
private:
Bar b;
Bar * const bp = &b;
};
https://wandbox.org/permlink/7JPzrvslrUwbvREb
Как называется данный говнопаттерн?
−1
function running(html, clear) {
var id, brk = true;
if(clear)
html.className = "";
if(html.className != "Ready") {
if(html.children.length > 0) {
if(!clear) {
for(id = 1; id < html.childNodes.length; ++ id) {
var active = findActive(html.childNodes[id]);
if(active == null) {
brk = true;
break;
}
brk = active.className != "Ready" ? false : brk;
}
}
if(!brk && html.childNodes[0].value && html.childNodes[0].max) {
if(clear)
html.childNodes[0].value = 1;
else
if(html.childNodes[0].value <= html.childNodes[0].max) {
++ html.childNodes[0].value;
if(brk) {
for(id = 1; id < html.childNodes.length; ++ id)
findActive(html.childNodes[id], true);
html.parentNode.className = "";
}
return null;
} else {
html.parentNode.className = "Ready";
html.className = "";
return html;
}
}
if(!clear)
html.className = html.className != "Active" ? "Active" : "Ready";
return null;
} else {
if(!clear)
html.className = html.className != "Active" ? "Active" : "Ready";
return html;
}
}
return html;
}
Должен бегать по вложенным элементам и анимировать их.
0
using (var stream = File.Open(inFile, FileMode.Open))
using (var reader = new StreamReader(stream))
using (var csvReader = new CsvReader(reader, new Configuration
{
HeaderValidated = HeaderValidated,
MissingFieldFound = null,
PrepareHeaderForMatch = header =>
CultureInfo.CurrentCulture.TextInfo.ToTitleCase(header)
}))
using (var outStream = File.Open(outFile, FileMode.CreateNew, FileAccess.Write, FileShare.Read))
using (var writer = new StreamWriter(outStream))
using (var csvWriter = new CsvWriter(writer))
−6
/* Q: Can someone recommend a more elegant way to achieve these compile-time constants? */
template <int> struct Map;
template <> struct Map<0> {static const int value = 4;};
template <> struct Map<1> {static const int value = 8;};
template <> struct Map<2> {static const int value = 15;};
template <int> struct MapInverse;
template <> struct MapInverse<4> {static const int value = 0;};
template <> struct MapInverse<8> {static const int value = 1;};
template <> struct MapInverse<15> {static const int value = 2;};
/* A: Another TMP approach for a linear search using C++11: */
#include <type_traits>
// === Types:
// Usage:
// Function<Map<x1,y1>,Map<x2,y2>,...>
template<int D, int R> struct Map { enum { domain=D, range=R }; };
template<typename ...A> struct Function {};
// === Metafunctions:
// Usage:
// ApplyFunction<x,F>::value
template<int I, typename M> struct ApplyFunction;
// Usage:
// ApplyFunctionInverse<x,F>::value
template<int I, typename M> struct ApplyFunctionInverse;
// ==== Example:
// Define function M to the mapping in your original post.
typedef Function<Map<0,4>,Map<1,8>,Map<2,15>> M;
// ==== Implementation details
template<typename T> struct Identity { typedef T type; };
template<int I, typename A, typename ...B> struct ApplyFunction<I, Function<A,B...> > {
typedef typename
std::conditional <I==A::domain
, Identity<A>
, ApplyFunction<I,Function<B...>> >::type meta;
typedef typename meta::type type;
enum { value = type::range };
};
template<int I, typename A> struct ApplyFunction<I, Function<A>> {
typedef typename
std::conditional <I==A::domain
, Identity<A>
, void>::type meta;
typedef typename meta::type type;
enum { value = type::range };
};
// Linear search by range
template<int I, typename A> struct ApplyFunctionInverse<I, Function<A>> {
typedef typename
std::conditional <I==A::range
, Identity<A>
, void>::type meta;
typedef typename meta::type type;
enum { value = type::domain };
};
template<int I, typename A, typename ...B> struct ApplyFunctionInverse<I, Function<A,B...> > {
typedef typename
std::conditional <I==A::range
, Identity<A>
, ApplyFunctionInverse<I,Function<B...>> >::type meta;
typedef typename meta::type type;
enum { value = type::domain };
};
// ==============================
// Demonstration
#include <iostream>
int main()
{
// Applying function M
std::cout << ApplyFunction<0,M>::value << std::endl;
std::cout << ApplyFunction<1,M>::value << std::endl;
std::cout << ApplyFunction<2,M>::value << std::endl;
// Applying function inverse M
std::cout << ApplyFunctionInverse<4,M>::value << std::endl;
std::cout << ApplyFunctionInverse<8,M>::value << std::endl;
std::cout << ApplyFunctionInverse<15,M>::value << std::endl;
}
Элегантненько.
s: https://stackoverflow.com/questions/26075969/compile-time-map-and-inverse-map-values
−6
https://github.com/syn2cat/pidor
−10
Вопрос
Кто знает, как динамически выделить память, заполнить её нужными инструкциями, и исполнить этот код, не испытав при этом анальной боли и не получить Segmentation Fault ?
0
class Task:
def set_activity( activity_method ):
# проанализировать исходный код activity_method
# разделить цепочку команд на N частей
pass
def _get_parts_number():
return N
def _run_part( part_num ):
# выполнить часть part_num
pass
def run(tasks):
execution = True
part_num = 0
while execution:
execution = False
for task in tasks:
if part_num < task._get_parts_number():
task._run_part( part_num )
execution = True
part_num += 1
Попросил коллегу реализовать concurrency многозадачность, он на питоне нагавнякал такое.
+1
public static class MyExtensions {
private static Random _random = new Random();
public static bool IsMnogo(this object value) {
try {
var n = double.Parse(value.ToString());
return n > 9999999999;
} catch {
return true;
}
}
public static bool IsDavno(this DateTime value) {
return value < new DateTime(1900 + _random.Next(10, 90), 04, 17);
}
}
−2
for word in {"Блять", "пишите", "красивые" ,"коды" ,"уёбки", ",", "ради", "энтузиазма", "и", "плодотворного", "труда", ",", "почитайте", "книжку", "сталина", "и", "поймёте", "как", "надо", "делать", "сруны", "говнокодерные!"}; do
echo "$word"
done
хули?
0
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" href="css/style.css">
<!--[if IE]>
<script src="https://raw.githubusercontent.com/aFarkas/html5shiv/master/dist/html5shiv.min.js"></script>
<![endif]-->
<style>
article, aside, details, figcaption, figure, footer,header,
hgroup, menu, nav, section { display: block; }
</style>
</head>
<body>
<form id="form">
<input type="date">
<input id="inp" type="email" required>
<input type="submit">
</form><br>
<section itemtype="http://data-vocabulary.org/Person" itemscope>
<h1 itemprop="name">Mark Pilgrim</h1>
<p><img itemprop="photo" src="http://www.example.com/photo.jpg" alt="[me smiling]"></p>
<p><a itemprop="url" href="http://diveintomark.org/">weblog</a></p>
</section>
<progress id="pg" value="50" max="100">
<br>
<script>
let forward = true;
function pgset() {
if(forward) {
pg.value = +pg.value + 1;
if(+pg.value == 100)
forward = false;
}
else {
pg.value = +pg.value - 1;
if(+pg.value == 0)
forward = true;
}
}
//setInterval(pgset, 100); //нахуй!
</script>
</body>
</html>
Куда мне ещё говно скидывать??