- Почему глобальные объекты и статика — это зло? Можете показать на примере кода?
- Расскажите об инверсии управления и как она улучшает организацию кода.
- Закон Деметры (Принцип минимальной информированности) гласит, что каждый программный модуль должен обладать ограниченным знанием о других модулях и должен взаимодействовать только с непосредственными «друзьями» (иногда его формулируют как «Не разговаривай с незнакомцами»). Можете написать код, который нарушает этот принцип? Почему у него плохая организация и как её исправить?
- Active-Record — шаблон проектирования, который поощряет внедрение в сам объект функций, таких как Insert, Update и Delete, и свойств, которые соответствуют столбцам некоей базовой таблицы в базе данных. По вашему мнению и опыту, какие ограничения и подводные камни у этого шаблона?
- Data-Mapper — шаблон проектирования, который поощряет использование слоя преобразователей (mappers), перемещающих данные между объектами и базой данных, в то же
This is for adding the query parameters to the URL. These scripts can be also used for Javascript. When I created an endpoint with some query parameters, I had used the scripts of various patterns every time. Today, I prepared this sample script to unify them. If this is also useful for you, I'm glad.
String.prototype.addQuery = function (obj) {Here I would like to introduce about the limitation of images for inserting to Spreadsheet using Google Apps Script (GAS). When you want to insert the images to Spreadsheet using GAS, insertImage() of class Sheet is usually used for this situation. At this time, an error sometimes occurs. This indicates that there is the limitation for inserting images to Spreadsheet. So I investigated the limitation.
As a result, it was found that the limitation depends on the image area (pixels^2) rather than the file size of it. The maximum area of image which can be inserted was 1,048,576 pixels^2.
In order to investigate the limitation, I have converged the condition by changing the file size and the image size. By this, it was found that the limitation depends on the image area (pixels^2) rather than the file size of it. For this confirmation, I can show you the following experimental data.
| function ChunkyCache(cache, chunkSize){ | |
| chunkSize = chunkSize || 100*1024; | |
| return { | |
| put: function (key, value, timeout) { | |
| var json = JSON.stringify(value); | |
| var cSize = Math.floor(chunkSize / 2); | |
| var chunks = []; | |
| var index = 0; | |
| while (index < json.length){ | |
| cKey = key + "_" + index; |
This is a sample script for easily retrieving the reformatted scripts without comments in a project using Google Apps Script (GAS).
When I create GAS script, if the format of script is not correct, the script editor lets me know about it. By this, I can find that the script editor and/or Google Drive checks the format of scripts. I had wished if I could use this function. Recently, I noticed an interesting function. A GAS project is created and when function myFunction() {Logger.log(this)} is run in the script, I noticed that all scripts in the project are included in this. Furthermore, when I saw the retrieved script, also I noticed that their scripts are reformatted and all comments are removed. In the case of Apps Script API, when the scripts are retrieved by the API, the retrieved script is the same to the original one. So I think that this will help users retrieve simply the reformat
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <script> | |
| var data | |
| var formId = 'form' | |
| function drawForm() { | |
| if (!data) return | |
| var outputEl = document.getElementById(formId); |
| const gulp = require( 'gulp' ); | |
| const spawn = require( 'child_process' ).spawn; | |
| /** | |
| * This solution to execute and watch a shell function from Gulp is | |
| * adapted from https://stackoverflow.com/a/10232330/3232832 | |
| * | |
| * e.g. callSpawn( 'ping', [ '-c 5', 'google.com' ], cb ); | |
| */ | |
| function callSpawn( command, arguments, cb ) { |
| /* | |
| Suppose there is some endpoint that returns a jsonp to you, as in Google Visualization API | |
| It gives you a text response that looks like this: | |
| "some.namespace.nameOfFunction({obj:'blah'})" | |
| We want the object inside that function call. | |
| In a google app scripting context, we have no choice but to evaluate it the old-fashioned way, using "evil" eval(). | |
| This solution builds a variable that resolves the namespace some.namespace.blah.blah and which ultimately becomes | |
| a function that returns the passed parameter. | |
| We build the variable with raw text, then eval it, giving the local context the ability to resolve the namespace and |