Save the changes made to a String to WebTranslateIt.com
498411
def update
      success = true
      tries ||= 3
      request = Net::HTTP::Put.new("/api/projects/#{Connection.api_key}/strings/#{self.id}.yaml")
      WebTranslateIt::Util.add_fields(request)
      request.body = self.to_json
      
      self.translations.each do |translation|
        translation.string_id = self.id
        translation.save
      end
      
      begin
        Util.handle_response(Connection.http_connection.request(request), true, true)
      rescue Timeout::Error
        puts "Request timeout. Will retry in 5 seconds."
        if (tries -= 1) > 0
          sleep(5)
          retry
        else
          success = false
        end
      end
      success
    end
8239
def text_changed(self):
        """"""
        # Save text as bytes, if it was initially bytes
        if self.is_binary:
            self.text = to_binary_string(self.edit.toPlainText(), 'utf8')
        else:
            self.text = to_text_string(self.edit.toPlainText())
        if self.btn_save_and_close:
            self.btn_save_and_close.setEnabled(True)
            self.btn_save_and_close.setAutoDefault(True)
            self.btn_save_and_close.setDefault(True)
85601
function performChange(content) {
  const exampleFile = ExampleFile.fromPath(this.file.path);
  const match = content.match(/<!---([\s\S]*)?--->/);
  if (!match) {
    return content;
  }
  gutil.log('changing', exampleFile.title);
  const frontmatter = JSON.parse(match[1]);
  const yaml = require('js-yaml');
  const yamlFrontmatter = `<!---

${yaml.safeDump(frontmatter)}
--->
${content.substring(match[0].length)}`;
  /*
  if (!/<title>/.test(content)) {
    content = content.replace(/<meta charset="utf-8">/g,
        '<meta charset="utf-8">\n  <title>' + exampleFile.title() + '</title>');
  }
  */
  return yamlFrontmatter;
}
1052369
def save(self):
        """"""
        self._connection.run(['change', '-i'], stdin=format(self), marshal_output=False)
        self._dirty = False
354298
function (key, regexp, replacement, editor) {
            key = key.toLowerCase();

            return getPreviousKeyForEditing(key, editor)
            .then(bindr(Result.andThen, editOnlyWhenPreviousKeyExists))
            .then(bindr(Result.andThen, function (description) {
                const old_message = description.message;
                const new_message = old_message
                    .replace(regexp, replacement)
                    .replace(/\s+/, " ");

                if (old_message === new_message) {
                    return Fail("unchanged");
                }

                if (new_message.length > maxMessageLength) {
                    return Fail("message-length-exceeded");
                }

                if (new_message === "") {
                    return Fail("no-message-left");
                }

                description.message = new_message;
                description.editor = editor;
                description.time = now();

                return Ok(description);
            }))
            .then(bindr(Result.andThen, beforeUpdate))
            .then(bindr(Result.map, function (value) {
                db.set(key, value);
                return value;
            }));
        }
981276
def save_to(self, nameprefix, switch=False):
        
        if not nameprefix or not isinstance(nameprefix, basestring):
            raise _Error('filename prefix must be a nonempty string')

        if nameprefix == self.default_prefix:
            raise _Error('cannot save to default name "' + nameprefix + '...", chose another name')

        if nameprefix == self.name_prefix:
            return

        for name in self.file_names:
            open(nameprefix + name + '.dat', 'w').write(open(self.name_prefix + name + '.dat').read())

        if switch:
            self.name_prefix = nameprefix
1253384
function() {
            var alteredData = findDeltas(oldConfig, newConfig);
            //
            // send all the configuration information that changes during the session
            //
            if (alteredData) {
                logDebug("cfg=" + JSON.stringify(alteredData.added));

                if (self.webSocket) {
                    sendSignalling(null, "setUserCfg", {setUserCfg: alteredData.added}, null, null);
                }
            }
            oldConfig = newConfig;
        }
939497
function replaceAt(content, index, oldString, newString) {
  logger.debug(`Replacing ${oldString} with ${newString} at index ${index}`);
  return (
    content.substr(0, index) +
    newString +
    content.substr(index + oldString.length)
  );
}
963904
function tweakI18nStrings(data) {
  // Rip off the CommonJS header/footer
  var output = '';
  data.replace(outline, function(m, inner) {
    // Remove the trailing spaces
    output += inner.replace(/ *$/, '');
  });

  if (output === '') {
    throw new Error('Mismatch in lib/gcli/nls/strings.js');
  }

  var strings = [];

  // Convert each of the string definitions
  var reply = output.replace(singleString, function(m, note, x, name, value) {
    strings.push({
      note: note,
      noteAlsoFor: [],
      name: name,
      value: value
    });
    return '';
  });

  console.log('reply="' + reply + '"');

  strings = strings.filter(function(string) {
    return ignoreStrings.indexOf(string.name) === -1;
  });

  // All strings should have a note, but sometimes we describe several strings
  // with one note, so if a string has no note then we add it to noteAlsoFor
  // in the last string with a note
  var lastStringWithNote = -1;
  strings.forEach(function(string, i) {
    if (string.note === '') {
      strings[lastStringWithNote].noteAlsoFor.push(string.name);
    }
    else {
      lastStringWithNote = i;
    }
  });

  // Make a single one line string from the the multi-line JS comments
  strings.forEach(function(string) {
    if (string.note !== '') {
      string.note = string.note.replace(/\n? *\/\/ */g, ' ')
                               .replace(/^ /, '')
                               .replace(/\n$/, '');
    }
  });

  // Add the 'LOCALIZATION NOTE' and word wrap
  strings.forEach(function(string) {
    if (string.note !== '') {
      string.noteAlsoFor.unshift(string.name);
      var names = '';
      if (string.noteAlsoFor.length > 1) {
        names = ' (' + string.noteAlsoFor.join(', ') + ')';
      }

      string.note = 'LOCALIZATION NOTE' + names + ': ' + string.note;
      string.note = '\n# ' + wordWrap(string.note, 77).join('\n# ') + '\n';
    }
  });

  // The values were escaped JavaScript strings to be property values they
  // need unescaping
  strings.forEach(function(string) {
    string.value = string.value.replace(/\\\\/g, '\\').replace(/\\'/g, '\'');
  });

  // Join to get the output
  output = strings.map(function(string) {
    return string.note + string.name + '=' + string.value + '\n';
  }).join('');

  return '' +
    '# This Source Code Form is subject to the terms of the Mozilla Public\n' +
    '# License, v. 2.0. If a copy of the MPL was not distributed with this\n' +
    '# file, You can obtain one at http://mozilla.org/MPL/2.0/.\n' +
    '\n' +
    '# LOCALIZATION NOTE These strings are used inside the Web Console\n' +
    '# command line which is available from the Web Developer sub-menu\n' +
    '# -> \'Web Console\'.\n' +
    '# The correct localization of this file might be to keep it in\n' +
    '# English, or another language commonly spoken among web developers.\n' +
    '# You want to make that choice consistent across the developer tools.\n' +
    '# A good criteria is the language in which you\'d find the best\n' +
    '# documentation on web development on the web.\n' +
    '\n' +
    '# For each command there are in general two strings. As an example consider\n' +
    '# the \'pref\' command.\n' +
    '# commandDesc (e.g. prefDesc for the command \'pref\'): this string contains a\n' +
    '# very short description of the command. It\'s designed to be shown in a menu\n' +
    '# alongside the command name, which is why it should be as short as possible.\n' +
    '# commandManual (e.g. prefManual for the command \'pref\'): this string will\n' +
    '# contain a fuller description of the command. It\'s diplayed when the user\n' +
    '# asks for help about a specific command (e.g. \'help pref\').\n' +
    output;
}
213432
function formatToJsonXMLString(changes, shallow) {
            var properties = [];

            var diff = changes.value;
            if (changes.changed == 'equal') {
                return $sce.trustAsHtml(inspect(diff, shallow));
            }

            for (var key in diff) {
                properties.push(formatChange(key, diff[key], shallow));
            }

            return $sce.trustAsHtml('<span>' + openChar + '</span>\n<div class="diff-level">' + properties.join('<span>,</span>\n') + '\n</div><span>' + closeChar + '</span>');

        }
653567
public function saveinnlang()
    {
        $soxId = $this->getEditObjectId();
        $aParams = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("editval");

        // checkbox handling
        if (!isset($aParams['oxwrapping__oxactive'])) {
            $aParams['oxwrapping__oxactive'] = 0;
        }

        $oWrapping = oxNew(\OxidEsales\Eshop\Application\Model\Wrapping::class);

        if ($soxId != "-1") {
            $oWrapping->load($soxId);
        } else {
            $aParams['oxwrapping__oxid'] = null;
            //$aParams = $oWrapping->ConvertNameArray2Idx( $aParams);
        }

        //Disable editing for derived articles
        if ($oWrapping->isDerived()) {
            return;
        }

        $oWrapping->setLanguage(0);
        $oWrapping->assign($aParams);
        $oWrapping->setLanguage($this->_iEditLang);

        $oWrapping = \OxidEsales\Eshop\Core\Registry::getUtilsFile()->processFiles($oWrapping);
        $oWrapping->save();

        // set oxid if inserted
        $this->setEditObjectId($oWrapping->getId());
    }
1124070
void saveScript() throws IOException {
		// We'll always try to read it in with the default next time its loaded
		this.charset = ExtensionScript.DEFAULT_CHARSET;
		try ( BufferedWriter bw = Files.newBufferedWriter(file.toPath(), charset)) {
			bw.append(getContents());
		}
		this.lastModified = file.lastModified();
	}
640968
public void actionChangeBodyElement() {

        try {
            // save eventually changed content of the editor to the temporary file
            Locale oldLocale = CmsLocaleManager.getLocale(getParamOldelementlanguage());
            performSaveContent(getParamOldelementname(), oldLocale);
        } catch (CmsException e) {
            // show error page
            try {
                showErrorPage(this, e);
            } catch (JspException exc) {
                // should usually never happen
                if (LOG.isInfoEnabled()) {
                    LOG.info(exc);
                }
            }
        }
        // re-initialize the element name if the language has changed
        if (!getParamElementlanguage().equals(getParamOldelementlanguage())) {
            initBodyElementName(getParamOldelementname());
        }
        // get the new editor content
        initContent();
    }
1262053
function saveTransformedData(uri) {
  return function (data) {
    return db.put(uri, JSON.stringify(data))
      .then(function () {
        // If the Promise resolves it means we saved,
        // so let's return the data
        return data;
      });
  };
}
292028
def changes_str2(self, tab_string='  '):
        '''
        
        '''
        changes = []
        for item in self._get_recursive_difference(type='intersect'):
            if item.diffs:
                changes.append('{tab}{0}={1} (updated):\n{tab}{tab}{2}'
                               ''.format(self._key, item.past_dict[self._key],
                                         item.changes_str.replace(
                                             '\n',
                                             '\n{0}{0}'.format(tab_string)),
                                         tab=tab_string))
        for item in self._get_recursive_difference(type='removed'):
            if item.past_dict:
                changes.append('{tab}{0}={1} (removed)'.format(
                    self._key, item.past_dict[self._key], tab=tab_string))
        for item in self._get_recursive_difference(type='added'):
            if item.current_dict:
                changes.append('{tab}{0}={1} (added): {2}'.format(
                    self._key, item.current_dict[self._key],
                    dict(item.current_dict), tab=tab_string))
        return '\n'.join(changes)
1079662
function saveNewVersion(version, versionFile) {
    fs.writeFileSync(versionFile, JSON.stringify({
        version
    }, null, 2), 'UTF-8');
}
1108869
function(src, regex, substr, options, index, actionName) {
    //takes the src content and changes the content
    var regExp = null,
        updatedSrc;
    if (typeof regex ===  'string') {
      regExp = new RegExp(regex , options); //regex => string
    } else {
      regExp = regex; //regex => RegExp object
    }
    updatedSrc = String(src).replace(regExp, substr); //note: substr can be a function
    index = typeof index === 'undefined' ? '' : index;
    if (!actionName) {
      grunt.log.verbose.ok(index + 1 + ' action(s) completed.');
    } else {
      grunt.log.verbose.ok(actionName + ' action completed.');
    }
    return updatedSrc;
  }