text:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<TITLE>
Constant Field Values (Apache Hadoop HDFS 2.3.0 API)
</TITLE>

<META NAME="date" CONTENT="2015-03-06">

<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">

      Overview
      Package
      Class
      Use
      Tree
      Deprecated
      Index
      Help

 PREV
 NEXT

  FRAMES
 NO FRAMES

  All Classes

Constant Field Values

Contents

org.apache.*

org.apache.*

org.apache.hadoop.hdfs.protocol.CacheDirectiveInfo.Expiration

public static final long
MAX_RELATIVE_EXPIRY_MS
2305843009213693951L

org.apache.hadoop.hdfs.protocol.CachePoolInfo

public static final long
DEFAULT_LIMIT
9223372036854775807L

public static final long
DEFAULT_MAX_RELATIVE_EXPIRY
2305843009213693951L

public static final long
LIMIT_UNLIMITED
9223372036854775807L

public static final long
RELATIVE_EXPIRY_NEVER
2305843009213693951L

org.apache.hadoop.hdfs.protocol.FSLimitException.MaxDirectoryItemsExceededException

protected static final long
serialVersionUID
1L

org.apache.hadoop.hdfs.protocol.FSLimitException.PathComponentTooLongException

protected static final long
serialVersionUID
1L

org.apache.hadoop.hdfs.qjournal.protocol.QJournalProtocolProtos.AcceptRecoveryRequestProto

public static final int
FROMURL_FIELD_NUMBER
3

public static final int
REQINFO_FIELD_NUMBER
1

public static final int
STATETOACCEPT_FIELD_NUMBER
2

org.apache.hadoop.hdfs.qjournal.protocol.QJournalProtocolProtos.FinalizeLogSegmentRequestProto

public static final int
ENDTXID_FIELD_NUMBER
3

public static final int
REQINFO_FIELD_NUMBER
1

public static final int
STARTTXID_FIELD_NUMBER
2

org.apache.hadoop.hdfs.qjournal.protocol.QJournalProtocolProtos.FormatRequestProto

public static final int
JID_FIELD_NUMBER
1

public static final int
NSINFO_FIELD_NUMBER
2

org.apache.hadoop.hdfs.qjournal.protocol.QJournalProtocolProtos.GetEditLogManifestRequestProto

public static final int
INPROGRESSOK_FIELD_NUMBER
4

public static final int
JID_FIELD_NUMBER
1

public static final int
SINCETXID_FIELD_NUMBER
2

org.apache.hadoop.hdfs.qjournal.protocol.QJournalProtocolProtos.GetEditLogManifestResponseProto

public static final int
FROMURL_FIELD_NUMBER
3

public static final int
HTTPPORT_FIELD_NUMBER
2

public static final int
MANIFEST_FIELD_NUMBER
1

org.apache.hadoop.hdfs.qjournal.protocol.QJournalProtocolProtos.GetJournalStateRequestProto

public static final int
JID_FIELD_NUMBER
1

org.apache.hadoop.hdfs.qjournal.protocol.QJournalProtocolProtos.GetJournalStateResponseProto

public static final int
FROMURL_FIELD_NUMBER
3

public static final int
HTTPPORT_FIELD_NUMBER
2

public static final int
LASTPROMISEDEPOCH_FIELD_NUMBER
1

org.apache.hadoop.hdfs.qjournal.protocol.QJournalProtocolProtos.HeartbeatRequestProto

public static final int
REQINFO_FIELD_NUMBER
1

org.apache.hadoop.hdfs.qjournal.protocol.QJournalProtocolProtos.IsFormattedRequestProto

public static final int
JID_FIELD_NUMBER
1

org.apache.hadoop.hdfs.qjournal.protocol.QJournalProtocolProtos.IsFormattedResponseProto

public static final int
ISFORMATTED_FIELD_NUMBER
1

org.apache.hadoop.hdfs.qjournal.protocol.QJournalProtocolProtos.JournalIdProto

public static final int
IDENTIFIER_FIELD_NUMBER
1

org.apache.hadoop.hdfs.qjournal.protocol.QJournalProtocolProtos.JournalRequestProto

public static final int
FIRSTTXNID_FIELD_NUMBER
2

public static final int
NUMTXNS_FIELD_NUMBER
3

public static final int
RECORDS_FIELD_NUMBER
4

public static final int
REQINFO_FIELD_NUMBER
1

public static final int
SEGMENTTXNID_FIELD_NUMBER
5

org.apache.hadoop.hdfs.qjournal.protocol.QJournalProtocolProtos.NewEpochRequestProto

public static final int
EPOCH_FIELD_NUMBER
3

public static final int
JID_FIELD_NUMBER
1

public static final int
NSINFO_FIELD_NUMBER
2

org.apache.hadoop.hdfs.qjournal.protocol.QJournalProtocolProtos.NewEpochResponseProto

public static final int
LASTSEGMENTTXID_FIELD_NUMBER
1

org.apache.hadoop.hdfs.qjournal.protocol.QJournalProtocolProtos.PersistedRecoveryPaxosData

public static final int
ACCEPTEDINEPOCH_FIELD_NUMBER
2

public static final int
SEGMENTSTATE_FIELD_NUMBER
1

org.apache.hadoop.hdfs.qjournal.protocol.QJournalProtocolProtos.PrepareRecoveryRequestProto

public static final int
REQINFO_FIELD_NUMBER
1

public static final int
SEGMENTTXID_FIELD_NUMBER
2

org.apache.hadoop.hdfs.qjournal.protocol.QJournalProtocolProtos.PrepareRecoveryResponseProto

public static final int
ACCEPTEDINEPOCH_FIELD_NUMBER
2

public static final int
LASTCOMMITTEDTXID_FIELD_NUMBER
4

public static final int
LASTWRITEREPOCH_FIELD_NUMBER
3

public static final int
SEGMENTSTATE_FIELD_NUMBER
1

org.apache.hadoop.hdfs.qjournal.protocol.QJournalProtocolProtos.PurgeLogsRequestProto

public static final int
MINTXIDTOKEEP_FIELD_NUMBER
2

public static final int
REQINFO_FIELD_NUMBER
1

org.apache.hadoop.hdfs.qjournal.protocol.QJournalProtocolProtos.RequestInfoProto

public static final int
COMMITTEDTXID_FIELD_NUMBER
4

public static final int
EPOCH_FIELD_NUMBER
2

public static final int
IPCSERIALNUMBER_FIELD_NUMBER
3

public static final int
JOURNALID_FIELD_NUMBER
1

org.apache.hadoop.hdfs.qjournal.protocol.QJournalProtocolProtos.SegmentStateProto

public static final int
ENDTXID_FIELD_NUMBER
2

public static final int
ISINPROGRESS_FIELD_NUMBER
3

public static final int
STARTTXID_FIELD_NUMBER
1

org.apache.hadoop.hdfs.qjournal.protocol.QJournalProtocolProtos.StartLogSegmentRequestProto

public static final int
REQINFO_FIELD_NUMBER
1

public static final int
TXID_FIELD_NUMBER
2

org.apache.hadoop.hdfs.server.datanode.ReplicaNotFoundException

public static final String
NON_EXISTENT_REPLICA
"Cannot append to a non-existent replica "

public static final String
NON_RBW_REPLICA
"Cannot recover a non-RBW replica "

public static final String
UNEXPECTED_GS_REPLICA
"Cannot append to a replica with unexpeted generation stamp "

public static final String
UNFINALIZED_AND_NONRBW_REPLICA
"Cannot recover append/close to a replica that\'s not FINALIZED and not RBW "

public static final String
UNFINALIZED_REPLICA
"Cannot append to an unfinalized replica "

org.apache.hadoop.hdfs.server.namenode.CancelDelegationTokenServlet

public static final String
PATH_SPEC
"/cancelDelegationToken"

public static final String
TOKEN
"token"

org.apache.hadoop.hdfs.server.namenode.FSDirectory

public static final String
DOT_INODES_STRING
".inodes"

public static final String
DOT_RESERVED_PATH_PREFIX
"/.reserved"

public static final String
DOT_RESERVED_STRING
".reserved"

org.apache.hadoop.hdfs.server.namenode.GetDelegationTokenServlet

public static final String
PATH_SPEC
"/getDelegationToken"

public static final String
RENEWER
"renewer"

org.apache.hadoop.hdfs.server.namenode.INodeDirectory

protected static final int
DEFAULT_FILES_PER_DIRECTORY
5

org.apache.hadoop.hdfs.server.namenode.RenewDelegationTokenServlet

public static final String
PATH_SPEC
"/renewDelegationToken"

public static final String
TOKEN
"token"

org.apache.hadoop.hdfs.server.namenode.ha.proto.HAZKInfoProtos.ActiveNodeInfo

public static final int
HOSTNAME_FIELD_NUMBER
3

public static final int
NAMENODEID_FIELD_NUMBER
2

public static final int
NAMESERVICEID_FIELD_NUMBER
1

public static final int
PORT_FIELD_NUMBER
4

public static final int
ZKFCPORT_FIELD_NUMBER
5

org.apache.hadoop.hdfs.util.LightWeightHashSet<T>

protected static final float
DEFAULT_MAX_LOAD_FACTOR
0.75f

protected static final float
DEFAUT_MIN_LOAD_FACTOR
0.20000000298023224f

protected static final int
MINIMUM_CAPACITY
16

org.apache.hadoop.hdfs.util.MD5FileUtils

public static final String
MD5_SUFFIX
".md5"

org.apache.hadoop.hdfs.web.SWebHdfsFileSystem

public static final String
SCHEME
"swebhdfs"

org.apache.hadoop.hdfs.web.WebHdfsFileSystem

public static final String
PATH_PREFIX
"/webhdfs/v1"

public static final String
SCHEME
"webhdfs"

public static final int
VERSION
1

org.apache.hadoop.hdfs.web.resources.AccessTimeParam

public static final String
DEFAULT
"-1"

public static final String
NAME
"accesstime"

org.apache.hadoop.hdfs.web.resources.BlockSizeParam

public static final String
DEFAULT
"null"

public static final String
NAME
"blocksize"

org.apache.hadoop.hdfs.web.resources.BufferSizeParam

public static final String
DEFAULT
"null"

public static final String
NAME
"buffersize"

org.apache.hadoop.hdfs.web.resources.ConcatSourcesParam

public static final String
DEFAULT
""

public static final String
NAME
"sources"

org.apache.hadoop.hdfs.web.resources.CreateParentParam

public static final String
DEFAULT
"false"

public static final String
NAME
"createparent"

org.apache.hadoop.hdfs.web.resources.DelegationParam

public static final String
DEFAULT
""

public static final String
NAME
"delegation"

org.apache.hadoop.hdfs.web.resources.DestinationParam

public static final String
DEFAULT
""

public static final String
NAME
"destination"

org.apache.hadoop.hdfs.web.resources.DoAsParam

public static final String
DEFAULT
""

public static final String
NAME
"doas"

org.apache.hadoop.hdfs.web.resources.GroupParam

public static final String
DEFAULT
""

public static final String
NAME
"group"

org.apache.hadoop.hdfs.web.resources.HttpOpParam<E extends Enum<E> & HttpOpParam.Op>

public static final String
DEFAULT
"null"

public static final String
NAME
"op"

org.apache.hadoop.hdfs.web.resources.LengthParam

public static final String
DEFAULT
"null"

public static final String
NAME
"length"

org.apache.hadoop.hdfs.web.resources.ModificationTimeParam

public static final String
DEFAULT
"-1"

public static final String
NAME
"modificationtime"

org.apache.hadoop.hdfs.web.resources.NamenodeRpcAddressParam

public static final String
DEFAULT
""

public static final String
NAME
"namenoderpcaddress"

org.apache.hadoop.hdfs.web.resources.OffsetParam

public static final String
DEFAULT
"0"

public static final String
NAME
"offset"

org.apache.hadoop.hdfs.web.resources.OverwriteParam

public static final String
DEFAULT
"false"

public static final String
NAME
"overwrite"

org.apache.hadoop.hdfs.web.resources.OwnerParam

public static final String
DEFAULT
""

public static final String
NAME
"owner"

org.apache.hadoop.hdfs.web.resources.PermissionParam

public static final String
DEFAULT
"null"

public static final String
NAME
"permission"

org.apache.hadoop.hdfs.web.resources.RecursiveParam

public static final String
DEFAULT
"false"

public static final String
NAME
"recursive"

org.apache.hadoop.hdfs.web.resources.RenameOptionSetParam

public static final String
DEFAULT
""

public static final String
NAME
"renameoptions"

org.apache.hadoop.hdfs.web.resources.RenewerParam

public static final String
DEFAULT
"null"

public static final String
NAME
"renewer"

org.apache.hadoop.hdfs.web.resources.ReplicationParam

public static final String
DEFAULT
"null"

public static final String
NAME
"replication"

org.apache.hadoop.hdfs.web.resources.TokenArgumentParam

public static final String
DEFAULT
""

public static final String
NAME
"token"

org.apache.hadoop.hdfs.web.resources.UriFsPathParam

public static final String
NAME
"path"

org.apache.hadoop.hdfs.web.resources.UserParam

public static final String
DEFAULT
""

public static final String
NAME
"user.name"

      Overview
      Package
      Class
      Use
      Tree
      Deprecated
      Index
      Help

 PREV
 NEXT

  FRAMES
 NO FRAMES

  All Classes

Copyright © 2015 Apache Software Foundation. All Rights Reserved.


text:
package org.apache.cassandra.repair;

import java.io.IOException;
import java.net.InetAddress;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicBoolean;

import com.google.common.collect.Lists;
import com.google.common.util.concurrent.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.apache.cassandra.concurrent.DebuggableThreadPoolExecutor;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.dht.Range;
import org.apache.cassandra.dht.Token;
import org.apache.cassandra.gms.*;
import org.apache.cassandra.streaming.PreviewKind;
import org.apache.cassandra.streaming.SessionSummary;
import org.apache.cassandra.tracing.Tracing;
import org.apache.cassandra.utils.FBUtilities;
import org.apache.cassandra.utils.MerkleTrees;
import org.apache.cassandra.utils.Pair;

/**
 * Coordinates the (active) repair of a list of non overlapping token ranges.
 *
 * A given RepairSession repairs a set of replicas for a given set of ranges on a list
 * of column families. For each of the column family to repair, RepairSession
 * creates a {@link RepairJob} that handles the repair of that CF.
 *
 * A given RepairJob has the 2 main phases:
 *

 *
Validation phase: the job requests merkle trees from each of the replica involves
 *      ({@link org.apache.cassandra.repair.ValidationTask}) and waits until all trees are received (in
 *      validationComplete()).
 *

 *
Synchronization phase: once all trees are received, the job compares each tree with
 *      all the other using a so-called {@link SyncTask}. If there is difference between 2 trees, the
 *      concerned SyncTask will start a streaming of the difference between the 2 endpoint concerned.
 *

 *

 * The job is done once all its SyncTasks are done (i.e. have either computed no differences
 * or the streaming they started is done (syncComplete())).
 *
 * A given session will execute the first phase (validation phase) of each of it's job
 * sequentially. In other words, it will start the first job and only start the next one
 * once that first job validation phase is complete. This is done so that the replica only
 * create one merkle tree per range at a time, which is our way to ensure that such creation starts
 * roughly at the same time on every node (see CASSANDRA-2816). However the synchronization
 * phases are allowed to run concurrently (with each other and with validation phases).
 *
 * A given RepairJob has 2 modes: either sequential or not (RepairParallelism). If sequential,
 * it will requests merkle tree creation from each replica in sequence (though in that case
 * we still first send a message to each node to flush and snapshot data so each merkle tree
 * creation is still done on similar data, even if the actual creation is not
 * done simulatneously). If not sequential, all merkle tree are requested in parallel.
 * Similarly, if a job is sequential, it will handle one SyncTask at a time, but will handle
 * all of them in parallel otherwise.
 */
public class RepairSession extends AbstractFuture<RepairSessionResult> implements IEndpointStateChangeSubscriber,
                                                                                IFailureDetectionEventListener
{
    private static Logger logger = LoggerFactory.getLogger(RepairSession.class);

    public final UUID parentRepairSession;
    /** Repair session ID */
    private final UUID id;
    public final String keyspace;
    private final String[] cfnames;
    public final RepairParallelism parallelismDegree;
    public final boolean pullRepair;
    /** Range to repair */
    public final Collection<Range<Token>> ranges;
    public final Set<InetAddress> endpoints;
    public final boolean isConsistent;
    public final PreviewKind previewKind;

    private final AtomicBoolean isFailed = new AtomicBoolean(false);

    // Each validation task waits response from replica in validating ConcurrentMap (keyed by CF name and endpoint address)
    private final ConcurrentMap<Pair<RepairJobDesc, InetAddress>, ValidationTask> validating = new ConcurrentHashMap<>();
    // Remote syncing jobs wait response in syncingTasks map
    private final ConcurrentMap<Pair<RepairJobDesc, NodePair>, RemoteSyncTask> syncingTasks = new ConcurrentHashMap<>();

    // Tasks(snapshot, validate request, differencing, ...) are run on taskExecutor
    public final ListeningExecutorService taskExecutor = MoreExecutors.listeningDecorator(DebuggableThreadPoolExecutor.createCachedThreadpoolWithMaxSize("RepairJobTask"));

    private volatile boolean terminated = false;

    /**
     * Create new repair session.
     *
     * @param parentRepairSession the parent sessions id
     * @param id this sessions id
     * @param ranges ranges to repair
     * @param keyspace name of keyspace
     * @param parallelismDegree specifies the degree of parallelism when calculating the merkle trees
     * @param endpoints the data centers that should be part of the repair; null for all DCs
     * @param repairedAt when the repair occurred (millis)
     * @param pullRepair true if the repair should be one way (from remote host to this host and only applicable between two hosts--see RepairOption)
     * @param cfnames names of columnfamilies
     */
    public RepairSession(UUID parentRepairSession,
                         UUID id,
                         Collection<Range<Token>> ranges,
                         String keyspace,
                         RepairParallelism parallelismDegree,
                         Set<InetAddress> endpoints,
                         boolean isConsistent,
                         boolean pullRepair,
                         PreviewKind previewKind,
                         String... cfnames)
    {
        assert cfnames.length > 0 : "Repairing no column families seems pointless, doesn't it";

        this.parentRepairSession = parentRepairSession;
        this.id = id;
        this.parallelismDegree = parallelismDegree;
        this.keyspace = keyspace;
        this.cfnames = cfnames;
        this.ranges = ranges;
        this.endpoints = endpoints;
        this.isConsistent = isConsistent;
        this.previewKind = previewKind;
        this.pullRepair = pullRepair;
    }

    public UUID getId()
    {
        return id;
    }

    public Collection<Range<Token>> getRanges()
    {
        return ranges;
    }

    public void waitForValidation(Pair<RepairJobDesc, InetAddress> key, ValidationTask task)
    {
        validating.put(key, task);
    }

    public void waitForSync(Pair<RepairJobDesc, NodePair> key, RemoteSyncTask task)
    {
        syncingTasks.put(key, task);
    }

    /**
     * Receive merkle tree response or failed response from {@code endpoint} for current repair job.
     *
     * @param desc repair job description
     * @param endpoint endpoint that sent merkle tree
     * @param trees calculated merkle trees, or null if validation failed
     */
    public void validationComplete(RepairJobDesc desc, InetAddress endpoint, MerkleTrees trees)
    {
        ValidationTask task = validating.remove(Pair.create(desc, endpoint));
        if (task == null)
        {
            assert terminated;
            return;
        }

        String message = String.format("Received merkle tree for %s from %s", desc.columnFamily, endpoint);
        logger.info("{} {}", previewKind.logPrefix(getId()), message);
        Tracing.traceRepair(message);
        task.treesReceived(trees);
    }

    /**
     * Notify this session that sync completed/failed with given {@code NodePair}.
     *
     * @param desc synced repair job
     * @param nodes nodes that completed sync
     * @param success true if sync succeeded
     */
    public void syncComplete(RepairJobDesc desc, NodePair nodes, boolean success, List<SessionSummary> summaries)
    {
        RemoteSyncTask task = syncingTasks.get(Pair.create(desc, nodes));
        if (task == null)
        {
            assert terminated;
            return;
        }

        logger.debug("{} Repair completed between {} and {} on {}", previewKind.logPrefix(getId()), nodes.endpoint1, nodes.endpoint2, desc.columnFamily);
        task.syncComplete(success, summaries);
    }

    private String repairedNodes()
    {
        StringBuilder sb = new StringBuilder();
        sb.append(FBUtilities.getBroadcastAddress());
        for (InetAddress ep : endpoints)
            sb.append(", ").append(ep);
        return sb.toString();
    }

    /**
     * Start RepairJob on given ColumnFamilies.
     *
     * This first validates if all replica are available, and if they are,
     * creates RepairJobs and submit to run on given executor.
     *
     * @param executor Executor to run validation
     */
    public void start(ListeningExecutorService executor)
    {
        String message;
        if (terminated)
            return;

        logger.info("{} new session: will sync {} on range {} for {}.{}", previewKind.logPrefix(getId()), repairedNodes(), ranges, keyspace, Arrays.toString(cfnames));
        Tracing.traceRepair("Syncing range {}", ranges);
        if (!previewKind.isPreview())
        {
            SystemDistributedKeyspace.startRepairs(getId(), parentRepairSession, keyspace, cfnames, ranges, endpoints);
        }

        if (endpoints.isEmpty())
        {
            logger.info("{} {}", previewKind.logPrefix(getId()), message = String.format("No neighbors to repair with on range %s: session completed", ranges));
            Tracing.traceRepair(message);
            set(new RepairSessionResult(id, keyspace, ranges, Lists.<RepairResult>newArrayList()));
            if (!previewKind.isPreview())
            {
                SystemDistributedKeyspace.failRepairs(getId(), keyspace, cfnames, new RuntimeException(message));
            }
            return;
        }

        // Checking all nodes are live
        for (InetAddress endpoint : endpoints)
        {
            if (!FailureDetector.instance.isAlive(endpoint))
            {
                message = String.format("Cannot proceed on repair because a neighbor (%s) is dead: session failed", endpoint);
                logger.error("{} {}", previewKind.logPrefix(getId()), message);
                Exception e = new IOException(message);
                setException(e);
                if (!previewKind.isPreview())
                {
                    SystemDistributedKeyspace.failRepairs(getId(), keyspace, cfnames, e);
                }
                return;
            }
        }

        // Create and submit RepairJob for each ColumnFamily
        List<ListenableFuture<RepairResult>> jobs = new ArrayList<>(cfnames.length);
        for (String cfname : cfnames)
        {
            RepairJob job = new RepairJob(this, cfname, isConsistent, previewKind);
            executor.execute(job);
            jobs.add(job);
        }

        // When all RepairJobs are done without error, cleanup and set the final result
        Futures.addCallback(Futures.allAsList(jobs), new FutureCallback<List<RepairResult>>()
        {
            public void onSuccess(List<RepairResult> results)
            {
                // this repair session is completed
                logger.info("{} {}", previewKind.logPrefix(getId()), "Session completed successfully");
                Tracing.traceRepair("Completed sync of range {}", ranges);
                set(new RepairSessionResult(id, keyspace, ranges, results));

                taskExecutor.shutdown();
                // mark this session as terminated
                terminate();
            }

            public void onFailure(Throwable t)
            {
                logger.error("{} Session completed with the following error", previewKind.logPrefix(getId()), t);
                Tracing.traceRepair("Session completed with the following error: {}", t);
                forceShutdown(t);
            }
        });
    }

    public void terminate()
    {
        terminated = true;
        validating.clear();
        syncingTasks.clear();
    }

    /**
     * clear all RepairJobs and terminate this session.
     *
     * @param reason Cause of error for shutdown
     */
    public void forceShutdown(Throwable reason)
    {
        setException(reason);
        taskExecutor.shutdownNow();
        terminate();
    }

    public void onJoin(InetAddress endpoint, EndpointState epState) {}
    public void beforeChange(InetAddress endpoint, EndpointState currentState, ApplicationState newStateKey, VersionedValue newValue) {}
    public void onChange(InetAddress endpoint, ApplicationState state, VersionedValue value) {}
    public void onAlive(InetAddress endpoint, EndpointState state) {}
    public void onDead(InetAddress endpoint, EndpointState state) {}

    public void onRemove(InetAddress endpoint)
    {
        convict(endpoint, Double.MAX_VALUE);
    }

    public void onRestart(InetAddress endpoint, EndpointState epState)
    {
        convict(endpoint, Double.MAX_VALUE);
    }

    public void convict(InetAddress endpoint, double phi)
    {
        if (!endpoints.contains(endpoint))
            return;

        // We want a higher confidence in the failure detection than usual because failing a repair wrongly has a high cost.
        if (phi < 2 * DatabaseDescriptor.getPhiConvictThreshold())
            return;

        // Though unlikely, it is possible to arrive here multiple time and we
        // want to avoid print an error message twice
        if (!isFailed.compareAndSet(false, true))
            return;

        Exception exception = new IOException(String.format("Endpoint %s died", endpoint));
        logger.error(String.format("{} session completed with the following error", previewKind.logPrefix(getId())), exception);
        // If a node failed, we stop everything (though there could still be some activity in the background)
        forceShutdown(exception);
    }
}

redpajama_set_name: RedPajamaGithub


text:
package com.alibaba.json.bvt.bug;

import org.junit.Assert;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import junit.framework.TestCase;

public class Bug_for_issue_434 extends TestCase {

    public void test_for_issue() throws Exception {
        String json = "{value:[\"null\"]}";
        JSONObject parse = JSONObject.parseObject(json);
        JSONArray jsonArray = parse.getJSONArray("value");
        Assert.assertEquals(1, jsonArray.size());
    }

}


text:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<feed><tipo>Rua</tipo><logradouro>Bahia</logradouro><bairro>Guaíra</bairro><cidade>Curitiba</cidade><uf>PR</uf><cep>80630250</cep></feed>


text:
import '@web/third_party/vscode/codicon.css';
import { Workbench } from './ui/workbench';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { applyTheme } from '@web/theme';
import '@web/common.css';

(async () => {
  applyTheme();
  if (window.location.protocol !== 'file:') {
    if (window.location.href.includes('isUnderTest=true'))
      await new Promise(f => setTimeout(f, 1000));
    navigator.serviceWorker.register('sw.bundle.js');
    if (!navigator.serviceWorker.controller) {
      await new Promise<void>(f => {
        navigator.serviceWorker.oncontrollerchange = () => f();
      });
    }

    // Keep SW running.
    setInterval(function() { fetch('ping'); }, 10000);
  }

  ReactDOM.render(<Workbench/>, document.querySelector('#root'));
})();


text:
class Note
  attr_reader :path

  @@app = nil
  @@titles = {}

  def self.open(*args)
    @@app.new *args
  end

  DefaultOptions = {
    :password => 'password',
    :confirmation => true
  }

  def save_as(name, with_options = {})
    options = DefaultOptions.merge with_options #(1)

    @path = @@app.path_to(name)                 #(2)
    File.delete @path if File.exist? @path

    menu 'File', 'Save As...'                   #(3)

    enter_filename @path                        #(4)
    assign_password options
  end

  def exit!(with_options = {})
    options = DefaultOptions.merge with_options

    menu 'File', 'Exit'

    @prompted[:to_confirm_exit] = dialog(@@titles[:exit]) do |d|
      d.click(options[:save_as] ? '_Yes' : '_No')
    end

    if options[:save_as]
      path = @@app.path_to options[:save_as]
      enter_filename path
      assign_password options
    end
  end

  def change_password(with_options = {})
    old_options = {
      :password => with_options[:old_password]} #(5)

    new_options = {
      :password => with_options[:password],
      :confirmation =>
        with_options[:confirmation] ||
        with_options[:password]}                #(6)

    menu 'File', 'Change Password...'

    unlock_password old_options
    assign_password new_options
  end

  def about
    menu 'Help', @@titles[:about_menu]

    @prompted[:with_help_text] = dialog(@@titles[:about]) do |d|
      d.click '_OK'
    end
  end

  [:undo, :cut, :copy, :paste, :find_next].each do |method|
    item = method.to_s.split('_').collect {|m| m.capitalize}.join(' ')
    define_method(method) {menu 'Edit', item, :wait} #(7)
  end

  def has_prompted?(kind)
    @prompted[kind]
  end

private

  def enter_filename(path, approval = '_Save')
    dialog(@@titles[:file]) do |d| #(8)
      d.type_in path
      d.click approval
    end
  end

  def unlock_password(with_options = {})
    options = DefaultOptions.merge with_options
    options[:confirmation] = false #(9)

    enter_password options
    watch_for_error
  end

  def assign_password(with_options = {})
    options = DefaultOptions.merge with_options

    enter_password options
    watch_for_error

    if @prompted[:with_error]
      enter_password :cancel_password => true #(10)
    end
  end

end

require 'fileutils'

class Note
  def self.fixture(name)
    source = @@app.path_to(name + 'Fixture')
    target = @@app.path_to(name)

    FileUtils.rm target if File.exist? target
    FileUtils.copy source, target
  end
end


text:
<?php

namespace Lug\Bundle\ResourceBundle\Tests\Form\Type;

use Lug\Bundle\ResourceBundle\Form\Type\CsrfProtectionType;
use Lug\Bundle\ResourceBundle\Tests\Form\EventSubscriber\Mock\FlashCsrfProtectionSubscriberMock;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\Forms;

/**
 * @author GeLo <geloen.eric@gmail.com>
 */
class CsrfProtectionTypeTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var FormFactoryInterface
     */
    private $factory;

    /**
     * @var CsrfProtectionType
     */
    private $csrfProtectionType;

    /**
     * @var FlashCsrfProtectionSubscriberMock
     */
    private $flashCsrfProtectionSubscriber;

    /**
     * {@inheritdoc}
     */
    protected function setUp()
    {
        $this->flashCsrfProtectionSubscriber = $this->createFlashCsrfProtectionSubscriberMock();
        $this->csrfProtectionType = new CsrfProtectionType($this->flashCsrfProtectionSubscriber);

        $this->factory = Forms::createFormFactoryBuilder()
            ->addType($this->csrfProtectionType)
            ->getFormFactory();
    }

    public function testInheritance()
    {
        $this->assertInstanceOf(AbstractType::class, $this->csrfProtectionType);
    }

    public function testIdUnicity()
    {
        $form1 = $this->factory
            ->create(CsrfProtectionType::class)
            ->createView();

        $form2 = $this->factory
            ->create(CsrfProtectionType::class)
            ->createView();

        $this->assertNotSame($form1->vars['id'], $form2->vars['id']);
    }

    public function testSubmit()
    {
        $form = $this->factory
            ->create(CsrfProtectionType::class)
            ->submit([]);

        $view = $form->createView();

        $this->assertArrayHasKey('submit', $view->children);
        $this->assertArrayHasKey('clicked', $view->children['submit']->vars);

        $this->assertSame(
            [[$this->flashCsrfProtectionSubscriber, 'onPostSubmit']],
            $form->getConfig()->getEventDispatcher()->getListeners(FormEvents::POST_SUBMIT)
        );
    }

    /**
     * @return FlashCsrfProtectionSubscriberMock
     */
    private function createFlashCsrfProtectionSubscriberMock()
    {
        return new FlashCsrfProtectionSubscriberMock();
    }
}


text:
title: Boolean Type
---

# Boolean Type

`boolean` is your basic JavaScript true/false value.

```typescript
let isDone: boolean = false;
```


text:
<?php

namespace Oro\Bundle\FormBundle\Form\Type;

use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Form\Exception\InvalidConfigurationException;
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\PropertyAccess\PropertyPath;

use Oro\Bundle\EntityBundle\ORM\DoctrineHelper;
use Oro\Bundle\FormBundle\Form\DataTransformer\EntityCreateOrSelectTransformer;

class OroEntityCreateOrSelectType extends AbstractType
{
    const NAME = 'oro_entity_create_or_select';

    const MODE_CREATE = 'create';
    const MODE_GRID   = 'grid';
    const MODE_VIEW   = 'view';
    const MODE_EDIT   = 'edit'; // this mode is fully supported in choice type only

    /**
     * @var DoctrineHelper
     */
    protected $doctrineHelper;

    /**
     * @param DoctrineHelper $doctrineHelper
     */
    public function __construct(DoctrineHelper $doctrineHelper)
    {
        $this->doctrineHelper = $doctrineHelper;
    }

    /**
     * {@inheritDoc}
     */
    public function getName()
    {
        return self::NAME;
    }

    /**
     * {@inheritDoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        // disable validation for new entity in case of existing entity
        $builder->addEventListener(
            FormEvents::PRE_SUBMIT,
            function (FormEvent $event) use ($options) {
                $data = $event->getData();
                $mode = !empty($data['mode']) ? $data['mode'] : $options['mode'];
                if ($mode != OroEntityCreateOrSelectType::MODE_CREATE) {
                    $this->disableNewEntityValidation($event->getForm(), $options);
                }
            }
        );

        // transform data from array to entity and vice versa
        $builder->addViewTransformer(
            new EntityCreateOrSelectTransformer($this->doctrineHelper, $options['class'], $options['mode'])
        );

        // new entity field
        $builder->add(
            'new_entity',
            $options['create_entity_form_type'],
            $this->getNewEntityFormOptions($options)
        );

        // existing entity field
        $builder->add(
            'existing_entity',
            'oro_entity_identifier',
            array(
                'required' => $options['required'],
                'class' => $options['class'],
                'multiple' => false,
            )
        );

        // rendering mode
        $builder->add('mode', 'hidden');
    }

    /**
     * @param array $options
     * @return array
     */
    protected function getNewEntityFormOptions(array $options)
    {
        return array_merge(
            $options['create_entity_form_options'],
            array(
                'required' => $options['required'],
                'data_class' => $options['class'],
            )
        );
    }

    /**
     * @param FormInterface $form
     * @param array $options
     */
    protected function disableNewEntityValidation(FormInterface $form, array $options)
    {
        // disable all validation for new entity field
        $form->remove('new_entity');
        $form->add(
            'new_entity',
            $options['create_entity_form_type'],
            array_merge(
                $this->getNewEntityFormOptions($options),
                array('validation_groups' => false)
            )
        );
    }

    /**
     * Important options:
     * - class - FQCN used for this form type
     * - create_entity_form_type - form type used to render create entity form
     * - create_entity_form_options - options for create entity form
     * - grid_name - name of the grid used to select existing entity
     * - existing_entity_grid_id - grid row field name used as entity identifier
     * - view_widgets - array with list of widgets used to render entity view (YAML formatted example)
     *      - {
     *          'route_name': '',
     *          'route_parameters': (optional)
     *              <route_parameter_name>: string|PropertyPath
     *              ...
     *          'grid_row_to_route': (optional)
     *              <route_parameter_name>: <grid_row_field_name>,
     *          'widget_alias' => 'my_widget_alias' (optional)
     *      }
     * - mode - view rendering mode, by default guessed based on data:
     *      - self::MODE_CREATE - entity create form is rendered
     *      - self::MODE_GRID - grid with allowed entities is rendered
     *      - self::MODE_VIEW - entity view is rendered
     *
     * {@inheritDoc}
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setRequired(
            array(
                'class',
                'create_entity_form_type',
                'grid_name',
                'view_widgets'
            )
        );

        $resolver->setDefaults(
            array(
                'data_class' => null,
                'create_entity_form_options' => array(),
                'existing_entity_grid_id' => 'id',
                'mode' => self::MODE_CREATE,
            )
        );

        $resolver->setNormalizers(
            array(
                'view_widgets' => function (Options $options, array $viewWidgets) {
                    foreach ($viewWidgets as $key => $widgetData) {
                        if (empty($widgetData['route_name'])) {
                            throw new InvalidConfigurationException(
                                'Widget route name is not defined'
                            );
                        }

                        if (!array_key_exists('route_parameters', $widgetData)) {
                            $widgetData['route_parameters'] = array('id' => new PropertyPath('id'));
                        }

                        if (!array_key_exists('grid_row_to_route', $widgetData)) {
                            $widgetData['grid_row_to_route'] = array('id' => 'id');
                        }

                        $viewWidgets[$key] = $widgetData;
                    }

                    return $viewWidgets;
                }
            )
        );
    }

    /**
     * {@inheritDoc}
     */
    public function buildView(FormView $view, FormInterface $form, array $options)
    {
        $viewWidgets = $options['view_widgets'];
        $entity = $form->getData();
        $propertyAccessor = PropertyAccess::createPropertyAccessor();

        foreach ($viewWidgets as $key => $widgetData) {
            foreach ($widgetData['route_parameters'] as $name => $value) {
                if ($value instanceof PropertyPath) {
                    try {
                        $value = $propertyAccessor->getValue($entity, $value);
                    } catch (\Exception $e) {
                        $value = null;
                    }
                    $widgetData['route_parameters'][$name] = $value;
                }
            }

            if (empty($widgetData['widget_alias'])) {
                $widgetData['widget_alias'] = $form->getName() . '_' . $widgetData['route_name'];
            }

            $viewWidgets[$key] = $widgetData;
        }

        $view->vars['view_widgets'] = $viewWidgets;
        $view->vars['grid_name'] = $options['grid_name'];
        $view->vars['existing_entity_grid_id'] = $options['existing_entity_grid_id'];
    }
}


text:
<!DOCTYPE html>

        <title>
    Signing Kernel Modules for Secure Boot | Superdanby
 </title>

        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
        <link rel="shortcut icon" type="image/jpeg" href="/Blog/abouts/me.gif" />

        <link rel="stylesheet" href="/Blog/style.min.css">

        Superdanby

        ABOUT
        CATEGORY
        TAG

            2017/05/25
            @

                   Fedora

Signing Kernel Modules for Secure Boot

                Fedora

                Secure Boot

                MOK

                TOC

Preparation

Key Creation

Create Signing Keys

Sign the Module

Register the Keys with Machine Owner Key

Reboot

MOK Enrollment

Check if the Module is Signed

Done!

Preparation

Make sure your Secure Boot is off.
In order to sign the modules, they should exist in the current environment.
Turning on Secure Boot will block the modules to load in the first place.

Key Creation

Create Signing Keys

openssl req -new -x509 -newkey rsa:2048 -keyout MOK.priv -outform DER -out MOK.der -nodes -days 36500 -subj "/CN=Descriptive name/"
Descriptive name is the name of the key. E.g. "/CN=Yee~"

Sign the Module

sudo /usr/src/kernels/$(uname -r)/scripts/sign-file sha256 ./MOK.priv ./MOK.der $(modinfo -n MODULE_NAME )
Note that you can sign multiple modules at a time. Just repeat this step until all modules are signed.

Register the Keys with Machine Owner Key

sudo mokutil --import MOK.der
You’ll be prompt to enter a password for later use in MOK.

Reboot

reboot

MOK Enrollment

Press anykey to enter MOK within 10 seconds.

Enroll MOK

Continue

Insert the password you just created.

OK

More with MOK

Check if the Module is Signed

mokutil --list-enrolled

Done!

You can now turn Secure Boot back on!

    <button id="expand-btn" href="" onclick="expand_disqus()">Comments</button>

        Powered by Hugo with theme
        zmd

        © 2020 by Superdanby
        ♥


text:
package com.beerbong.otaplatform.updater;

import java.io.File;

import org.json.JSONObject;
import org.json.JSONTokener;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;

import com.beerbong.otaplatform.R;
import com.beerbong.otaplatform.manager.ManagerFactory;
import com.beerbong.otaplatform.util.Constants;
import com.beerbong.otaplatform.util.HttpStringReader;
import com.beerbong.otaplatform.util.HttpStringReader.HttpStringReaderListener;
import com.beerbong.otaplatform.util.URLStringReader;

public class TWRPUpdater extends Updater implements Updater.UpdaterListener {

    public interface TWRPUpdaterListener {

        public void checkTWRPCompleted(long newVersion);
    }

    private Context mContext;
    private TWRPUpdaterListener mListener;
    private String mBoard;
    private String mInstallCommand;
    private boolean mScanning;

    public TWRPUpdater(Context context, TWRPUpdaterListener listener) {
        mContext = context;
        mListener = listener;

        mBoard = Constants.getProperty(PROPERTY_DEVICE);
    }

    @Override
    public void onReadEnd(String buffer) {
        mScanning = false;
        try {
            GooPackage info = null;
            if (!"false".equals(buffer)) {
                JSONObject result = (JSONObject) new JSONTokener(buffer).nextValue();
                info = new GooPackage(result, -1);
            }

            versionFound(info);
        } catch (Exception ex) {
            System.out.println(buffer);
            ex.printStackTrace();
            versionError(null);
        }
    }

    @Override
    public void onReadError(Exception ex) {
        Constants.showToastOnUiThread(mContext, R.string.check_twrp_updates_error);
        if (mListener != null) {
            ((Activity) mContext).runOnUiThread(new Runnable() {

                public void run() {
                    mListener.checkTWRPCompleted(-1);
                }
            });
        }
    }

    @Override
    public String getDeveloperId() {
        return "OpenRecovery";
    }

    @Override
    public String getName() {
        return "TWRP";
    }

    @Override
    public int getVersion() {
        return 0;
    }

    public void check() {
        if (isScanning()) {
            return;
        }
        searchVersion();
    }

    public void installTWRP(final File file, String md5) {
        String fileMd5 = Constants.md5(file);
        if (!fileMd5.equals(md5)) {
            Constants.showToastOnUiThread(mContext, R.string.check_twrp_error_md5);
            return;
        }
        if (mInstallCommand == null) {
            new HttpStringReader(new HttpStringReaderListener() {

                @Override
                public void onReadEnd(String buffer) {
                    if (buffer == null || "".equals(buffer) || "false".equals(buffer)) {
                        mInstallCommand = null;
                    } else {
                        mInstallCommand = buffer;
                    }
                    reallyInstallTWRP(file);
                }

                @Override
                public void onReadError(Exception ex) {
                    mInstallCommand = null;
                }

            }).execute(new String[] { "http://goo.im/json2&action=get_install_command&ro_board="
                    + mBoard });
        } else {
            reallyInstallTWRP(file);
        }
    }

    private void reallyInstallTWRP(File file) {
        String path = file.getAbsolutePath();
        if (path.endsWith(".img")) {
            if (mInstallCommand != null) {
                String command = mInstallCommand.replace("#FILE#", path);
                ManagerFactory.getSUManager(mContext).execute(command);
                Constants.showToastOnUiThread(mContext, R.string.twrp_installed);
            } else {
                // TODO flash image throug recovery
            }
        } else if (path.endsWith(".zip")) {
            // TODO install zip throug recovery
        }
    }

    @Override
    public void searchVersion() {
        mScanning = true;
        new URLStringReader(this).execute("http://goo.im/json2&action=recovery&ro_board=" + mBoard);
    }

    @Override
    public boolean isScanning() {
        return mScanning;
    }

    @Override
    public void versionFound(final PackageInfo info) {
        mScanning = false;
        if (info != null) {
            showNewTWRPFound(info);
        } else {
            Constants.showToastOnUiThread(mContext, R.string.check_twrp_updates_no_new);
        }
        if (mListener != null) {
            ((Activity) mContext).runOnUiThread(new Runnable() {

                public void run() {
                    mListener.checkTWRPCompleted(info == null ? -1 : info.getVersion());
                }
            });
        }
    }

    @Override
    public void versionError(String error) {
        mScanning = false;
        if (error != null) {
            Constants.showToastOnUiThread(mContext,
                    mContext.getResources().getString(R.string.check_twrp_updates_error) + ": "
                            + error);
        } else {
            Constants.showToastOnUiThread(mContext, R.string.check_twrp_updates_error);
        }
        if (mListener != null) {
            ((Activity) mContext).runOnUiThread(new Runnable() {

                public void run() {
                    mListener.checkTWRPCompleted(-1);
                }
            });
        }
    }

    private void showNewTWRPFound(final PackageInfo info) {
        ((Activity) mContext).runOnUiThread(new Runnable() {

            public void run() {
                try {
                    new AlertDialog.Builder(mContext)
                            .setTitle(R.string.new_twrp_found_title)
                            .setMessage(
                                    mContext.getResources().getString(
                                            R.string.new_twrp_found_summary,
                                            new Object[] { info.getFilename() }))
                            .setPositiveButton(android.R.string.ok,
                                    new DialogInterface.OnClickListener() {

                                        public void onClick(DialogInterface dialog, int whichButton) {
                                            dialog.dismiss();

                                            ((Activity) mContext).runOnUiThread(new Runnable() {

                                                public void run() {
                                                    ManagerFactory.getFileManager(mContext).download(
                                                            mContext, info.getPath(), info.getFilename(),
                                                            info.getMd5(), false,
                                                            Constants.DOWNLOADTWRP_NOTIFICATION_ID);
                                                }
                                            });
                                        }
                                    })
                            .setNegativeButton(android.R.string.cancel,
                                    new DialogInterface.OnClickListener() {

                                        public void onClick(DialogInterface dialog, int whichButton) {
                                            dialog.dismiss();
                                        }
                                    }).show();
                } catch (Exception ex) {
                    // app closed?
                }
            }
        });
    }

}


text:
from __future__ import division, print_function

# Multicut Pipeline implemented with luigi
# Blockwise solver tasks

import luigi

from .pipelineParameter import PipelineParameter
from .dataTasks import ExternalSegmentation
from .customTargets import HDF5DataTarget
from .multicutProblemTasks import MulticutProblem
from .blocking_helper import NodesToBlocks
from .tools import config_logger, run_decorator
from .nifty_helper import run_nifty_solver, string_to_factory, available_factorys

import os
import logging
import time

import numpy as np
from concurrent import futures

# import the proper nifty version
try:
    import nifty
except ImportError:
    try:
        import nifty_with_cplex as nifty
    except ImportError:
        import nifty_with_gurobi as nifty

# init the workflow logger
workflow_logger = logging.getLogger(__name__)
config_logger(workflow_logger)

# parent class for blockwise solvers
class BlockwiseSolver(luigi.Task):

    pathToSeg = luigi.Parameter()
    globalProblem  = luigi.TaskParameter()
    numberOfLevels = luigi.Parameter()
    keyToSeg = luigi.Parameter(default='data')

    def requires(self):
        # block size in first hierarchy level
        initialBlockShape = PipelineParameter().multicutBlockShape
        # block overlap, for now same for each hierarchy lvl
        block_overlap = PipelineParameter().multicutBlockOverlap

        problems = [self.globalProblem]
        block_factor = 1

        for level in range(self.numberOfLevels):
            # TODO check that we don't get larger than the actual shape here
            block_shape = list(map(lambda x: x * block_factor, initialBlockShape))
            problems.append(ReducedProblem(pathToSeg=self.pathToSeg,
                                           problem=problems[-1],
                                           blockShape=block_shape,
                                           blockOverlap=block_overlap,
                                           level=level,
                                           keyToSeg=self.keyToSeg))
            block_factor *= 2

        return problems

    def run(self):
        raise NotImplementedError("BlockwiseSolver is abstract and does not implement a run functionality!")

    # map back to the global solution
    def map_node_result_to_global(self, problems, reduced_node_result, reduced_problem_index=-1):

        n_nodes_global = problems[0].read('number_of_nodes')
        reduced_problem = problems[reduced_problem_index]
        to_global_nodes = reduced_problem.read("new2global")

        # TODO vectorize
        node_result = np.zeros(n_nodes_global, dtype='uint32')
        for node_id, node_res in enumerate(reduced_node_result):
            node_result[to_global_nodes[node_id]] = node_res

        return node_result

    def output(self):
        raise NotImplementedError("BlockwiseSolver is abstract and does not implement the output functionality!")

# produce reduced global graph from subproblems
# solve global multicut problem on the reduced graph
class BlockwiseMulticutSolver(BlockwiseSolver):

    @run_decorator
    def run(self):

        problems = self.input()

        # we solve the problem for the costs and the edges of the last level of hierarchy
        reduced_problem = problems[-1]

        reduced_graph = nifty.graph.UndirectedGraph()
        reduced_graph.deserialize(reduced_problem.read("graph"))
        reduced_costs = reduced_problem.read("costs")
        reduced_objective = nifty.graph.opt.multicut.multicutObjective(reduced_graph, reduced_costs)

        #
        # run global multicut inference
        #

        # we use fm with kl as default backend, because this shows the best scaling behaviour
        solver_type = PipelineParameter().globalSolverType
        inf_params  = dict(sigma=PipelineParameter().multicutSigmaFusion,
                           number_of_iterations=PipelineParameter().multicutNumIt,
                           n_stop=PipelineParameter().multicutNumItStopGlobal,
                           n_threads=PipelineParameter().multicutNThreadsGlobal,
                           n_fuse=PipelineParameter().multicutNumFuse,
                           seed_fraction=PipelineParameter().multicutSeedFractionGlobal)

        workflow_logger.info("BlockwiseMulticutSolver: Solving problems with solver %s" % solver_type)
        workflow_logger.info(
            "BlockwiseMulticutSolver: With Params %s" % ' '.join(
                ['%s, %s,' % (str(k), str(v)) for k, v in inf_params.items()]
            )
        )

        # we set visit-nth to 1 for the fusion move solvers and to 100 for kernighan lin
        # NOTE: we will not use ilp here, so it does not matter that it is handled incorrectly
        visit_nth = 1 if solver_type.startswith('fm') else 100

        factory = string_to_factory(reduced_objective, solver_type, inf_params)
        reduced_node_result, energy, t_inf = run_nifty_solver(
            reduced_objective,
            factory,
            verbose=1,
            time_limit=PipelineParameter().multicutGlobalTimeLimit,
            visit_nth=visit_nth
        )
        workflow_logger.info(
            "BlockwiseMulticutSolver: Inference of reduced problem for the whole volume took: %f s" % t_inf[-1]
        )

        workflow_logger.info(
            "BlockwiseMulticutSolver: Problem solved with energy %f"
            % energy[-1]
        )

        # TODO change to debug
        if workflow_logger.isEnabledFor(logging.INFO):
            assert len(energy) == len(t_inf)
            workflow_logger.info(
                "BlockwiseMulticutSolver: logging energy during inference:"
            )
            for ii in range(len(energy)):
                workflow_logger.info(
                    "BlockwiseMulticutSolver: t: %f s energy: %f" % (t_inf[ii], energy[ii])
                )

        node_result = self.map_node_result_to_global(problems, reduced_node_result)
        self.output().write(node_result)

    def output(self):
        save_name = "BlockwiseMulticutSolver_L%i_%s_%s_%s.h5" % (
            self.numberOfLevels,
            '_'.join(map(str, PipelineParameter().multicutBlockShape)),
            '_'.join(map(str, PipelineParameter().multicutBlockOverlap)),
            "modified" if PipelineParameter().defectPipeline else "standard"
        )
        save_path = os.path.join(PipelineParameter().cache, save_name)
        return HDF5DataTarget(save_path)

class ReducedProblem(luigi.Task):

    pathToSeg = luigi.Parameter()
    problem   = luigi.TaskParameter()

    blockShape   = luigi.ListParameter()
    blockOverlap = luigi.ListParameter()

    level = luigi.Parameter()
    keyToSeg = luigi.Parameter(default='data')

    def requires(self):
        return {"sub_solution": BlockwiseSubSolver(pathToSeg=self.pathToSeg,
                                                   problem=self.problem,
                                                   blockShape=self.blockShape,
                                                   blockOverlap=self.blockOverlap,
                                                   level=self.level,
                                                   keyToSeg=self.keyToSeg),
                "problem": self.problem}

    # TODO we need to recover the edges between blocks for the stitching solver
    @run_decorator
    def run(self):

        workflow_logger.info(
            "ReducedProblem: Reduced problem for level %i with block shape: %s"
            % (self.level, str(self.blockShape))
        )

        inp = self.input()
        problem   = inp["problem"]
        cut_edges = inp["sub_solution"].read()

        g = nifty.graph.UndirectedGraph()
        g.deserialize(problem.read("graph"))

        # merge the edges that are not cuts
        # and find the new nodes as well as the mapping
        # from new 2 old nodes

        # we time all the stuff for benchmarking
        t_merge = time.time()
        uv_ids = g.uvIds()

        ufd = nifty.ufd.ufd(g.numberOfNodes)

        merge_nodes = uv_ids[cut_edges == 0]
        ufd.merge(merge_nodes)

        old2new_nodes = ufd.elementLabeling()
        new2old_nodes = ufd.representativesToSets()
        # number of nodes for the new problem
        number_of_new_nodes = len(new2old_nodes)
        workflow_logger.info("ReducedProblem: Merging nodes took: %f s" % (time.time() - t_merge))

        t_edges = time.time()
        # find new edges and costs
        uv_ids_new = self.find_new_edges_and_costs(uv_ids,
                                                   problem,
                                                   cut_edges,
                                                   number_of_new_nodes,
                                                   old2new_nodes)
        workflow_logger.info("ReducedProblem: Computing new edges took: %f s" % (time.time() - t_edges))

        # serialize the node converter
        t_serialize = time.time()
        self.serialize_node_conversions(problem, old2new_nodes, new2old_nodes, number_of_new_nodes)
        workflow_logger.info("ReducedProblem: Serializing node converters took: %f s" % (time.time() - t_serialize))

        workflow_logger.info("ReucedProblem: Nodes: From %i to %i" % (g.numberOfNodes, number_of_new_nodes))
        workflow_logger.info("ReucedProblem: Edges: From %i to %i" % (g.numberOfEdges, len(uv_ids_new)))

    def find_new_edges_and_costs(self,
                                 uv_ids,
                                 problem,
                                 cut_edges,
                                 number_of_new_nodes,
                                 old2new_nodes):

        # find mapping from new to old edges with nifty impl
        edge_mapping = nifty.tools.EdgeMapping(len(uv_ids))
        edge_mapping.initializeMapping(uv_ids, old2new_nodes)

        # get the new uv-ids
        uv_ids_new = edge_mapping.getNewUvIds()

        # map the old costs to new costs
        costs  = problem.read("costs")
        new_costs = edge_mapping.mapEdgeValues(costs)

        # map the old outer edges to new outer edges
        outer_edge_ids = self.input()["sub_solution"].read("outer_edges")
        with futures.ThreadPoolExecutor(max_workers=PipelineParameter().nThreads) as tp:
            tasks = [tp.submit(edge_mapping.getNewEdgeIds, oeids) for oeids in outer_edge_ids]
            new_outer_edges = np.array([np.array(t.result()) for t in tasks])

        assert len(new_costs) == len(uv_ids_new)
        reduced_graph = nifty.graph.UndirectedGraph(number_of_new_nodes)
        reduced_graph.insertEdges(uv_ids_new)

        out = self.output()
        out.write(reduced_graph.serialize(), "graph")
        out.write(reduced_graph.numberOfNodes, 'number_of_nodes')
        out.write(new_costs, "costs")
        out.writeVlen(new_outer_edges, 'outer_edges')

        return uv_ids_new

    def serialize_node_conversions(self, problem, old2new_nodes, new2old_nodes, number_of_new_nodes):

        if self.level == 0:
            global2new = old2new_nodes
            new2global = new2old_nodes

        else:
            global2new_last = problem.read("global2new").astype(np.uint32)
            new2global_last = problem.read("new2global")

            global2new = -1 * np.ones_like(global2new_last, dtype=np.int32)
            new2global = []

            # TODO vectorize
            for newNode in range(number_of_new_nodes):
                oldNodes = new2old_nodes[newNode]
                globalNodes = np.concatenate(new2global_last[oldNodes])
                global2new[globalNodes] = newNode
                new2global.append(globalNodes)

        assert -1 not in global2new
        global2new = global2new.astype('uint32')

        out = self.output()
        out.write(global2new, "global2new")

        # need to serialize this differently, due to list of list
        new2old_nodes = np.array([np.array(n2o, dtype='uint32') for n2o in new2old_nodes])
        out.writeVlen(new2old_nodes, "new2old")

        new2global = np.array([np.array(n2g, dtype='uint32') for n2g in new2global])
        out.writeVlen(new2global, "new2global")

    def output(self):
        save_name = "ReducedProblem_L%i_%s_%s_%s.h5" % (
            self.level,
            '_'.join(map(str, self.blockShape)),
            '_'.join(map(str, self.blockOverlap)),
            "modified" if PipelineParameter().defectPipeline else "standard"
        )
        save_path = os.path.join(PipelineParameter().cache, save_name)
        return HDF5DataTarget(save_path)

class BlockwiseSubSolver(luigi.Task):

    pathToSeg = luigi.Parameter()
    problem   = luigi.TaskParameter()

    blockShape   = luigi.ListParameter()
    blockOverlap = luigi.ListParameter()

    level = luigi.Parameter()
    # needs to be true if we want to use the stitching - by overlap solver
    serializeSubResults = luigi.Parameter(default=False)

    # will outer edges be cut ?
    # should be left at true, because results seem to degraded if false
    cutOuterEdges = luigi.Parameter(default=True)

    keyToSeg = luigi.Parameter(default='data')

    def requires(self):
        initialShape = PipelineParameter().multicutBlockShape
        overlap      = PipelineParameter().multicutBlockOverlap

        nodes2blocks = NodesToBlocks(self.pathToSeg,
                                     initialShape,
                                     overlap,
                                     keyToSeg=self.keyToSeg)
        return {"seg": ExternalSegmentation(self.pathToSeg),
                "problem": self.problem,
                "nodes2blocks": nodes2blocks}

    @run_decorator
    def run(self):
        # Input
        inp = self.input()
        seg = inp["seg"]
        seg.open(self.keyToSeg)
        problem = inp["problem"]
        costs = problem.read("costs")
        nodes2blocks = inp["nodes2blocks"].read()

        graph = nifty.graph.UndirectedGraph()
        graph.deserialize(problem.read("graph"))
        number_of_edges = graph.numberOfEdges

        global2new_nodes = None if self.level == 0 else problem.read("global2new")

        workflow_logger.info("BlockwiseSubSolver: Starting extraction of subproblems.")
        t_extract = time.time()
        subproblems = self._run_subproblems_extraction(seg, graph, nodes2blocks, global2new_nodes)
        workflow_logger.info("BlockwiseSubSolver: Extraction time for subproblems %f s" % (time.time() - t_extract,))

        workflow_logger.info("BlockwiseSubSolver: Starting solvers for subproblems.")
        t_inf_total = time.time()
        self._solve_subproblems(costs, subproblems, number_of_edges)
        workflow_logger.info(
            "BlockwiseSubSolver: Inference time total for subproblems %f s" % (time.time() - t_inf_total,)
        )

        seg.close()

    # extract all sub-problems for current level
    def _run_subproblems_extraction(self, seg, graph, nodes2blocks, global2new_nodes):

        # get the initial blocking
        # block size in first hierarchy level
        initial_block_shape = PipelineParameter().multicutBlockShape
        initial_overlap = list(PipelineParameter().multicutBlockOverlap)
        initial_blocking = nifty.tools.blocking(roiBegin=[0, 0, 0],
                                                roiEnd=list(seg.shape(key=self.keyToSeg)),
                                                blockShape=list(initial_block_shape))

        # function for subproblem extraction
        # extraction only for level 0
        def extract_subproblem(block_id, sub_blocks):
            node_list = np.unique(np.concatenate([nodes2blocks[sub_id] for sub_id in sub_blocks]))
            if self.level != 0:
                node_list = np.unique(global2new_nodes[node_list])
            workflow_logger.debug(
                "BlockwiseSubSolver: block id %i: Number of nodes %i" % (block_id, len(node_list.shape))
            )
            inner_edges, outer_edges, subgraph = graph.extractSubgraphFromNodes(node_list.tolist())
            # we can get 0 inner edges, if we have a subblock with just a single node
            # or a subblock with only ignore edges.
            # we filter these blocks, because they mess up the sub-solver
            if len(inner_edges) <= 1:
                return False
            return np.array(inner_edges), np.array(outer_edges), subgraph, node_list

        block_overlap = list(self.blockOverlap)
        blocking = nifty.tools.blocking(roiBegin=[0, 0, 0],
                                        roiEnd=list(seg.shape(key=self.keyToSeg)),
                                        blockShape=self.blockShape)
        number_of_blocks = blocking.numberOfBlocks

        workflow_logger.info(
            "BlockwiseSubSolver: Extracting sub-problems with current blocking of shape %s with overlaps %s."
            % (str(self.blockShape), str(block_overlap))
        )

        n_workers = min(number_of_blocks, PipelineParameter().nThreads)
        # parallel
        with futures.ThreadPoolExecutor(max_workers=n_workers) as executor:
            tasks = []
            for block_id in range(number_of_blocks):

                # get the current block with additional overlap
                block = blocking.getBlockWithHalo(block_id, block_overlap).outerBlock
                block_begin, block_end = block.begin, block.end
                workflow_logger.debug(
                    "BlockwiseSubSolver: block id %i start %s end %s" % (block_id, str(block_begin), str(block_end))
                )

                # if we are past level 0, we must assemble the initial blocks, from which this block is made up of
                # otherwise we simply schedule this block
                if self.level > 0:
                    sub_blocks = initial_blocking.getBlockIdsInBoundingBox(block_begin, block_end, initial_overlap)
                else:
                    sub_blocks = [block_id]

                tasks.append(executor.submit(extract_subproblem, block_id, sub_blocks))
            sub_problems = [task.result() for task in tasks]
            sub_problems = [sub_prob for sub_prob in sub_problems if sub_prob]

        out = self.output()
        out.writeVlen(np.array([sub_prob[1] for sub_prob in sub_problems]),
                      'outer_edges')

        # if we serialize the sub-results, write out the block positions and the sub nodes here
        if self.serializeSubResults:
            out.write(
                np.concatenate([
                    np.array(blocking.getBlockWithHalo(block_id, block_overlap).outerBlock.begin)[None, :]
                    for block_id in range(number_of_blocks)],
                    axis=0
                ),
                'block_begins'
            )
            out.write(
                np.concatenate([
                    np.array(blocking.getBlockWithHalo(block_id, block_overlap).outerBlock.end)[None, :]
                    for block_id in range(number_of_blocks)],
                    axis=0
                ),
                'block_ends'
            )
            out.writeVlen(
                np.array([sub_prob[3] for sub_prob in sub_problems]),
                'sub_nodes'
            )

        return sub_problems

    def _solve_subproblems(self, costs, sub_problems, number_of_edges):

        sub_solver_type = PipelineParameter().subSolverType
        if sub_solver_type in ('fm-ilp', 'fm-kl'):
            solver_params  = dict(
                sigma=PipelineParameter().multicutSigmaFusion,
                number_of_iterations=PipelineParameter().multicutNumIt,
                n_stop=PipelineParameter().multicutNumItStopGlobal,
                n_threads=0,
                n_fuse=PipelineParameter().multicutNumFuse,
                seed_fraction=PipelineParameter().multicutSeedFraction
            )
        else:
            solver_params = dict()

        workflow_logger.info("BlockwiseSubSolver: Solving sub-problems with solver %s" % sub_solver_type)
        workflow_logger.info(
            "BlockwiseSubSolver: With Params %s" % ' '.join(
                ['%s, %s,' % (str(k), str(v)) for k, v in solver_params.items()]
            )
        )

        def _solve_mc(g, costs, block_id):
            workflow_logger.debug(
                "BlockwiseSubSolver: Solving MC Problem for block %i with %i nodes / %i edges"
                % (block_id, g.numberOfNodes, g.numberOfEdges)
            )
            obj = nifty.graph.opt.multicut.multicutObjective(g, costs)
            factory = string_to_factory(obj, sub_solver_type, solver_params)
            solver = factory.create(obj)
            t_inf  = time.time()
            res    = solver.optimize()
            workflow_logger.debug(
                "BlockwiseSubSolver: Inference for block %i with fusion moves solver in %f s"
                % (block_id, time.time() - t_inf)
            )
            return res

        # sequential for debugging
        # sub_results = []
        # for block_id, sub_problem in enumerate(sub_problems):
        #     print("Sequential prediction for block id:", block_id)
        #     print(type(sub_problem[0]))
        #     print(sub_problem[0].shape)
        #     print(sub_problem[0].dtype)
        #     sub_results.append(_solve_mc(sub_problem[2], costs[sub_problem[0]], block_id))

        n_workers = min(len(sub_problems), PipelineParameter().nThreads)
        with futures.ThreadPoolExecutor(max_workers=n_workers) as executor:
            tasks = [executor.submit(_solve_mc,
                     sub_problem[2],
                     costs[sub_problem[0]],
                     block_id) for block_id, sub_problem in enumerate(sub_problems)]
        sub_results = [task.result() for task in tasks]

        cut_edges = np.zeros(number_of_edges, dtype=np.uint8)
        assert len(sub_results) == len(sub_problems), str(len(sub_results)) + " , " + str(len(sub_problems))

        for block_id in range(len(sub_problems)):

            # get the cut edges from the subproblem
            node_result = sub_results[block_id]
            sub_uv_ids = sub_problems[block_id][2].uvIds()

            edge_result = node_result[sub_uv_ids[:, 0]] != node_result[sub_uv_ids[:, 1]]

            cut_edges[sub_problems[block_id][0]] += edge_result
            # add up outer edges
            if self.cutOuterEdges:
                cut_edges[sub_problems[block_id][1]] += 1

        # all edges which are cut at least once will be cut
        out = self.output()
        cut_edges[cut_edges >= 1] = 1
        out.write(cut_edges)

        # if we serialize the sub results, write them here
        if self.serializeSubResults:
            out.writeVlen(
                np.array([sub_res for sub_res in sub_results]),
                'sub_results'
            )

    def output(self):
        save_name = "BlockwiseSubSolver_L%i_%s_%s_%s.h5" % (
            self.level,
            '_'.join(map(str, self.blockShape)),
            '_'.join(map(str, self.blockOverlap)),
            "modified" if PipelineParameter().defectPipeline else "standard"
        )
        save_path = os.path.join(PipelineParameter().cache, save_name)
        return HDF5DataTarget(save_path)

# only works for level 1 for now!
class TestSubSolver(luigi.Task):

    pathToSeg = luigi.Parameter()
    pathToClassifier = luigi.Parameter()

    blockShape   = luigi.ListParameter(default=PipelineParameter().multicutBlockShape)
    blockOverlap = luigi.ListParameter(default=PipelineParameter().multicutBlockOverlap)

    def requires(self):
        nodes2blocks = NodesToBlocks(self.pathToSeg, self.blockShape, self.blockOverlap)
        return {
            "seg": ExternalSegmentation(self.pathToSeg),
            "problem": MulticutProblem(self.pathToSeg, self.pathToClassifier),
            "nodes2blocks": nodes2blocks
        }

    @run_decorator
    def run(self):
        # Input
        inp = self.input()
        seg = inp["seg"]
        seg.open()
        problem = inp["problem"]
        costs = problem.read("costs")
        nodes2blocks = inp["nodes2blocks"].read()

        graph = nifty.graph.UndirectedGraph()
        graph.deserialize(problem.read("graph"))

        workflow_logger.info("TestSubSolver: Starting extraction of subproblems.")
        subproblems = self._run_subproblems_extraction(seg, graph, nodes2blocks)

        workflow_logger.info("TestSubSolver: Starting solvers for subproblems.")
        self._solve_subproblems(costs, subproblems)

        seg.close()

    def _run_subproblems_extraction(self, seg, graph, nodes2blocks):

        # function for subproblem extraction
        # extraction only for level 0
        def extract_subproblem(blockId):
            node_list = nodes2blocks[blockId]
            inner_edges, outer_edges, subgraph = graph.extractSubgraphFromNodes(node_list.tolist())
            return np.array(inner_edges), np.array(outer_edges), subgraph

        blocking = nifty.tools.blocking(roiBegin=[0, 0, 0], roiEnd=seg.shape(), blockShape=self.blockShape)
        number_of_blocks = blocking.numberOfBlocks
        # sample block-ids corresponding to the number of threads
        n_threads = PipelineParameter().nThreads
        sampled_blocks = np.random.choice(number_of_blocks, min(n_threads, number_of_blocks), replace=False)

        # parallel
        with futures.ThreadPoolExecutor(max_workers=PipelineParameter().nThreads) as executor:
            tasks = [executor.submit(extract_subproblem, block_id) for block_id in sampled_blocks]
            sub_problems = [task.result() for task in tasks]

        assert len(sub_problems) == len(sampled_blocks), "%i, %i" % (len(sub_problems), len(sampled_blocks))
        return sub_problems

    def _solve_subproblems(self, costs, sub_problems):

        def _test_mc(g, costs, sub_solver_type):

            if sub_solver_type in ('fm-ilp', 'fm-kl'):
                solver_params  = dict(
                    sigma=PipelineParameter().multicutSigmaFusion,
                    number_of_iterations=PipelineParameter().multicutNumIt,
                    n_stop=PipelineParameter().multicutNumItStopGlobal,
                    n_threads=0,
                    n_fuse=PipelineParameter().multicutNumFuse,
                    seed_fraction=PipelineParameter().multicutSeedFraction
                )
            else:
                solver_params = dict()

            obj = nifty.graph.opt.multicut.multicutObjective(g, costs)
            solver = string_to_factory(obj, sub_solver_type, solver_params).create(obj)
            t_inf  = time.time()
            res    = solver.optimize()
            t_inf  = time.time() - t_inf
            return obj.evalNodeLabels(res), t_inf

        workflow_logger.info("TestSubSolver: Running sub-block tests for %i blocks" % len(sub_problems))
        available = available_factorys()
        results = {}

        for sub_solver_type in available:
            with futures.ThreadPoolExecutor(max_workers=PipelineParameter().nThreads) as executor:
                tasks = [executor.submit(
                    _test_mc,
                    sub_problem[2],
                    costs[sub_problem[0]],
                    sub_solver_type) for sub_problem in sub_problems]
                sub_results = [task.result() for task in tasks]
                mean_energy = np.mean([rr[0] for rr in sub_results])
                mean_time   = np.mean([rr[1] for rr in sub_results])
                results[sub_solver_type] = (mean_energy, mean_time)

        for_serialization = []
        for sub_solver_type in available:
            res = results[sub_solver_type]
            workflow_logger.info(
                "TestSubSolver: Result of %s: mean-energy: %f, mean-inference-time: %f"
                % (sub_solver_type, res[0], res[1])
            )
            for_serialization.append([res[0], res[1]])

        self.output().write(available, 'solvers')
        self.output().write(np.array(for_serialization), 'results')

    def output(self):
        blcksize_str = "_".join(map(str, list(self.blockShape)))
        save_name = "TestSubSolver_%s_%s.h5" \
            % (blcksize_str, "modified" if PipelineParameter().defectPipeline else "standard")
        save_path = os.path.join(PipelineParameter().cache, save_name)
        return HDF5DataTarget(save_path)


text:
<?php

namespace DCarbone\PHPFHIRGenerated\DSTU1\PHPFHIRTests\FHIRElement\FHIRBackboneElement\FHIRConformance;

use PHPUnit\Framework\TestCase;
use DCarbone\PHPFHIRGenerated\DSTU1\FHIRElement\FHIRBackboneElement\FHIRConformance\FHIRConformanceMessaging;

/**
 * Class FHIRConformanceMessagingTest
 * @package \DCarbone\PHPFHIRGenerated\DSTU1\PHPFHIRTests\FHIRElement\FHIRBackboneElement\FHIRConformance
 */
class FHIRConformanceMessagingTest extends TestCase
{
    public function testCanConstructTypeNoArgs()
    {
        $type = new FHIRConformanceMessaging();
        $this->assertInstanceOf('\DCarbone\PHPFHIRGenerated\DSTU1\FHIRElement\FHIRBackboneElement\FHIRConformance\FHIRConformanceMessaging', $type);
    }
}


text:
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/usb.h>

#define DRIVER_AUTHOR "Greg Kroah-Hartman, greg@kroah.com"
#define DRIVER_DESC "USB LED Driver"

enum led_type {
	DELCOM_VISUAL_SIGNAL_INDICATOR,
	DREAM_CHEEKY_WEBMAIL_NOTIFIER,
};

/* table of devices that work with this driver */
static const struct usb_device_id id_table[] = {
	{ USB_DEVICE(0x0fc5, 0x1223),
			.driver_info = DELCOM_VISUAL_SIGNAL_INDICATOR },
	{ USB_DEVICE(0x1d34, 0x0004),
			.driver_info = DREAM_CHEEKY_WEBMAIL_NOTIFIER },
	{ USB_DEVICE(0x1d34, 0x000a),
			.driver_info = DREAM_CHEEKY_WEBMAIL_NOTIFIER },
	{ },
};
MODULE_DEVICE_TABLE(usb, id_table);

struct usb_led {
	struct usb_device	*udev;
	unsigned char		blue;
	unsigned char		red;
	unsigned char		green;
	enum led_type		type;
};

static void change_color(struct usb_led *led)
{
	int retval = 0;
	unsigned char *buffer;

	buffer = kmalloc(8, GFP_KERNEL);
	if (!buffer) {
		dev_err(&led->udev->dev, "out of memory\n");
		return;
	}

	switch (led->type) {
	case DELCOM_VISUAL_SIGNAL_INDICATOR: {
		unsigned char color = 0x07;

		if (led->blue)
			color &= ~0x04;
		if (led->red)
			color &= ~0x02;
		if (led->green)
			color &= ~0x01;
		dev_dbg(&led->udev->dev,
			"blue = %d, red = %d, green = %d, color = %.2x\n",
			led->blue, led->red, led->green, color);

		retval = usb_control_msg(led->udev,
					usb_sndctrlpipe(led->udev, 0),
					0x12,
					0xc8,
					(0x02 * 0x100) + 0x0a,
					(0x00 * 0x100) + color,
					buffer,
					8,
					2000);
		break;
	}

	case DREAM_CHEEKY_WEBMAIL_NOTIFIER:
		dev_dbg(&led->udev->dev,
			"red = %d, green = %d, blue = %d\n",
			led->red, led->green, led->blue);

		buffer[0] = led->red;
		buffer[1] = led->green;
		buffer[2] = led->blue;
		buffer[3] = buffer[4] = buffer[5] = 0;
		buffer[6] = 0x1a;
		buffer[7] = 0x05;

		retval = usb_control_msg(led->udev,
					usb_sndctrlpipe(led->udev, 0),
					0x09,
					0x21,
					0x200,
					0,
					buffer,
					8,
					2000);
		break;

	default:
		dev_err(&led->udev->dev, "unknown device type %d\n", led->type);
	}

	if (retval)
		dev_dbg(&led->udev->dev, "retval = %d\n", retval);
	kfree(buffer);
}

#define show_set(value)	\
static ssize_t show_##value(struct device *dev, struct device_attribute *attr,\
			    char *buf)					\
{									\
	struct usb_interface *intf = to_usb_interface(dev);		\
	struct usb_led *led = usb_get_intfdata(intf);			\
									\
	return sprintf(buf, "%d\n", led->value);			\
}									\
static ssize_t set_##value(struct device *dev, struct device_attribute *attr,\
			   const char *buf, size_t count)		\
{									\
	struct usb_interface *intf = to_usb_interface(dev);		\
	struct usb_led *led = usb_get_intfdata(intf);			\
	int temp = simple_strtoul(buf, NULL, 10);			\
									\
	led->value = temp;						\
	change_color(led);						\
	return count;							\
}									\
static DEVICE_ATTR(value, S_IRUGO | S_IWUSR, show_##value, set_##value);
show_set(blue);
show_set(red);
show_set(green);

static int led_probe(struct usb_interface *interface,
		     const struct usb_device_id *id)
{
	struct usb_device *udev = interface_to_usbdev(interface);
	struct usb_led *dev = NULL;
	int retval = -ENOMEM;

	dev = kzalloc(sizeof(struct usb_led), GFP_KERNEL);
	if (dev == NULL) {
		dev_err(&interface->dev, "out of memory\n");
		goto error_mem;
	}

	dev->udev = usb_get_dev(udev);
	dev->type = id->driver_info;

	usb_set_intfdata(interface, dev);

	retval = device_create_file(&interface->dev, &dev_attr_blue);
	if (retval)
		goto error;
	retval = device_create_file(&interface->dev, &dev_attr_red);
	if (retval)
		goto error;
	retval = device_create_file(&interface->dev, &dev_attr_green);
	if (retval)
		goto error;

	if (dev->type == DREAM_CHEEKY_WEBMAIL_NOTIFIER) {
		unsigned char *enable;

		enable = kmemdup("\x1f\x02\0\x5f\0\0\x1a\x03", 8, GFP_KERNEL);
		if (!enable) {
			dev_err(&interface->dev, "out of memory\n");
			retval = -ENOMEM;
			goto error;
		}

		retval = usb_control_msg(udev,
					usb_sndctrlpipe(udev, 0),
					0x09,
					0x21,
					0x200,
					0,
					enable,
					8,
					2000);

		kfree(enable);
		if (retval != 8)
			goto error;
	}

	dev_info(&interface->dev, "USB LED device now attached\n");
	return 0;

error:
	device_remove_file(&interface->dev, &dev_attr_blue);
	device_remove_file(&interface->dev, &dev_attr_red);
	device_remove_file(&interface->dev, &dev_attr_green);
	usb_set_intfdata(interface, NULL);
	usb_put_dev(dev->udev);
	kfree(dev);
error_mem:
	return retval;
}

static void led_disconnect(struct usb_interface *interface)
{
	struct usb_led *dev;

	dev = usb_get_intfdata(interface);

	device_remove_file(&interface->dev, &dev_attr_blue);
	device_remove_file(&interface->dev, &dev_attr_red);
	device_remove_file(&interface->dev, &dev_attr_green);

	/* first remove the files, then set the pointer to NULL */
	usb_set_intfdata(interface, NULL);

	usb_put_dev(dev->udev);

	kfree(dev);

	dev_info(&interface->dev, "USB LED now disconnected\n");
}

static struct usb_driver led_driver = {
	.name =		"usbled",
	.probe =	led_probe,
	.disconnect =	led_disconnect,
	.id_table =	id_table,
};

module_usb_driver(led_driver);

MODULE_AUTHOR(DRIVER_AUTHOR);
MODULE_DESCRIPTION(DRIVER_DESC);
MODULE_LICENSE("GPL");


text:
// flow-typed signature: 33067eb281d22648f5a71f91308267fa
// flow-typed version: <<STUB>>/mailcheck_v^1.1.1/flow_v0.75.0

/**
 * This is an autogenerated libdef stub for:
 *
 *   'mailcheck'
 *
 * Fill this stub out by replacing all the `any` types.
 *
 * Once filled out, we encourage you to share your work with the
 * community by sending a pull request to:
 * https://github.com/flowtype/flow-typed
 */

declare module 'mailcheck' {
  declare module.exports: any;
}

/**
 * We include stubs for each file inside this npm package in case you need to
 * require those files directly. Feel free to delete any files that aren't
 * needed.
 */
declare module 'mailcheck/script/server' {
  declare module.exports: any;
}

declare module 'mailcheck/spec/lib/console-runner' {
  declare module.exports: any;
}

declare module 'mailcheck/spec/lib/jasmine-1.2.0/jasmine-html' {
  declare module.exports: any;
}

declare module 'mailcheck/spec/lib/jasmine-1.2.0/jasmine' {
  declare module.exports: any;
}

declare module 'mailcheck/spec/lib/jquery' {
  declare module.exports: any;
}

declare module 'mailcheck/spec/mailcheckSpec' {
  declare module.exports: any;
}

declare module 'mailcheck/src/mailcheck' {
  declare module.exports: any;
}

declare module 'mailcheck/src/mailcheck.min' {
  declare module.exports: any;
}

// Filename aliases
declare module 'mailcheck/script/server.js' {
  declare module.exports: $Exports<'mailcheck/script/server'>;
}
declare module 'mailcheck/spec/lib/console-runner.js' {
  declare module.exports: $Exports<'mailcheck/spec/lib/console-runner'>;
}
declare module 'mailcheck/spec/lib/jasmine-1.2.0/jasmine-html.js' {
  declare module.exports: $Exports<'mailcheck/spec/lib/jasmine-1.2.0/jasmine-html'>;
}
declare module 'mailcheck/spec/lib/jasmine-1.2.0/jasmine.js' {
  declare module.exports: $Exports<'mailcheck/spec/lib/jasmine-1.2.0/jasmine'>;
}
declare module 'mailcheck/spec/lib/jquery.js' {
  declare module.exports: $Exports<'mailcheck/spec/lib/jquery'>;
}
declare module 'mailcheck/spec/mailcheckSpec.js' {
  declare module.exports: $Exports<'mailcheck/spec/mailcheckSpec'>;
}
declare module 'mailcheck/src/mailcheck.js' {
  declare module.exports: $Exports<'mailcheck/src/mailcheck'>;
}
declare module 'mailcheck/src/mailcheck.min.js' {
  declare module.exports: $Exports<'mailcheck/src/mailcheck.min'>;
}


text:
Swift 动态桥接库

#Installation
pod 'LCNibBridge', '~> 1.2.3'

or pod search LCNibBridge to check

#Overview
Design

![Design](https://github.com/liutongchao/LCNibBridge/blob/master/LCNibBridgeDemo/ScreenShot/desig.png)

Runtime

![Runtime](https://github.com/liutongchao/LCNibBridge/blob/master/LCNibBridgeDemo/ScreenShot/run.png)

#How to use

1.Build your view class and its xib file. (Same name required)

![class](https://github.com/liutongchao/LCNibBridge/blob/master/LCNibBridgeDemo/ScreenShot/class.png)

2.Put a placeholder view in target IB (xib or storyboard), Set its class.

![class](https://github.com/liutongchao/LCNibBridge/blob/master/LCNibBridgeDemo/ScreenShot/story.png)

3.Conform to LCNibBridge protocol

      import UIKit
      import LCNibBridge

      class Test: UIView ,  LCNibBridge{

      }

###如果你在天朝,请看我的中文博客
>http://www.jianshu.com/p/d39f19d60544


text:
package autopilot

import (
	"runtime"

	"github.com/btcsuite/btcutil"
)

// TopCentrality is a simple greedy technique to create connections to nodes
// with the top betweenness centrality value. This algorithm is usually
// referred to as TopK in the literature. The idea is that by opening channels
// to nodes with top betweenness centrality we also increase our own betweenness
// centrality (given we already have at least one channel, or create at least
// two new channels).
// A different and much better approach is instead of selecting nodes with top
// centrality value, we extend the graph in a loop by inserting a new non
// existing edge and recalculate the betweenness centrality of each node. This
// technique is usually referred to as "greedy" algorithm and gives better
// results than TopK but is considerably slower too.
type TopCentrality struct {
	centralityMetric *BetweennessCentrality
}

// A compile time assertion to ensure TopCentrality meets the
// AttachmentHeuristic interface.
var _ AttachmentHeuristic = (*TopCentrality)(nil)

// NewTopCentrality constructs and returns a new TopCentrality heuristic.
func NewTopCentrality() *TopCentrality {
	metric, err := NewBetweennessCentralityMetric(
		runtime.NumCPU(),
	)
	if err != nil {
		panic(err)
	}

	return &TopCentrality{
		centralityMetric: metric,
	}
}

// Name returns the name of the heuristic.
func (g *TopCentrality) Name() string {
	return "top_centrality"
}

// NodeScores will return a [0,1] normalized map of scores for the given nodes
// except for the ones we already have channels with. The scores will simply
// be the betweenness centrality values of the nodes.
// As our current implementation of betweenness centrality is non-incremental,
// NodeScores will recalculate the centrality values on every call, which is
// slow for large graphs.
func (g *TopCentrality) NodeScores(graph ChannelGraph, chans []LocalChannel,
	chanSize btcutil.Amount, nodes map[NodeID]struct{}) (
	map[NodeID]*NodeScore, error) {

	// Calculate betweenness centrality for the whole graph.
	if err := g.centralityMetric.Refresh(graph); err != nil {
		return nil, err
	}

	normalize := true
	centrality := g.centralityMetric.GetMetric(normalize)

	// Create a map of the existing peers for faster filtering.
	existingPeers := make(map[NodeID]struct{})
	for _, c := range chans {
		existingPeers[c.Node] = struct{}{}
	}

	result := make(map[NodeID]*NodeScore, len(nodes))
	for nodeID := range nodes {
		// Skip nodes we already have channel with.
		if _, ok := existingPeers[nodeID]; ok {
			continue
		}

		// Skip passed nodes not in the graph. This could happen if
		// the graph changed before computing the centrality values as
		// the nodes we iterate are prefiltered by the autopilot agent.
		score, ok := centrality[nodeID]
		if !ok {
			continue
		}

		result[nodeID] = &NodeScore{
			NodeID: nodeID,
			Score:  score,
		}
	}

	return result, nil
}


text:
<!doctype html>

	<meta charset="utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<title>Oops! Nothing here...</title>
	<link rel="stylesheet" type="text/css" href="http://sysop.matthias-werner.net/assets/css/styles_feeling_responsive.css" />

    <link href='http://fonts.googleapis.com/css?family=Lato:400,700,400italic|Volkhov' rel='stylesheet' type='text/css' />

	<meta name="description" content="Maybe the webpage was moved or deleted; or did you maybe mistype the link?" />

	<link rel="icon" sizes="32x32" href="http://sysop.matthias-werner.net/assets/img/favicon-32x32.png" />

	<link rel="icon" sizes="192x192" href="http://sysop.matthias-werner.net/assets/img/touch-icon-192x192.png" />

	<link rel="apple-touch-icon-precomposed" sizes="180x180" href="http://sysop.matthias-werner.net/assets/img/apple-touch-icon-180x180-precomposed.png" />

	<link rel="apple-touch-icon-precomposed" sizes="152x152" href="http://sysop.matthias-werner.net/assets/img/apple-touch-icon-152x152-precomposed.png" />

	<link rel="apple-touch-icon-precomposed" sizes="144x144" href="http://sysop.matthias-werner.net/assets/img/apple-touch-icon-144x144-precomposed.png" />

	<link rel="apple-touch-icon-precomposed" sizes="120x120" href="http://sysop.matthias-werner.net/assets/img/apple-touch-icon-120x120-precomposed.png" />

	<link rel="apple-touch-icon-precomposed" sizes="114x114" href="http://sysop.matthias-werner.net/assets/img/apple-touch-icon-114x114-precomposed.png" />

	<link rel="apple-touch-icon-precomposed" sizes="76x76" href="http://sysop.matthias-werner.net/assets/img/apple-touch-icon-76x76-precomposed.png" />

	<link rel="apple-touch-icon-precomposed" sizes="72x72" href="http://sysop.matthias-werner.net/assets/img/apple-touch-icon-72x72-precomposed.png" />

	<link rel="apple-touch-icon-precomposed" href="http://sysop.matthias-werner.net/assets/img/apple-touch-icon-precomposed.png" />

	<meta name="msapplication-TileImage" content="http://sysop.matthias-werner.net/assets/img/msapplication_tileimage.png" />

	<meta name="msapplication-TileColor" content="#fabb00" />

	<meta property="og:locale" content="en_EN" />

	<meta property="og:title" content="Oops! Nothing here..." />
	<meta property="og:description" content="Matthias Werners Blog. " />
	<meta property="og:url" content="http://sysop.matthias-werner.net//404.html" />
	<meta property="og:site_name" content="Systems Operational" />

	<link type="text/plain" rel="author" href="http://sysop.matthias-werner.net/humans.txt" />

 Systems Operational

Navigation

Über mich

Start

                Blog

Archive

aihPos

HTTP 404

Oops! Nothing here...

				Maybe the webpage was moved or deleted; or did you maybe mistype the link?

No problem!

Try…

…to start over on the home page;

…to search below;

if you can't find it, ask about it.

Search

<form id="search" onsubmit="google_search(); return false;">
	<input type="text" id="google-search" placeholder="Suchbegriff eingeben und Eingabetaste drücken" />
</form>

	Search Google for:

search-term site:http://sysop.matthias-werner.net/

        

Über diese Website

              Matthias Werners Blog.
              Mehr ›


text:
@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (nonatomic, strong) UIWindow *window;
@property (nonatomic, strong) UITabBarController *tabBarController;

@end


text:
$.ajaxSetup ({
    cache: false
});

$(function() {
    reloadNetworks();

    /**
     * Handlers for the setup tab
     */
    $("#reloadNetworks").click(function() {
        reloadNetworks();
    });

    $("#saveButton").click(function() {
        loading("show");
        var passwd = $("#passwd").val();
        var ssid = $("#network").val();
        var post = $.post( "/hotspot/save", {'password':passwd, 'ssid':ssid});
        post.done(function( data ) {
            //nothing
        });
        loading("hide");
    });

    $("#shutdownButton").click(function() {
        loading("show");
        $.getJSON('/hotspot/shutdown', function(data) {
            //nothing
        });
        loading("hide");
    });

    /**
     * Handlers for the console tab
     */
     $("#commandSubmit").click(function() {
        loading("show");
        var command = $("#commands").val();
        var post = $.post( "/hotspot/command", {'command':command});
        post.done(function( data ) {
            $("#output").val(data.output);
            $("#erroutput").val(data.error);
        });
        loading("hide");
     });

    $("#commandClear").click(function() {
        $("#commands").val('');
        $("#output").val('');
        $("#erroutput").val('');
    });

    $("#loadLogs").click(function() {
        $("#log").val('');
        $.getJSON('/hotspot/log', function(data) {
            $("#log").val(data.output);
        });
    });

});

function reloadNetworks() {
    loading("show");
    $.getJSON('/hotspot/networks', function(data) {
        $('#network').empty();
        $.each(data, function(key, value) {
            for(var i=0; i<value.length; i++) {
                var val = value[i];
                var option = $('<option />');
                option.attr('value', val.ssid).text(val.ssid + ' (' + val.authentication + ')');
                if(i == 0) {
                    option.attr('selected', 'true');
                }
                $('#network').append(option);
            }
        });
        $('#network').selectmenu('refresh');
    });
    loading("hide");
}

/**
 *
 */
function loading(showOrHide) {
    setTimeout(function(){
        $.mobile.loading(showOrHide);
    }, 1);
}


text:
P- poly precision resistors
---------------------------

Spice Model Information
~~~~~~~~~~~~~~~~~~~~~~~

-  Cell Name: :cell:`res_xhigh_po_XpXX`, :cell:`sky130_fd_pr__res_xhigh_po`
-  Model Type: subcircuit

Operating ranges where SPICE models are valid

-  :math:`|V_{r0} – V_{r1}| = 0` to 5.0V
-  Currents up to 500 µA/µm of width (preferred use ≤ 100 µA/µm)

Details
~~~~~~~

The resistors have 5 different fixed widths, plus a variable W/L option.

-  0.35 (0p35)
-  0.69 (0p69)
-  1.41 (1p41)
-  2.85 (2p83)
-  5.73 (5p73)

They are modeled as subcircuits, using a conventional resistor model combined with the capacitance under the resistor, as well as matching parameters and temperature coefficients. The fixed-width resistors may only be used in the above configurations. Each resistor end is contacted using a slot licon. Length is variable and measured between the front ends of the slot licons.

The resistors are modeled using the same equations as for the P+ poly resistors. In the case of the P- poly resistors, a separate implant is used to set the sheet resistance to 2000 ohm/sq.

Fixed value resistors have the same layout footprints as their P+ poly counterparts. Electrical and e-test specs are still TBD, once sufficient silicon has been evaluated. More details on the use of the precision resistors, and their models, are in the document ***SKY130 process Family Device Models*** (002-21997), currently under development.

The symbols for the 2000 ohm/sq precision resistors are shown below:

|symbol-res_xhigh_po_0p35| |symbol-res_xhigh_po_0p69|

:model:`sky130_fd_pr__res_xhigh_po_0p35` :model:`sky130_fd_pr__res_xhigh_po_0p69`

|symbol-res_xhigh_po_1p41| |symbol-res_xhigh_po_2p85|

:model:`sky130_fd_pr__res_xhigh_po_1p41` :model:`sky130_fd_pr__res_xhigh_po_2p85`

|symbol-res_xhigh_po_5p73|

:model:`sky130_fd_pr__res_xhigh_po_5p73`

A generic version of the poly resistor is also available, which permits user inputs for W and L, and connections in series or parallel.

|symbol-res_xhigh_po|

.. |symbol-res_xhigh_po_0p35| image:: symbol-res_xhigh_po_0p35.svg
.. |symbol-res_xhigh_po_0p69| image:: symbol-res_xhigh_po_0p69.svg
.. |symbol-res_xhigh_po_1p41| image:: symbol-res_xhigh_po_1p41.svg
.. |symbol-res_xhigh_po_2p85| image:: symbol-res_xhigh_po_2p85.svg
.. |symbol-res_xhigh_po_5p73| image:: symbol-res_xhigh_po_5p73.svg
.. |symbol-res_xhigh_po| image:: symbol-res_xhigh_po.svg