- 1
define('OKVED_TRY_BUILD_CHUNK_IF_IT_NOT_FOUND_IN_CHUNKCACHE', TRUE);
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+1
define('OKVED_TRY_BUILD_CHUNK_IF_IT_NOT_FOUND_IN_CHUNKCACHE', TRUE);
Написал строчку и думаю - то ли я наговнокодил с названием, то ли соломки подстелил, так, что через месяц я ТОЧНО вспомню, зачем оно нужно...
0
class Program
{
static void Main(string[] args)
{
Cell[] cells = new Cell[15];
cells[1] = new Cell(); //и ещё 14 подобных строк
cells[1].AddAdjacentCell(cells[2], 1);
cells[1].AddAdjacentCell(cells[5], 2); //и так для всех 15 ячеек
Spore spore01 = new Spore(true, false, true, true, false, true);
Spore spore02 = new Spore(true, true, true, true, true, true);
for(Int16 i = 1; i <= 14; i++)
for (Int16 k = 1; k <= 14; k++)
{
if (i != k)
{
Console.Write("Trying " + i + " " + k + "... ");
cells[i].AddSpore(spore01);
cells[k].AddSpore(spore02);
bool badAttempt = false;
for(Int16 c = 1; c <= 14; c++)
{
if (cells[c].state == CellState.Empty)
{
badAttempt = true;
break;
}
}
Console.WriteLine(badAttempt.ToString());
}
}
Console.ReadLine();
}
}
class Cell
{
public CellState state;
private Cell[] adjacentCells = new Cell[6];
private Spore currentSpore = null;
public Cell()
{
this.state = CellState.Empty;
for (Int16 i = 0; i <= 5; i++)
{
this.adjacentCells[i] = null;
}
}
public void AddAdjacentCell(Cell cell, Int16 direction)
{
if (direction >= 6)
return;
this.adjacentCells[direction] = cell;
}
public void Ray(Int16 direction)
{
if (this.adjacentCells[direction] == null)
return;
if (this.adjacentCells[direction].state == CellState.Spore)
return;
this.state = CellState.Light;
this.adjacentCells[direction].Ray(direction);
}
public void AddSpore(Spore spore)
{
this.state = CellState.Spore;
this.currentSpore = spore;
for (Int16 i = 0; i <= 5; i++)
{
if (this.currentSpore.directions[i] == true)
this.Ray(i);
}
}
public void Reset()
{
this.state = CellState.Empty;
this.currentSpore = null;
for (Int16 i = 0; i <= 5; i++)
{
this.adjacentCells[i] = null;
}
}
}
enum CellState
{
Empty,
Light,
Spore
}
class Spore
{
public bool[] directions = new bool[6];
public Spore(params bool[] rays)
{
for (Int16 i = 0; i <= 5; i++)
this.directions[i] = rays[i];
}
}
}
(обсуждение программы для поиска решений для одной головоломки под Андроид)
- Да щас напишем, хуль там делать то?
(через 5 минут)
- Ой, переполнение стека...
- ...
−2
type Speaker interface {
SayHello()
}
type Human struct {
Greeting string
}
func (Human) SayHello() {
fmt.Println("Hello")
}
...
var s Speaker
s = Human{Greeting: "Hello"}
s.SayHello()
Отсюда: https://habrahabr.ru/post/276981/
−4
var up = document.getElementById('upload'),
text1 = document.getElementById('text1'),
text2 = document.getElementById('text2'),
sliderSize = document.getElementById('sliderSize'),
sliderImage = document.getElementById('sliderImage'),
file = document.getElementById('image'),
canvas = document.getElementById('canvas'),
uploaded = document.getElementById('uploaded'),
placeholder_image = document.getElementById('placeholder_image');
up.addEventListener('click', uploadToImgur);
text1.addEventListener('keyup', updateImage);
text2.addEventListener('keyup', updateImage);
sliderSize.addEventListener('change', updateImage);
sliderImage.addEventListener('change', updateImage);
file.addEventListener('change', changeAndUpdateImage);
function readFile(fileInput, callback) {
var f = fileInput.files[0];
var reader = new FileReader();
reader.onload = (function(theFile) {
return function(e) {
callback(e.target.result);
};
})(f);
reader.readAsDataURL(f);
}
var curImg = null;
placeholder_image.onload = function() {
curImg = placeholder_image;
updateImage();
}
function changeAndUpdateImage() {
var img = new Image();
readFile(file, function(dataURL) {
img.onload = function() {
curImg = img;
sliderImage.value = Math.max(img.width, img.height);
canvas.width = img.width;
canvas.height = img.height;
//canvas.style.height = img.height + 'px';
//canvas.style.width = img.width + 'px';
updateImage();
}
img.src = dataURL;
});
}
function drawLines(ctx, lines, x, y, yStep) {
lines = lines.split('\n');
if (yStep < 0) lines = lines.reverse();
lines.forEach(function(l, k) {
ctx.strokeText(l, x, y + yStep * k);
ctx.fillText(l, x, y + yStep * k);
});
}
function updateImage() {
var LINE_HEIGHT = 1.1;
var PARAGRAPH_HEIGHT = 1.5;
var imgSizeLimit = parseFloat(sliderImage.value);
var canvasSize = autoScale({
w: curImg.width,
h: curImg.height
}, imgSizeLimit);
canvas.width = canvasSize.w;
canvas.height = canvasSize.h;
var ctx = canvas.getContext("2d");
var txtSize = parseFloat(sliderSize.value) || 24;
if (!curImg) return;
ctx.strokeStyle = '#000000';
ctx.fillStyle = '#ffffff';
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.drawImage(curImg, 0, 0, canvas.width, canvas.height);
ctx.font = txtSize + "px Impact";
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.lineWidth = Math.round(Math.max(1, txtSize / 12));
drawLines(ctx, text1.value, canvas.width / 2,
txtSize * PARAGRAPH_HEIGHT / 2, LINE_HEIGHT * txtSize);
drawLines(ctx, text2.value, canvas.width / 2,
canvas.height - txtSize * PARAGRAPH_HEIGHT / 2, -1 * LINE_HEIGHT * txtSize );
+3
const char _LETTERS[] =
"000000000000000000000000000000000000000000000000000000000000000001111111111<...>";
const char _DIGITS[] =
"000000000000000000000000000000000000000000000000111111111100000000000000000<...>";
const char _CONTROL_CHARS[] =
"111111111111111111111111111111110000000000000000000000000000000000000000000<...>";
const char _PUNCT_CHARS[] =
"000000000000000000000000000000000111011111101111000000000011000110000000000<...>";
const char _SEP_CHARS[] =
"000000000000000000000000000000001000000000000000000000000000000000000000000<...>";
const char _SYM_CHARS[] =
"000000000000000000000000000000000000100000010000000000000000111000000000000<...>";
#define min(i,l,I) (((i) < (l)) ? (((i) < (I)) ? (i) : (I)) : (((l) < (I)) ? (l) : (I)))
bool CharIsLetter(wchar_t c) {
return _LETTERS[c] != L'0';
}
bool CharIsDigit(wchar_t c) {
return _DIGITS[c] != L'0';
}
bool CharIsControl(wchar_t c) {
return _CONTROL_CHARS[c] != L'0';
}
bool CharIsPunctuation(wchar_t c) {
return _PUNCT_CHARS[c] != L'0';
}
bool CharIsSeparator(wchar_t c) {
return _SEP_CHARS[c] != L'0';
}
bool CharIsSymbol(wchar_t c) {
return _SYM_CHARS[c] != L'0';
}
Лёшенька Кондратьев учится оптимизации
+1
$product = ORM::factory('product');
// $product-> ... = ...;
$price = ORM::factory('price');
$price->save();
$product->price = $price->id;
$product->save();
$price->product = $product->id;
// $price-> ... = ...;
$price->save();
Для гарантии
+4
public function validate($value) {
try {
$date = new \DateTime($value);
return true;
} catch (\Exception $e) {
return false;
}
}
DateTime Validator
+2
<!DOCTYPE html>
<!--Привет, друг!
Привет, друг.
Чушь какая.-->
<title>CMW | Авторизация</title>
<!-- <Meta> -->
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- </Meta> -->
<!-- <Stylesheet> -->
<link rel="stylesheet" href="./Stylesheet/index.css">
<!-- </Stylesheet> -->
<!-- <div style="background-color: #2b333e">Для рекламы</div> -->
<header class="z-depth-1">
<!-- Фиксация навигации при прокрутке -->
<div class="navbar-fixed">
<nav>
<div class="nav-wrapper">
<div class="container"><a href="#" data-activates="slide-out" class="button-collapse"><i class="mdi-navigation-menu"></i></a></div>
<a class="navbar-brand navigation__logo" href="main.html"></a>
<a href="auth.html"><button type="submit" class="btn button__main navbar-right authorization">Авторизация</button></a>
</div>
</nav>
</div>
</header>
Верстку от дизайнера привезли
+1
import std.io;
import std.string;
import calendar.month;
module calendar.date;
namespace Chrono
{
export
struct Date {
Date(int, Month, int);
int day() const
{
return d;
}
Month month() const
{
return m;
}
Int year() const
{
return y;
}
private:
int d;
Month m;
int y;
};
export
std::ostream &operator<<(std::ostream &, const Date &);
export
std::string to_string(const Date &);
}
По мотивам: http://habrahabr.ru/company/infopulse/blog/267781/
зы. https://github.com/isocpp/CppCoreGuidelines/blob/master/talks/Large-Scale-C%2B%2B-With-Modules.pdf
+1
var getVisualizerCount = function() {
var count = 0;
if (visualizerConfig && visualizerConfig.visualizers) {
for (var i = 0; i < visualizerConfig.visualizers.length; i++) {
count = count + 1;
}
}
return count;
};
Достался проект от индусов. И такого коровьего д****а, хоть ж***й жуй. По мере нахождения запощу еще.