- 1
- 2
- 3
- 4
- 5
- 6
<?php
$data = file_get_contents("/path/to/photo.jpg"); // Read the file's contents
$name = 'myphoto.jpg';
force_download($name, $data);
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+155
<?php
$data = file_get_contents("/path/to/photo.jpg"); // Read the file's contents
$name = 'myphoto.jpg';
force_download($name, $data);
Я знаю конечно что это не говнокод, но последствия будут ужасными если не передать сразу же в функцию данные (т.к. PHP будет копировать содержимое дважды), представьте себе файл в 2МБ и много запросов, сервер капут в два раза быстрее.
- https://ellislab.com/codeigniter/user-guide/helpers/download_helper.html
−126
&НаСервере
Процедура ПриСозданииНаСервере(Отказ, СтандартнаяОбработка)
НовыйДокумент = Документы.ДокументПредЗаявка.СоздатьДокумент();
НовыйДокумент.Дата = ТекущаяДата();
НовыйДокумент.Записать(РежимЗаписиДокумента.Проведение);
СПД = НовыйДокумент.Ссылка;
//Открываем документ
ОткрытьЗначение(СПД);
КонецПроцедуры
Я не вкурил, но полагаю, что ЭТО новый способ создания документа на основании...
+151
//...
<script>splashRadar('leftcol', 1);</script>
<script>splashRadar('baseStyles');</script>
//...
На мейл.сру.
+157
$('#id_accept_eula').click(function () {
// код аффтара
try {
var v = 1 - this.getAttribute('value');
this.setAttribute('value', v);
if (v == 1) {
$('#submit_button').removeAttr('disabled');
} else {
$('#submit_button').attr('disabled', 'disabled');
}
} catch (e) {
alert('exc: ' + e);
}
// заменил на
$("#submit_button").prop('disabled', !this.checked);
});
Когда платят за строки кода...
+131
/*
* Copyright (C) 2007-2012 Allwinner Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
#ifndef __DISP_DISPLAY_I_H__
#define __DISP_DISPLAY_I_H__
#include "ebios_de.h"
#include "ebios_lcdc_tve.h"
#include "drv_disp_i.h" /* For DISP_XXXXXX status codes */
#define DE_INF __inf
#define DE_WRN __wrn
#define OSAL_IRQ_RETURN IRQ_HANDLED
#define HANDTOID(handle) ((handle) - 100)
#define IDTOHAND(ID) ((ID) + 100)
#define INTC_IRQNO_SCALER0 SW_INT_IRQNO_DEFEBE0
#define INTC_IRQNO_SCALER1 SW_INT_IRQNO_DEFEBE1
#define INTC_IRQNO_LCDC0 SW_INT_IRQNO_LCDCTRL0
#define INTC_IRQNO_LCDC1 SW_INT_IRQNO_LCDCTRL1
#define MAX_SPRITE_BLOCKS 32
/*basic data information definition*/
enum {
FALSE = 0,
TRUE
};
#define DIS_NULL 0
#define BIT0 0x00000001
#define BIT1 0x00000002
#define BIT2 0x00000004
#define BIT3 0x00000008
#define BIT4 0x00000010
#define BIT5 0x00000020
#define BIT6 0x00000040
#define BIT7 0x00000080
#define BIT8 0x00000100
#define BIT9 0x00000200
#define BIT10 0x00000400
#define BIT11 0x00000800
#define BIT12 0x00001000
#define BIT13 0x00002000
#define BIT14 0x00004000
#define BIT15 0x00008000
#define BIT16 0x00010000
#define BIT17 0x00020000
#define BIT18 0x00040000
#define BIT19 0x00080000
#define BIT20 0x00100000
#define BIT21 0x00200000
#define BIT22 0x00400000
#define BIT23 0x00800000
#define BIT24 0x01000000
#define BIT25 0x02000000
#define BIT26 0x04000000
#define BIT27 0x08000000
#define BIT28 0x10000000
#define BIT29 0x20000000
#define BIT30 0x40000000
#define BIT31 0x80000000
#endif
Нашёл в драйвере дисплея. Вместо 1<<N.
+156
$data = $DB->...
reset($data);
while (list(, $row) = each($data)) {
// do somethig with $row
}
Я не понимаю, почему просто не использовать foreach?!
+125
(closer-mop:defclass virtual-metaclass (closer-mop:standard-class) ())
(closer-mop:defclass virtual-slot-definition
(closer-mop:standard-slot-definition)
((function :initarg :function
:accessor virtual-slot-definition-function)))
(defmethod slot-definition-allocation ((slotd virtual-slot-definition))
:virtual)
(defmethod (setf slot-definition-allocation)
(allocation (slotd virtual-slot-definition))
(unless (eq allocation :virtual)
(error "Cannot change the allocation of a ~S"
'virtual-direct-slot-definition)) allocation)
(closer-mop:defclass virtual-direct-slot-definition
(closer-mop:standard-direct-slot-definition
virtual-slot-definition) ())
(defmethod closer-mop:direct-slot-definition-class
((class virtual-metaclass) &rest initargs)
;; Use virtual-direct-slot-definition if appropriate.
(if (eq (getf initargs :allocation) :virtual)
(find-class 'virtual-direct-slot-definition)
(call-next-method)))
(closer-mop:defclass virtual-effective-slot-definition
(closer-mop:standard-effective-slot-definition
virtual-slot-definition) ())
(defmethod closer-mop:effective-slot-definition-class
((class virtual-metaclass) &rest initargs)
;; Use virtual-effective-slot-definition if appropriate.
(let ((slot-initargs (getf initargs :initargs)))
(if (member :virtual-slot slot-initargs)
(find-class 'virtual-effective-slot-definition)
(call-next-method))))
(defmethod closer-mop:compute-effective-slot-definition
((class virtual-metaclass) name direct-slot-definitions)
;; Copy the function into the effective slot definition
;; if appropriate.
(let ((effective-slotd (call-next-method)))
(dolist (slotd direct-slot-definitions)
(when (typep slotd 'virtual-slot-definition)
(setf (virtual-slot-definition-function effective-slotd)
(virtual-slot-definition-function slotd))
(return)))
effective-slotd))
(defmethod closer-mop:slot-value-using-class
((class virtual-metaclass) object slot-name)
(let ((slotd (find slot-name (closer-mop:class-slots class)
:key 'closer-mop:slot-definition-name)))
(if (typep slotd 'virtual-slot-definition)
(funcall (cadr (virtual-slot-definition-function slotd)) :get object)
(call-next-method))))
(defmethod (setf closer-mop:slot-value-using-class)
(value (class virtual-metaclass) object slotd)
(if (typep slotd 'virtual-slot-definition)
;; This is ugly and probably not portable, but what if?
(funcall (cadr (virtual-slot-definition-function slotd))
:set object value)
(call-next-method)))
(defmethod closer-mop:slot-boundp-using-class
((class virtual-metaclass) object slot-name)
(let ((slotd (find slot-name (closer-mop:class-slots class)
:key 'closer-mop:slot-definition-name)))
(if (typep slotd 'virtual-slot-definition)
(funcall (cadr (virtual-slot-definition-function slotd)) :is-set object)
(call-next-method))))
(defmethod closer-mop:slot-makunbound-using-class
((class virtual-metaclass) object slot-name)
(let ((slotd (find slot-name (closer-mop:class-slots class)
:key 'closer-mop:slot-definition-name)))
(if (typep slotd 'virtual-slot-definition)
(funcall (virtual-slot-definition-function slotd) :unset object)
(call-next-method))))
О простоте объектно-ориентированого программирования, или страшная правда, которую от вас так долго скрывали.
Написано по мотивам: http://www.lispworks.com/documentation/lw50/LWUG/html/lwuser-173.htm В попытке сделать это, по возможности, портабельным (на SBCL вроде даже завелось).
Я понимаю, что читать это никто не будет, поэтому, краткий пересказ событий:
Захотелось мне виртуальных свойств, ну тоесть так, чтобы при обращении к Сипипишной библиотеке, для которой я ваяю оберкту не было различий между обычными Лисповыми объектами и Сипипишными.
Простой вариант - скопировать значения, но перформанс же!
И вот родился этот вариант. (Использование не показано, т.как не влезло).
+153
$("div.entry-comment-wrapper").has("p strong a").each( function (i,e){
$.ajax({'url':'http://govnokod.ru/ratings/comment/'+$(e).attr('id').replace('comment-','')+'/against'}) } );
+173
var magnitude = parseInt('10' + new Array(8).join('0'));
вот такое встретилось
+138
p.fANT = Convert.ToUInt16(((devStat & (1 << 13)) != 0 ? "1" : "0") + ((devStat & (1 << 12)) != 0 ? "1" : "0"), 2);
Вот сижу думаю так задуманно или автор сам не понял что написал