- 1
- 2
- 3
- 4
- 5
function(dateToAdjust) {
dateToAdjust = new Date(dateToAdjust);
var offsetMs = dateToAdjust.getTimezoneOffset() * 60000;
return new Date(dateToAdjust.getTime() - offsetMs);
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+156
function(dateToAdjust) {
dateToAdjust = new Date(dateToAdjust);
var offsetMs = dateToAdjust.getTimezoneOffset() * 60000;
return new Date(dateToAdjust.getTime() - offsetMs);
}
даты в js, люблю их даже больше чем в php
+137
// For a portable version of timegm(), set the TZ environment variable to
// UTC, call mktime(3) and restore the value of TZ. Something like
#include <time.h>
#include <stdlib.h>
time_t
my_timegm(struct tm *tm)
{
time_t ret;
char *tz;
tz = getenv("TZ");
if (tz)
tz = strdup(tz);
setenv("TZ", "", 1);
tzset();
ret = mktime(tm);
if (tz) {
setenv("TZ", tz, 1);
free(tz);
} else
unsetenv("TZ");
tzset();
return ret;
}
Цитата из man timegm. Сборка unix timestamp из компонент (год, месяц и т.п.).
Удобно, наглядно, потокобезопасно.
+50
if ( !log.append(log_line) )
log.append("Can't append to log");
+54
// We now have a locale string, but the global locale can be changed by
// another thread. If we allow this thread's locale to be updated before we're done
// with this string, it might be freed from under us.
// Call versions of the wide-to-MB-char conversions that do not update the current thread's
// locale.
//...
/*
* Note that we are using a risky trick here. We are adding this
* locale to an existing threadlocinfo struct, and thus starting
* the locale's refcount with the same value as the whole struct.
* That means all code which modifies both threadlocinfo::refcount
* and threadlocinfo::lc_category[]::refcount in structs that are
* potentially shared across threads must make those modifications
* under _SETLOCALE_LOCK. Otherwise, there's a race condition
* for some other thread modifying threadlocinfo::refcount after
* we load it but before we store it to refcount.
*/
MS VS 2013 CRT
+157
function calcHTime($stt) {
$secs = time() - $stt;
$h = (int) ($secs / 3600);
$m = (int) (($secs - ($h * 3600)) / 60);
$s = (int) ($secs - ($h * 3600) - ($m * 60));
return sprintf("%02d:%02d:%02d", $h, $m, $s);
}
+159
function time(){
var vr=new Date();
var hour=vr.getHours();
var min=vr.getMinutes();
var sec=vr.getSeconds();
if (sec<=9) {
if (min<=9) {
if (hour<=9) {
document.forms[0].elements[0].value = "0" + hour +":"+ "0" + min +":"+ "0" + sec;
}
else {
document.forms[0].elements[0].value = hour +":"+ "0" + min +":"+ "0" + sec;
}
}
else {
if (hour<=9) {
document.forms[0].elements[0].value = "0" + hour +":"+ min +":"+ "0" + sec;
}
else {
document.forms[0].elements[0].value = hour +":"+ min +":"+ "0" + sec;
}
}
}
else {
if (min<=9) {
if (hour<=9) {
document.forms[0].elements[0].value = "0" + hour +":"+ "0" + min +":"+ sec;
}
else {
document.forms[0].elements[0].value = hour +":"+ "0" + min +":"+ sec;
}
}
else {
if (hour<=9) {
document.forms[0].elements[0].value = "0" + hour +":"+ min +":"+ sec;
}
else {
document.forms[0].elements[0].value = hour +":"+ min +":"+ sec;
}
}
}
setTimeout("time()",1000);
}
Вот такой вот toString().
+133
void Nay_Prer_Timer2(void)
{
Obr_Func_Prer.Sh_Time2 = Obr_Func_Prer.Sh_Time2_Init;
Spec_Vkl_Indic.Sh_Time2 = Spec_Vkl_Indic.Sh_Time2_Init;
Spec_Vykl_Indic.Sh_Time2 = Spec_Vykl_Indic.Sh_Time2_Init;
Flag_Morg=0; // Флаг моргания для Config_Bibl_Max6954
Flag_Vykl_Diod=0;
if(Config_Bibl_Max6954&0x4) // 2-й бит =1 - Прерывания разрешены
Vkl_Prer_Timer2();
return;
}
Чел писал тестовое задание для микроконтроллера (поморгать светодиодами).
На вопрос что означает слово Nay в названии функции был дан ответ - это сокращение от нач. (начало).
−396
BOOL = omg;
if (omg == YES)
{
[self go];
}
else
{
if (omg == YES)
{
omg = YES;
[self go];
}
}
МОИ ГЛАЗАААА
+56
bool XIsEmptyString( LPCTSTR str )
{
CString s(str);
s.TrimLeft();
s.TrimRight();
return ( s.IsEmpty() || s == _T("") );
}
Кажется разработчика настиг приступ паранойи.
Взято из библиотека XMLite
−170
CREATE TRIGGER TR_Table1 ON Table1
INSTEAD OF INSERT
AS
INSERT INTO Table1
SELECT * FROM INSERTED
Диалект MS SQL
INSTEAD OF INSERT - триггер, отменяющий вставку и передающий список значений, указанных в запросе в псевдотаблице INSERTED.
т.е. автор вместо того чтобы позволить северу вставлять строк решил каждый раз вставлять их лично.