#_fields
Explore tagged Tumblr posts
Text

👉 I mean Haven’t We all been there?
Birthday Remembrances. Today, Jan 29, 1880 – #WCFields, American actor, singer, and screenwriter (d. 1946) was born.
( https://en.wikipedia.org/wiki/W._C._Fields )
0 notes
Text
@import url(https://fonts.bunny.net/css?family=ibm-plex-sans:400,600); #_form_1_font-size:14px;line-height:1.6;font-family:arial, helvetica, sans-serif;margin:0#_form_1_ *outline:0._form_hidedisplay:none;visibility:hidden._form_showdisplay:block;visibility:visible#_form_1_._form-toptop:0#_form_1_._form-bottombottom:0#_form_1_._form-leftleft:0#_form_1_._form-rightright:0#_form_1_ input[type="text"],#_form_1_ input[type="tel"],#_form_1_ input[type="date"],#_form_1_ textareapadding:6px;height:auto;border:#979797 1px solid;border-radius:4px;color:#000000 !important;font-size:14px;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box#_form_1_ textarearesize:none#_form_1_ ._submit-webkit-appearance:none;cursor:pointer;font-family:arial, sans-serif;font-size:14px;text-align:center;background:#004CFF !important;border:0 !important;-moz-border-radius:4px !important;-webkit-border-radius:4px !important;border-radius:4px !important;color:#FFFFFF !important;padding:10px !important#_form_1_ ._submit:disabledcursor:not-allowed;opacity:0.4#_form_1_ ._submit.processingposition:relative#_form_1_ ._submit.processing::beforecontent:"";width:1em;height:1em;position:absolute;z-index:1;top:50%;left:50%;border:double 3px transparent;border-radius:50%;background-image:linear-gradient(#004CFF, #004CFF), conic-gradient(#004CFF, #FFFFFF);background-origin:border-box;background-clip:content-box, border-box;animation:1200ms ease 0s infinite normal none running _spin#_form_1_ ._submit.processing::aftercontent:"";position:absolute;top:0;bottom:0;left:0;right:0;background:#004CFF !important;border:0 !important;-moz-border-radius:4px !important;-webkit-border-radius:4px !important;border-radius:4px !important;color:#FFFFFF !important;padding:10px !important@keyframes _spin0%transform:translate(-50%, -50%) rotate(90deg)100%transform:translate(-50%, -50%) rotate(450deg)#_form_1_ ._close-iconcursor:pointer;background-image:url("https://d226aj4ao1t61q.cloudfront.net/esfkyjh1u_forms-close-dark.png");background-repeat:no-repeat;background-size:14.2px 14.2px;position:absolute;display:block;top:11px;right:9px;overflow:hidden;width:16.2px;height:16.2px#_form_1_ ._close-icon:beforeposition:relative#_form_1_ ._form-bodymargin-bottom:30px#_form_1_ ._form-image-leftwidth:150px;float:left#_form_1_ ._form-content-rightmargin-left:164px#_form_1_ ._form-brandingcolor:#fff;font-size:10px;clear:both;text-align:left;margin-top:30px;font-weight:100#_form_1_ ._form-branding ._logodisplay:block;width:130px;height:14px;margin-top:6px;background-image:url("https://d226aj4ao1t61q.cloudfront.net/hh9ujqgv5_aclogo_li.png");background-size:130px auto;background-repeat:no-repeat#_form_1_ .form-sr-onlyposition:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0, 0, 0, 0);border:0#_form_1_ ._form-label,#_form_1_ ._form_element ._form-labelfont-weight:bold;margin-bottom:5px;display:block#_form_1_._dark ._form-brandingcolor:#333#_form_1_._dark ._form-branding ._logobackground-image:url("https://d226aj4ao1t61q.cloudfront.net/jftq2c8s_aclogo_dk.png")#_form_1_ ._form_elementposition:relative;margin-bottom:10px;font-size:0;max-width:100%#_form_1_ ._form_element *font-size:14px#_form_1_ ._form_element._clearclear:both;width:100%;float:none#_form_1_ ._form_element._clear:afterclear:left#_form_1_ ._form_element input[type="text"],#_form_1_ ._form_element input[type="date"],#_form_1_ ._form_element select,#_form_1_ ._form_element textarea:not(.g-recaptcha-response)display:block;width:100%;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;font-family:inherit#_form_1_ ._field-wrapperposition:relative#_form_1_ ._inline-stylefloat:left#_form_1_ ._inline-style input[type="text"]width:150px#_form_1_ ._inline-style:not(._clear)+._inline-style:not(._clear)margin-left:20px#_form_1_ ._form_element img._form-imagemax-width:100%#_form_1_ ._form_element ._form-fieldsetborder:0;padding:0.01em 0 0 0;margin:0;min-width:0#_form_1_ ._clear-elementclear:left#_form_1_ .
_full_widthwidth:100%#_form_1_ ._form_full_fielddisplay:block;width:100%;margin-bottom:10px#_form_1_ input[type="text"]._has_error,#_form_1_ textarea._has_errorborder:#F37C7B 1px solid#_form_1_ input[type="checkbox"]._has_erroroutline:#F37C7B 1px solid#_form_1_ ._errordisplay:block;position:absolute;font-size:14px;z-index:10000001#_form_1_ ._error._abovepadding-bottom:4px;bottom:39px;right:0#_form_1_ ._error._belowpadding-top:8px;top:100%;right:0#_form_1_ ._error._above ._error-arrowbottom:-4px;right:15px;border-left:8px solid transparent;border-right:8px solid transparent;border-top:8px solid #FFDDDD#_form_1_ ._error._below ._error-arrowtop:0;right:15px;border-left:8px solid transparent;border-right:8px solid transparent;border-bottom:8px solid #FFDDDD#_form_1_ ._error-innerpadding:12px 12px 12px 36px;background-color:#FFDDDD;background-image:url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 16 16' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M16 8C16 12.4183 12.4183 16 8 16C3.58172 16 0 12.4183 0 8C0 3.58172 3.58172 0 8 0C12.4183 0 16 3.58172 16 8ZM9 3V9H7V3H9ZM9 13V11H7V13H9Z' fill='%23CA0000'/%3E%3C/svg%3E");background-repeat:no-repeat;background-position:12px center;font-size:14px;font-family:arial, sans-serif;font-weight:600;line-height:16px;color:#000;text-align:center;text-decoration:none;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;box-shadow:0px 1px 4px rgba(31, 33, 41, 0.298295)@media only screen and (max-width:319px)#_form_1_ ._error-innerpadding:7px 7px 7px 25px;font-size:12px;line-height:12px;background-position:4px center;max-width:100px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis#_form_1_ ._error-inner._form_errormargin-bottom:5px;text-align:left#_form_1_ ._button-wrapper ._error-inner._form_errorposition:static#_form_1_ ._error-inner._no_arrowmargin-bottom:10px#_form_1_ ._error-arrowposition:absolute;width:0;height:0#_form_1_ ._error-htmlmargin-bottom:10px.pika-singlez-index:10000001 !important#_form_1_ input[type="text"].datetime_datewidth:69%;display:inline#_form_1_ select.datetime_timewidth:29%;display:inline;height:32px#_form_1_ input[type="date"].datetime_datewidth:69%;display:inline-flex#_form_1_ input[type="time"].datetime_timewidth:29%;display:inline-flex@media (min-width:320px) and (max-width:667px)::-webkit-scrollbardisplay:none#_form_1_margin:0;width:100%;min-width:100%;max-width:100%;box-sizing:border-box#_form_1_ *-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;font-size:1em#_form_1_ ._form-contentmargin:0;width:100%#_form_1_ ._form-innerdisplay:block;min-width:100%#_form_1_ ._form-title,#_form_1_ ._inline-stylemargin-top:0;margin-right:0;margin-left:0#_form_1_ ._form-titlefont-size:1.2em#_form_1_ ._form_elementmargin:0 0 20px;padding:0;width:100%#_form_1_ ._form-element,#_form_1_ ._inline-style,#_form_1_ input[type="text"],#_form_1_ label,#_form_1_ p,#_form_1_ textarea:not(.g-recaptcha-response)float:none;display:block;width:100%#_form_1_ ._row._checkbox-radio labeldisplay:inline#_form_1_ ._row,#_form_1_ p,#_form_1_ labelmargin-bottom:0.7em;width:100%#_form_1_ ._row input[type="checkbox"],#_form_1_ ._row input[type="radio"]margin:0 !important;vertical-align:middle !important#_form_1_ ._row input[type="checkbox"]+span labeldisplay:inline#_form_1_ ._row span labelmargin:0 !important;width:initial !important;vertical-align:middle !important#_form_1_ ._form-imagemax-width:100%;height:auto !important#_form_1_ input[type="text"]padding-left:10px;padding-right:10px;font-size:16px;line-height:1.3em;-webkit-appearance:none#_form_1_ input[type="radio"],#_form_1_ input[type="checkbox"]display:inline-block;width:1.3em;height:1.3em;font-size:1em;margin:0 0.3em 0 0;vertical-align:baseline#_form_1_ button[type="submit"]padding:20px;font-size:1.5em#_form_1_ ._inline-stylemargin:20px 0 0 !important#_form_1_ .sms_consent_checkboxoverflow:auto#_form_1_ .sms_consent_checkbox input[type="checkbox"]float:left;margin:5px 10px 10px 0#_form_1_ .
sms_consent_checkbox .sms_consent_messagedisplay:inline;width:95%;float:left;text-align:left;margin-bottom:10px#_form_1_ .sms_consent_checkbox .sms_consent_message.sms_consent_miniwidth:90%#_form_1_position:relative;text-align:left;margin:25px auto 0;padding-top:20px;padding-right:20px;padding-bottom:20px;padding-left:20px;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;background:#FFFFFF !important;border:0px solid #B0B0B0 !important;max-width:500px;-moz-border-radius:0px !important;-webkit-border-radius:0px !important;border-radius:0px !important;color:#000000#_form_1_._inline-form,#_form_1_._inline-form ._form-contentfont-family:"IBM Plex Sans", Helvetica, sans-serif#_form_1_._inline-form ._row span,#_form_1_._inline-form ._row labelfont-family:"IBM Plex Sans", Helvetica, sans-serif;font-size:14px;font-weight:400;line-height:1.6em#_form_1__inlineform input[type="text"],#_form_1__inlineform input[type="date"],#_form_1__inlineform input[type="tel"],#_form_1__inlineform select,#_form_1__inlineform textarea:not(.g-recaptcha-response)font-family:"IBM Plex Sans", Helvetica, sans-serif;font-size:14px;font-weight:400;font-color:#000000;line-height:1.6em#_form_1_._inline-form ._html-code *:not(h1, h2, h3, h4, h5, h6),#_form_1_._inline-form ._form-thank-youfont-family:"IBM Plex Sans", Helvetica, sans-serif#_form_1_._inline-form ._form-label,#_form_1_._inline-form ._form-emailidentifier,#_form_1_._inline-form ._form-checkbox-option-labelfont-family:"IBM Plex Sans", Helvetica, sans-serif;font-size:14px;font-weight:700;line-height:1.6em#_form_1_._inline-form ._submitmargin-top:12px;font-family:"IBM Plex Sans", Helvetica, sans-serif#_form_1_._inline-form ._html-code h1,#_form_1_._inline-form ._html-code h2,#_form_1_._inline-form ._html-code h3,#_form_1_._inline-form ._html-code h4,#_form_1_._inline-form ._html-code h5,#_form_1_._inline-form ._html-code h6,#_form_1_._inline-form ._form-titlefont-size:22px;line-height:normal;font-weight:600;margin-bottom:0#_form_1_._inline-form ._form-brandingfont-family:"IBM Plex Sans", Helvetica, sans-serif;font-size:13px;font-weight:100;font-style:normal;text-decoration:none#_form_1_:before,#_form_1_:aftercontent:" ";display:table#_form_1_:afterclear:both#_form_1_._inline-stylewidth:auto;display:inline-block#_form_1_._inline-style input[type="text"],#_form_1_._inline-style input[type="date"]padding:10px 12px#_form_1_._inline-style button._inline-styleposition:relative;top:27px#_form_1_._inline-style pmargin:0#_form_1_._inline-style ._button-wrapperposition:relative;margin:16px 12.5px 0 20px#_form_1_ ._form-thank-youposition:relative;left:0;right:0;text-align:center;font-size:18px#_form_1_ ._form-pc-confirmation ._submitmargin-top:16px@media (min-width:320px) and (max-width:667px)#_form_1_._inline-form._inline-style ._inline-style._button-wrappermargin-top:20px !important;margin-left:0 !important#_form_1_ .iti.iti--allow-dropdown.iti--separate-dial-codewidth:100%#_form_1_ .iti inputwidth:100%;height:32px;border:#979797 1px solid;border-radius:4px#_form_1_ .iti--separate-dial-code .iti__selected-flagbackground-color:#FFFFFF;border-radius:4px#_form_1_ .iti--separate-dial-code .iti__selected-flag:hoverbackground-color:rgba(0, 0, 0, 0.05)#_form_1_ .iti__country-listborder-radius:4px;margin-top:4px;min-width:460px#_form_1_ .iti__country-list--dropupmargin-bottom:4px#_form_1_ .phone-error-hiddendisplay:none#_form_1_ .phone-errorcolor:#E40E49#_form_1_ .phone-input-errorborder:1px solid #E40E49 !important#_form_1_._inline-form ._form-content ._form-list-subscriptions-field fieldsetmargin:0;margin-bottom:1.1428571429em;border:none;padding:0#_form_1_._inline-form ._form-content ._form-list-subscriptions-field fieldset:last-childmargin-bottom:0#_form_1_._inline-form ._form-content ._form-list-subscriptions-field legendmargin-bottom:1.1428571429em#_form_1_._inline-form ._form-content ._form-list-subscriptions-field labeldisplay:flex;align-items:flex-start;justify-content:flex-start;margin-bottom:0.
8571428571em#_form_1_._inline-form ._form-content ._form-list-subscriptions-field label:last-childmargin-bottom:0#_form_1_._inline-form ._form-content ._form-list-subscriptions-field inputmargin:0;margin-right:8px#_form_1_._inline-form ._form-content ._form-list-subscriptions-field ._form-checkbox-option-labeldisplay:block;font-weight:400;margin-top:-4px#_form_1_._inline-form ._form-content ._form-list-subscriptions-field ._form-checkbox-option-label-with-descriptiondisplay:block;font-weight:700;margin-top:-4px#_form_1_._inline-form ._form-content ._form-list-subscriptions-field ._form-checkbox-option-descriptionmargin:0;font-size:0.8571428571em#_form_1_._inline-form ._form-content ._form-list-subscriptions-field ._form-subscriptions-unsubscribe-all-descriptionline-height:normal;margin-top:-2px Suscribirse para recibir novedades por correo Añada un mensaje descriptivo en el que se informe al visitante sobre el registro. Nombre completo Correo electrónico* Enviar Marketing por ActiveCampaign window.cfields = []; window._show_thank_you = function(id, message, trackcmp_url, email) var form = document.getElementById('_form_' + id + '_'), thank_you = form.querySelector('._form-thank-you'); form.querySelector('._form-content').style.display = 'none'; thank_you.innerHTML = message; thank_you.style.display = 'block'; const vgoAlias = typeof visitorGlobalObjectAlias === 'undefined' ? 'vgo' : visitorGlobalObjectAlias; var visitorObject = window[vgoAlias]; if (email && typeof visitorObject !== 'undefined') visitorObject('setEmail', email); visitorObject('update'); else if (typeof(trackcmp_url) != 'undefined' && trackcmp_url) // Site tracking URL to use after inline form submission. _load_script(trackcmp_url); if (typeof window._form_callback !== 'undefined') window._form_callback(id); ; window._show_unsubscribe = function(id, message, trackcmp_url, email) var form = document.getElementById('_form_' + id + '_'), unsub = form.querySelector('._form-thank-you'); var branding = form.querySelector('._form-branding'); if (branding) branding.style.display = 'none'; form.querySelector('._form-content').style.display = 'none'; unsub.style.display = 'block'; form.insertAdjacentHTML('afterend', message) const vgoAlias = typeof visitorGlobalObjectAlias === 'undefined' ? 'vgo' : visitorGlobalObjectAlias; var visitorObject = window[vgoAlias]; if (email && typeof visitorObject !== 'undefined') visitorObject('setEmail', email); visitorObject('update'); else if (typeof(trackcmp_url) != 'undefined' && trackcmp_url) // Site tracking URL to use after inline form submission. _load_script(trackcmp_url); if (typeof window._form_callback !== 'undefined') window._form_callback(id); ; window._show_error = function(id, message, html) var form = document.getElementById('_form_' + id + '_'), err = document.createElement('div'), button = form.querySelector('button'), old_error = form.querySelector('._form_error'); if (old_error) old_error.parentNode.removeChild(old_error); err.innerHTML = message; err.className = '_error-inner _form_error _no_arrow'; var wrapper = document.createElement('div'); wrapper.className = '_form-inner'; wrapper.appendChild(err); button.parentNode.insertBefore(wrapper, button); var submitButton = form.querySelector('[id^="_form"][id$="_submit"]'); submitButton.disabled = false; submitButton.classList.remove('processing'); if (html) var div = document.createElement('div');
div.className = '_error-html'; div.innerHTML = html; err.appendChild(div); ; window._show_pc_confirmation = function(id, header, detail, show, email) var form = document.getElementById('_form_' + id + '_'), pc_confirmation = form.querySelector('._form-pc-confirmation'); if (pc_confirmation.style.display === 'none') form.querySelector('._form-content').style.display = 'none'; pc_confirmation.innerHTML = "" + header + "" + "" + detail + "" + "Administrar preferencias"; pc_confirmation.style.display = 'block'; var mp = document.querySelector('input[name="mp"]'); mp.value = '0'; else form.querySelector('._form-content').style.display = 'inline'; pc_confirmation.style.display = 'none'; var hideButton = document.getElementById('hideButton'); // Add event listener to the button hideButton.addEventListener('click', function() var submitButton = document.querySelector('#_form_1_submit'); submitButton.disabled = false; submitButton.classList.remove('processing'); var mp = document.querySelector('input[name="mp"]'); mp.value = '1'; const cacheBuster = new URL(window.location.href); cacheBuster.searchParams.set('v', new Date().getTime()); window.location.href = cacheBuster.toString(); ); const vgoAlias = typeof visitorGlobalObjectAlias === 'undefined' ? 'vgo' : visitorGlobalObjectAlias; var visitorObject = window[vgoAlias]; if (email && typeof visitorObject !== 'undefined') visitorObject('setEmail', email); visitorObject('update'); else if (typeof(trackcmp_url) != 'undefined' && trackcmp_url) // Site tracking URL to use after inline form submission. _load_script(trackcmp_url); if (typeof window._form_callback !== 'undefined') window._form_callback(id); ; window._load_script = function(url, callback, isSubmit) var head = document.querySelector('head'), script = document.createElement('script'), r = false; var submitButton = document.querySelector('#_form_1_submit'); script.charset = 'utf-8'; script.src = url; if (callback) script.onload = script.onreadystatechange = function() this.readyState == 'complete')) r = true; callback(); ; script.onerror = function() if (isSubmit) if (script.src.length > 10000) _show_error("1", "Lo sentimos, ocurrió un error con el envío. Acorta tus respuestas y vuelve a intentarlo."); else _show_error("1", "Lo sentimos, ocurrió un error con el envío. Vuelve a intentarlo."); submitButton.disabled = false; submitButton.classList.remove('processing'); head.appendChild(script); ; (function() if (window.location.search.search("excludeform") !== -1) return false; var getCookie = function(name) ; )' + name + '=([^;]+)')); return match ? match[2] : null; var setCookie = function(name, value) var now = new Date(); var time = now.getTime(); var expireTime = time + 1000 * 60 * 60 * 24 * 365; now.setTime(expireTime); document.cookie = name + '=' + value + '; expires=' + now + ';path=/; Secure; SameSite=Lax;'; var addEvent = function(element, event, func) if (element.addEventListener) element.addEventListener(event, func); else var oldFunc = element['on' + event]; element['on' + event] = function() oldFunc.apply(this, arguments); func.apply(this, arguments); ; var _removed = false; var form_to_submit = document.getElementById('_form_1_'); var allInputs = form_to_submit.querySelectorAll('input, select, textarea'), tooltips = [], submitted = false;
var getUrlParam = function(name) if (name.toLowerCase() !== 'email') false; // email is a special case because a plus is valid in the email address var qString = window.location.search; if (!qString) return false; var parameters = qString.substr(1).split('&'); for (var i = 0; i < parameters.length; i++) var parameter = parameters[i].split('='); if (parameter[0].toLowerCase() === 'email') return parameter[1] === undefined ? true : decodeURIComponent(parameter[1]); return false; ; var acctDateFormat = "%m/%d/%Y"; var getNormalizedDate = function(date, acctFormat) %e).*%m/gi) !== null) return decodedDate.replace(/(\d2).*(\d2).*(\d4)/g, '$3-$2-$1'); else if (Date.parse(decodedDate)) var dateObj = new Date(decodedDate); var year = dateObj.getFullYear(); var month = dateObj.getMonth() + 1; var day = dateObj.getDate(); return `$year-$month < 10 ? `0$month` : month-$day < 10 ? `0$day` : day`; return false; ; var getNormalizedTime = function(time) var hour, minutes; var decodedTime = decodeURIComponent(time); var timeParts = Array.from(decodedTime.matchAll(/(\d1,2):(\d1,2)\W*([AaPp][Mm])?/gm))[0]; if (timeParts[3]) // 12 hour format var isPM = timeParts[3].toLowerCase() === 'pm'; if (isPM) hour = parseInt(timeParts[1]) === 12 ? '12' : `$parseInt(timeParts[1]) + 12`; else hour = parseInt(timeParts[1]) === 12 ? '0' : timeParts[1]; else // 24 hour format hour = timeParts[1]; var normalizedHour = parseInt(hour) < 10 ? `0$parseInt(hour)` : hour; var minutes = timeParts[2]; return `$normalizedHour:$minutes`; ; for (var i = 0; i < allInputs.length; i++) var regexStr = "field\\[(\\d+)\\]"; var results = new RegExp(regexStr).exec(allInputs[i].name); if (results != undefined) allInputs[i].dataset.name = allInputs[i].name.match(/\[time\]$/) ? `$window.cfields[results[1]]_time` : window.cfields[results[1]]; else allInputs[i].dataset.name = allInputs[i].name; var fieldVal = getUrlParam(allInputs[i].dataset.name); if (fieldVal) allInputs[i].type == "checkbox") if (allInputs[i].value == fieldVal) allInputs[i].checked = true; else if (allInputs[i].type == "date") allInputs[i].value = getNormalizedDate(fieldVal, acctDateFormat); else if (allInputs[i].type == "time") allInputs[i].value = getNormalizedTime(fieldVal); else allInputs[i].value = fieldVal; var remove_tooltips = function() for (var i = 0; i < tooltips.length; i++) tooltips[i].tip.parentNode.removeChild(tooltips[i].tip); tooltips = []; ; var remove_tooltip = function(elem) for (var i = 0; i < tooltips.length; i++) if (tooltips[i].elem === elem) tooltips[i].tip.parentNode.removeChild(tooltips[i].tip); tooltips.splice(i, 1); return; ; var create_tooltip = function(elem, text) var tooltip = document.createElement('div'), arrow = document.createElement('div'), inner = document.createElement('div'), new_tooltip = ; if (elem.type != 'radio' && elem.type != 'checkbox') tooltip.className = '_error'; arrow.className = '_error-arrow'; inner.className = '_error-inner'; inner.innerHTML = text; tooltip.appendChild(arrow);
tooltip.appendChild(inner); elem.parentNode.appendChild(tooltip); else tooltip.className = '_error-inner _no_arrow'; tooltip.innerHTML = text; elem.parentNode.insertBefore(tooltip, elem); new_tooltip.no_arrow = true; new_tooltip.tip = tooltip; new_tooltip.elem = elem; tooltips.push(new_tooltip); return new_tooltip; ; var resize_tooltip = function(tooltip) doc.scrollTop) - (doc.clientTop ; var resize_tooltips = function() if (_removed) return; for (var i = 0; i < tooltips.length; i++) if (!tooltips[i].no_arrow) resize_tooltip(tooltips[i]); ; var validate_field = function(elem, remove) elem.id == 'ca[11][v]')) if (elem.className.includes('phone-input-error')) elem.className = elem.className + ' _has_error'; no_error = false; if (no_error && elem.name == 'email') if (!value.match(/^[\+_a-z0-9-'&=]+(\.[\+_a-z0-9-']+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]2,)$/i)) elem.className = elem.className + ' _has_error'; no_error = false; tooltip = create_tooltip(elem, "Introduzca una dirección de correo electrónico válida."); if (no_error && /date_field/.test(elem.className)) if (!value.match(/^\d\d\d\d-\d\d-\d\d$/)) elem.className = elem.className + ' _has_error'; no_error = false; tooltip = create_tooltip(elem, "Introduzca una fecha válida."); tooltip ? resize_tooltip(tooltip) : false; return no_error; ; var needs_validate = function(el) ; var validate_form = function(e) var err = form_to_submit.querySelector('._form_error'), no_error = true; if (!submitted) submitted = true; for (var i = 0, len = allInputs.length; i < len; i++) var input = allInputs[i]; if (needs_validate(input)) input.type == 'time') addEvent(input, 'blur', function() this.value = this.value.trim(); validate_field(this, true); ); addEvent(input, 'input', function() validate_field(this, true); ); else if (input.type == 'radio' remove_tooltips(); for (var i = 0, len = allInputs.length; i < len; i++) var elem = allInputs[i]; if (needs_validate(elem)) if (elem.tagName.toLowerCase() !== "select") elem.value = elem.value.trim(); validate_field(elem) ? true : no_error = false; if (!no_error && e) e.preventDefault(); resize_tooltips(); return no_error; ; addEvent(window, 'resize', resize_tooltips); addEvent(window, 'scroll', resize_tooltips); var hidePhoneInputError = function(inputId) var errorMessage = document.getElementById("error-msg-" + inputId); var input = document.getElementById(inputId); errorMessage.classList.remove("phone-error"); errorMessage.classList.add("phone-error-hidden"); input.classList.remove("phone-input-error"); ; var initializePhoneInput = function(input, defaultCountry) return window.intlTelInput(input, utilsScript: "https://unpkg.com/[email protected]/build/js/utils.js", autoHideDialCode: false, separateDialCode: true, initialCountry: defaultCountry, preferredCountries: [] ); var setPhoneInputEventListeners = function(inputId, input, iti) input.addEventListener('blur', function()
var errorMessage = document.getElementById("error-msg-" + inputId); if (input.value.trim()) if (iti.isValidNumber()) iti.setNumber(iti.getNumber()); if (errorMessage.classList.contains("phone-error")) hidePhoneInputError(inputId); else showPhoneInputError(inputId) else if (errorMessage.classList.contains("phone-error")) hidePhoneInputError(inputId); ); input.addEventListener("countrychange", function() iti.setNumber(''); ); input.addEventListener("keydown", function(e) var charCode = (e.which) ? e.which : e.keyCode; if (charCode > 31 && (charCode < 48 ); ; var showPhoneInputError = function(inputId) var errorMessage = document.getElementById("error-msg-" + inputId); var input = document.getElementById(inputId); errorMessage.classList.add("phone-error"); errorMessage.classList.remove("phone-error-hidden"); input.classList.add("phone-input-error"); ; var _form_serialize = function(form); const formSupportsPost = false; var form_submit = function(e) e.preventDefault(); if (validate_form()) // use this trick to get the submit button & disable it using plain javascript var submitButton = e.target.querySelector('#_form_1_submit'); submitButton.disabled = true; submitButton.classList.add('processing'); var serialized = _form_serialize( document.getElementById('_form_1_') ).replace(/%0A/g, '\\n'); var err = form_to_submit.querySelector('._form_error'); err ? err.parentNode.removeChild(err) : false; async function submitForm() var formData = new FormData(); const searchParams = new URLSearchParams(serialized); searchParams.forEach((value, key) => if (key !== 'hideButton') formData.append(key, value); //formData.append(key, value); ); let request = headers: "Accept": "application/json" , body: formData, method: "POST" ; let pageUrlParams = new URLSearchParams(window.location.search); if (pageUrlParams.has('t')) request.headers.Authorization = 'Bearer ' + pageUrlParams.get('t'); const response = await fetch('https://kampa5569.activehosted.com/proc.php?jsonp=true', request); return response.json(); if (formSupportsPost) submitForm().then((data) => eval(data.js); ); else _load_script('https://kampa5569.activehosted.com/proc.php?' + serialized + '&jsonp=true', null, true); return false; ; addEvent(form_to_submit, 'submit', form_submit); )();
0 notes
Text
0 notes
Text
namedtuple in Python
namedtuple in Python: The namedtuple method returns a tuple-like object with fields accessible with named indexes and the integer indexes of normal tuples. The biggest problem with ordinary tuples is that you have to remember the index of each field.....
The namedtuple method returns a tuple-like object with fields accessible with namedindexes and the integer indexes of normal tuples. The biggest problem with ordinary tuples is that you have to remember the index of each field of a tuple object so namedtuple() helps to remember the index of each field of a tuple object in ordinary tuples. It can be especially useful in an application where there…
View On WordPress
0 notes
Text
i wish i had the time/energy to make one of those videos set to the hall of the mountain king abt the chair catastrophe happening on "philosophy twitter"
#i personally find it unbearably corny to talk abt “_field/occupation/religion__ twitter” but yknow#tep.txt
40 notes
·
View notes
Photo

*I mean Haven’t We all been there? Birthday Remembrances. Today, Jan 29, 1880 – W. C. Fields, American actor, singer, and screenwriter (d. 1946) was born. (https://en.wikipedia.org/wiki/W._C._Fields)
2 notes
·
View notes
Text
ESP32 Arduino Tutorial 25-3. Protocol buffers: Encoding a DS18B20 temperature measurement
Introduction
In this tutorial we will check how to obtain a measurement from the DS18B20 temperature sensor and encode it using protocol buffers. We will be using the ESP32 and the Arduino core.
For an introduction on Nanopb, the protocol buffers library we are going to use, please check this previous tutorial. It explains how to install the library on the Arduino core and how to generate the message definitions from the .proto file.
For an introductory tutorial on the DS18B20 and how to connect it to the ESP32, please check here. The post also explains how to install the needed libraries.
So, for this tutorial, we will move one step forward and start using real measurements in our protobuf messages, since so far we have only been using dummy data. We will be fetching the measurements periodically and generating the corresponding protobuf messages.
The tests were performed using a DFRobot’s ESP32 module integrated in a ESP32 development board and a waterproof version of the sensor.
The .proto
Before we start coding, we need to define our message type, in a .proto file. We will be using the proto2 syntax.
We will call our message type “MeasurementMessage“. Its definition will be very simple since it will only contain a float field called “temperature“.
Since we only have one field, we will assign it the unique number 1. Additionally, our field will be required.
The final content of the .proto file can be seen below. As covered in the introductory tutorial, we need to compile our .proto file with the protoc compiler, in order to obtain the .h and .c files containing the message definitions and all the utilities needed to encode the message.
syntax = "proto2"; message MeasurementMessage { required float temperature = 1; }
I’ve called my file MeasurementMessage.proto, which means that the compilation procedure will generate the two following files:
MeasurementMessage.pb.h
MeasurementMessage.pb.c
As explained in the already mentioned tutorial, we should navigate to the Arduino sketch folder, create a new folder called “src“ and paste the generated files there, so we can import them in the Arduino code.
The code
As usual, we will start our code by the includes. The first one will be the include of the .h file created by the protoc compiler, which contains the C struct with our message definition. Recall that the .h and the .c files were placed in a folder called src, so we need to use that path in our include.
#include "src/MeasurementMessage.pb.h"
Followed by that, we should include the Nanopb library files.
#include "pb_common.h" #include "pb.h" #include "pb_encode.h"
To finalize the includes, we need the OneWire.h and the DallasTemperature.h, which are both used to interact with the DS18B20.
#include "OneWire.h" #include "DallasTemperature.h"
Next, we need an object of class OneWire, which is used under the hood by the DallasTemperature.h library to exchange data with the temperature sensor. As input, the constructor of this class receives the number of the microcontroller pin that is connected to the DS18B20. In my case, I’m using pin 22, but you can test with other pins.
Additionally, we will need to instantiate an object of class DallasTemperature, which is the one we are going to use to fetch our temperature measurements. The constructor of this class receives as input the address of our previously declared OneWire object.
OneWire oneWire(22); DallasTemperature tempSensor(&oneWire);
Moving to the setup function, we start by opening a serial connection, so we can output the messages generated by our program.
Additionally, we will call the begin method on our DallasTemperature object, in order for it to initialize the OneWire bus.
The whole setup function can be seen below.
void setup() { Serial.begin(115200); tempSensor.begin(); }
We will take care of obtaining the measurements and serializing them to the protobuf binary format on the Arduino main loop.
So, we will start by declaring a byte buffer to hold our serialized message. We will declare a buffer with 30 bytes, which is more than enough to accommodate our message.
After that, we will declare our message and initialize it. Recall from the previous tutorial that the name of the generated C struct is the same of the message type name defined in the .proto file, which means the struct is called MeasurementMessage.
We will also take advantage of the define that is generated during the compiling procedure, which allows to initialize the message. Recall that this define has the name of the message followed by “_init_zero“. You can confirm what this define does by looking into the MeasurementMessage.pb.h file.
uint8_t buffer[30]; MeasurementMessage message = MeasurementMessage_init_zero;
Next we will create the stream that is needed to write the serialized message to the memory buffer we just declared. We do this by calling the pb_ostream_from_buffer function, passing as first input the buffer and as second its size.
As output, the function will return a struct of type pb_ostream_t, which we will use later.
pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer));
Before we serialize the message, we need to assign the temperature measurement obtained from the DS18B20 to the message temperature field.
To start a temperature conversion, we will first call the requestTemperaturesByIndex method of the DallasTemperature object, passing as input the index of the sensor we want to use. Since we have only one sensor attached to the OneWire bus, we use the index 0.
Finally, to obtain the actual temperature measurement, we call the getTempCByIndex method on the same object, passing as input also the index 0.
This method returns as output the temperature in degrees Celsius as a float, which means we can directly assign the value to the temperature field of our message struct.
tempSensor.requestTemperaturesByIndex(0); message.temperature = tempSensor.getTempCByIndex(0);
Now that we have the measurement assigned to our message temperature field, we can take care of the serialization procedure. So, to serialize the struct, we call the pb_encode function.
As first input, the function receives the address of our previously created stream. As second input, we need to pass the automatically generated fields description array, which has the name of the message appended by “_fields“. As third and final parameter, we pass the address of our message.
Note that this function call returns as output a Boolean value indicating if the procedure was successful (true) or not (false), which we will leverage for error checking.
bool status = pb_encode(&stream, MeasurementMessage_fields, &message); if (!status) { Serial.println("Failed to encode"); return; }
To finalize the code, we will print the temperature obtained from the sensor, so we can confirm it matches what is being encoded in the message. We can directly access the temperature value of our C struct.
Note that we will be printing the measurement with 2 decimal places, which is the default when we pass a float to the println method of the Serial object. If you want to use more decimal places, the println method can receive an additional value specifying how many decimal places should be used.
Serial.print("Temperature: "); Serial.println(message.temperature);
After that, we will print the encoded message in hexadecimal format.
Serial.print("Message: "); for(int i = 0; i<stream.bytes_written; i++){ Serial.printf("%02X",buffer[i]); }
The final code can be seen below. It already includes a 10 seconds delay between each iteration of the Arduino loop.
#include "src/MeasurementMessage.pb.h" #include "pb_common.h" #include "pb.h" #include "pb_encode.h" #include "OneWire.h" #include "DallasTemperature.h" OneWire oneWire(22); DallasTemperature tempSensor(&oneWire); void setup() { Serial.begin(115200); tempSensor.begin(); } void loop() { uint8_t buffer[30]; MeasurementMessage message = MeasurementMessage_init_zero; pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer)); tempSensor.requestTemperaturesByIndex(0); message.temperature = tempSensor.getTempCByIndex(0); bool status = pb_encode(&stream, MeasurementMessage_fields, &message); if (!status) { Serial.println("Failed to encode"); return; } Serial.print("Temperature: "); Serial.println(message.temperature); Serial.print("Message: "); for(int i = 0; i<stream.bytes_written; i++){ Serial.printf("%02X",buffer[i]); } Serial.println(); delay(10000); }
Testing the code
To test the code, simply compile it and upload it to your ESP32 board, after finishing all the connections to the sensor. Once the procedure finishes, open the Arduino IDE serial monitor. You should get an output similar to figure 1, which shows the temperature measurements and the corresponding protobuf messages being periodically printed.
Figure 1 – Output of the program.
You can copy the messages and use this online tool to decode them and compare their value against the temperature measurements, as shown in figure 2. Nonetheless, recall that we have only used two decimal places when printing the temperature measurements directly but we did not change anything in the serialized value, so there may be a small difference in the values.
Figure 2 – Decoding one of the messages.
0 notes
Link
Several months ago, Brad Pitt and Jennifer Aniston established, in secret, in the novel, who lived in the past, and now, when we all thought that the relationship was stronger than ever, the star of `` Friends he got tired of some of the actor's actions, and asked for time to give. According to the magazine `` Heat '', the evil being raised before the actors, they go in isolation, in which case Brad Pitt should leave in a manner consistent with the friend, Alia Shawkat, and with a variety of sources for reflect an approach to love between the two. "She already told Brad that they had better be separated, to let him know what you want!"he begins by explaining a source close to the actress, adding that about forty only confirms the distance between the two actors. "They are in separate houses, and if the relationship was not good, the fact is that this separation does not help. They are further than ever, and Brad Pitt takes advantage of this period to try to have a good time with the children. "Children ask to go outThe truth is that Brad Pitt has been a big privacy concern, as the parents of six children, in common with Angelina Jolie, have expressed a desire to spend more time with his father, due to pressure from the series. "For them, it is not easy to spend this time with her mother, because after all, Angelina has a business and it is difficult. Brad is therefore trying to manage the conflict remotely and bring the children closer to him, ”explains the source. window.fbAsyncInit = function () FB.init( appId: '228623943821084', xfbml: true, version: 'v3.2' ); ; (function (d, s, id) var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "https://connect.facebook.net/en_US/sdk.js"; fjs.parentNode.insertBefore(js, fjs); (document, 'script', 'facebook-jssdk')); var $_fields = ; !function (f, b, e, v, n, t, s) if (f.fbq) return; n = f.fbq = function () n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments) ; if (!f._fbq) f._fbq = n; n.push = n; n.loaded = !0; n.version = '2.0'; n.queue = []; t = b.createElement(e); t.async = !0; t.src = v; s = b.getElementsByTagName(e)[0]; s.parentNode.insertBefore(t, s) (window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js'); fbq('init', '211806875838166'); fbq('track', 'PageView'); https://oltnews.com/jennifer-aniston-suspected-of-cheating-and-it-comes-back-to-brad-pitt-the-liver-matzav-review?_unique_id=5e9d3b941026f
0 notes
Text
Get Started
#_form_1_ { font-size:14px; line-height:1.6; font-family:arial, helvetica, sans-serif; margin:0; } #_form_1_ * { outline:0; } ._form_hide { display:none; visibility:hidden; } ._form_show { display:block; visibility:visible; } #_form_1_._form-top { top:0; } #_form_1_._form-bottom { bottom:0; } #_form_1_._form-left { left:0; } #_form_1_._form-right { right:0; } #_form_1_ input[type="text"],#_form_1_ input[type="date"],#_form_1_ textarea { padding:6px; height:auto; border:#979797 1px solid; border-radius:4px; color:#000 !important; font-size:13px; -webkit-box-sizing:border-box; -moz-box-sizing:border-box; box-sizing:border-box; } #_form_1_ textarea { resize:none; } #_form_1_ ._submit { -webkit-appearance:none; cursor:pointer; font-family:arial, sans-serif; font-size:14px; text-align:center; background:#333 !important; border:0 !important; -moz-border-radius:4px !important; -webkit-border-radius:4px !important; border-radius:4px !important; color:#fff !important; padding:10px !important; } #_form_1_ ._close-icon { cursor:pointer; background-image:url('https://d226aj4ao1t61q.cloudfront.net/esfkyjh1u_forms-close-dark.png'); background-repeat:no-repeat; background-size:14.2px 14.2px; position:absolute; display:block; top:11px; right:9px; overflow:hidden; width:16.2px; height:16.2px; } #_form_1_ ._close-icon:before { position:relative; } #_form_1_ ._form-body { margin-bottom:30px; } #_form_1_ ._form-image-left { width:150px; float:left; } #_form_1_ ._form-content-right { margin-left:164px; } #_form_1_ ._form-branding { color:#fff; font-size:10px; clear:both; text-align:left; margin-top:30px; font-weight:100; } #_form_1_ ._form-branding ._logo { display:block; width:130px; height:14px; margin-top:6px; background-image:url('https://d226aj4ao1t61q.cloudfront.net/hh9ujqgv5_aclogo_li.png'); background-size:130px auto; background-repeat:no-repeat; } #_form_1_ ._form-label,#_form_1_ ._form_element ._form-label { font-weight:bold; margin-bottom:5px; display:block; } #_form_1_._dark ._form-branding { color:#333; } #_form_1_._dark ._form-branding ._logo { background-image:url('https://d226aj4ao1t61q.cloudfront.net/jftq2c8s_aclogo_dk.png'); } #_form_1_ ._form_element { position:relative; margin-bottom:10px; font-size:0; max-width:100%; } #_form_1_ ._form_element * { font-size:14px; } #_form_1_ ._form_element._clear { clear:both; width:100%; float:none; } #_form_1_ ._form_element._clear:after { clear:left; } #_form_1_ ._form_element input[type="text"],#_form_1_ ._form_element input[type="date"],#_form_1_ ._form_element select,#_form_1_ ._form_element textarea:not(.g-recaptcha-response) { display:block; width:100%; -webkit-box-sizing:border-box; -moz-box-sizing:border-box; box-sizing:border-box; } #_form_1_ ._field-wrapper { position:relative; } #_form_1_ ._inline-style { float:left; } #_form_1_ ._inline-style input[type="text"] { width:150px; } #_form_1_ ._inline-style:not(._clear) + ._inline-style:not(._clear) { margin-left:20px; } #_form_1_ ._form_element img._form-image { max-width:100%; } #_form_1_ ._clear-element { clear:left; } #_form_1_ ._full_width { width:100%; } #_form_1_ ._form_full_field { display:block; width:100%; margin-bottom:10px; } #_form_1_ input[type="text"]._has_error,#_form_1_ textarea._has_error { border:#f37c7b 1px solid; } #_form_1_ input[type="checkbox"]._has_error { outline:#f37c7b 1px solid; } #_form_1_ ._error { display:block; position:absolute; font-size:13px; z-index:10000001; } #_form_1_ ._error._above { padding-bottom:4px; top:-41px; right:0; } #_form_1_ ._error._below { padding-top:4px; top:100%; right:0; } #_form_1_ ._error._above ._error-arrow { bottom:0; right:15px; border-left:5px solid transparent; border-right:5px solid transparent; border-top:5px solid #f37c7b; } #_form_1_ ._error._below ._error-arrow { top:0; right:15px; border-left:5px solid transparent; border-right:5px solid transparent; border-bottom:5px solid #f37c7b; } #_form_1_ ._error-inner { padding:8px 12px; background-color:#f37c7b; font-size:13px; font-family:arial, sans-serif; color:#fff; text-align:center; text-decoration:none; -webkit-border-radius:4px; -moz-border-radius:4px; border-radius:4px; } #_form_1_ ._error-inner._form_error { margin-bottom:5px; text-align:left; } #_form_1_ ._button-wrapper ._error-inner._form_error { position:static; } #_form_1_ ._error-inner._no_arrow { margin-bottom:10px; } #_form_1_ ._error-arrow { position:absolute; width:0; height:0; } #_form_1_ ._error-html { margin-bottom:10px; } .pika-single { z-index:10000001 !important; } @media all and (min-width:320px) and (max-width:667px) { ::-webkit-scrollbar { display:none; } #_form_1_ { margin:0; width:100%; min-width:100%; max-width:100%; box-sizing:border-box; } #_form_1_ * { -webkit-box-sizing:border-box; -moz-box-sizing:border-box; box-sizing:border-box; font-size:1em; } #_form_1_ ._form-content { margin:0; width:100%; } #_form_1_ ._form-inner { display:block; min-width:100%; } #_form_1_ ._form-title,#_form_1_ ._inline-style { margin-top:0; margin-right:0; margin-left:0; } #_form_1_ ._form-title { font-size:1.2em; } #_form_1_ ._form_element { margin:0 0 20px; padding:0; width:100%; } #_form_1_ ._form-element,#_form_1_ ._inline-style,#_form_1_ input[type="text"],#_form_1_ label,#_form_1_ p,#_form_1_ textarea:not(.g-recaptcha-response) { float:none; display:block; width:100%; } #_form_1_ ._row._checkbox-radio label { display:inline; } #_form_1_ ._row,#_form_1_ p,#_form_1_ label { margin-bottom:0.7em; width:100%; } #_form_1_ ._row input[type="checkbox"],#_form_1_ ._row input[type="radio"] { margin:0 !important; vertical-align:middle !important; } #_form_1_ ._row input[type="checkbox"] + span label { display:inline; } #_form_1_ ._row span label { margin:0 !important; width:initial !important; vertical-align:middle !important; } #_form_1_ ._form-image { max-width:100%; height:auto !important; } #_form_1_ input[type="text"] { padding-left:10px; padding-right:10px; font-size:16px; line-height:1.3em; -webkit-appearance:none; } #_form_1_ input[type="radio"],#_form_1_ input[type="checkbox"] { display:inline-block; width:1.3em; height:1.3em; font-size:1em; margin:0 0.3em 0 0; vertical-align:baseline; } #_form_1_ button[type="submit"] { padding:20px; font-size:1.5em; } #_form_1_ ._inline-style { margin:20px 0 0 !important; } } #_form_1_ { position:relative; text-align:left; margin:25px auto 0; padding:20px; -webkit-box-sizing:border-box; -moz-box-sizing:border-box; box-sizing:border-box; *zoom:1; background:#fff !important; border:0px solid #b0b0b0 !important; width:500px; -moz-border-radius:0px !important; -webkit-border-radius:0px !important; border-radius:0px !important; color:#000 !important; } #_form_1_ ._form-title { font-size:22px; line-height:22px; font-weight:600; margin-bottom:0; } #_form_1_:before,#_form_1_:after { content:" "; display:table; } #_form_1_:after { clear:both; } #_form_1_._inline-style { width:auto; display:inline-block; } #_form_1_._inline-style input[type="text"],#_form_1_._inline-style input[type="date"] { padding:10px 12px; } #_form_1_._inline-style button._inline-style { position:relative; top:27px; } #_form_1_._inline-style p { margin:0; } #_form_1_._inline-style ._button-wrapper { position:relative; margin:27px 12.5px 0 20px; } #_form_1_ ._form-thank-you { position:relative; left:0; right:0; text-align:center; font-size:18px; } @media all and (min-width:320px) and (max-width:667px) { #_form_1_._inline-form._inline-style ._inline-style._button-wrapper { margin-top:20px !important; margin-left:0 !important; } }
Your Free Consultation
Request your free consultation now. It will be approximately 20-30 minutes long.
Full Name*
Email*
Budget*
$500 per Month $1000 per Month $2000 per Month
Keyword*
Website URL*
Submit
Marketing by
window.cfields = {"1":"budget","2":"keyword","3":"website_url"}; window._show_thank_you = function(id, message, trackcmp_url) { var form = document.getElementById('_form_' + id + '_'), thank_you = form.querySelector('._form-thank-you'); form.querySelector('._form-content').style.display = 'none'; thank_you.innerHTML = message; thank_you.style.display = 'block'; if (typeof(trackcmp_url) != 'undefined' && trackcmp_url) { // Site tracking URL to use after inline form submission. _load_script(trackcmp_url); } if (typeof window._form_callback !== 'undefined') window._form_callback(id); }; window._show_error = function(id, message, html) { var form = document.getElementById('_form_' + id + '_'), err = document.createElement('div'), button = form.querySelector('button'), old_error = form.querySelector('._form_error'); if (old_error) old_error.parentNode.removeChild(old_error); err.innerHTML = message; err.className = '_error-inner _form_error _no_arrow'; var wrapper = document.createElement('div'); wrapper.className = '_form-inner'; wrapper.appendChild(err); button.parentNode.insertBefore(wrapper, button); document.querySelector('[id^="_form"][id$="_submit"]').disabled = false; if (html) { var div = document.createElement('div'); div.className = '_error-html'; div.innerHTML = html; err.appendChild(div); } }; window._load_script = function(url, callback) { var head = document.querySelector('head'), script = document.createElement('script'), r = false; script.type = 'text/javascript'; script.charset = 'utf-8'; script.src = url; if (callback) { script.onload = script.onreadystatechange = function() { if (!r && (!this.readyState || this.readyState == 'complete')) { r = true; callback(); } }; } head.appendChild(script); }; (function() { if (window.location.search.search("excludeform") !== -1) return false; var getCookie = function(name) { var match = document.cookie.match(new RegExp('(^|; )' + name + '=([^;]+)')); return match ? match[2] : null; } var setCookie = function(name, value) { var now = new Date(); var time = now.getTime(); var expireTime = time + 1000 * 60 * 60 * 24 * 365; now.setTime(expireTime); document.cookie = name + '=' + value + '; expires=' + now + ';path=/'; } var addEvent = function(element, event, func) { if (element.addEventListener) { element.addEventListener(event, func); } else { var oldFunc = element['on' + event]; element['on' + event] = function() { oldFunc.apply(this, arguments); func.apply(this, arguments); }; } } var _removed = false; var form_to_submit = document.getElementById('_form_1_'); var allInputs = form_to_submit.querySelectorAll('input, select, textarea'), tooltips = [], submitted = false; var getUrlParam = function(name) { var regexStr = '[\?&]' + name + '=([^&#]*)'; var results = new RegExp(regexStr, 'i').exec(window.location.href); return results != undefined ? decodeURIComponent(results[1]) : false; }; for (var i = 0; i < allInputs.length; i++) { var regexStr = "field\\[(\\d+)\\]"; var results = new RegExp(regexStr).exec(allInputs[i].name); if (results != undefined) { allInputs[i].dataset.name = window.cfields[results[1]]; } else { allInputs[i].dataset.name = allInputs[i].name; } var fieldVal = getUrlParam(allInputs[i].dataset.name); if (fieldVal) { if (allInputs[i].type == "radio" || allInputs[i].type == "checkbox") { if (allInputs[i].value == fieldVal) { allInputs[i].checked = true; } } else { allInputs[i].value = fieldVal; } } } var remove_tooltips = function() { for (var i = 0; i < tooltips.length; i++) { tooltips[i].tip.parentNode.removeChild(tooltips[i].tip); } tooltips = []; }; var remove_tooltip = function(elem) { for (var i = 0; i < tooltips.length; i++) { if (tooltips[i].elem === elem) { tooltips[i].tip.parentNode.removeChild(tooltips[i].tip); tooltips.splice(i, 1); return; } } }; var create_tooltip = function(elem, text) { var tooltip = document.createElement('div'), arrow = document.createElement('div'), inner = document.createElement('div'), new_tooltip = {}; if (elem.type != 'radio' && elem.type != 'checkbox') { tooltip.className = '_error'; arrow.className = '_error-arrow'; inner.className = '_error-inner'; inner.innerHTML = text; tooltip.appendChild(arrow); tooltip.appendChild(inner); elem.parentNode.appendChild(tooltip); } else { tooltip.className = '_error-inner _no_arrow'; tooltip.innerHTML = text; elem.parentNode.insertBefore(tooltip, elem); new_tooltip.no_arrow = true; } new_tooltip.tip = tooltip; new_tooltip.elem = elem; tooltips.push(new_tooltip); return new_tooltip; }; var resize_tooltip = function(tooltip) { var rect = tooltip.elem.getBoundingClientRect(); var doc = document.documentElement, scrollPosition = rect.top - ((window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0)); if (scrollPosition < 40) { tooltip.tip.className = tooltip.tip.className.replace(/ ?(_above|_below) ?/g, '') + ' _below'; } else { tooltip.tip.className = tooltip.tip.className.replace(/ ?(_above|_below) ?/g, '') + ' _above'; } }; var resize_tooltips = function() { if (_removed) return; for (var i = 0; i < tooltips.length; i++) { if (!tooltips[i].no_arrow) resize_tooltip(tooltips[i]); } }; var validate_field = function(elem, remove) { var tooltip = null, value = elem.value, no_error = true; remove ? remove_tooltip(elem) : false; if (elem.type != 'checkbox') elem.className = elem.className.replace(/ ?_has_error ?/g, ''); if (elem.getAttribute('required') !== null) { if (elem.type == 'radio' || (elem.type == 'checkbox' && /any/.test(elem.className))) { var elems = form_to_submit.elements[elem.name]; if (!(elems instanceof NodeList || elems instanceof HTMLCollection) || elems.length <= 1) { no_error = elem.checked; } else { no_error = false; for (var i = 0; i < elems.length; i++) { if (elems[i].checked) no_error = true; } } if (!no_error) { tooltip = create_tooltip(elem, "Please select an option."); } } else if (elem.type =='checkbox') { var elems = form_to_submit.elements[elem.name], found = false, err = []; no_error = true; for (var i = 0; i < elems.length; i++) { if (elems[i].getAttribute('required') === null) continue; if (!found && elems[i] !== elem) return true; found = true; elems[i].className = elems[i].className.replace(/ ?_has_error ?/g, ''); if (!elems[i].checked) { no_error = false; elems[i].className = elems[i].className + ' _has_error'; err.push("Checking %s is required".replace("%s", elems[i].value)); } } if (!no_error) { tooltip = create_tooltip(elem, err.join(' ')); } } else if (elem.tagName == 'SELECT') { var selected = true; if (elem.multiple) { selected = false; for (var i = 0; i < elem.options.length; i++) { if (elem.options[i].selected) { selected = true; break; } } } else { for (var i = 0; i < elem.options.length; i++) { if (elem.options[i].selected && !elem.options[i].value) { selected = false; } } } if (!selected) { elem.className = elem.className + ' _has_error'; no_error = false; tooltip = create_tooltip(elem, "Please select an option."); } } else if (value === undefined || value === null || value === '') { elem.className = elem.className + ' _has_error'; no_error = false; tooltip = create_tooltip(elem, "This field is required."); } } if (no_error && elem.name == 'email') { if (!value.match(/^[\+_a-z0-9-'&=]+(\.[\+_a-z0-9-']+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$/i)) { elem.className = elem.className + ' _has_error'; no_error = false; tooltip = create_tooltip(elem, "Enter a valid email address."); } } if (no_error && /date_field/.test(elem.className)) { if (!value.match(/^\d\d\d\d-\d\d-\d\d$/)) { elem.className = elem.className + ' _has_error'; no_error = false; tooltip = create_tooltip(elem, "Enter a valid date."); } } tooltip ? resize_tooltip(tooltip) : false; return no_error; }; var needs_validate = function(el) { return el.name == 'email' || el.getAttribute('required') !== null; }; var validate_form = function(e) { var err = form_to_submit.querySelector('._form_error'), no_error = true; if (!submitted) { submitted = true; for (var i = 0, len = allInputs.length; i < len; i++) { var input = allInputs[i]; if (needs_validate(input)) { if (input.type == 'text') { addEvent(input, 'blur', function() { this.value = this.value.trim(); validate_field(this, true); }); addEvent(input, 'input', function() { validate_field(this, true); }); } else if (input.type == 'radio' || input.type == 'checkbox') { (function(el) { var radios = form_to_submit.elements[el.name]; for (var i = 0; i < radios.length; i++) { addEvent(radios[i], 'click', function() { validate_field(el, true); }); } })(input); } else if (input.tagName == 'SELECT') { addEvent(input, 'change', function() { validate_field(this, true); }); } } } } remove_tooltips(); for (var i = 0, len = allInputs.length; i < len; i++) { var elem = allInputs[i]; if (needs_validate(elem)) { if (elem.tagName.toLowerCase() !== "select") { elem.value = elem.value.trim(); } validate_field(elem) ? true : no_error = false; } } if (!no_error && e) { e.preventDefault(); } resize_tooltips(); return no_error; }; addEvent(window, 'resize', resize_tooltips); addEvent(window, 'scroll', resize_tooltips); window._old_serialize = null; if (typeof serialize !== 'undefined') window._old_serialize = window.serialize; _load_script("//d3rxaij56vjege.cloudfront.net/form-serialize/0.3/serialize.min.js", function() { window._form_serialize = window.serialize; if (window._old_serialize) window.serialize = window._old_serialize; }); var form_submit = function(e) { e.preventDefault(); if (validate_form()) { // use this trick to get the submit button & disable it using plain javascript document.querySelector('[id^="_form"][id$="_submit"]').disabled = true; var serialized = _form_serialize(document.getElementById('_form_1_')); var err = form_to_submit.querySelector('._form_error'); err ? err.parentNode.removeChild(err) : false; _load_script('https://kanwarmanoriadigital.activehosted.com/proc.php?' + serialized + '&jsonp=true'); } return false; }; addEvent(form_to_submit, 'submit', form_submit); })();
The post Get Started appeared first on Kanwar Manoria Digital.
from Kanwar Manoria Digital http://kanwarmanoria.digital/seo/get-started/
0 notes
Text
Making Child Documents Working with Spring-data-solr
Via http://ift.tt/2nhFF90
The Problem We use spring-data-solr in our project - as we like its conversion feature which can convert string to enum, entity to json data and etc, and vice versa, and recently we need use Solr's nested documents feature which spring-data-solr doesn't support. Issues in Spring-data-solr SolrInputDocument class contains a Map _fields AND List _childDocuments.
Spring-data-solr converts java entity class to SolrDocument. It provides two converters: MappingSolrConverter and SolrJConverter. MappingSolrConverter converts the entity to a Map: MappingSolrConverter.write(Object, Map, SolrPersistentEntity) SolrJConverter uses solr's DocumentObjectBinder to convert entity to SolrInputDocument, it will convert field that is annotated with @Field(child = true) to child documents. - This also means that spring-data-solt's convert features will not work with SolrJConverter BUT SolrJConverter still just thinks SolrInputDocument is a map and add all into the destination: Map sink - SolrJConverter.write(Object, Map) After this, the child documents is discarded. The Fix We still want to use spring-data-solr's conversion functions - partly because we don't want to rewrite everything to use SolrJ directly. So when save to solr: we uses spring-data-solr's MappingSolrConverter to convert parent entity as solrInputDocument, then convert child entities as solrInputDocuments and add them into parent's solrInputDocument. When read from solr, we read the SolrDocument as parent entity, then read its child documents as child entities and add them into parent entity.
public class ParentEntity { @Field(child = true) private List<ChildEntity> children; } @Autowired protected SolrClient solrClient; // we add our own converters into MappingSolrConverter // for more, please check // http://ift.tt/1Uq7cPj @Autowired protected MyMappingSolrConverter solrConverter; public void save(@Nonnull final ParentEntity parentEntity) { final SolrInputDocument solrInputDocument = solrConverter.createAndWrite(parentEntity); daddChildDocuemnts(parentEntity, solrInputDocument); try { solrClient.add(getCollection(), solrInputDocument); solrClient.commit(getCollection()); } catch (SolrServerException | IOException e) { throw new BusinessException(e, "failed to save " + parentEntity); } } protected void daddChildDocuemnts(@Nonnull final ParentEntity parentEntity, @Nonnull final SolrInputDocument solrInputDocument) { solrInputDocument.addChildDocuments(parentEntity.getChildren().stream() .map(child -> solrConverter.createAndWrite(child)).collect(Collectors.toList())); } public List<T> querySolr(final SolrParams query) { try { final QueryResponse response = solrClient.query(getCollection(), query); return convertFromSolrDocs(response.getResults()); } catch (final Exception e) { throw new BusinessException("data retrieve failed." + query); } } /* * Also return child documents in solr response as ChildEntity if it exists */ protected List<ParentEntity> convertFromSolrDocs(final SolrDocumentList docList) { List<ParentEntity> result = new ArrayList<>(); if (docList != null) { result = docList.stream().map(solrDoc -> { final ParentEntity parentEntity = solrConverter.read(ParentEntity.class, solrDoc); final List<SolrDocument> childDocs = solrDoc.getChildDocuments(); if (childDocs != null) { ParentEntity.setChildren( childDocs.stream().map(childSolrDoc -> solrConverter.read(ChildEntity.class, solrDoc)) .collect(Collectors.toList())); } return parentEntity; }).collect(Collectors.toList()); } return result; }
Related Mix Spring Data Solr and SolrJ in Solr Cloud 5 SolrJ: Support Converter and make it easier to extend DocumentObjectBinder
From lifelongprogrammer.blogspot.com
0 notes
Text

*I mean Haven’t We all been there?
Birthday Remembrances. Today, Jan 29, 1880 – #WCFields, American actor, singer, and screenwriter (d. 1946) was born.
(https://en.wikipedia.org/wiki/W._C._Fields)
0 notes
Photo

*I mean Haven’t We all been there? Birthday Remembrances. Today, Jan 29, 1880 – #WCFields, American actor, singer, and screenwriter (d. 1946) was born.
(https://en.wikipedia.org/wiki/W._C._Fields)
0 notes
Text
ESP32 / ESP8266 Arduino Tutorial:4. Protocol Buffers
Introduction
In this tutorial we will learn how to get started using Protocol Buffers with the Arduino core. In this introductory example, we will check how to declare a message type and how to encode it. This tutorial was tested both on the ESP32 and on the ESP8266.
Protocol buffers are a data serialization format from Google which are supported in multiple programming languages [1]. Protocol Buffers messages are encoded in a binary format [2], which means they are not human readable unless we decode them back to a readable format.
One of the main advantages of using Protocol Buffers is that the serialization and deserialization process is fast and the generated messages are small. For example, in the project website it is claimed that Protocol Buffers are 20 to 100 times faster and 3 to 10 times smaller than XML [3]. Around the web, there are also a lot of benchmarks that indicate Protocol Buffers are faster and smaller than JSON [4][5].
For our tests we are going to use Nanopb, a C implementation of Protocol Buffers that targets 32-bit microcontrollers [6]. You can check the GitHub page of the library here.
When using Protocol Buffers, we need to specify how we want to structure the data that will be serialized. This is done by defining message types in a .proto file [3]. After the definition of the messages, we need to run a protocol buffer compiler for the specific language we are using, to generate data access classes for our messages [3].
The tests on the ESP32 were performed using a DFRobot’s ESP-WROOM-32 device integrated in a ESP32 FireBeetle board. The tests on the ESP8266 were performed on a DFRobot’s ESP8266 FireBeetle board.
Setting up the environment
In order to get started, we need to download the latest release of Nanopb from the downloads page. The downloads page includes versions for Linux, Mac and Windows, as shown below at figure 1. I’ll be performing the tests on a Windows 8.1 machine.
Figure 1 – Downloading Nanopb.
Once the download finishes, unzip the content. You should get a folder hierarchy similar to figure 2.
Figure 2 – Folder hierarchy of Nanopb.
In the previous image, there are two highlighted areas that are of interest for this tutorial. The first one is the generator-bin folder, which contains the already mentioned compiler that we will need to use to compile our .proto files.
Inside that folder, we can create a new folder called “proto_files“, where we will place our message definitions. Note that the name of the folder is arbitrary as it is its location. Naturally, we can define it where we want it in our computer as long as we use the correct paths when running the compilation tool.
Inside the folder, create a file called test.proto. For now, you can leave it empty. We will get back to it later.
If you go back to the root of the Nanopb project, you should see some .c and .h files, as also highlighted in figure 2. We will need those files when compiling our code. So, copy them all. The list of files copied should be the following:
pb.h
pb_common.h
pb_common.c
pb_encode.h
pb_encode.c
pb_decode.h
pb_decode.c
In order to be able to use Nanopb as a regular Arduino library, go to the folder where your Arduino libraries are. Typically, the path where the libraries are located is:
C:\Users\#yourUserName#\Documents\Arduino\libraries
Once you locate the Arduino libraries folder, create a new folder inside called Nanopb, next to your other libraries. There, paste the previously copied .c and .h files.
Defining the .proto file
Now that we have created our Nanopb library, we need to go back to the .proto file, so we can define our message.
In the first line, we need to declare the syntax version we are using to define our message. In our case, we will be using the proto2syntax.
syntax = "proto2";
Next, we need to define our message type. We start by using the message keyword, followed by the actual name of our message type. I’ll be calling it TestMessage.
Then, the message fields are declared between curly brackets.
message TestMessage { // body of message }
For each field we declare in our message, we need to specify its data type and its name. Additionally, each field needs to have a unique number. The unique numbers are used to identify the fields in the binary data format [7], so the name of the field is not serialized.
Additionally, for each field, we need to specify if it is optional, required or repeated. Required means the message must have that field exactly one time, optional means the field can not exist or the message can have it at most one time, and repeated means the field can be repeated any number of times (including zero) [7].
In or message, we will declare an integer field called test_number that will be required. For this simple example we will only make use of one field and thus we should assign it the unique number 1.
required int32 test_number = 1;
The final file content can be seen below. After finishing its edition, save it.
syntax = "proto2"; message TestMessage { required int32 test_number = 1; }
Now we need to compile the .proto file, so we can use it in our code. In case of Nanopb, since it offers a pure C implementation, this compiling procedure will generate C structs to represent our messages.
In order to compile it, open a command prompt and navigate to the generator-bin folder. There, the command to compile the messages has the following syntax, where you should change #pathToProtoFile# to the location of your .proto file:
protoc --nanopb_out=. #pathToProtoFile#
If you created a proto_files inside the generator-bin folder and placed the .proto file there like I did, the command is:
protoc --nanopb_out=. proto_files/test.proto
After running the command, a test.pb.c and a test.pb.h file should be created in the folder where you have your .proto definition, as shown in figure 3.
Figure 3 – Generated files.
If you open the .h file, you should see that it has a struct called TestMessage defined there, as shown in figure 4. It matches the message name we have used in the .proto file. Also, the struct as an integer field called test_number, like we also specified.
Figure 4 – Struct definition in generated header file.
We will need both the .c and the .h file, so copy them. Since these are the message definitions which are specific of our program, we should not place them in the Nanopb library folder we have created previously.
So, on your Arduino sketch folder, simply create a folder called src and paste the previously copied filed there, as shown in figure 5.
Figure 5 – Arduino sketch folder with .c and .h files.
The code
We will start our code by doing some includes. The first one corresponds to the .h file we have obtained after compiling our .proto file. This will make available the struct that was created by the compilation process.
Remember that we have the file in a folder inside the sketch directory, so we need to provide the correct path when including the file.
#include "src/test.pb.h"
After that,we need to include the header files we have pasted in our Nanopb library folder, with the exception of the pb_decode.h, since we are not going to decode the message in this introductory tutorial.
#include "pb_common.h" #include "pb.h" #include "pb_encode.h"
Moving on to the Arduino setup function, we will start by opening a serial connection, to later output some results of our program.
Serial.begin(115200);
Then, we will declare an array of bytes that will serve as a buffer to hold the serialized message. For this tutorial we will declare a buffer with a size big enough to hold all our structure, so we won’t need to worry about calculating the maximum size the message can have.
uint8_t buffer[128];
Next, we will declare our message data structure and initialize it. Nanopb generates a define that allows to initialize the data struct, which has the following name:
#MessageName#_init_zero
So, in our case, the declaration and initialization of the structure is done like below:
TestMessage message = TestMessage_init_zero;
Nanopb uses the concept of streams to access data in encoded format [8]. So, the next thing we will do is calling the pb_ostream_from_buffer function, which constructs an output stream for writing into a memory buffer [9].
We need to pass as first input our previously declared buffer and as second input the maximum number of bytes to write, which should be the size of our buffer. This function call will return a struct of type pb_ostream_t.
pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer));
Now that we have our stream, we should set the value of our message field before we encode it. Recall that we had a field called test_number in our .proto file, which also exists in the TestMessage struct we have declared.
So, we will access that field of the struct and assign it a value.
message.test_number = 540;
Now, to do the actual encoding, we need to call the pb_encode function.
As first input, we need to pass the address of our pb_ostream_t variable. As second, we need to pass a fields description array that is auto-generated for us in the compilation process, which has the following syntax:
#MessageName#_fields
As third and final argument, we need to pass the address of our TestMessage struct.
As output, this function call returns a Boolean value that indicates if the encoding of the content was successful (true) or not (false), which we can use for error check.
bool status = pb_encode(&stream, TestMessage_fields, &message); if (!status) { Serial.println("Failed to encode"); return; }
If the serialization is performed without errors, our buffer should already contain the data. But before we access it, we can check how many bytes were written by accessing the bytes_written field of the pb_ostream_t variable.
Serial.println(stream.bytes_written);
Finally, we will iterate through all the bytes of the encoded message and print them to the serial port in hexadecimal format. Note that since we know exactly how many bytes were written, we can use that value as stopping condition for our loop, rather that reading the whole buffer.
for(int i = 0; i<stream.bytes_written; i++){ Serial.printf("%02X",buffer[i]); }
The final code can be seen below, with some additional prints for readability.
#include "src/test.pb.h" #include "pb_common.h" #include "pb.h" #include "pb_encode.h" void setup() { Serial.begin(115200); uint8_t buffer[128]; TestMessage message = TestMessage_init_zero; pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer)); message.test_number = 540; bool status = pb_encode(&stream, TestMessage_fields, &message); if (!status) { Serial.println("Failed to encode"); return; } Serial.print("Message Length: "); Serial.println(stream.bytes_written); Serial.print("Message: "); for(int i = 0; i<stream.bytes_written; i++){ Serial.printf("%02X",buffer[i]); } } void loop() {}
Testing the code
To test the code, simply compile it and upload it to your device. Once the procedure finishes, open the Arduino IDE serial monitor. You should get an output similar to figure 6, which shows both how many bytes were written and the binary message, in hexadecimal format.
Figure 6 – Output of the program, including the encoded message.
Copy the whole message bytes. Then, go to this online decoder and paste the content in the first text input box (the one that accepts hexadecimal format). It should output a result similar to figure 7, which shows the value we have assigned to our field (540). Note that the name of the field is not included in the serialized message but rather the unique number of the field, which makes the message much smaller (only 3 bytes).
Figure 7 – Decoding the message with an online tool.
0 notes
Photo

*I mean Haven’t We all been there? Birthday Remembrances. Today, Jan 29, 1880 – W. C. Fields, American actor, singer, and screenwriter (d. 1946) was born. (https://en.wikipedia.org/wiki/W._C._Fields)
0 notes
Link
From http://ift.tt/1ajReyV
The Problem We use spring-data-solr in our project - as we like its conversion feature which can convert string to enum, entity to json data and etc, and vice versa, and recently we need use Solr's nested documents feature which spring-data-solr doesn't support. Issues in Spring-data-solr SolrInputDocument class contains a Map _fields AND List _childDocuments.
Spring-data-solr converts java entity class to SolrDocument. It provides two converters: MappingSolrConverter and SolrJConverter. MappingSolrConverter converts the entity to a Map: MappingSolrConverter.write(Object, Map, SolrPersistentEntity) SolrJConverter uses solr's DocumentObjectBinder to convert entity to SolrInputDocument, it will convert field that is annotated with @Field(child = true) to child documents. - This also means that spring-data-solt's convert features will not work with SolrJConverter BUT SolrJConverter still just thinks SolrInputDocument is a map and add all into the destination: Map sink - SolrJConverter.write(Object, Map) After this, the child documents is discarded. The Fix We still want to use spring-data-solr's conversion functions - partly because we don't want to rewrite everything to use SolrJ directly. So when save to solr: we uses spring-data-solr's MappingSolrConverter to convert parent entity as solrInputDocument, then convert child entities as solrInputDocuments and add them into parent's solrInputDocument. When read from solr, we read the SolrDocument as parent entity, then read its child documents as child entities and add them into parent entity.
public class ParentEntity { @Field(child = true) private List<ChildEntity> children; } @Autowired protected SolrClient solrClient; // we add our own converters into MappingSolrConverter // for more, please check // http://ift.tt/1Uq7cPj @Autowired protected MyMappingSolrConverter solrConverter; public void save(@Nonnull final ParentEntity parentEntity) { final SolrInputDocument solrInputDocument = solrConverter.createAndWrite(parentEntity); daddChildDocuemnts(parentEntity, solrInputDocument); try { solrClient.add(getCollection(), solrInputDocument); solrClient.commit(getCollection()); } catch (SolrServerException | IOException e) { throw new BusinessException(e, "failed to save " + parentEntity); } } protected void daddChildDocuemnts(@Nonnull final ParentEntity parentEntity, @Nonnull final SolrInputDocument solrInputDocument) { solrInputDocument.addChildDocuments(parentEntity.getChildren().stream() .map(child -> solrConverter.createAndWrite(child)).collect(Collectors.toList())); } public List<T> querySolr(final SolrParams query) { try { final QueryResponse response = solrClient.query(getCollection(), query); return convertFromSolrDocs(response.getResults()); } catch (final Exception e) { throw new BusinessException("data retrieve failed." + query); } } /* * Also return child documents in solr response as ChildEntity if it exists */ protected List<ParentEntity> convertFromSolrDocs(final SolrDocumentList docList) { List<ParentEntity> result = new ArrayList<>(); if (docList != null) { result = docList.stream().map(solrDoc -> { final ParentEntity parentEntity = solrConverter.read(ParentEntity.class, solrDoc); final List<SolrDocument> childDocs = solrDoc.getChildDocuments(); if (childDocs != null) { ParentEntity.setChildren( childDocs.stream().map(childSolrDoc -> solrConverter.read(ChildEntity.class, solrDoc)) .collect(Collectors.toList())); } return parentEntity; }).collect(Collectors.toList()); } return result; }
Related Mix Spring Data Solr and SolrJ in Solr Cloud 5 SolrJ: Support Converter and make it easier to extend DocumentObjectBinder
0 notes
Photo

Birthday Remembrances. Today, Jan 29, 1880 – W. C. Fields, American actor, singer, and screenwriter (d. 1946) was born. (https://en.wikipedia.org/wiki/W._C._Fields) *I mean Haven't We all been there? ;)
0 notes