takes people names from blockchain and writes deduped names in a 'cache'
762046
def create_search_index():
    

    # create people name cache
    counter = 0

    people_names = []
    twitter_handles = []
    usernames = []

    log.debug("-" * 5)
    log.debug("Creating search index")

    for user in namespace.find():
        # the profile/info to be inserted
        search_profile = {}

        counter += 1

        if(counter % 1000 == 0):
            log.debug("Processed entries: %s" % counter)

        if validUsername(user['username']):
            pass
        else:
            continue

        profile = get_json(user['profile'])


        hasBazaarId=False
        # search for openbazaar id in the profile
        if 'account' in profile:
            for accounts in profile['account']:
                if  accounts['service'] == 'openbazaar':
                   hasBazaarId = True
                   search_profile['openbazaar']=accounts['identifier']

        if (hasBazaarId == False):
            search_profile['openbazaar'] = None

        if 'name' in profile:
            try:
                name = profile['name']
            except:
                continue

            try:
                name = name['formatted'].lower()
            except:
                name = name.lower()
            people_names.append(name)
            search_profile['name'] = name

        else:
            search_profile['name'] = None

        if 'twitter' in profile:
            twitter_handle = profile['twitter']

            try:
                twitter_handle = twitter_handle['username'].lower()
            except:
                try:
                    twitter_handle = profile['twitter'].lower()
                except:
                    continue

            twitter_handles.append(twitter_handle)
            search_profile['twitter_handle'] = twitter_handle

        else:
            search_profile['twitter_handle'] = None

        search_profile['fullyQualifiedName'] = user['fqu']
        search_profile['username'] = user['username']
        usernames.append(user['fqu'])

        search_profile['profile'] = profile
        search_profiles.save(search_profile)


    # dedup names
    people_names = list(set(people_names))
    people_names = {'name': people_names}

    twitter_handles = list(set(twitter_handles))
    twitter_handles = {'twitter_handle': twitter_handles}

    usernames = list(set(usernames))
    usernames = {'username': usernames}

    # save final dedup results to mongodb (using it as a cache)
    people_cache.save(people_names)
    twitter_cache.save(twitter_handles)
    username_cache.save(usernames)

    optimize_db()

    log.debug('Created name/twitter/username search index')
913687
def dedupFasta(reads):
    
    seen = set()
    add = seen.add
    for read in reads:
        hash_ = md5(read.sequence.encode('UTF-8')).digest()
        if hash_ not in seen:
            add(hash_)
            yield read
1215427
def locked_blocks_iterator(blockfile, start_info=(0, 0), cached_headers=50, batch_size=50):
    
    f = blockfile
    current_state = []

    def change_state(bc, ops):
        for op, bh, work in ops:
            if op == 'add':
                current_state.append(bh)
                pass
            else:
                current_state.pop()
    bc = BlockChain()
    bc.add_change_callback(change_state)
    bhs = []
    index = 0
    info_offset = start_info
    while 1:
        v = blockfile.next_offset(info_offset)
        if v is None:
            break
        block_offset, info_offset = v
        f.jump_to(block_offset)
        bh = Block.parse_as_header(f)
        bh.info = block_offset

        bhs.append(bh)
        if len(bhs) > batch_size:
            bc.add_headers(bhs)
            bhs = []
            if len(current_state) > cached_headers:
                for bh in current_state[:cached_headers]:
                    bh.index = index
                    yield bh
                    index += 1
                    bc.lock_to_index(index)
                current_state = current_state[cached_headers:]
378288
def _update_names(self):
        """"""

        d = dict(
            table=self.table_name,
            time=self.time,
            space=self.space,
            grain=self.grain,
            variant=self.variant,
            segment=self.segment
        )

        assert self.dataset

        name = PartialPartitionName(**d).promote(self.dataset.identity.name)

        self.name = str(name.name)
        self.vname = str(name.vname)
        self.cache_key = name.cache_key
        self.fqname = str(self.identity.fqname)
1173385
function nameDuplicates(duplicates) {
    // enumerate duplicate hash groups in sorted order
    var hashes = Object.keys(duplicates).sort();

    // process each group
    processGroup(0);
    function processGroup(i) {
      if(i === hashes.length) {
        // done, create JSON-LD array
        return createArray();
      }

      // name each group member
      var group = duplicates[hashes[i]];
      var results = [];
      nameGroupMember(group, 0);
      function nameGroupMember(group, n) {
        if(n === group.length) {
          // name bnodes in hash order
          results.sort(function(a, b) {
            a = a.hash;
            b = b.hash;
            return (a < b) ? -1 : ((a > b) ? 1 : 0);
          });
          for(var r in results) {
            // name all bnodes in path namer in key-entry order
            // Note: key-order is preserved in javascript
            for(var key in results[r].pathNamer.existing) {
              namer.getName(key);
            }
          }
          return processGroup(i + 1);
        }

        // skip already-named bnodes
        var bnode = group[n];
        if(namer.isNamed(bnode)) {
          return nameGroupMember(group, n + 1);
        }

        // hash bnode paths
        var pathNamer = new UniqueNamer('_:b');
        pathNamer.getName(bnode);
        _hashPaths(bnode, bnodes, namer, pathNamer,
          function(err, result) {
            if(err) {
              return callback(err);
            }
            results.push(result);
            nameGroupMember(group, n + 1);
          });
      }
    }
  }
1031455
def cache_keys(keys):
    """"""
    d = known_keys()
    known_names = dict(zip(d.values(), d.keys()))
    for k in keys:
        i = (ord(k),) if len(k) == 1 else known_names[k]
        _key_cache.insert(0, i)
542123
def sync(self, vault_client):
        """"""
        if self.present and not self.existing:
            LOG.info("Writing new %s to %s",
                     self.secret_format, self)
            self.write(vault_client)
        elif self.present and self.existing:
            if self.diff() == CHANGED or self.diff() == OVERWRITE:
                LOG.info("Updating %s in %s",
                         self.secret_format, self)
                self.write(vault_client)
        elif not self.present and not self.existing:
            LOG.info("No %s to remove from %s",
                     self.secret_format, self)
        elif not self.present and self.existing:
            LOG.info("Removing %s from %s",
                     self.secret_format, self)
            self.delete(vault_client)
136326
def repair_duplicate_names(self):
		
		for name in self._all_names():
			cur = self.db.find({'names': name})
			main_doc = next(cur)
			for duplicate in cur:
				query = {'_id': main_doc['_id']}
				update = {
					'$inc': {'value': duplicate['value']},
					'$push': {'names': {'$each': duplicate['names']}},
				}
				self.db.update(query, update)
				self.db.remove(duplicate)
542090
def create(ctx, to, amount, symbol, secret, hash, account, expiration):
    
    ctx.blockchain.blocking = True
    tx = ctx.blockchain.htlc_create(
        Amount(amount, symbol),
        to,
        secret,
        hash_type=hash,
        expiration=expiration,
        account=account,
    )
    tx.pop("trx", None)
    print_tx(tx)
    results = tx.get("operation_results", {})
    if results:
        htlc_id = results[0][1]
        print("Your htlc_id is: {}".format(htlc_id))
691070
function usernameIsUnique ( id ) {
        var deferred = q.defer();

        db.users.query( [ { key: 'identities.basic.username', cmp: '=', value: user.identities.basic.username } ] ,
            { limit: 1, skip: 0 } ).then(
                function ( payload ) {
                    if ( payload.total === 0 ) {
                        deferred.resolve();
                    }
                    else if( !_.isUndefined( id ) && payload.results[0]._id.toString() === id.toString() ) {
                        deferred.resolve();
                    }
                    else {
                        deferred.reject( new Error(messages.duplicate_username) );
                    }
                },
                function ( err ) {
                    deferred.reject( err );
                }
            );

        return deferred.promise;
    }
670805
def get_blockcypher_walletname_from_mpub(mpub, subchain_indices=[]):
    '''
    
    '''

    #  http://stackoverflow.com/a/19877309/1754586
    mpub = mpub.encode('utf-8')

    if subchain_indices:
        mpub += ','.join([str(x) for x in subchain_indices]).encode('utf-8')
    return 'X%s' % sha256(mpub).hexdigest()[:24]
857774
function getName(name) {
    const ext = path.extname(name);
    
    const nameCrypt = crypto.createHash('sha1')
        .update(name)
        .digest('hex') + ext;
    
    return getDir() + nameCrypt;
}
681182
def cache_from_names(self):
        """"""
        cache_from = self.cache_from()

        if not cache_from or cache_from is NotSpecified:
            return

        if cache_from is True:
            yield self.image_name
            return

        for thing in cache_from:
            if not isinstance(thing, six.string_types):
                yield thing.image_name
            else:
                yield thing
610322
function hashJsonSync(data, algorithm) {
    var hash = crypto.createHash(algorithm);
    (function feed(val) {
        var keys = _.keys(val).sort();
        if (keys.length) {
            hash.update(JSON.stringify(keys), 'utf8');
            _.forEach(keys, function (key) {
                var value = val[key];
                if (!_.isUndefined(value)) {
                    if (!_.isObject(value)) {
                        hash.update(JSON.stringify(value), 'utf8');
                    }
                    else {
                        feed(value);
                    }
                }
            });
        }
    })(JSON.parse(JSON.stringify(data)));
    return hash.digest();
}
929440
def make_raw_transaction(
    network: str,
    inputs: list,
    outputs: list,
    locktime: Locktime,
    timestamp: int=int(time()),
    version: int=1,
) -> MutableTransaction:
    ''''''

    network_params = net_query(network)

    if network_params.name.startswith("peercoin"):
        return MutableTransaction(
            version=version,
            ins=inputs,
            outs=outputs,
            locktime=locktime,
            network=network_params,
            timestamp=timestamp,
        )

    return MutableTransaction(
        version=version,
        ins=inputs,
        outs=outputs,
        locktime=locktime,
        network=network_params,
    )
125868
def deposit!(amount, source_account_id, dedupe_id = SecureRandom.uuid)
      data = {
        amount: amount,
        source_account_id: source_account_id,
        dedupe_id: dedupe_id,
      }

      response = Monzo.client.put("/pots/#{@id}/deposit", data)
      parsed_response = parse_response(response)
      update_self(parsed_response)
    end
455616
function writeScriptLockedPayToPubKeyHash(address, locktime, buffer, offset) {
    let locktime_buffer = Buffer.from(locktime, 'hex');
    offset = buffer.writeUInt8(27 + locktime_buffer.length, offset); //Script length
    offset = buffer.writeUInt8(locktime_buffer.length, offset); //Length of locktime
    offset += locktime_buffer.copy(buffer, offset);
    offset = buffer.writeUInt8(OPS.OP_NUMEQUALVERIFY, offset);
    offset = buffer.writeUInt8(OPS.OP_DUP, offset);
    offset = buffer.writeUInt8(OPS.OP_HASH160, offset);
    //Write previous output address
    offset = buffer.writeUInt8(20, offset); //Address length
    offset += Buffer.from(base58check.decode(address, 'hex').data, 'hex').copy(buffer, offset);
    offset = buffer.writeUInt8(OPS.OP_EQUALVERIFY, offset);
    offset = buffer.writeUInt8(OPS.OP_CHECKSIG, offset);
    return offset;
}