- 1
- 2
- 3
- 4
- 5
function htmlspecialchars (s) {
const el = document.createElement('span');
el.innerText = s;
return el.innerHTML.replace(/<br>/g, "\n");
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+1
function htmlspecialchars (s) {
const el = document.createElement('span');
el.innerText = s;
return el.innerHTML.replace(/<br>/g, "\n");
}
Почему в жепаскрипте нет прямого доступа к этой функции? Почему я должен для этого работать с DOM или сам писать эту поеботу на рагулярках? Почему асё так анально?
+1
import SwiftUI
struct LandmarkDetail: View {
@EnvironmentObject var userData: UserData
var landmark: Landmark
var landmarkIndex: Int {
userData.landmarks.firstIndex(where: { $0.id == landmark.id })!
}
var body: some View {
VStack {
MapView(landmark: landmark)
.frame(height: 300)
CircleImage(image: landmark.image(forSize: 250))
.offset(y: -130)
.padding(.bottom, -130)
VStack(alignment: .leading) {
HStack {
Text(landmark.name)
.font(.title)
Button(action: {
self.userData.landmarks[self.landmarkIndex].isFavorite.toggle()
}) {
if self.userData.landmarks[self.landmarkIndex].isFavorite {
Image(systemName: "star.fill")
.foregroundColor(Color.yellow)
} else {
Image(systemName: "star")
.foregroundColor(Color.gray)
}
}
}
HStack(alignment: .top) {
Text(landmark.park)
.font(caption)
Spacer()
Text(landmark.state)
.font(.caption)
}
}
.padding()
Spacer()
}
.navigationBarTitle(Text(landmark.name), displayMode: .inline)
}
}
https://developer.apple.com/tutorials/swiftui/handling-user-input
Принципиально новый нескучный "декларативный" UI от компании Apple. В наличии:
* магические константы
* спагетти из замыканий
* биндинги, страшные как атомная война
* где-то внутри модная хипстерская реактивная либа
На фоне этого кошмара qml кажется вершиной инженерной мысли
+1
// 3.7 Position-independent Limitation
// At runtime an MRE program needs to be dynamically loaded into RAM. In other words, the addresses of the variables and functions can be dynamically assigned when they are loaded. This requires that the code be position-independent. If the code needs to determine the addresses at compile time, then it will fail to compile.
// The following code exemplifies this error.
/* 1 */
int a[10], b[10];
struct c {
int* d;
int* e;
};
struct c f = {a, b};
/* 2 */
void func1(void) {}
typedef struct struct1 {
int a;
void (*fun)(void);
} struct1;
struct1 array1[1] = {0, func1};
/* 3 */
char *str = "test";
char * list[] = {"zero", "one", "two"};
// The solution is as follows:
/* 1 */
int a[10], b[10];
struct c {
int* d;
int* e;
};
struct c f;
void init1(void) {
f.d = a;
f.e = b;
}
/* 2 */
void func1(void) {}
typedef struct struct1 {
int a;
void (*fun)(void);
} struct1;
struct1 array1[1];
void init2(void) {
array1[0].a = 0;
array1[0].fun = func1;
}
/* 3 */
char str[] = "test";
char list[][10] = {"zero", "one", "two"};
MRE Developer FAQ
This document contains information that is proprietary to MediaTek Inc.
Загрузчик программ из MRE не умеет сложные фиксапы, поэтому изменяйте свой код, чтобы в нём не было адресов, которые нужно определять в момент загрузки.
+1
Если ВидОперации = Перечисления.МОЛ_ВидыОперацийПоступленияСырья.Перемещение Тогда
ДоговорКонтрагента = "";
ТипЦен = "";
Если Сырье.Количество()>0 Тогда
Для каждого СтрокаСырье Из Сырье Цикл
СтрокаСырье.Цена = 0;
СтрокаСырье.Сумма = 0;
СтрокаСырье.СуммаНДС = 0;
КонецЦикла;
КонецЕсли;
КонецЕсли;
Добавлена проверка, чтобы цикл вдруг не выполнился при пустой таб части!
Кстати выполняется при открытии формы и постоянно вызывает модифицированность
Молокозавод 1.3.121
+1
<script>
window["flags"] = {
"purcTOFlag": "true" == "true" ? true : false,
"ENBL_CANCEL_POLICY": "true" == "true" ? true : false,
"ENBL_BACKUP_CHECK_OLD_DEVICES": "false" == "true" ? true : false,
"ENBL_DIRECT_ACCESS_LINKS": "true" == "true" ? true : false,
"ENBL_NEW_ABG_URL": "true" == "true" ? true : false,
"cr_9839666": "true" == "true" ? true : false,
"cubaCRFlag": "true" == "true" ? true : false,
"cubaMultiCityCRFlag": "true" == "true" ? true : false,
"youthCRFlag": "true" == "true" ? true : false,
"ENABLE_AFOP_MODE": "true" == "true" ? true : false,
"SHARE_ITINERARY_ON_FACEBOOK": "false" == "true" ? true : false,
"cr_11668201": "true" == "true" ? true : false,
"hotelCRFlag": "true" == "true" ? true : false,
"cr_adoshareitinerary": "false" == "true" ? true : false,
"ROUNDOFF_AMOUNT_FOR_US_EDITION": "true" == "true" ? true : false,
"hideSeatPromotionalBanner": "true" == "true" ? true : false,
"enablePremiumRougeCR": "true" == "true" ? true : false,
"availFareSplit": "true" == "true" ? true : false,
"improvedMixedCabin": "true" == "true" ? true : false,
"adoPassengerPrepopulate": "true" == "true" ? true : false,
"adoIataInformation": "true" == "true" ? true : false,
"premiumRougeSeatSelection": "true" == "true" ? true : false,
"displayIntlTerminal": "true" == "true" ? true : false,
"continueDisabledLightboxIsEnabled": "true" == "true" ? true : false,
"createAeroplanFromConf": "true" == "true" ? true : false,
"contOnAvailPage": "true" == "true" ? true : false,
"alpiSpecialAssistanceCRFlag": "true" == "true" ? true : false,
"removePaxTitle": "false" == "true" ? true : false,
"perDiemInsurance": "true" == "true" ? true : false,
"isVisaCheckoutEnabled": "true" == "true" ? true : false,
"isCashRewardEnabled": "true" == "true" ? true : false,
"masterPassCRFlag": "true" == "true" ? true : false,
"masterPassAllowedEdition": "CA\-en:CA\-fr:CA\-zh",
"youthphase2CRFlag": "true" == "true" ? true : false,
"isCitylistPerfEnabled": "true" == "true" ? true : false,
"isSingleTravelOptionEnabled": "false" == "true" ? true : false,
"retainPaymentInformation": "true" == "true" ? true : false,
"hotelChildAgeCR": "true" == "true" ? true : false,
"displayGeoFirst": "true" == "true" ? true : false,
"displayDiscAvail": "true" == "true" ? true : false,
"premiumRougeUpsell": "true" == "true" ? true : false,
"enableReplaceOpinionLabs": "true" == "true" ? true : false,
"displayOalRef": "true" == "true" ? true : false,
"newTravelOptionsLayoutFlag": "true" == "true" ? true : false,
"hotelWidgetAPI": "true" == "true" ? true : false,
"enableCombinedPhoneNo": "true" == "true" ? true : false,
"hideTripSummaryForMobile": "true" == "true" ? true : false,
"enableSecureAttribute": "true" == "true" ? true : false,
"enhancedPreviewSeatMap": "true" == "true" ? true : false,
"enhancedSeatMap": "true" == "true" ? true : false,
"firstClassCabinCR": "true" == "true" ? true : false,
.
.
}
Taken from aircanada.com. Enjoy!
+1
utf8 = {}
function utf8.charbytes(s, i)
-- argument defaults
i = i or 1
local c = string.byte(s, i)
-- determine bytes needed for character, based on RFC 3629
if c > 0 and c <= 127 then
-- UTF8-1
return 1
elseif c >= 194 and c <= 223 then
-- UTF8-2
local c2 = string.byte(s, i + 1)
return 2
elseif c >= 224 and c <= 239 then
-- UTF8-3
local c2 = s:byte(i + 1)
local c3 = s:byte(i + 2)
return 3
elseif c >= 240 and c <= 244 then
-- UTF8-4
local c2 = s:byte(i + 1)
local c3 = s:byte(i + 2)
local c4 = s:byte(i + 3)
return 4
end
end
function utf8.len(s)
local pos = 1
local bytes = string.len(s)
local len = 0
while pos <= bytes and len ~= chars do
local c = string.byte(s,pos)
len = len + 1
pos = pos + utf8.charbytes(s, pos)
end
if chars ~= nil then
return pos - 1
end
return len
end
print(utf8.len("Аутизм")) --6
local mt = {__len = function(self)
local k=0
for _,v in pairs(self) do
k = k+1;
if k > 1 then print(1) return #self end
end
if k==1 and type(self[1])=="string" then
print(utf8.len(self[k]))
end
end};
setmetatable(_G,{
__index = function(self, key) return setmetatable({key},mt) end}
)
t=(#Аутизм) --12
Чот пытался - но словил хуйца.
+1
<?php
function php2js ($var) {
if (is_array($var)) {
$res = "[";
$array = array();
foreach ($var as $a_var) {
$array[] = php2js($a_var);
}
//return "[" . join(",", $array) . "]";
return "" . join(",", $array) . "";
}
elseif (is_bool($var)) {
return $var ? "true" : "false";
}
elseif (is_int($var) || is_integer($var) || is_double($var) || is_float($var)) {
return $var;
}
elseif (is_string($var)) {
//return "\"" . addslashes(stripslashes($var)) . "\"";
return "" . addslashes(stripslashes($var)) . "";
}
return FALSE;
}
+1
namespace belugina
{
void Simple_Merging_Sort (char *name){
int a1, a2, k, i, j, kol, tmp;
FILE *f, *f1, *f2;
kol = 0;
if ( (f = fopen(name,"r")) == NULL )
printf("\nИсходный файл не может быть прочитан...");
else { while ( !feof(f) ) {
fscanf(f,"%d",&a1);
kol++;
}
fclose(f);
}
k = 1;
while ( k < kol ){
f = fopen(name,"r");
f1 = fopen("smsort_1","w");
f2 = fopen("smsort_2","w");
if ( !feof(f) ) fscanf(f,"%d",&a1);
while ( !feof(f) ){
for ( i = 0; i < k && !feof(f) ; i++ ){
fprintf(f1,"%d ",a1); fscanf(f,"%d",&a1); }
for ( j = 0; j < k && !feof(f) ; j++ ){
fprintf(f2,"%d ",a1); fscanf(f,"%d",&a1);}
}
fclose(f2); fclose(f1); fclose(f);
f = fopen(name,"w"); f1 = fopen("smsort_1","r");
f2 = fopen("smsort_2","r");
if ( !feof(f1) ) fscanf(f1,"%d",&a1);
if ( !feof(f2) ) fscanf(f2,"%d",&a2);
while ( !feof(f1) && !feof(f2) ){
i = 0; j = 0;
while ( i < k && j < k && !feof(f1) && !feof(f2) ) {
if ( a1 < a2 ) {
fprintf(f,"%d ",a1); fscanf(f1,"%d",&a1);i++;}
else {
fprintf(f,"%d ",a2);fscanf(f2,"%d",&a2); j++;}
}
while ( i < k && !feof(f1) ) {
fprintf(f,"%d ",a1); fscanf(f1,"%d",&a1); i++;}
while ( j < k && !feof(f2) ) {
fprintf(f,"%d ",a2); fscanf(f2,"%d",&a2); j++;}
}
while ( !feof(f1) ) {
fprintf(f,"%d ",a1); fscanf(f1,"%d",&a1); }
while ( !feof(f2) ) {
fprintf(f,"%d ",a2); fscanf(f2,"%d",&a2); }
fclose(f2); fclose(f1); fclose(f); k *= 2;
}
remove("smsort_1"); remove("smsort_2");
}
}
Вектор это не динамический массив.
+1
void Merging_Sort (int n, int *x){
int i, j, k, t, s, Fin1, Fin2;
int* tmp = new int[n];
k = 1;
while (k < n){
t = 0; s = 0;
while (t+k < n){
Fin1 = t+k;
Fin2 = (t+2*k < n ? t+2*k : n);
i = t; j = Fin1;
for ( ; i < Fin1 && j < Fin2 ; s++){
if (x[i] < x[j]) {
tmp[s] = x[i]; i++;
} else {
tmp[s] = x[j]; j++;
}
}
for ( ; i < Fin1; i++, s++) tmp[s] = x[i];
for ( ; j < Fin2; j++, s++) tmp[s] = x[j];
t = Fin2;
} k *= 2;
for (s = 0; s < t; s++) x[s] = tmp[s];
}
delete(tmp);
}
Это новый вид искусство?
+1
namespace belugina
{
void Hoar_Sort (int k, int *x){
Quick_Sort (0, k-1, x);}
}
Как вы думаете это новая форма рекурсии?