- 1
- 2
- 3
- 4
- 5
- 6
- 7
function isDateGreaterOrEqualNow($d)
{
if (!$d) return false;
$t = getdate();
$t = mktime(0, 0, 0, $t['mon'], $t['mday'], $t['year']);
return $d >= $t;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
function isDateGreaterOrEqualNow($d)
{
if (!$d) return false;
$t = getdate();
$t = mktime(0, 0, 0, $t['mon'], $t['mday'], $t['year']);
return $d >= $t;
}
Космическое сравнение дат
−1
<CustomTimePicker
ref={ref => {
if (!ref || this.moved || this.handled)
return;
this.handled = true;
ref.picker.addEventListener('click', () => {
if (this.moved)
return;
setTimeout(() => {
const panel = ref.panelInstance;
if (!panel || !panel._reactInternalInstance)
return;
const node = panel._reactInternalInstance._renderedComponent._hostNode.parentNode.parentNode.parentNode;
this.moved = true;
this.refs.container.appendChild(node);
ref.picker.click();
ref.picker.click();
}, 0);
});
}}
showSecond={false}
value={this.props.value || moment()}
className="timepicker"
onChange={(e) => this.handleChange(e)}
format={this.format}
use12Hours
/>
+2
switch (address & 0xF000)
{
case 0x0000:
case 0x1000:
case 0x2000:
case 0x3000:
return rom[address];
case 0x4000:
case 0x5000:
case 0x6000:
case 0x7000:
return rom[address + 0x4000 * (bank_index - 1)];
case 0x8000:
case 0x9000:
return vram[address - 0x8000];
case 0xA000:
case 0xB000:
return sram[address - 0xA000];
case 0xC000:
case 0xD000:
return wram[address - 0xC000];
case 0xE000:
case 0xF000:
switch (address & 0x0F00)
{
case 0x0000:
case 0x0100:
case 0x0200:
case 0x0300:
case 0x0400:
case 0x0500:
case 0x0600:
case 0x0700:
case 0x0800:
case 0x0900:
case 0x0A00:
case 0x0B00:
case 0x0C00:
case 0x0D00:
return wram[address - 0xF000];
case 0x0E00:
switch (address & 0x00F0)
{
case 0x0000:
case 0x0010:
case 0x0020:
case 0x0030:
case 0x0040:
case 0x0050:
case 0x0060:
case 0x0070:
case 0x0080:
case 0x0090:
return oam[address - 0xFE00];
case 0x00A0:
case 0x00B0:
case 0x00C0:
case 0x00D0:
case 0x00E0:
case 0x00F0:
return 0b00;
}
case 0x0F00:
switch (address & 0x00F0)
{
case 0x0000:
case 0x0010:
case 0x0020:
case 0x0030:
case 0x0040:
case 0x0050:
case 0x0060:
case 0x0070:
return io_regs[address - 0xFF00];
case 0x0080:
case 0x0090:
case 0x00A0:
case 0x00B0:
case 0x00C0:
case 0x00D0:
case 0x00E0:
case 0x00F0:
switch (address & 0x000F)
{
case 0x0000:
case 0x0001:
case 0x0002:
case 0x0003:
case 0x0004:
case 0x0005:
case 0x0007:
case 0x0008:
case 0x0009:
case 0x000A:
case 0x000B:
case 0x000C:
case 0x000D:
case 0x000E:
return hram[address - 0xFF80];
case 0x000F:
0
#include <optional>
namespace aim {
template <typename T, template <typename> typename Cont>
struct is_valid {};
template <typename T, template <typename> typename Cont>
struct chain;
template <typename T, template <typename> typename Cont>
struct chain {
using value_type_t = T;
using holder_t = Cont<value_type_t>;
chain()
{}
chain(holder_t&& value_)
: value(std::move(value_))
{}
template <typename Func>
constexpr auto otherwise(Func&& func) {
return chain<T, Cont>{std::move(func())};
}
template <typename Func>
constexpr auto with(Func&& func) -> chain<value_type_t, Cont> {
if (bool(value)) {
return chain<value_type_t, Cont>{Cont<value_type_t>{func(*value)}};
}
else {
return chain<value_type_t, Cont>{};
}
}
holder_t value;
};
template <typename T, template <typename> typename Cont>
chain(Cont<T>&&) -> chain<T, Cont>;
template <typename T, template <typename> typename Cont>
struct use {
using value_type_t = T;
using holder_t = Cont<value_type_t>;
use(holder_t&& value)
: value(std::move(value))
{}
template <typename Func>
constexpr auto with(Func&& func) -> chain<value_type_t, Cont> {
if (is_valid<T, Cont>{}(value)) {
return chain<value_type_t, Cont>{Cont<value_type_t>{func(*value)}};
}
else {
return chain<value_type_t, Cont>{};
}
}
holder_t value;
};
template <typename T, template <typename> typename Cont>
use(Cont<T>&&) -> use<T, Cont>;
}
namespace aim {
template <typename T>
struct is_valid<T, std::optional> {
constexpr bool operator()(std::optional<T> const& value) {
return bool(value);
}
};
}
#include <iostream>
#include <memory>
int main() {
{
std::optional<int> a;
aim::use(std::move(a)).with([](auto v) {
std::cout << v << '\n';
return 1;
}).otherwise([](){
std::cout << "it's none!\n";
return 2;
}).with([](auto v){
std::cout << v << '\n';
return 3;
});
}
}
говно
+2
$value = $grandTotal - $tax;
$total_name = $this->__('Grandtotal_excl_tax')." (".$this->__('excl. tax').")";
$row = '<div class="columns xsmall-6 small-6">';
$row .= $total_name;
$row .= '</div><div class="columns xsmall-6 small-6 align-right">'.$this->helper('checkout')->formatPrice($value).'</div>';
$totals["grand_total_excl_tax"] = $row;
//$orderedTotals = Mage::getStoreConfig('onestepcheckout/general/summary_totals');
$orderedTotals = "subtotal,aw_giftcard_duty,aw_giftcard_duty_discount,shipping,cashondelivery,shipping_discount,discount,aw_giftcard,grand_total_excl_tax,tax,grand_total";
$orderedTotals = explode(',', $orderedTotals);
foreach($orderedTotals as $total) {
$total = trim($total);
if (isset($totals[$total])) {
echo $totals[$total];
}
}
?>
</div>
Разгребаем проект на Magento доставшийся в наследство. Умеете ли вы готовить Array() так как готовят его в строках 11-12 ?
#littleitaly
0
# returns yesterday reports
def get_yesterday_reports(self):
pass
def get_waterfall_sources(self, wf_id, active_only=False):
# TODO: check if meta property is equal to the number of items in the array
# return test.mock_waterfall_sources.get_sources()
status = '1' if active_only else urllib.quote('0,1') # '0%2C1&'
self.get_auth_token()
encoded = urllib.urlencode({'authorization': self.token})
url = BASE_URL + "/waterfall-ad-sources?advertiser=&itemsPerPage=9999&name=&page=1&sortAsc=true&sortBy=tier&status={}&tier=&waterfall={}&{}" \
.format(status, wf_id, encoded)
retries = 1
while retries <= 3:
response = requests.get(url)
if response.status_code == 200:
break
else:
logging.error('Failed GET request to StreamRail, status code {}, {} retries'
.format(response.status_code, retries))
retries += 1
assert response.status_code == 200
try:
data = simplejson.loads(response.content)
waterfall_sources = data['waterfallAdSources']
assert int(data['meta']['total']) == len(waterfall_sources)
return waterfall_sources
except:
logging.exception("Could not load ad sources for waterfall {} from StreamRail:\n"
"{}".format(wf_id, response.headers))
raise
Хотя, с другой стороны, все эти рекламораспространители так выглядят. Но тут просто кучно так получилось.
+1
<div class="checkbox removeSpan">
<input id="all-standard-colors" name="all-standard-colors" type="checkbox"
data-bind="checked: $parent.selectAllStandardColors enable: $parent.isTabEnabled"/>
<label for="all-standard-colors">All standard</label>
</div>
<style>
div.checkbox > input + label {
padding: 4px 0 4px 29px;
background-image: url("../images/unchecked-checkbox.png");
background-size: 21px;
background-position: left center;
background-repeat: no-repeat;
}
div.checkbox > input:checked + label {
background-image: url("../images/checkbox-checked.png");
background-size: 21px;
background-position: left center;
background-repeat: no-repeat;
}
</style>
<script>
$(document).ready(function() {
setInterval(function(){
$('.removeSpan span').remove();
}, 2000);
});
</script>
UI на knockout.js. Есть бага - пропадает галочка на чекбоксе. Выясняется что knockout для валидации вставляет после input тега невидимый span
<span></span>
Неизвестный товарищ фиксит это не вдаваясь в детали верстки и CSS селекторы - добавляет специальный класс, которым маркает все чекбоксы и поллер который убирает из них span каждые 2 секунды. Но про это никто не узнает. В течении полугода появляется еще десяток другой багов с отображением чекбоксов которые фиксят не вдаваясь в детали. И только потом замечают странный класс removeSpan и находят поллер в недрах domUtil.js, удаляют его и меняют один символ в стилях - вместо div.checkbox > input + label стало div.checkbox > input ~ label
−1
static bool
do_convert(iconv_t cd, const char * src, int src_len,
char ** dst, int *dst_len)
{
char * ret;
char *inbuf;
char *outbuf;
int alloc_size;
int output_pos;
size_t inbytesleft;
size_t outbytesleft;
if(src_len < 0)
src_len = strlen(src);
#if 0
fprintf(stderr, "Converting:\n");
bgav_hexdump(src, src_len, 16);
#endif
alloc_size = src_len + BYTES_INCREMENT;
inbytesleft = src_len;
/* We reserve space here to add a final '\0' */
outbytesleft = alloc_size-1;
ret = malloc(alloc_size);
inbuf = (char *)src;
outbuf = ret;
while(1)
{
if(iconv(cd, (ICONV_CONST char **)&inbuf, &inbytesleft,
&outbuf, &outbytesleft) == (size_t)-1)
{
switch(errno)
{
case E2BIG:
output_pos = (int)(outbuf - ret);
alloc_size += BYTES_INCREMENT;
outbytesleft += BYTES_INCREMENT;
ret = realloc(ret, alloc_size);
if (ret == NULL)
{
cdio_warn("Can't realloc(%d).", alloc_size);
return false;
}
outbuf = ret + output_pos;
break;
default:
cdio_warn("Iconv failed: %s", strerror(errno));
if (ret != NULL)
free(ret);
return false;
break;
}
}
if(!inbytesleft)
break;
}
/* Zero terminate */
*outbuf = '\0';
/* Set return values */
*dst = ret;
if(dst_len)
*dst_len = (int)(outbuf - ret);
#if 0
fprintf(stderr, "Conversion done, src:\n");
bgav_hexdump(src, src_len, 16);
fprintf(stderr, "dst:\n");
bgav_hexdump((uint8_t*)(ret), (int)(outbuf - ret), 16);
#endif
return true;
}
https://github.com/pbatard/rufus/blob/edcfd43ed550b17f23f9534f4b3b5cdd7fffdefc/src/libcdio/driver/utf8.c#L170-L248
0
void SetTitleBarIcon(HWND hDlg)
{
int i16, s16, s32;
HICON hSmallIcon, hBigIcon;
// High DPI scaling
i16 = GetSystemMetrics(SM_CXSMICON);
// Adjust icon size lookup
s16 = i16;
s32 = (int)(32.0f*fScale);
if (s16 >= 54)
s16 = 64;
else if (s16 >= 40)
s16 = 48;
else if (s16 >= 28)
s16 = 32;
else if (s16 >= 20)
s16 = 24;
if (s32 >= 54)
s32 = 64;
else if (s32 >= 40)
s32 = 48;
else if (s32 >= 28)
s32 = 32;
else if (s32 >= 20)
s32 = 24;
// Create the title bar icon
hSmallIcon = (HICON)LoadImage(hMainInstance, MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, s16, s16, 0);
SendMessage (hDlg, WM_SETICON, ICON_SMALL, (LPARAM)hSmallIcon);
hBigIcon = (HICON)LoadImage(hMainInstance, MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, s32, s32, 0);
SendMessage (hDlg, WM_SETICON, ICON_BIG, (LPARAM)hBigIcon);
}
https://github.com/pbatard/rufus/blob/92d046e663811fd922262f1f347ad2ebe8e09b97/src/stdlg.c#L1607-L1639
+1
def gsubn text
text.gsub('\n','').gsub('\t','').gsub('\r','').gsub(/\"/,'').gsub('@@@@','. ').gsub(" "," ")
end
последний gsub меняет два пробела на один