text
stringlengths
20
1.01M
url
stringlengths
14
1.25k
dump
stringlengths
9
15
lang
stringclasses
4 values
source
stringclasses
4 values
Available with Spatial Analyst license. Available with Image Analyst license. Summary Generates an Esri classifier definition file (.ecd) using the Random Trees classification method. The random trees classifier is an image classification technique that is resistant to overfitting and can work with segmented images and other ancillary raster datasets. For standard image inputs, the tool accepts multiband imagery with any bit depth, and it will perform the Random Trees classification on a pixel basis or segment, based on the input training feature file. Usage The Random Trees classification method is a collection of individual decision trees in which each tree is generated from different samples and subsets of the training data. The idea behind calling these decision trees is that for every pixel that is classified, a number of decisions are made in rank order of importance. When you graph these for a pixel, it looks like a branch. When you classify the entire dataset, the branches form a tree. This method is called random trees because you are actually classifying the dataset a number of times based on a random subselection of training pixels, resulting in many decision trees. To make a final decision, each tree has a vote. This process works to mitigate overfitting. The Random Trees classification method is a supervised machine-learning classifier based on constructing a multitude of decision trees, choosing random subsets of variables for each tree, and using the most frequent tree output as the overall classification. The Random Trees classification method corrects for the decision trees' propensity for overfitting to their training sample data. With this method, a number of trees are grown—by an analogy, a forest—and variation among the trees is introduced by projecting the training data into a randomly chosen subspace before fitting each tree. The decision at each node is optimized by a randomized procedure.. Any Esri-supported raster is accepted as input, including raster products, segmented rasters, mosaics, image services, and generic raster datasets. Segmented rasters must be 8-bit rasters with 3 bands. To create the training sample file, use the Training Samples Manager pane from the Classification Tools drop-down menu. The Segment Attributes parameter is only active if one of the raster layer inputs is a segmented image. To classify time series raster data using the Continuous Change Detection and Classification (CCDC) algorithm, first run the Analyze Changes Using CCDC tool and use the output change analysis raster as the input raster for this training tool. The training sample data must have been collected at multiple times using the Training Samples Manager. The dimension value for each sample is listed in a field in the training sample feature class, which is specified in the Dimension Value Field parameter. Parameters TrainRandomTreesClassifier(in_raster, in_training_features, out_classifier_definition, {in_additional_raster}, {max_num_trees}, {max_tree_depth}, {max_samples_per_class}, {used_attributes}, {dimension_value_field}) Code sample This is a Python sample for the TrainRandomTreesClassifier tool. import arcpy from arcpy.ia import * # Check out the ArcGIS Image Analyst extension license arcpy.CheckOutExtension("ImageAnalyst") TrainRandomTreesClassifier("c:/test/moncton_seg.tif", "c:/test/train.gdb/train_features", "c:/output/moncton_sig_SVM.ecd", "c:/test/moncton.tif", "50", "30", "1000", "COLOR;MEAN;STD;COUNT;COMPACTNESS;RECTANGULARITY") This is a Python script sample for the TrainRandomTreesClassifier tool. # Import system modules import arcpy from arcpy.ia import * # Set local variables inSegRaster = "c:/test/cities_seg.tif" train_features = "c:/test/train.gdb/train_features" out_definition = "c:/output/cities_sig.ecd" in_additional_raster = "c:/cities.tif" maxNumTrees = "50" maxTreeDepth = "30" maxSampleClass = "1000" attributes = "COLOR;MEAN;STD;COUNT;COMPACTNESS;RECTANGULARITY" # Check out the ArcGIS Image Analyst extension license arcpy.CheckOutExtension("ImageAnalyst") # Execute TrainRandomTreesClassifier(inSegRaster, train_features, out_definition, in_additional_raster, maxNumTrees, maxTreeDepth, maxSampleClass, attributes) This example shows how to train a random trees classifier using a change analysis raster from the Analyze Changes Using CCDC tool. # Import system modules import arcpy from arcpy.ia import * # Check out the ArcGIS Image Analyst extension license arcpy.CheckOutExtension("ImageAnalyst") # Define input parameters in_changeAnalysisRaster = "c:/test/LandsatCCDC.crf" train_features = "c:/test/train.gdb/train_features" out_definition = "c:/output/change_detection.ecd" in_additional_raster = "" maxNumTrees = 50 maxTreeDepth = 30 maxSampleClass = 1000 attributes = None dimension_field = "DateTime" # Execute arcpy.ia.TrainRandomTreesClassifier( in_changeAnalysisRaster, train_features, out_definition, in_additional_raster, maxNumTrees, maxTreeDepth, maxSampleClass, attributes, dimension_field) Environments Licensing information - Basic: Requires Image Analyst or Spatial Analyst - Standard: Requires Image Analyst or Spatial Analyst - Advanced: Requires Image Analyst or Spatial Analyst
https://pro.arcgis.com/en/pro-app/latest/tool-reference/image-analyst/train-random-trees-classifier.htm
CC-MAIN-2022-33
en
refinedweb
The fundamental concept of React.js React is a flexible, efficient, open-source Javascript library. It was developed by Facebook (2013) for building user interfaces. It allows us to create a complex UI by making components. components are reuseble 1. JSX in React Usually JSXjust syntactic sugar for React.createElement(component, props, ...children) The JSX code : <div>My Name is Hossain</div> Compile into : React.createElement("div", null, "My Name is Hossain"); 2. JavaScript Expressions as Props We can pass any javascript expression in props with {} . Flowing the example below : <Component sum={5 + 9 + 1} /> For Component , the have value props.sum will be 15 . because the expression is 5 + 6 + 1 . 3. String Literals We can pass a string as a prop. there two JSX expressions are equivalent. it the same as the HTML attribute. <Component name="Hossain" /> <Component name={'Hossain'} /> 4. Spread Attributes We can already have as props as an object, and we went to pass props in JSX. we can use ... “spread” operator to pass a props objects. const App = () => { const props = {name: 'Hossain', age: 20}; return <Person {...props} /> } 5. Children in JSX You can pass more JSX as children props.children or Display nested component as same as HTML. <Container> <App1 /> <App2 /> </Container> 6. defaultProps defaultProps can be defined property in class component. it set default props in the class . This is used for undefind but not use null class Container extends React.Component { // ... }Container.defaultProps = { color: 'red' }; 7. Use the Production Build If you are not sure your build process set up currently, you can install React Developer Tools for Chrome. if you visit your site with React production mood, you can see the React Developer Tools background color is dark. but your site is development mood, you can see the React Developer Tools background color is red. if you build your site with create-react-app , you can be flowing this commend: npm run build or yarn build 8. State Until now, we can use static data, but when data is changing for state change, we can use useState the form React hooks . flowing the example blew: useState is a function. Its default value of the count value. if setCount() to change state value. count value is changing. const App = () => { [count, setCount] = useState(0); const handleClick = () => { setCount(count + 1) } return ( <div> <h3>{count}</h3> <button onClick={handleClick}>Click Me</button> </div> ); } 9. Conditional Rendering: In JSX possible to use the ternary operator for conditional rendering. <div>{name ? name : 'What is your name?'}</div> 10. Handling Events Handling events to react element is very similar to handle events in the DOM element. there are some syntax deferent - React element name use camelCase. - With JSX you can pass a function as an event handler, rather than a string. <button onClick={() => console.log('Clicked me')}> Click me </button>
https://rimawahid3.medium.com/the-fundamental-concept-of-react-js-a8644ee69a56?source=user_profile---------1-------------------------------
CC-MAIN-2022-33
en
refinedweb
- Activation functions - Logistic Regression - Neural Network overview - Parameters vs Hyperparameters - Application: recognize a cat - Python tips This is my note for the course (Neural Networks and Deep Learning).. If you want to break into cutting-edge AI, this course will help you do so. Activation functions 👉 Check Comparison of activation functions on wikipedia. Why non-linear activation functions in NN Model? Suppose (linear) You might not have any hidden layer! Your model is just Logistic Regression, no hidden unit! Just use non-linear activations for hidden layers! Sigmoid function - Usually used in the output layer in the binary classification. - Don't use sigmoid in the hidden layers! Signmoid function graph on Wikipedia. import numpy as np import numpy as np def sigmoid(z): return 1 / (1+np.exp(-z)) def sigmoid_derivative(z): return sigmoid(z)*(1-sigmoid(z)) Softmax function The output of the softmax function can be used to represent a categorical distribution – that is, a probability distribution over K different possible outcomes. Udacity Deep Learning Slide on Softmax def softmax(x): z_exp = np.exp(z) z_sum = np.sum(z_exp, axis=1, keepdims=True) return z_exp / z_sum tanh function (Hyperbolic tangent) - tanh is better than sigmoid because mean 0 and it centers the data better for the next layer. - Don't use sigmoid on hidden units except for the output layer because in the case , sigmoid is better than tanh. def tanh(z): return (np.exp(z) - np.exp(-z)) / (np.exp(z) + np.exp(-z)) Graph of tanh from analyticsindiamag. ReLU - ReLU (Rectified Linear Unit). - Its derivative is much different from 0 than sigmoid/tanh learn faster! - If you aren't sure which one to use in the activation, use ReLU! - Weakness: derivative ~ 0 in the negative side, we use Leaky ReLU instead! However, Leaky ReLU aren't used much in practice! def relu(z): return np.maximum(0, z) ReLU (left) and Leaky ReLU (right) Logistic Regression - Usually used for binary classification (there are only 2 outputs). In the case of multiclass classification, we can use one vs all (couple multiple logistic regression steps). Gradient Descent Gradient Descent is an algorithm to minimizing the cose function . It contains 2 steps: Forward Propagation (From to compute the cost ) and Backward Propagation (compute derivaties and optimize the parameters ). Initialize and then repeat until convergence (: number of training examples, : learning rate, : cost function, : activation function): The dimension of variables: , , . Code def logistic_regression_model(X_train, Y_train, X_test, Y_test, num_iterations = 2000, learning_rate = 0.5): m = X_train.shape[1] # number of training examples # INITIALIZE w, b w = np.zeros((X_train.shape[0], 1)) b = 0 # GRADIENT DESCENT for i in range(num_iterations): # FORWARD PROPAGATION (from x to cost) A = sigmoid(np.dot(w.T, X_train) + b) cost = -1/m * (np.dot(Y, np.log(A.T)) + p.dot((1-Y), np.log(1-A.T))) # BACKWARD PROPAGATION (find grad) dw = 1/m * np.dot(X_train, (A-Y).T) db = 1/m * np.sum(A-Y) cost = np.squeeze(cost) # OPTIMIZE w = w - learning_rate*dw b = b - learning_rate*db # PREDICT (with optimized w, b) Y_pred = np.zeros((1,m)) w = w.reshape(X.shape[0], 1) A = sigmoid(np.dot(w.T,X_test) + b) Y_pred_test = A > 0.5 Neural Network overview Notations - : th training example. - : number of examples. - : number of layers. - : number of features (# nodes in the input). - : number of nodes in the output layer. - : number of nodes in the hidden layers. - : weights for . - : activation in the input layer. - : activation in layer , node . - : activation in layer , example . - . Dimensions - . - . - . - . L-layer deep neural network L-layer deep neural network. Image from the course. - Initialize parameters / Define hyperparameters - Loop for num_iterations: - Forward propagation - Compute cost function - Backward propagation - Update parameters (using parameters, and grads from backprop) - Use trained parameters to predict labels. Initialize parameters - In the Logistic Regression, we use for (it's OK because LogR doesn't have hidden layers) but we can't in the NN model! - If we use , we'll meet the completely symmetric problem. No matter how long you train your NN, hidden units compute exactly the same function No point to having more than 1 hidden unit! - We add a little bit in and keep in . Forward & Backward Propagation Blocks of forward and backward propagation deep NN. Unknown source. Blocks of forward and backward propagation deep NN. Image from the course. Forward Propagation: Loop through number of layers: - (linear) - (for , non-linear activations) - (sigmoid function) Cost function: Backward Propagation: Loop through number of layers - . - for , non-linear activations: - . - . - . - . Update parameters: loop through number of layers (for ) - . - . Code def L_Layer_NN(X, Y, layers_dims, learning_rate=0.0075, num_iterations=3000, print_cost=False): costs = [] m = X_train.shape[1] # number of training examples L = len(layer_dims) # number of layers # INITIALIZE W, b params = {'W':[], 'b':[]} for l in range(L): params['W'][l] = np.random.randn(layer_dims[l], layer_dims[l-1]) * 0.01 params['b'][l] = np.zeros((layer_dims[l], 1)) # GRADIENT DESCENT for i in range(0, num_iterations): # FORWARD PROPAGATION (Linear -> ReLU x (L-1) -> Linear -> Sigmoid (L)) A = X caches = {'A':[], 'W':[], 'b':[], 'Z':[]} for l in range(L): caches['A_prev'].append(A) # INITIALIZE W, b W = params['W'][l] b = params['b'][l] caches['W'].append(W) caches['b'].append(b) # RELU X (L-1) Z = np.dot(W, A) + b if l != L: # hidden layers A = relu(Z) else: # output layer A = sigmoid(Z) caches['Z'].append(Z) # COST cost = -1/m * np.dot(np.log(A), Y.T) - 1/m * np.dot(np.log(1-A), 1-Y.T) #FORWARD PROPAGATION (Linear -> ReLU x (L-1) -> Linear -> Sigmoid (L)) dA = - (np.divide(Y, A) - np.divide(1 - Y, 1 - A)) grads = {'dW':[], 'db':[]} for l in reversed(range(L)): cache_Z = caches['Z'][l] if l != L-1: # hidden layers dZ = np.array(dA, copy=True) dZ[Z <= 0] = 0 else: # output layer dZ = dA * sigmoid(cache_Z)*(1-sigmoid(cache_Z)) cache_A_prev = caches['A_prev'][l] dW = 1/m * np.dot(dZ, cache_A_prev.T) db = 1/m * np.sum(dZ, axis=1, keepdims=True) dA = np.dot(W.T, dZ) grads['dW'].append(dW) grads['db'].append(db) # UPDATE PARAMETERS for l in range(L): params['W'][l+1] = params['W'][l] - grads['dW'][l] params['b'][l+1] = params['b'][l] - grads['db'][l] if print_cost and i % 100 == 0: print ("Cost after iteration %i: %f" %(i, cost)) if print_cost and i % 100 == 0: costs.append(cost) return parameter Parameters vs Hyperparameters - Parameters: . - Hyperparameters: - Learning rate (). - Number of iterations (in gradient descent algorithm) ( num_iterations). - Number of layers (). - Number of nodes in each layer (). - Choice of activation functions (their form, not their values). - Always use vectorized if possible! Especially for number of examples! - We can't use vectorized for number of layers, we need for. - Sometimes, functions computed with Deep NN (more layers, fewer nodes in each layer) is better than Shallow (fewer layers, more nodes). E.g. function XOR. - Deeper layer in the network, more complex features to be determined! - Applied deep learning is a very empirical process! Best values depend much on data, algorithms, hyperparameters, CPU, GPU,... - Learning algorithm works sometimes from data, not from your thousands line of codes (surprise!!!) Application: recognize a cat This section contains an idea, not a complete task! Image to vector conversion. Image from the course. L-layer deep neural network. Image from the course. Python tips ○ Reshape quickly from (10,9,9,3) to (9*9*3,10): X = np.random.rand(10, 9, 9, 3) X = X.reshape(10,-1).T ○ Don't use loop, use vectorization!
https://dinhanhthi.com/deeplearning-ai-course-1/
CC-MAIN-2022-33
en
refinedweb
This module groups classes and namespaces that have to do with handling degrees of freedom. The central class of this group is the DoFHandler class: it is built on top of a triangulation and a finite element class and allocated degrees of freedom on each cell of the triangulation as required for the finite element space described by the finite element object. There are other variants of the DoFHandler class such as hp::DoFHandler that do similar things for more special cases. DoFHandler objects are used together with objects of type FiniteElement (or hp::FECollection in the case of hp::DoFHandler) to enumerate all the degrees of freedom that exist in a triangulation for this particular finite element. As such, the combination of mesh, finite element, and DoF handler object can be thought of as providing a basis of the finite element space: the mesh provides the locations at which basis functions are defined; the finite element describes what kinds of basis functions exist; and the DoF handler object provides an enumeration of the basis, i.e., it is provides a concrete structure of the space so that we can describe functions in this finite dimensional space by vectors of coefficients. DoFHandlers extend Triangulation objects (and the other classes in the Grid classes module) in that they, too, offer iterators that run over all cells, faces, or other geometric objects that make up a triangulation. These iterators are derived from the triangulation iterators and therefore offer the same functionality, but they also offer additional functions. For example, they allow to query the indices of the degrees of freedom associated with the present cell. Note that DoFHandler classes are not derived from Triangulation, though they use Triangulation objects; the reason is that there can be more than one DoFHandler object that works on the same Triangulation object. In addition to the DoF handler classes, this module holds a number of auxiliary classes not commonly used in application programs, as well as three classes that are not directly associated with the data structures of the DoFHandler class. The first of these is the ConstraintMatrix class that stores and treats the constraints associated with hanging nodes. Secondly, the DoFRenumbering namespace offers functions that can reorder degrees of freedom; among its functions are ones that sort degrees of freedom in downstream direction, for example, and ones that sort degrees of freedom in such a way that the bandwidth of associated matrices is minimized. Finally, the DoFTools namespace offers a variety of algorithms around handling degrees of freedom. The flags used in tables by certain make_*_pattern functions to describe whether two components of the solution couple in the bilinear forms corresponding to cell or face terms. An example of using these flags is shown in the introduction of step-46. In the descriptions of the individual elements below, remember that these flags are used as elements of tables of size FiniteElement::n_components times FiniteElement::n_components where each element indicates whether two components do or do not couple. Definition at line 190 of file dof_tools.h.
http://www.dealii.org/developer/doxygen/deal.II/group__dofs.html
CC-MAIN-2017-17
en
refinedweb
.shutdown;23 24 import javax.naming.InitialContext ;25 26 import org.jboss.system.ServiceMBeanSupport;27 28 /** A service that calls System.exit from its stopService method. Note that29 * this service cannot be deployed when the server is shutdown as its call30 * to System.exit(0) will hang the vm in java.lang.Shutdown.exit as the31 * as the Shutdown.class monitor is already held by the signal handler.32 * 33 * @author Scott.Stark@jboss.org34 * @version $Revision: 43459 $35 */36 public class ExitOnShutdown37 extends ServiceMBeanSupport38 implements ExitOnShutdownMBean39 {40 protected void startService() throws Exception 41 {42 InitialContext ctx = new InitialContext ();43 ctx.bind("ExitOnShutdown", Boolean.TRUE);44 }45 46 protected void stopService() throws Exception 47 {48 Thread thread = new Thread (new Runnable ()49 {50 public void run()51 {52 System.exit(0);53 }54 }, "ExitOnShutdown");55 thread.start();56 }57 }58 Java API By Example, From Geeks To Geeks. | Our Blog | Conditions of Use | About Us_ |
http://kickjava.com/src/org/jboss/test/jmx/shutdown/ExitOnShutdown.java.htm
CC-MAIN-2017-17
en
refinedweb
dgaudet 98/04/08 18:28:58 Modified: . STATUS Log: I, too, retract my votes, opinions, and plans regarding 1.3. Revision Changes Path 1.282 +14 -52 apache-1.3/STATUS Index: STATUS =================================================================== RCS file: /export/home/cvs/apache-1.3/STATUS,v retrieving revision 1.281 retrieving revision 1.282 diff -u -r1.281 -r1.282 --- STATUS 1998/04/09 00:42:54 1.281 +++ STATUS 1998/04/09 01:28:57 1.282 @@ -15,7 +15,7 @@ or not, and if not, what changes are needed to make it right. Approve guidelines as written: - +1: Dean, Paul, Jim, Martin, Ralf, Randy, Brian, Ken + +1: Paul, Jim, Martin, Ralf, Randy, Brian, Ken +0: -1: @@ -195,15 +195,12 @@): + * uri issues - RFC2068 requires a server to recognize its own IP addr(s) in dot notation, we do this fine if the user follows the dns-caveats documentation... we should handle it in the case the user doesn't ever @@ -233,11 +230,11 @@ ap_xxx: +1: Ken, Brian, Ralf, Martin, Paul, Randy - Public API functions (e.g., palloc) - ap_xxx: +1: Ralf, Dean, Randy, Martin, Brian, Paul + ap_xxx: +1: Ralf, Randy, Martin, Brian, Paul - Private functions which we can't make static (because of cross-object usage) but should be (e.g., new_connection) - ap_xxx: +1: Dean, Randy, Martin, Brian, Paul + ap_xxx: +1: Randy, Martin, Brian, Paul -0: Ralf apx_xxx: +1: Ralf appri_xxx: +0: Ralf @@ -246,7 +243,7 @@ status_module) which are used special in Configure, mod_so, etc and have to be exported: [CANNOT BE DONE AUTOMATICALLY BY RENAME.PL!] - ..._module:+1: Dean + ..._module:+1: +0: Ralf ap_xxx: +1: -0: Ralf @@ -293,32 +290,6 @@ the user while still providing the private symbolspace. - - Dean: [Use ap_ only]. - - Furthermore, nobody has explained just what happens when - functions which are "part of the API", such as palloc - suddenly get moved to libap and are no longer "part of - the API". Calling it apapi_palloc is foolish. The name - "ap_palloc" has two prefixes for those not paying attention, - the first "ap_" protects apache's namespace. The next, - "p" indicates it is a pool function. Similarly we would - have "ap_table_get". There's no need to waste space with - "apapi_table_get", the "api" part is just redundant. - - If folks can't figure out what is in the api and what - isn't THEN IT'S IS A DOCUMENTATION PROBLEM. It's not - a code problem. They have to look in header files or - other docs anyhow to learn how to use a function, so why - should they repeatedly type apapi ? - - ap_ is a name space protection mechanism, it is not a - documentation mechanism. - - Randy: I agree with Dean 100%. The work created to keep this straight far outweighs any gain this could give. @@ -342,14 +313,7 @@ background of our cognitive model of the source code). *. + it a lot. * The binary should have the same name on Win32 and UNIX. +1: Ken @@ -362,15 +326,15 @@ * Maybe a http_paths.h file? See <Pine.BSF.3.95q.971209222046.25627D-100000@valis.worldgate.com> - +1: Dean, Brian, Paul, Ralf, Martin + +1: Brian, Paul, Ralf, Mart + * root's environment is inherited by the Apache server. Jim & Ken + think we should recommend using 'env' to build the appropriate environment. Marc and Alexei don't see any big deal. Martin says that not every "env" has a -u flag. @@ -381,13 +345,11 @@ Apache should be sending 200 *and* Accept-Ranges. * Marc's socket options like source routing (kill them?) - Marc, Dean, Martin say Yes + Marc, Martin say Yes * Ken's PR#1053: an error when accessing a negotiated document explicitly names the variant selected. Should it do so, or should the base input name be referenced? - Dean says: doesn't seem important enough to be in the STATUS... - it's probably a pain to fix. * Proposed API Changes: @@ -396,7 +358,7 @@ field is r->content_languages. Heck it's not even mentioned in apache-devsite/mmn.txt when we got content_languages (note the s!). The proposal is to remove r->content_language: - Status: Dean +1, Paul +1, Ralf +1, Ken +1 + Status: Paul +1, Ralf +1, Ken +1 - child_exit() is redundant, it can be implemented via cleanups. It is not "symmetric" in the sense that there is no exit API method to go @@ -405,7 +367,7 @@ mod_mmap_static, and mod_php3 for example). The proposal is to remove the child_exit() method and document cleanups as the method of handling this need. - Status: Dean +1, Rasmus +1, Paul +1, Jim +1, + Status: Rasmus +1, Paul +1, Jim +1, Martin +1, Ralf +1, Ken +1 * Don't wait for WIN32: It's been quite some time and WIN32 doesn't seem @@ -415,7 +377,7 @@ Proposal: the next release should be named 1.3.0 and should be labelled "stable on unix, beta on NT". - +1: Dean + +1: -0: Ralf (because we've done a lot of good but new stuff in 1.3b6-dev now and we should give us at least one pre-release before the so-called "release" [1.3.0]. @@ -429,7 +391,7 @@ candidate on unix, beta on NT". The release after that will be called 1.3.0 "stable on unix, beta on NT". +1: Jim, Ralf, Randy, Brian, Martin - +0: Dean + +0: Notes: Randy: APACI should go in a beta release if it is to go in at all.
http://mail-archives.apache.org/mod_mbox/httpd-cvs/199804.mbox/%3C19980409012859.7109.qmail@hyperreal.org%3E
CC-MAIN-2017-17
en
refinedweb
Download presentation Presentation is loading. Please wait. Published byIsabel Horton Modified about 1 year ago 1 Lecture 20 – Swing Layout Programming Lecturer: Prof Jim Warren 2 Overview With a toolkit like Swing, it’s more like you give the window manager ideas (or at best requirements) for your interface will look like, rather than specifying it exactly – Good in some ways: it can resize intelligently, and potentially the look-and-feel can evolve over time – But it is a paradigm that takes getting used to: working with layout managers Also, there’s the perennial problem of lack of “screen real estate” – How do we fit everything in?! 3 Windows Can managed real estate issues with window placements Tiled windowsOverlapping windowsCascading windowsInterrupted cascade 4 Window Interfaces – SDI Single Document Interface Single document interface—Microsoft Internet Explorer® 5 Window Interfaces – MDI Multiple Document Interface (more powerful, but also more complex for user) Multiple document interface—Adobe PhotoShop® application. 6 6 Scrollbar Example Part 1 import javax.swing.*; import java.awt.*; import java.awt.event.*; public class ScrollBarExample { JFrame frame; JPanel panel; JTextArea area; JTextField field; JScrollPane scrollpane; public static void main(String[] args) { ScrollBarExample v = new ScrollBarExample(); } public ScrollBarExample() { // see next slide… } Simple technique to manage screen real estate 7 7 Scrollbar Example Part 2 public ScrollBarExample() { frame = new JFrame("ScrollBarExample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(100, 130); field = new JTextField(7); area = new JTextArea("…", 3, 7); scrollpane = new JScrollPane(area); scrollpane.getHorizontalScrollBar().addAdjustmentListener(new AdjustmentListener(){ public void adjustmentValueChanged( AdjustmentEvent e){ field.setText("Position=" + e.getValue()); } }); panel = new JPanel(); panel.add(field); panel.add(scrollpane); frame.add(panel); frame.setVisible(true); } Yes, it’s that easy to make something be in a scroll pane Anonymous class used to create event handler 8 Tabbed pane Good for managing space);... protected JComponent makeTextPanel(String text) { JPanel panel = new JPanel(false); JLabel filler = new JLabel(text); filler.setHorizontalAlignment(JLabel.CENTER); panel.setLayout(new GridLayout(1, 1)); panel.add(filler); return panel; 9 Tab heuristics Be sure to create good names for your tabs – “Details 1” and “Details 2” is a total failure! The end user should have a good intuition for what is under each tab based on its name – Similar reasoning applies when naming the entries on a hierarchical menu – user should be able to guess fairly reliably which submenu has their desired option It’s OK if some tabs are less packed with fields than others if that results in better tab names It’s not great to have so many tabs that it takes multiple rows – Consider what else you can do as an alternative (e.g., put rarer options under an “Options...” button; and do you really need all these details? – watch for ‘feature creep’) 10 Layout managers in Swing Everything goes through a layout manager in Swing – Learning to control them well let’s you get the UI you really want BorderLayout is default for content pane – All extra space is given to ‘CENTER’ From 11 Box Layout Respects components requested max sizes Allows you to set alignments 12 Flow layout Default layout manager for JPanel Simply lays out components left to right in order they are added Adds another row if its not wide enough to hold all its contents 13 Grid Layouts Flexible GridBagLayout lets you specify rows of cells – Cells can span columns – Rows can have different heights Using GridLayout is simpler if you want a uniform table of rows and columns 14 GridBayLayout code JButton button; pane.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); button = new JButton("Button 1");); Set the layout of a container with a new layout manager – in this case ‘pane’ is the result of frame.getContentPane() Attributes of the GridBagConstraints object determine position/behaviour of objects once added to the pane.fill indicates button fills available space;.weightx determines how space is allocated among columns 15); Padding makes the object use more space internally.gridwidth makes the object span columns Insets create space between object and edges of its cell 16 Getting it just right: Glue and Rigid Areas Don’t let the layout managers push you around! – Get the alignment your design calls for 17 Glue and Rigid Areas “Glue” expands to fill all the available space between other components 18 Getting it right For sophisticated dialogs you’ll often need to nest layout managers (e.g., JPanels with vertical BoxLayouts within a BorderLayout) – See “Nesting Layout Managers to Achieve Nirvana” at ortcourse.html#nesting (it’s AWT, but easily transfers to Swing) 19 Summary Swing gives you mechanisms to make ‘conventional’ GUIs With effort, you can override default behaviours and make custom layouts and controls, too Results from layout managers and event handlers can end up surprising you Keep sight of your design – Don’t be a slave to your toolkit – Then again, know when to compromise rather than fail Similar presentations © 2017 SlidePlayer.com Inc.
http://slideplayer.com/slide/4235866/
CC-MAIN-2017-17
en
refinedweb
Template::Plugin::Filter - Base class for plugin filters package MyOrg::Template::Plugin::MyFilter; use Template::Plugin::Filter; use base qw( Template::Plugin::Filter ); sub filter { my ($self, $text) = @_; # ...mungify $text... return $text; } # now load it... [% USE MyFilter %] # ...and use the returned object as a filter [% FILTER $MyFilter %] ... [% END %] This module implements a base class for plugin filters. It hides the underlying complexity involved in creating and using filters that get defined and made available by loading a plugin. To use the module, simply create your own plugin module that is inherited from the Template::Plugin::Filter class. package MyOrg::Template::Plugin::MyFilter; use Template::Plugin::Filter; use base qw( Template::Plugin::Filter ); Then simply define your filter() method. When called, you get passed a reference to your plugin object ($self) and the text to be filtered. sub filter { my ($self, $text) = @_; # ...mungify $text... return $text; } To use your custom plugin, you have to make sure that the Template Toolkit knows about your plugin namespace. my $tt2 = Template->new({ PLUGIN_BASE => 'MyOrg::Template::Plugin', }); Or for individual plugins you can do it like this: my $tt2 = Template->new({ PLUGINS => { MyFilter => 'MyOrg::Template::Plugin::MyFilter', }, }); Then you USE your plugin in the normal way. [% USE MyFilter %] The object returned is stored in the variable of the same name, 'MyFilter'. When you come to use it as a FILTER, you should add a dollar prefix. This indicates that you want to use the filter stored in the variable 'MyFilter' rather than the filter named 'MyFilter', which is an entirely different thing (see later for information on defining filters by name). [% FILTER $MyFilter %] ...text to be filtered... [% END %] You can, of course, assign it to a different variable. [% USE blat = MyFilter %] [% FILTER $blat %] ...text to be filtered... [% END %] Any configuration parameters passed to the plugin constructor from the USE directive are stored internally in the object for inspection by the filter() method (or indeed any other method). Positional arguments are stored as a reference to a list in the _ARGS item while named configuration parameters are stored as a reference to a hash array in the _CONFIG item. For example, loading a plugin as shown here: [% USE blat = MyFilter 'foo' 'bar' baz = 'blam' %] would allow the filter() method to do something like this: sub filter { my ($self, $text) = @_; my $args = $self->{ _ARGS }; # [ 'foo', 'bar' ] my $conf = $self->{ _CONFIG }; # { baz => 'blam' } # ...munge $text... return $text; } By default, plugins derived from this module will create static filters. A static filter is created once when the plugin gets loaded via the USE directive and re-used for all subsequent FILTER operations. That means that any argument specified with the FILTER directive are ignored. Dynamic filters, on the other hand, are re-created each time they are used by a FILTER directive. This allows them to act on any parameters passed from the FILTER directive and modify their behaviour accordingly. There are two ways to create a dynamic filter. The first is to define a $DYNAMIC class variable set to a true value. package MyOrg::Template::Plugin::MyFilter; use Template::Plugin::Filter; use base qw( Template::Plugin::Filter ); use vars qw( $DYNAMIC ); $DYNAMIC = 1; The other way is to set the internal _DYNAMIC value within the init() method which gets called by the new() constructor. sub init { my $self = shift; $self->{ _DYNAMIC } = 1; return $self; } When this is set to a true value, the plugin will automatically create a dynamic filter. The outcome is that the filter() method will now also get passed a reference to an array of postional arguments and a reference to a hash array of named parameters. So, using a plugin filter like this: [% FILTER $blat 'foo' 'bar' baz = 'blam' %] would allow the filter() method to work like this: sub filter { my ($self, $text, $args, $conf) = @_; # $args = [ 'foo', 'bar' ] # $conf = { baz => 'blam' } } In this case can pass parameters to both the USE and FILTER directives, so your filter() method should probably take that into account. [% USE MyFilter 'foo' wiz => 'waz' %] [% FILTER $MyFilter 'bar' biz => 'baz' %] ... [% END %] You can use the merge_args() and merge_config() methods to do a quick and easy job of merging the local (e.g. FILTER) parameters with the internal (e.g. USE) values and returning new sets of conglomerated data. sub filter { my ($self, $text, $args, $conf) = @_; $args = $self->merge_args($args); $conf = $self->merge_config($conf); # $args = [ 'foo', 'bar' ] # $conf = { wiz => 'waz', biz => 'baz' } ... } You can also have your plugin install itself as a named filter by calling the install_filter() method from the init() method. You should provide a name for the filter, something that you might like to make a configuration option. sub init { my $self = shift; my $name = $self->{ _CONFIG }->{ name } || 'myfilter'; $self->install_filter($name); return $self; } This allows the plugin filter to be used as follows: [% USE MyFilter %] [% FILTER myfilter %] ... [% END %] or [% USE MyFilter name = 'swipe' %] [% FILTER swipe %] ... [% END %] Alternately, you can allow a filter name to be specified as the first positional argument. sub init { my $self = shift; my $name = $self->{ _ARGS }->[0] || 'myfilter'; $self->install_filter($name); return $self; } [% USE MyFilter 'swipe' %] [% FILTER swipe %] ... [% END %] Here's a complete example of a plugin filter module. package My::Template::Plugin::Change; use Template::Plugin::Filter; use base qw( Template::Plugin::Filter ); sub init { my $self = shift; $self->{ _DYNAMIC } = 1; # first arg can specify filter name $self->install_filter($self->{ _ARGS }->[0] || 'change'); return $self; } sub filter { my ($self, $text, $args, $config) = @_; $config = $self->merge_config($config); my $regex = join('|', keys %$config); $text =~ s/($regex)/$config->{ $1 }/ge; return $text; } 1; Andy Wardley <abw@andywardley.com> 1.31,::Filters, Template::Manual::Filters
http://search.cpan.org/~abw/Template-Toolkit-2.14/lib/Template/Plugin/Filter.pm
CC-MAIN-2017-17
en
refinedweb
I've a directive that I want to publish on npm. I read the doc here and after that here is what I did: npm init npm publish npm install --save-dev @NgModule({ declarations: [ AppComponent, MyDirective //this is not found ], You imported import {...} from 'your-package-name/your-main-js'; it, right? Here's a nice guide to create npm packages for Angular2. If you want to create a component package, remember to inline your templates/styles ! Otherwise your app will be broken.. Or you could use a script like this to inline those templates/styles.. Maybe this repo as a starting point will help:
https://codedump.io/share/c0TnD5FlstDl/1/angular-2-directive-as-npm-package
CC-MAIN-2017-17
en
refinedweb
, it's several days after I said 'in the next day', but I've finally uploaded a new TemplateServer version. Changes: - several small bug fixes - reimplemented the #block directive to avoid maximum recursion depth errors with large blocks. - created many new test cases in the regression testing suite - added an example site to the examples/ directory - started the User's Guide The User's Guide is just a skeleton at the moment. I'm in the process of filling it in. I'd appreciate any examples. Version 0.8.1 will contain a less skeletal User's Guide. Cheers, Tavis On Monday 28 May 2001 12:15, Manfred Nowak wrote: > The only problem is to start the AppServer for WebKit. > Can i do that from within WebKit.cgi or must my ISP > start this? I haven't worked with WebKit.cgi but I'm sure you could modify it to restart the AppServer if it's not running. Another option is to use a chron job to check up on the AppServer and restart it if necessary. Tavis Mike Orr wrote: >. What are these modifications? sorry, I'm a WebNewbie :-(? am I the only one who want to use Webware over an ISP ? Manfred On 28 May 01, at 12:35, Ian Bicking wrote: >.. A typical site constructed with CGI -- where there are a few portions that are dynamic, and more portions that are static -- will probably use less resources over time. This is what most shared hosts are targetting. Also, a run-away process takes a lot of resources, and CGI is better protected from this. It would be spiffy if the adapters -- which are more isolated and hopefully more robust -- could act as the superego for AppServer, restarting it if it takes too long, doesn't respond, or isn't there at all. I suppose that could be as simple as calling an rc script as [os.]system("webware restart") whenever the connection to the AppServer is denied or times out.. Ian. At 08:24 AM 5/28/2001 +0200, J=F6rn Schrader wrote: >Is the above code thread-save. > >Joern. I happen to know that Geoff does mix both techniques in the same manner=20 than you have described. So do I. I think his earlier message was just emphasizing that the initialization=20 code should go in the module. Feel free to load up SitePage with as many conveniences as appropriate for= =20 your site. -Chuck Hi all, i try to work with WebKit on my own Homepage. How do i start AppServer on the Server of my ISP or can i run WebKit only on Intranets ?? Best regards Manfred >This isn't thread-safe -- 2 servlets could create the store at the same time. > >You're better off putting the store initialization into a module that gets >imported -- then Python automatically ensures that only one thread imports >it at once. (Either that or you should explicitly use a threading.Lock >object to make it thread-safe.) > >If you want to "pre-load" the store when the app server starts up to reduce >response time, then you can put the import into the __init__.py in your >context directory. __init__.py automatically gets imported when the app >server starts. Thanks Geoff for your hint concerning thread-safety. But Ian's way to have a Base Servlet that cares for store opening is attractive too. Do you think, that one can mix both methods by having a store initialization module that gets imported in a base servlet: # MyObjectStore.py from MiddleKit.Run.MySQLObjectStore import MySQLObjectStore store = MySQLObjectStore() store.readModelFileNamed('MyMiddleKitModel') # MyPage.py from MyObjectStore import store from WebKit.Page import Page class MyPage(Page): def Store(self): return store # MyDerivedPage.py from MyPage import MyPage class MyDerivedPage(MyPage): def writeContent(self): currentStore = self.Store() # do something with currentStore Is the above code thread-save. Joern. Howdy: I finally got around to trying the latest Webware (0.5.1-rc3) and I'm stuck. I ran the install.py thing, and then moved the WebKit.cgi over to my apache setup to test it (I'll get around to recompiling apache for something better later). I fixed the permissions, and changed the line in the cgi to point to the WebKit directory, but all I get is Internal Server Error or 404 Not Found. Apache is working and serving up static text, as well as several other cgi's like viewcvs. What am I missing? Conceptual questions: I assume apache listens as normal on port 80, and the WebKit.cgi talks to the AppServer over the loopback interface? The appserver says it's listening on port 8086 on the loopback - is this correct? I have a somewhat kluged apache setup with a virtual host on the external interface and the non-virtual setup on the internal one. Could this be the problem? I get 404 errors when I use my internal domain name in the URL to WebKit.cgi, but 500 errors when I use the IP address. Everything else seems to work okay (even Zope, before I removed it). Thanks in advance, Steve ************************************************************* Steve Arnold sarnold@... Assoc. Faculty, Dept of Geography, Allan Hancock College Linux: It's not just for nerds anymore... I agree to receive quotes, newsletters and other information from sourceforge.net and its partners regarding IT services and products. I understand that I can withdraw my consent at any time. Please refer to our Privacy Policy or Contact Us for more details
https://sourceforge.net/p/webware/mailman/webware-discuss/?viewmonth=200105&viewday=28
CC-MAIN-2017-17
en
refinedweb
Package: wnpp Severity: wishlist Owner: Arnaud Fontaine <arnau@debian.org> * Package name : xml_marshaller Version : 0.9.7 Upstream Author : Nicolas Delaby <nicolas@nexedi.com> * URL : * License : Python License (CNRI Python License) Programming Lang: Python Description : Converting Python objects to XML and back again Marshals simple Python data types into a custom XML format. The Marshaller and Unmarshaller classes can be subclassed in order to implement marshalling into a different XML DTD. It is fully compatible with PyXML implementation and enable namespace support for XML Input/Output. This package is required for package slapos.slap, which I will maintain as part of my work. This package will be packaged within the python-modules debian team. Regards, Arnaud Fontaine
https://lists.debian.org/debian-devel/2011/04/msg00954.html
CC-MAIN-2017-17
en
refinedweb
This source code shows how to use the Sencha Touch Ext.XTemplate: Short source code examples. The following Python example shows how to split a string into a list, get the second element from the list (which happens to be a long), and convert that string to a long value: line = 'Foo bar baz|1234567890' ts = line.split('|', 1)[1] t = long(ts) I needed to do this for my Radio Pi project, and this code worked out well. Here’s an example of how to print the formatted time in Python: import time print time.strftime("%a, %b %d %I:%M %p") That code results in the following output: Thu, May 29 11:26 AM To see what’s running on a Mac OS X port, use this lsof command: $ sudo lsof -i :5150 This command shows what’s running on port 5150. Just change that to whatever port you want to see. To build a Sencha ExtJS application, move to your project’s root directory, then run this command: $ sencha app build Assuming that the build works fine, you can test the production build in your browser at a URL like this: I just tried a quick test of transparency/translucency on Mac OS X using Java, and in short, here is the source code I used to create a transparent/translucent Java JFrame on Mac OS X 10.9: Here are a few examples of how to set the Font on Java Swing components, including JTextArea, JLabel, and JList: // jtextarea textArea.setFont(new Font("Monaco", Font.PLAIN, 20)); // jlabel label.setFont(new Font("Helvetica Neue", Font.PLAIN, 14)); // jlist list.setFont(new Font("Helvetica Neue", Font.PLAIN, 12)); A test application You can use code like the following Scala code to easily test different fonts. Modify however you need to, but it displays a JFrame with a JTextArea, and you can change the font on it: If you want the horizontal and/or vertical scrollbars to always show on a Java JScrollPane, configure them like this: scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); Other options are: HORIZONTAL_SCROLLBAR_AS_NEEDED HORIZONTAL_SCROLLBAR_NEVER and: I just learned how to send STDOUT and STDERR to a file in a Java application (without using Unix shell redirect symbols). Just add these two lines of code to the main method in your Java (or Scala) program: System.setOut(new PrintStream("/Users/al/Projects/Sarah2/std.out")); System.setErr(new PrintStream("/Users/al/Projects/Sarah2/std.err")); Then when you use: System.out.println("foo"); or Nothing major here, I just wanted to note the use of several scalacOptions in the following build.sbt example:): I learned today that you break out of a Sencha ExtJS Store each loop by returning false from your function. This code shows the technique: Sencha ExtJS - How to dynamically create a form textfield (Ext.form.field.Text) Without much introduction, here’s a large block of Sencha ExtJS controller code. The code needs to be cleaned up, but at the moment it shows: The following code shows how to dynamically create a Sencha ExtJS form textfield, i.e., a Ext.form.field.Text field. Maybe one of the best things about this example is that it shows how to get input focus on a textfield: Without any significant introduction, here are some more Sencha ExtJS code examples. I’m just trying to make my example code easier for me to find; if it helps you, that’s cool, too. The following code shows: Here are two Sencha ExtJS Ext.Ajax.request JSON POST and GET examples. The first one shows how to add a Stock by getting all of the values in a Sencha form (Ext.form.Panel). Keys that I learned recently are: formPanel.getForm()gets the form (Ext.form.Basic) Ext.JSON.encode(formPanel.getValues())JSON encodes all of the form values Here’s the code: onStockFormKeyPress: function(textfield, event, options) { if(event.getKey() == event.ENTER) { Ext.Msg.alert('Keys','You pressed the Enter key'); } } This function is called when the keypress event is handled in the init function of my controller class: Sencha ExtJS Ext.Msg.show examples Here’s a simple Sencha Ext.Msg.show example: Ext.Msg.show({ title: 'Dude', msg: 'Dude, you need to select at least one link.', buttons: Ext.Msg.OK, icon: Ext.Msg.WARNING }); I’ll add more Ext.Msg.show examples here over time.
http://alvinalexander.com/source-code-snippets?page=8
CC-MAIN-2017-17
en
refinedweb
I was creating an application that was displaying on a graph a number of different items, and I wanted to visually differentiate these items by their text. If you've not used XAML Converters before then in simple terms, they are class that implements the IValueConverter interface. This interface has two methods Convert and ConvertBack. The methods take an object of one type and convert it to another. This class can then be added as a resource to your XAML markup and used in any binding. See this MSDN article for more information. The class is straight forward and looks like: using System; using System.Security.Cryptography; using System.Text; using System.Windows.Data; using System.Windows.Media; public class StringToBrushConverter : IValueConverter { public object Convert(object value, Type targetType , object parameter, System.Globalization.CultureInfo culture) { if (value != null && value is string) { string text = (string) value; byte[] data; //create a 16 byte md5 hash of the string using (MD5 md5 = MD5.Create()) data = md5.ComputeHash(Encoding.UTF8.GetBytes(text)); //use 3 values from the hash to create the colour //provide an alpha value to prevent readability issues //if this colour is used as a text background return new SolidColorBrush( Color.FromArgb(180, data[0], data[7], data[15])); } return new SolidColorBrush(Color.FromRgb(255, 255, 255)); } public object ConvertBack(object value, Type targetType , object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } After some checks that your passed object is a string, we calculate a MD5 hash of the string and pick 3 random values from that hash (the data[0], data[7] and data[15]) to create a new brush. If you're asking why? That's reasonable, this wasn't my first solution, I started with what probably everyone would start with, converting the string to their ASCII codes. And yes this works, but there's a fairly massive issue...consider strings that almost the same (e.g. DataItem5, DataItem16) with the ASCII method you'll end up with colours that are pretty much indistinguishable. The reason is for most text your using around 90 values and you're mapping that to a pool of 2,147,483,947 possible colours. If you want to use this approach in a Windows Forms or ASP or anywhere else, then you only need the code within the if block, and then just return the Color rather than the XAML SolidColorBrush object. Points of Interest Is there a less computationally expensive method of achieving the same thing? Could you ever implement the ConvertBack method? :D 1st and hopefully only version:) This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
http://www.codeproject.com/Tips/787343/Strings-To-Colours
CC-MAIN-2017-17
en
refinedweb
Network Video Analytics in C#: How to achieve line detection (NVA - Object Detection) The of a reliable security system. One of these new technologies is object detection. Inside object detection, there are the so-called feature-based methods. These methods aim to find possible matches between the features of the object and the image of the camera. The topic of this tutorial belongs to these feature-based methods. The following tutorial aims to introduce line detection. First, you can read a brief theoretical background about object detection in general and line detection. After this part you will find a detailed description on how to implement this exciting function in C# along with creating a graphical user interface for the program. I hope this article will help you in developing your own application to perform line detection. What will you need to succeed? Before we start programming, let's see what devices are needed for this game. Obviously, it is necessary to have a USB camera device to work with. You can consult the webpage for USB cameras; there are some pretty nice ones there. Regarding the software part of the business, you need to download Visual C# 2010 Express and .Net Framework 4. Those are needed for the coding procedure. One final part is missing now: a camera SDK that you can use for developing your line detecting solution. I found this software, Ozeki's Camera SDK to be useful, it was easy to work with, and so I can recommend it to you. Now that you are fully prepared to start working, take a look at the literature. What is object detection and line detection? To get a deeper knowledge about object detection, we can consult our old friend, the Internet. As it is stated on Wikipedia, "object detection is a computer technology related to computer vision and image processing that deals with detecting instances of semantic objects of a certain class (such as humans, buildings, or cars) in digital images and videos. Well-researched domains of object detection include face detection and pedestrian detection." Another source, Mathworks describes object detection as "the process of finding instances of real-world objects such as faces, bicycles, and buildings in images or videos." As possible fields of usage, the webpage lists image retrieval, security, surveillance, and automated vehicle parking systems. If we dig deeper in this topic we can find line detection. The basic task of line detection is to indicate if an object on the camera's image crosses any of the virtual lines we have on our image. You can use this function for security purposes or, for example, to observe costumer traffic in your shop. Fine, now here comes the exciting part of the story. Let's see how to implement this function. Creating the C# code To detect lines on the image of a camera, we should use the ILinedetector object. After creating an instance of ILineDetector with the help of the static ImageProcesserFactory class, it will be able to detect lines on frames and on videos, too. In case of frames, we can make the image with the help of the Process() method of the instance, while in the case of videos, we should use the ImageProcesserHandler mediahandler. After this tiny piece of information, let the actual work begin! As the first step of coding we should apply the using lines. using System; using System.Drawing; using System.Windows.Forms; using Ozeki.Media.MediaHandlers; using Ozeki.Media.MediaHandlers.Video; using Ozeki.Media.MediaHandlers.Video.CV; using Ozeki.Media.MediaHandlers.Video.CV.Data; using Ozeki.Media.MediaHandlers.Video.CV.Processer; using Ozeki.Media.Video.Controls; Then we qualify the namespace in our code. namespace LineDetection { After these basic steps, it is necessary to add the global variables to our code. Here, you will need Webcamera_webCamera. This instance will help us to get the image of the camera. The next variable is MediaConnector_connector. Its task is to connect the mediahandlers. Now, here comes ImageProcesserHandler_imageProcesserHandler. This guy is a mediahandler that runs the instances that implements the IImageProcesser interface. Now we have the interface that is responsible for line detection and that implements the IImageProcesser interface: ILineDetector_lineDetector. Three more variables to go. FrameCapture_frameCapture is another mediahandler. You can configure the frequency of processing with this one. We have the VideoViewerWF instance that is a GUI tool for Windows Forms applications and it will help you to display the video. And last but not least, we have the DrawingImageProvider instance that is also a mediahandler. (Mediahandlers... mediahandlers everywhere.) Its task is to prepare the image, sent by the VideoSender class mediahandlers, for the VideoViewerWF instance. Now we have all the necessary global variables set in our code. Let's see how it looks like now. public partial class Form1 : Form { WebCamera _webCamera; MediaConnector _connector; ImageProcesserHandler _imageProcesserHandler; ILineDetector _lineDetector; FrameCapture _frameCapture; VideoViewerWF _originalView; VideoViewerWF _processedView; DrawingImageProvider _originalImageProvider; DrawingImageProvider _processedImageProvider; We are done with the global variables for now, so we can move on to some methods that should be called to work out line detecting. The first of these methods is Init(). This is the method that initializes most of the global variables. This is where the FrameCapture mediahandler instance is configured and also, where the ILineDetector instance is created with the help of ImageProcesserFactory. We add this instance to the ImageProcesserHandler instance. Every time the ILineDetector instance processes an image, it will be indicated by the DetectionOccured event which we can subscribe for here, too. void Init() { _frameCapture = new FrameCapture(); _frameCapture.SetInterval(5); _webCamera = WebCamera.GetDefaultDevice(); _connector = new MediaConnector(); _originalImageProvider = new DrawingImageProvider(); _processedImageProvider = new DrawingImageProvider(); _lineDetector = ImageProcesserFactory.CreateLineDetector(); _lineDetector.DetectionOccurred += _lineDetector_DetectionOccurred; _imageProcesserHandler = new ImageProcesserHandler(); _imageProcesserHandler.AddProcesser(_lineDetector); } Our second method is the SetVideoViewers() method, that generates and initializes the objects that are responsible for displaying the video. It defines the VideoViewerWF instances, sets their properties, assigns the proper DrawingImageProvider instances and adds them to the GUI. void SetVideoViewers() { _originalView = new VideoViewerWF { BackColor = Color.Black, Location = new Point(10, 20), Size = new Size(320, 240) }; _originalView.SetImageProvider(_originalImageProvider); Controls.Add(_originalView); _processedView = new VideoViewerWF { BackColor = Color.Black, Location = new Point(350, 20), Size = new Size(320, 240) }; _processedView.SetImageProvider(_processedImageProvider); Controls.Add(_processedView); } We should not forget about the InvokeGUIThread() method. This is the method that handles the GUI thread. It executes the specified method asynchronously on the thread that the control's underlying handle was created on. void InvokeGUIThread(Action action) { BeginInvoke(action); } The next method, the InitDetectorFields() fills in the Text Boxes on the GUI with the configurations of the ILineDetector with the help of the InvokeGUIThread() helper method. void InitDetectorFields() { InvokeGuiThread(() => { chk_ShowImage.Checked = _lineDetector.ShowImage; tb_Red.Text = _lineDetector.DrawColor.R.ToString(); tb_Green.Text = _lineDetector.DrawColor.G.ToString(); tb_Blue.Text = _lineDetector.DrawColor.B.ToString(); tb_DrawThickness.Text = _lineDetector.DrawThickness.ToString(); tb_AngleResolution.Text = _lineDetector.AngleResolution.ToString(); tb_CannyThreshold.Text = _lineDetector.CannyThreshold.ToString(); tb_CannyThresholdLinking.Text = _lineDetector.CannyThresholdLinking.ToString(); tb_DistanceResolution.Text = _lineDetector.DistanceResolution.ToString(); tb_LineGap.Text = _lineDetector.LineGap.ToString(); tb_LineWidth.Text = _lineDetector.LineWidth.ToString(); tb_Threshold.Text = _lineDetector.Threshold.ToString(); }); } Moving on, we have the ConnectWebcam() method. This one is responsible for connecting the proper mediahandler instances with the help of the MediaConnector instance. One ImageProvider object receives the original image of the camera, while the other one receives the processed image. void ConnectWebcam() { _connector.Connect(_webCamera, _originalImageProvider); _connector.Connect(_webCamera, _frameCapture); _connector.Connect(_frameCapture, _imageProcesserHandler); _connector.Connect(_imageProcesserHandler, _processedImageProvider); After getting through all the initialization, the mediahandlers can start operating. Now, the Start() method will help us. void Start() { _originalView.Start(); _processedView.Start(); _frameCapture.Start(); _webCamera.Start(); } If you press the Set button that belongs to the Group Box on the GUI (we'll talk about it a little later), the following event will be called whose task is to configure the LineDetector. void btn_Set_Click(object sender, EventArgs e) { InvokeGUIThread(() => { _lineDetector.AngleResolution = Double.Parse(tb_AngleResolution.Text); _lineDetector.CannyThreshold = Double.Parse(tb_CannyThreshold.Text); _lineDetector.CannyThresholdLinking = Double.Parse(tb_CannyThresholdLinking.Text); _lineDetector.DistanceResolution = Double.Parse(tb_DistanceResolution.Text); _lineDetector.LineGap = Double.Parse(tb_LineGap.Text); _lineDetector.LineWidth = Double.Parse(tb_LineWidth.Text); _lineDetector.Threshold = Int32.Parse(tb_Threshold.Text); }); } Let's take a closer look to see what those values in this snippet are responsible for. At AngleResolution you can set the resolution in the angle area. CannyThreshold determines the value of thresholding to find initial segments of strong edges. The CannyThresholdLinking value is used to determine the number of pixels in the edges of an image. DistanceResolution defines the resolution between pixel-related units. LineGap indicates the minimum gap between lines detectable lines. LineWidth indicates the minimum width of detectable lines. For a line to be actually considered as detected, it is necessary to reach the value of Threshold. Post Process settings After the detection happened, you can configure how the output image should behave, what changes it shall undergo. You can configure these features with the help of the following settings. With the help of the ShowImage checkbox you can set if you only want to see the processed image with the detected shapes in the programme or you also want to have the original image. You can set the colour of the marking of the detected objects with DrawColor. With DrawThickness you can set the thickness of the marking of the detected objects. These settings are executed by the Set button on the highlight group box. If you click on this button, the following event will be called: void btn_HighlightSet_Click(object sender, EventArgs e) { InvokeGUIThread(() => { _lineDetector.ShowImage = chk_ShowImage.Checked; _lineDetector.DrawColor = Color.FromArgb(Int32.Parse(tb_Red.Text), Int32.Parse(tb_Green.Text), Int32.Parse(tb_Blue.Text)); _lineDetector.DrawThickness = Int32.Parse(tb_DrawThickness.Text); }); } Detection After processing each image/frame, the DetectionOccured event will pop up. void _lineDetector_DetectionOccurred(object sender, LineDetectedEventArgs e) { InvokeGUIThread(() => { lb_Detection.Items.Clear(); foreach (var info in e.Info) { lb_Detection.Items.Add(info); } }); } You can find the list of the detected lines in the arguments of this event and in that list you can query the starting and endpoint, the direction and the length of each line. Creating the GUI Of course, a nice user interface will be needed in order to manage the camera and line detection properly. I will provide you with some code snippets I used to create my GUI. As it can be seen on the picture, my GUI is built from 4 parts. The first part is where the original and the processed pictures are shown. Under this you can see the field where the list of detections is created. Two group boxes can be seen on the right, one for highlights and one for settings. Now take a closer look at the different parts of the user interface. Let's start with the two images. On the left side you can see the original image of the camera. this.label1.AutoSize = true; this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238))); this.label1.Location = new System.Drawing.Point(30, 265); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(87, 13); this.label1.TabIndex = 0; this.label1.Text = "Original image"; On the right side there is the processed image. this.label2.AutoSize = true; this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238))); this.label2.Location = new System.Drawing.Point(370, 265); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(103, 13); this.label2.TabIndex = 1; this.label2.Text = "Processed image"; The Set button under Settings was mentioned before with which you can configure the basic settings in your program. First, let's see how to create that almighty Set button. this.btn_Set.Location = new System.Drawing.Point(189, 368); this.btn_Set.Name = "btn_Set"; this.btn_Set.Size = new System.Drawing.Size(58, 23); this.btn_Set.TabIndex = 2; this.btn_Set.Text = "Set"; this.btn_Set.UseVisualStyleBackColor = true; this.btn_Set.Click += new System.EventHandler(this.btn_Set_Click); Now we have the button. But if we want to adjust any settings with it, we need some parameters that we can adjustJ Let's start with Angle Resolution. this.tb_AngleResolution.Location = new System.Drawing.Point(138, 26); this.tb_AngleResolution.Name = "tb_AngleResolution"; this.tb_AngleResolution.Size = new System.Drawing.Size(87, 20); this.tb_AngleResolution.TabIndex = 3; Now the code for the Canny Threshold comes. this.tb_CannyThreshold.Location = new System.Drawing.Point(138, 58); this.tb_CannyThreshold.Name = "tb_CannyThreshold"; this.tb_CannyThreshold.Size = new System.Drawing.Size(87, 20); this.tb_CannyThreshold.TabIndex = 4; And do not forget about Canny Threshold Linking. this.tb_CannyThresholdLinking.Location = new System.Drawing.Point(138, 90); this.tb_CannyThresholdLinking.Name = "tb_CannyThresholdLinking"; this.tb_CannyThresholdLinking.Size = new System.Drawing.Size(87, 20); this.tb_CannyThresholdLinking.TabIndex = 5; Or about Distance Resolution. this.tb_DistanceResolution.Location = new System.Drawing.Point(138, 122); this.tb_DistanceResolution.Name = "tb_DistanceResolution"; this.tb_DistanceResolution.Size = new System.Drawing.Size(87, 20); this.tb_DistanceResolution.TabIndex = 6; Almost done. Here comes the Line Gap. this.tb_LineGap.Location = new System.Drawing.Point(138, 154); this.tb_LineGap.Name = "tb_LineGap"; this.tb_LineGap.Size = new System.Drawing.Size(87, 20); this.tb_LineGap.TabIndex = 7; And the Line Widht. this.tb_LineWidth.Location = new System.Drawing.Point(138, 186); this.tb_LineWidth.Name = "tb_LineWidth"; this.tb_LineWidth.Size = new System.Drawing.Size(87, 20); this.tb_LineWidth.TabIndex = 8; And finally, the code for Threshold. this.tb_Threshold.Location = new System.Drawing.Point(138, 218); this.tb_Threshold.Name = "tb_Threshold"; this.tb_Threshold.Size = new System.Drawing.Size(87, 20); this.tb_Threshold.TabIndex = 9; These are the different settings you can adjust in your program. After we are ready creating the boxes where you can provide the values for these parameters, we can go on. As it was mentioned above, you will have a list of the detected lines. Here is how you can create the field for the list. this.lb_Detection.FormattingEnabled = true; this.lb_Detection.Location = new System.Drawing.Point(10, 322); this.lb_Detection.Name = "lb_Detection"; this.lb_Detection.Size = new System.Drawing.Size(660, 251); this.lb_Detection.TabIndex = 14; Let's go on with the other group box with of Highlights. This part also has got its Set button (in the code it has the name of HighlightSet to differentiate it from the other Set button). this.btn_HighlightSet.Location = new System.Drawing.Point(189, 129); this.btn_HighlightSet.Name = "btn_HighlightSet"; this.btn_HighlightSet.Size = new System.Drawing.Size(58, 23); this.btn_HighlightSet.TabIndex = 19; this.btn_HighlightSet.Text = "Set"; this.btn_HighlightSet.UseVisualStyleBackColor = true; this.btn_HighlightSet.Click += new System.EventHandler(this.btn_HighlightSet_Click); And two parameters to provide. this.tb_DrawThickness.Location = new System.Drawing.Point(138, 95); this.tb_DrawThickness.Name = "tb_DrawThickness"; this.tb_DrawThickness.Size = new System.Drawing.Size(87, 20); this.tb_DrawThickness.TabIndex = 17; this.tb_Blue.Location = new System.Drawing.Point(183, 59); this.tb_Blue.Name = "tb_Blue"; this.tb_Blue.Size = new System.Drawing.Size(42, 20); this.tb_Blue.TabIndex = 16; this.tb_Green.Location = new System.Drawing.Point(138, 59); this.tb_Green.Name = "tb_Green"; this.tb_Green.Size = new System.Drawing.Size(42, 20); this.tb_Green.TabIndex = 15; this.tb_Red.Location = new System.Drawing.Point(93, 59); this.tb_Red.Name = "tb_Red"; this.tb_Red.Size = new System.Drawing.Size(42, 20); this.tb_Red.TabIndex = 14; There is one checkbox here to set whether we want to see the original image or not: this.chk_ShowImage.AutoSize = true; this.chk_ShowImage.CheckAlign = System.Drawing.ContentAlignment.MiddleRight; this.chk_ShowImage.Location = new System.Drawing.Point(22, 25); this.chk_ShowImage.Name = "chk_ShowImage"; this.chk_ShowImage.Size = new System.Drawing.Size(85, 17); this.chk_ShowImage.TabIndex = 14; this.chk_ShowImage.Text = "ShowImage:"; this.chk_ShowImage.UseVisualStyleBackColor = true; At the end here you can see the Main form of the GUI. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(947, 581); this.Controls.Add(this.label12); this.Controls.Add(this.lb_Detection); this.Controls.Add(this.groupBox2); this.Controls.Add(this.groupBox1); this.Controls.Add(this.label2); this.Controls.Add(this.label1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.MaximizeBox = false; this.Name = "MainForm"; this.Text = "Line Detection"; this.Load += new System.EventHandler(this.MainForm_Load); this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); this.groupBox2.ResumeLayout(false); this.groupBox2.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); And we are done! It was fun, wasn't it? Conclusion Now line detecting is ready to be used! In this tutorial you could read some theoretic background about implementing line detecting in C# and a detailed practical description about this solution, including some code examples. The article also contains a detailed description about implementing a useful user interface for a program like this. I hope this brief tutorial was useful for you all. Good luck on developing your own solutions! References · · · · · · Hall of Fame Twitter Terms of Service Privacy Policy Contact Us Archives Tell A Friend
http://www.dotnetspark.com/kb/6531-network-video-analytics-c-sharp-how-to-achieve.aspx
CC-MAIN-2017-17
en
refinedweb
GameFromScratch.com Instead of updating all of the tutorials each time something is changed ( sadly, something I do not have the time for ), I will use this guide to track breaking changes as the occur. Libraries have been renamed from Sce.Pss to Sce.PlayStation. So instead of say: import Sce.Pss.Graphics; it is now: import Sce.Playstation.Graphics; The install path has changed from [Program Files]\Pss to [Program Files]\PSM. PssStudio is now PsmStudio. Oddly enough, for me at least, it didn’t create a start menu entry. Fortunately there is a conversion utility that will convert your code to the new naming standard. In C:\Program Files (x86)\SCE\PSM\tools ( on my 64bit Win7 install anyways ), there is a file named project_conv_098to099.bat. Simply drag your existing project folder on top of that script, or run it from a cmd prompt passing it your code directory, and your project will be updated. The full .99 release notes are available here. Here is the conversion process in action: General, Programming PSSDK, Tutorial, PlayStation Mobile
http://www.gamefromscratch.com/post/2012/07/13/PlayStation-Mobile-breaking-changes-guide.aspx
CC-MAIN-2017-17
en
refinedweb
An Essential Introduction to Machine Learning With a Step-by-Step Guide to Make Your Computer Learn using Google’s TensorFlow Machine Learning is all the rage. It’s effectiveness across industries is stunning, and it is rapidly improving. This short guide will allow you to understand the process, time, difficulty, and expected results. Finally, you’ll have the chance of making your machine learn to recognize handwriting. The goal is to cover a small part of Machine Learning in a sufficiently broad manner to provide to the non-practitioner an insight, a lens through which make decisions. What is the Machine Actually Learning? Machine Learning is very different from how we humans learn. We learn by observing, associating, repeating, abstracting, categorising, reconstructing, making mistakes, using different senses,… We can do it at will by placing our attention to what we want to learn or we can even store something that we have seen just once, per chance, for just a moment. How our brain and body does this exactly remains largely a fascinating mystery. Machine Learning (as of 2016) also uses a lot of repeating, abstracting, categorising, reconstructing, and making mistakes. However, computers don’t actually observe, they merely sense, because there isn’t yet a very effective system to attend to specific characteristics. Computers also don’t have yet a very effective way of using different senses or associating different elements. Machines need a lot of examples, a lot of time to train (1–2 weeks, depending on the task), and once the training is done, they don’t learn any more, at all. The Underlying Principle of How Machine Learning Works Machine Learning tries to find one single mathematical formula that takes the input (e.g., an image, a sound), and transforms it into a probability that it belongs to a trained category. The underlying principle is that a sufficiently complex formula can capture the common characteristics while filtering out the differences. The most effective structure that scientists have found this far is representing the formula as a network of connected elements, a so-called neural network. Each element — an artificial, simplified neuron — processes the input data from one or more sources by using simple operations such as addition and multiplication. The machine learns how these artificial neurons are connected and how they process the information. A typical network contains many many neurons — millions. The large amount of parameters is why it takes so long to train a neural network. The actual size of the network depends on the application, and although the theory is not yet conclusive, it has been found that a large network is more robust in recognize targets over a wide variety of inputs. This also shows that Machine Learning — despite the name — depends a lot on humans giving it a structure (e.g., the number of neurons in the example above), and appropriate training samples to learn. The Machine Learning Process The process consists of 3 main steps: - Architecture The human defines how the network looks and the rules for learning. - Training The machine analyses training data and adjusts the parameters, trying to find the best possible solution in the given architecture. - Usage The network is “frozen” (i.e., it doesn’t learn any more), and is fed with actual data to obtain the desired outcome. Process Step 1 — ARCHITECTURE The human defines: - Number of neurons - Number of layers - Sampling sizes - Convolution sizes - Pooling sizes - Neural response function (e.g., ReLU) - Error function (e.g., cross-entropy) - Error propagation mechanism - Number of iterations - And many more parameters… How are these characteristics decided? Part theory, part experience, part trial and error. The result of any Machine Learning system is only as good as the choice of its architecture. What is crucial about the architecture, is that it must allow for efficient training. For instance, the network must allow for an error signal to affect its individual components. Part of the reason why Machine Learning systems are becoming widely successful is that scientists such as Hinton, LeCun, and Bengio have found ways of training complex networks. Process Step 2 — TRAINING The neural network starts off with semi-random parameters, and then the computer iteratively improves them to minimize the difference — the error — between the inputs and the output. A typical procedure is the following: - Calculate the output of the neural network from a training input - Calculate the difference between the expected and the actual output - Change input, and carry out steps (1) and (2) again - Adjust the parameters of the neurons (e.g., slightly decrease the weight of a neuron if the output difference has increased) and of the network (e.g., freeze certain layers) - Start again from (1) After a number of iterations (chosen as part of the architecture), the overall performance is calculated, and if sufficient, the artificial neural network is ready to be deployed. What if the system doesn’t produce the desired outcome? Back to square 1: Architecture. There is not yet a method to tweak the parameters consequently to improve the system. What this highlights once again is that Machine Learning is a Swiss Army knife, but it’s up to the user to decide which tool to use, how, and when. Process Step 3 — USAGE Using a Machine Learning system consists in providing it with an input, and gathering the result. There is no more learning and very few parameters can be changed, if any at all. The processing speed depends on the complexity of the network, the efficiency of the code, and the hardware. Machine Learning has profited immensely from the gaming industry, which has spearheaded the development of increasingly powerful GPUs. Indeed, the Graphical Processing Units — originally used to display images on a screen — could be modified to carry out both the training and the production usage of neural networks. The underlying reason is that GPUs are capable of executing many simple operations in parallel, such as calculating the result of the interaction between individual neurons. Calculating millions of interactions at the same time instead of one after the other is a key advantage over other systems. Now Try It Yourself — A step-by-step guide to running Google TensorFlow Machine Learning on your computer Here is a simple example that you can try to run to get a feeling of what it means to architect, train, and use a Deep Learning network (as of 2016), right on your computer. The application we will train is recognizing hand-written digits. This was one of the original problems of AI research, and it had concrete industrial applications in the early days of digitalisation (read more about digital strategy here). For instance for recognizing amounts on banking cheques or addresses on mail envelopes. The Machine Learning framework we will use is Google’s Tensorflow. The steps are intended for a Mac (tested on OSX El Capitan 10.11.4 with Python 2.7). Instructions for Linux/Ubuntu are available here. Ready? Let’s go! Installation Launch terminal from spotlight (press ⌘–space on the keyboard and then write terminal, press enter). When the terminal window has opened, copy and paste the following commands (you’ll be asked your password): sudo easy_install pip sudo pip install --upgrade virtualenv virtualenv --system-site-packages ~/tensorflow source ~/tensorflow/bin/activate pip install --upgrade pip install jupyter cd tensorflow jupyter notebook This will open a tab in the browser (if not, troubleshoot here), from which you can create an interactive “notebook” by clicking on the spot indicated by the red arrow: The Python interactive notebook will open and looks like this: Now you’re ready to make your computer learn by itself. Setup of the Machine Learning environment for recognising digits First, add TensorFlow and other necessary components by copy-and-paste of the following in your Python notebook: import numpy as np import matplotlib as mp %matplotlib inline import matplotlib.pyplot as plt import tensorflow as tf sess = tf.Session() def getActivations(layer,stimuli): units = layer.eval(session=sess,feed_dict={x:np.reshape(stimuli,[1,784],order='F'),keep_prob:1.0}) plotNNFilter(units) def plotNNFilter(units): filters = units.shape[3] plt.figure(1, figsize=(20,20)) for i in xrange(0,filters): plt.subplot(7,6,i+1) plt.title('Filter ' + str(i)) plt.imshow(units[0,:,:,i], interpolation="nearest", cmap="gray") Then import the training and test data: from tensorflow.examples.tutorials.mnist import input_data mnist = input_data.read_data_sets("MNIST_data/", one_hot=True) We can take a look what the images look like: imageWidth = imageHeight = 28 testImageNumber = 1 # Change here to see another imageToUse = mnist.test.images[testImageNumber] plt.imshow(np.reshape(imageToUse,[imageWidth,imageHeight]), interpolation="nearest", cmap="gray_r") Machine Learning Process Step 1 — ARCHITECTURE Now is the time to start setting the basis of the machine learning by defining fundamental computations. What is interesting to note is that the 2D structure of the images is flattened into a 1D vector, because in this learning framework it doesn’t matter. inputVectorSize = imageWidth*imageHeight numberOfPossibleDigits = 10 # handwritten digits between 0 and 9 outputVectorSize = numberOfPossibleDigits x = tf.placeholder(tf.float32, [None, inputVectorSize],name="x-in") y_ = tf.placeholder(tf.float32, [None, outputVectorSize],name="y-in")') # overlapping strides (2: non-overlapping) def max_pool_2x2(x): return tf.nn.max_pool(x, ksize=[1, 2, 2, 1],strides=[1, 2, 2, 1], padding='SAME') Next, we set the layers to be trained, and how to calculate the final probability. As you can see, it’s a convolutional neural network (a.k.a., ConvNet) with a rectifying neuron (ReLU). In this case, the output is calculated using a normalised exponential, the softmax function. outputFeatures1 = 4 outputFeatures2 = 4 outputFeatures3 = 16 # Input x_image = tf.reshape(x, [-1,imageWidth,imageHeight,1]) # Individual neuron calculation: y = conv(x,weight) + bias # Layer 1: convolution W_conv1 = weight_variable([5, 5, 1, outputFeatures1]) b_conv1 = bias_variable([outputFeatures1]) h_conv1 = tf.nn.relu(conv2d(x_image, W_conv1) + b_conv1) h_pool1 = max_pool_2x2(h_conv1) # Layer 2: convolution W_conv2 = weight_variable([5, 5, outputFeatures1, outputFeatures2]) b_conv2 = bias_variable([outputFeatures2]) h_conv2 = tf.nn.relu(conv2d(h_pool1, W_conv2) + b_conv2) h_pool2 = max_pool_2x2(h_conv2) # Layer 3: convolution W_conv3 = weight_variable([5, 5, outputFeatures2, outputFeatures3]) b_conv3 = bias_variable([outputFeatures3]) h_conv3 = tf.nn.relu(conv2d(h_pool2, W_conv3) + b_conv3) # Layer 4: Densely connected layer W_fc1 = weight_variable([7 * 7 * outputFeatures3, 10]) b_fc1 = bias_variable([10]) h_conv3_flat = tf.reshape(h_conv3, [-1, 7*7*outputFeatures3]) keep_prob = tf.placeholder("float") h_conv3_drop = tf.nn.dropout(h_conv3_flat, keep_prob) # Output y_conv = tf.nn.softmax(tf.matmul(h_conv3_drop, W_fc1) + b_fc1) Then we define the method to adjust the parameters and what kind of difference between expected and actual output we want to use (in this case, cross-entropy). cross_entropy = -tf.reduce_sum(y_*tf.log(y_conv)) correct_prediction = tf.equal(tf.argmax(y_conv,1), tf.argmax(y_,1)) accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float")) train_step = tf.train.GradientDescentOptimizer(0.0001).minimize(cross_entropy) What TensorFlow actually does here, behind the scenes, is it adds new operations to your graph which implement backpropagation and gradient descent. Machine Learning Process Step 2 — TRAINING We’re now ready to let the computer learn to classify the image inputs into numbers from 0 to 9. sess.run(tf.initialize_all_variables()) iterations = 0 trainingImageBatchSize = 50 while iterations <= 1000: batch = mnist.train.next_batch(trainingImageBatchSize) train_step.run(session=sess, feed_dict={x:batch[0],y_:batch[1], keep_prob:0.5}) if iterations%100 == 0: trainAccuracy = accuracy.eval(session=sess, feed_dict={x:batch[0],y_:batch[1], keep_prob:1.0}) print("step %d, training accuracy %g"%(iterations, trainAccuracy)) iterations += 1 You’ll see that it takes quite some time to train (a few minutes), despite the small images and network. The more iterations, the better the accuracy, possibly (because it partially depends on the semi-random initialisation values) reaching a peak before 1000 iterations. While you wait for the results, ponder about the fact that you don’t see any of the values of the neurons, and that ultimately this doesn’t matter. When the machine is done learning, we can take a look at the different layers to see what they are calculating: testImageNumber = 1 # Change here to use another imageToUse = mnist.test.images[testImageNumber] getActivations(h_conv1,imageToUse) You can also try these: getActivations(h_conv2,imageToUse) getActivations(h_conv3,imageToUse) Machine Learning Process Step 3 — USAGE Finally, let’s see how well the network your computer learned is able to recognize all the handwritten digits in the dataset. testAccuracy = accuracy.eval(session=sess, feed_dict={x:mnist.test.images,y_:mnist.test.labels, keep_prob:1.0}) print("test accuracy %g"%(testAccuracy)) Congratulations! You taught your computer to recognize handwritten digits. If you wish, you can go further and customise the system to use your own handwriting. Cleanup and finish When you’re done, go back to the Terminal, hit twice Ctrl-C to exit Jupiter, then type: deactivate Then ⌘–q to quit the terminal. Start again To try out something else next time, the procedure is easier. Just copy and paste the following: source ~/tensorflow/bin/activate cd tensorflow jupyter notebook Thanks for reading! If you enjoyed this, you might like: Beyond Machine Learning
https://medium.com/the-future-beyond/an-essential-introduction-to-machine-learning-ac4b42c90252?source=collection_home---6------2----------
CC-MAIN-2017-17
en
refinedweb
0 First off this is my second day writing in Python. My manager switched us off SAS and moved us to Python and R which I actually am starting to like the flexibility. I have a few datasets that I work with on a regular basis that require a lot of cleaning before I can work with them and I would rather just call a class instead of copying and pasting code every time. The class below is the most basic one of them all I just read in the extract and pull out all records containing a certain DeviceType. Python Version: 3.3.2 class ReturnDataFrame: import pandas as pd from pandas import DataFrame def FileName(self,FileName): self.name=name EFile = pd.read_csv(FileName,delimiter = '~',names=['DateTime','DeviceType','Identifier','ServiceID','Communication Module Serial Number'], header=None) EFile = EFile[(EFile.DeviceType == 'X023G2Z')] def returnFile(self): return EFile Below is where I load in my class and instantiate it. This is the error I am recieving when I run X.FileName('F:/Python/WinterOnly.csv') NameError: global name 'pandas' is not defined import ReturnDataFrame from ReturnDataFrame import * X = returnDataFrame() X.FileName('F:/Python/Week05052013.csv') WeeklyFile = DataFrame() WeeklyFile = WeeklyFile.append(X.returnFile())
https://www.daniweb.com/programming/software-development/threads/481193/python-custom-class-return-dataframe
CC-MAIN-2017-17
en
refinedweb
It's not the same without you Join the community to find out what other Atlassian users are discussing, debating and creating. We used to use sub-tasks but have decided against using them anymore. I moved about 5,000 sub-tasks to one sub-task named simply "sub-task". The reason why is because you cannot bulk change a sub-task to be an issue. So I am stuck with one "sub-task" within my issue type scheme. My question is this: is there a way to allow sub-tasks (I don't want to manually move them to be issues) but prevent users from creating new ones? I have about 300 users and they are very difficult to train. Thanks! Hey Suzanne, You can remove any subtask issue types from your issue type configuration scheme. I should say I am looking for something within the workflow that would prevent users from creating sub-taaks. There are some great suggestions from the user community around moving those sub tasks into issues: If you can get this working then you can just disable sub-tasks natively. In the sub-task workflow in the Create Issue transition put a custom script validator (using Script Runner plugin): import com.opensymphony.workflow.InvalidInputException invalidInputException = new InvalidInputException("Subtasks cannot be created manually.") Problem is that it will complain after user pressing 'Create' button, not.
https://community.atlassian.com/t5/Jira-questions/I-need-to-prevent-user-from-creating-sub-task/qaq-p/429398
CC-MAIN-2018-34
en
refinedweb
maxlength on input box can be overriden by autocomplete Bug Description No, not a dupe. It's asking (without providing any reason other than Fx2-compat) that bug 345267 be reverted. Assuming the comments there are correct, and the current behavior is the same as every other browser except Fx2, it's a wontfix. Indeed. It's just strange behaviour for javascript to not respect html when the DOM is modified. Are there any official specifications on how this should actually work - rather than saying "other browsers do it like that"? If this mentality is used, then we'd have to duplicate all IE quirks as it's how the other half of the world is doing it. > Are there any official specifications on how this should actually > work - rather than saying "other browsers do it like that"? Not yet. HTML5 is specifying this behavior (and Firefox 3 is following the draft HTML5 spec). > then we'd have to duplicate all IE quirks We basically do duplicate all the IE quirks that don't violate existing specifications and are needed to make significant numbers of existing web sites work... So do all the other browsers. User-Agent: Mozilla/5.0 (X11; U; Linux i686; de; rv:1.9) Gecko/2008052912 Firefox/3.0 Build Identifier: Mozilla/5.0 (X11; U; Linux i686; de; rv:1.9) Gecko/2008052912 Firefox/3.0 It is possible to bypass the maximum length limitation for text input fields with autocomplete. Autocomplete offers any text, even if it's longer than what is allowed and the field is consequently populated after selecting the too long text. Reproducible: Always Steps to Reproduce: 1. Create a new html file with following content in the body: <form id="testForm" method="GET"> <input id="testInput" type="text" /> <input type="submit" /> </form> 2. Open the file in the browser and type "0123456789" in the input field and hit submit. 3. Change the file and add 'maxlength="5"' to the input field. 4. Go back to the browser and refresh. Actual Results: Now it is possible to select "0123456789" as value for the input field. Expected Results: Autocomplete should not render suggestions that are longer than _maxlength_ or when such a value is selected, it should be trimmed to a total length of _maxlength_. I believe this is quite a critical issue, as most developers rely on the size of the strings that are provided by the limited input fields. That is - many applications probably would behave in an unexpected manner, when provided with longer texts. Hunh - no doubt about it, confirmed via data url. I don't think this needs to be hidden, there are plenty of ways to get around maxlength parameters and they aren't something web developers should ever rely on as a safety mechanism; they only keep honest people honest, basically. The exploit possibilities seem somewhat remote, and only make slightly more visible an existing vulnerability in the target website (i.e. relying on maxlength). Nevertheless, we should fix it, and I'm surprised it hasn't come up earlier, but I'm not having any luck finding an existing bug. Bug 204506 is similar, but clearly didn't fix this problem. Bug 443363 is a dup of this bug. This is a regression from Firefox 2.0.0.x which correctly truncates the autocomplete data at the maxlength. > I believe this is quite a critical issue, as most developers rely on > the size of the strings that are provided by the limited input fields. That would be unwise. Hackers are not constrained by the maxlength limit and would love to find that exceeding it throws your server for a loop. Mike: did anyone re-work autocomplete for FF3? I assume the awesomebar is its own thing and not built on autocomplete but that could be wrong. The autocomplete code doesn't do anything special related to maxlength, so this was probably caused by bug 345267. That change made it possible to enter more than maxlength characters into a text field programmatically, to match other browsers. The autocomplete code sets the value via the same code path as page scripts, so it was affected too. Boris, can you look at this? This needs a fix on the autocomplete side: it needs to be checking the maxlength. It didn't need to before, as Gavin said, because it was relying on a core bug. Then we fixed the core bug. Created an attachment (id=335666) WIP I put this together a while ago but couldn't get the test to work. The entries added by the test are apparently not added correctly because they don't appear as options, and even if they did I'm not sure that the code I use to select the autocomplete entry will work. Created an attachment (id=389264) v.1 only show entries that fit (applies to patch v.3 on bug 446247) Instead of truncating, only show form history entries that will fit in the field. (From update of attachment 389264) >+ if (aField && aField.maxLength > -1) >+ result. Use an inline anonymous function here... foo = foo.filter(function (e) { return (element. (A refinement of having a local function in the if-block to do this, which would be my choice instead of having a tiny utility function stuck, at distance, onto the component's object). Created an attachment (id=390343) v.2 inline function & update unit tests (From update of attachment 390343) sr? for API change, this was added in 3.6 so there's no compat issues. Created an attachment (id=390676) v.3 fix bitrot (From update of attachment 390676) sr=mconnor verified with: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2b1pre) Gecko/20090925 Namoroka/3.6b1pre Thanks for reporting this bug and any supporting documentation. Since this bug has enough information provided for a developer to begin work, I'm going to mark it as Triaged and let them handle it from here. I am moving this to Firefox 3.5 as 3.0 will be EOL next month and this is a low priority issue. Thanks for taking the time to make Ubuntu better! Please report any other issues you may find. I think I was too hasty here. My test case was for javascript overriding maxlength, but I found https:/ Nevermind, I found the upstream bug which seems to be what you were describing. Take a look and if it's not, let us know. This is scheduled to be fixed in Firefox 3.6 Please report any other bugs you may find. " - maxlength not stop long values + maxlength on input box can be overriden by autocomplete " ok, i tryed say just this ! not problem with javascript only with autocomplete , javascript ist a choice of programmer, but auto complete its a feature of Firefox , i think that can not overriden forms restrictions , or will allow wrong datas to be input , auto-complete need respect maxlength value sorry for my bad english i am brasilian and are very hard to me explain the problem , firefox will be the source package... Created an attachment (id=323854) maxlength test
https://bugs.launchpad.net/ubuntu/+source/firefox-3.5/+bug/486284
CC-MAIN-2018-34
en
refinedweb
RepositoryGenerator 1.0.1 Repository Generator Repository Generator will generate an entire repository structure for you. All you need to supply a namespace which contains all your Entity Framework models and the RepositoryGenerator.tt will generate repositories for all your models, it will generate a generic repository providing you with basic functionality out of the box. A Unit of Work class will also be generated. Install-Package RepositoryGenerator -Version 1.0.1 dotnet add package RepositoryGenerator --version 1.0.1 paket add RepositoryGenerator --version 1.0.1 The NuGet Team does not provide support for this client. Please contact its maintainers for support. Dependencies - EntityFramework (>= 6.0.0)
https://www.nuget.org/packages/RepositoryGenerator/
CC-MAIN-2018-34
en
refinedweb
If you have used languages, such as Java or Python before, you might be familiar with the idea. Decorators are syntactic sugar that allow us to wrap and annotate classes and functions. In their current proposal (stage 1) only class and method level wrapping is supported. Functions may become supported later on. In Babel 6 you can enable this behavior through babel-plugin-syntax-decorators and babel-plugin-transform-decorators-legacy plugins. The former provides syntax level support whereas the latter gives the type of behavior we are going to discuss here. The greatest benefit of decorators is that they allow us to wrap behavior into simple, reusable chunks while cutting down the amount of noise. It is definitely possible to code without them. They just make certain tasks neater, as we saw with drag and drop related annotations. Sometimes, it is useful to know how methods are being called. You could of course attach console.log there but it's more fun to implement @log. That's a more controllable way to deal with it. Consider the example below: class Math { @log add(a, b) { return a + b; } } function log(target, name, descriptor) { var oldValue = descriptor.value; descriptor.value = function() { console.log(`Calling "${name}" with`, arguments); return oldValue.apply(null, arguments); }; return descriptor; } const math = new Math(); // passed parameters should get logged now math.add(2, 4); The idea is that our log decorator wraps the original function, triggers a console.log, and finally, calls it again while passing the original arguments to it. Especially if you haven't seen arguments or apply before, it might seem a little strange. apply can be thought as an another way to invoke a function while passing its context ( this) and parameters as an array. arguments receives function parameters implicitly so it's ideal for this case. This logger could be pushed to a separate module. After that, we could use it across our application whenever we want to log some methods. Once implemented decorators become powerful building blocks. The decorator receives three parameters: targetmaps to the instance of the class. namecontains the name of the method being decorated. descriptoris the most interesting piece as it allows us to annotate the method and manipulate its behavior. It could look like this: const descriptor = { value: () => {...}, enumerable: false, configurable: true, writable: true }; As you saw above, value makes it possible to shape the behavior. The rest allows you to modify behavior on method level. For instance, a @readonly decorator could limit access. @memoize is another interesting example as that allows you to implement easy caching for methods. @connect# @connect will wrap our component in another component. That, in turn, will deal with the connection logic ( listen/unlisten/setState). It will maintain the store state internally and then pass it to the child component that we are wrapping. During this process, it will pass the state through props. The implementation below illustrates the idea: app/decorators/connect.js import React from 'react'; const connect = (Component, store) => { return class Connect extends React.Component { constructor(props) { super(props); this.storeChanged = this.storeChanged.bind(this); this.state = store.getState(); store.listen(this.storeChanged); } componentWillUnmount() { store.unlisten(this.storeChanged); } storeChanged() { this.setState(store.getState()); } render() { return <Component {...this.props} {...this.state} />; } }; }; export default (store) => { return (target) => connect(target, store); }; Can you see the wrapping idea? Our decorator tracks store state. After that, it passes the state to the component contained through props. ...is known as a spread operator. It expands the given object to separate key-value pairs, or props, as in this case. You can connect the decorator with App like this: app/components/App.jsx ... import connect from '../decorators/connect'; ... @connect(NoteStore) export default class App extends React.Component { render() { const notes = this.props.notes; ... } ... } Pushing the logic to a decorator allows us to keep our components simple. If we wanted to add more stores to the system and connect them to components, it would be trivial now. Even better, we could connect multiple stores to a single component easily. We can build new decorators for various functionalities, such as undo, in this manner. They allow us to keep our components tidy and push common logic elsewhere out of sight. Well designed decorators can be used across projects. @connectToStores# Alt provides a similar decorator known as @connectToStores. It relies on static methods. Rather than normal methods that are bound to a specific instance, these are bound on class level. This means you can call them through the class itself (i.e., App.getStores()). The example below shows how we might integrate @connectToStores into our application. ... import connectToStores from 'alt-utils/lib/connectToStores'; @connectToStores export default class App extends React.Component { static getStores(props) { return [NoteStore]; }; static getPropsFromStores(props) { return NoteStore.getState(); }; ... } This more verbose approach is roughly equivalent to our implementation. It actually does more as it allows you to connect to multiple stores at once. It also provides more control over the way you can shape store state to props. Even though still a little experimental, decorators provide nice means to push logic where it belongs. Better yet, they provide us a degree of reusability while keeping our components neat and tidy. This book is available through Leanpub. By purchasing the book you support the development of further content.
https://survivejs.com/react/appendices/understanding-decorators/index.html
CC-MAIN-2018-34
en
refinedweb
Karma I have used this script in one of my missions. Since the 1.12 update on the stable branch I now find the bunkers are floating in mid air about 3-4m off the ground. I don't know what has changed in the game to cause this. The script was working perfectly up until then. Same problem with the bunkers floating :( if you could provide a work around, I'd love to use this. Hi Karma, I just found your script ( Vers 1.4) which is brilliant, but I have the same problem as the guys above. The bargate is in correct position but the bunkers spawn about 2 mtrs in the air and the guys manning them then drop to the ground whilst the bunkers stay floating. Did you have any joy sorting this. I do have a number of mods running ( TPW,ARMA helis etc) I know that this is an old script and no one has commented on it in a while, but in order to spawn the bunkers on the ground, instead of a couple of meters in the air, you have to edit the files: "karma_roadblocksites.sqf", "karma_roadblocksites1.sqf", etc. In "karma_roadblocksites.sqf", line 35 reads: _bunker1 = createVehicle ["Land_BagBunker_Small_F", _bargate modelToWorld [6.5,-2,-2], [], 0, "NONE"]; It should read: _bunker1 = createVehicle ["Land_BagBunker_Small_F", _bargate modelToWorld [6.5,-2,-4], [], 0, "NONE"]; Note the change to the Z coordinate that was made, a similar change must be made to line 37 in the same file and subsequently to the other bunker spawn lines in the other 3 karma_roadblocksites.sqf files. I hope that helps anyone attempting to install and use this script. Feel free to message me if you are still unsure how best to fix this script. Total comments : 4, displayed on page: 4 \MyDocuments\Arma 3-Other Profiles\YourProfileName\missions\YourMissionName karma_roadblock_list = [["roadblock_1",0,"NATO",1,0,1,0,10],["roadblock_2",0,"AAF",1,1,1,0,10]]; #include "karma_roadblock\karma_roadblock_start.sqf" karma_roadblock_list = [["your_marker_name_here",direction the roadblock would face (0-360),"side of units you want manning the gate",bargate destruction option (1 or 0),site type option (0,1,2,3),auto road direction (0,1),auto direction flip (0,1),roadscan distance (10)]]; karma_roadblock_list = [["roadblock_1",0,"CUSTOM",1,0,1,0,10,WEST,["B_Soldier_F", "B_soldier_AR_F", "B_soldier_LAT_F", "B_Soldier_GL_F"]], ["roadblock_2",0,"CUSTOM",1,1,1,0,10,WEST,["B_Soldier_F", "B_soldier_AR_F", "B_soldier_LAT_F", "B_Soldier_GL_F"]], ["roadblock_3",0,"CUSTOM",1,2,1,0,10,WEST,["B_Soldier_F", "B_soldier_AR_F", "B_soldier_LAT_F", "B_Soldier_GL_F"]], ["roadblock_4",0,"CUSTOM",1,3,1,0,10,WEST,["B_Soldier_F", "B_soldier_AR_F", "B_soldier_LAT_F", "B_Soldier_GL_F"]]]; karma_roadblock_debug = 1; karma_roadblock_distance = 15; karma_roadblock_check_sleep =!
http://www.armaholic.com/page.php?id=23003
CC-MAIN-2018-34
en
refinedweb
Code Inspection and Quick-Fixes in Visual Basic .NET Almost all JetBrains Rider JetBrains Rider's static code analysis can detect more than 150 different errors and problems in VB.NET code. The analysis is performed by applying code inspections to the current document or in any specified scope. To look through the list of available inspections for VB.NET, open the VB.NET node.page of JetBrains Rider settings (Ctrl+Alt+S), and then expand the Solution-Wide Analysis JetBrains Rider not only analyzes errors in the current file, but also inspects the whole solution taking the dependencies between files into account. It shows the results of analysis in the Errors in Solution window. For more information, see Solution-Wide Analysis. Inspect This Inspect This is a shortcut to several powerful analysis features, JetBrains Rider suggests to import the corresponding namespace and provides the necessary quick-fix. Add 'Async' modifier Asynchronous operations have some advantages over synchronous programming, so ReSharper keeps pace with the times and thoroughly supports the language features for asynchronous programming. GetQuotesAsync function contains the await operator, but the function isn't defined as asynchronous. JetBrains Rider detects such a mismatch and prompts you to improve the code using the Add 'Async' modifier quick-fix. After applying the quick-fix, the missing modifier is added to the function declaration. Change type If the type of a method's argument doesn't match the type of the corresponding method parameter, JetBrains Rider suggests changing the type of the argument and provides the necessary quick-fix. Initialize auto-property from constructor parameter If you have a constructor parameter and you want to initialize an existing auto-property with the parameter's value, use this quick-fix. Create method from usage If there is a call of a method that does not exist yet, JetBrains Rider provides the necessary quick-fix to create such a method.
https://www.jetbrains.com/help/rider/Code_Analysis_in_VB_NET.html
CC-MAIN-2018-34
en
refinedweb
Log message: p5-IPC-Run: update to 20180523.0. 20180523.0 Wed May 23 2018 - #99 - Fix using fd in child process when it happens to be the same number in the child as it was in the parent. Log message: Update to 0.99 Upstream changes:] Log message: Recursive revbump from lang/perl5 5.26.0 Log message: Updated p5-IPC-Run to 0.96. 0.96 Fri May 12 2017 - Update bug tracker to Log message: Updated devel/p5-IPC-Run to 0.95 -------------------------------- + an additional unit test - Catching previously non-detected malformed time strings - Let Timer accept all allowable perl numbers - allow the OS to choose the ephemeral port to use - Don't use version.pm to parse the perl version in Makefile.PL - perltidy - Do not import POSIX into local namespace (it's a memory hog).
http://pkgsrc.se/devel/p5-IPC-Run
CC-MAIN-2018-34
en
refinedweb
GREPPER SEARCH SNIPPETS USAGE DOCS INSTALL GREPPER All Languages >> Javascript >> javascript array stackoverflow “javascript array stackoverflow” Code Answer javascript array stackoverflow javascript by Crazy Crane on May 21 2020 Donate 1 var myArray = []; var id = 12; var value = 44; myArray[id]=value; Source: stackoverflow.com Add a Grepper Answer Javascript answers related to “javascript array stackoverflow” for loop stack overflow js input in javascript stackoverflow javascript append to array stack overflow javascript closure stack overflow javascript currying stack overflow javascript hello world stack overflow javascript show stack trace js filter issue stackoverflow js push to array site:stackoverflow.com map an array stack overflow range in javascript stackoverflow replace array element javascript stack overflow stack in javascript stack overflow reverese array js stackoverflow narrate text js stackoverflow: using es6 spread operator var in javascript stackoverflow Javascript queries related to “javascript array stackoverflow” stackoverflow javascript how to make an array get array of javascript stackoverflow type array in javascript stack overflow loop array in javascript stackoverflow javascritp array stack overflow array in javascript stack overflow array javascript stack overflow javascript array stack overflow javascript create object array stack overflow » import reactdom dangerouslySetInnerHTML did not match error in React useHistory is not exported form react-router-dom npm react router dom ReactDOM is not defined add bootstrap to react check react version ts ignore in jsx set port in react app get react version react start new app update react version create react app create react project redux thunk npm on enter key press react react native class component how to find out which version of React react get current route Can't resolve 'react-router-dom' create react app and tailwind command not found:create-react-app how to add comment in react js react-dom-router react js 'touch' is not recognized as an internal or external command, npx create-react-app 'Link' is not defined react/jsx-no-undef update create react app passing data in react router history,push create react app in existing folder external site links in react Link jsx in emmet use effect like component did mount yarn create react app property 'name' does not exist on type 'eventtarget' react 'useState' is not defined no-undef enzyme change input value redirect onclick react react props.children proptype sleep in react usehistory example command to create react app react create app setup react js on ubuntu how to check reactjs version in command prompt enzyme-adapter-react-17 usehistory, uselocation default props react make page refresh on top in react js react router dom push npm create react app react select with custom option useeffect umnount A template was not provided. This is likely because you're using an outdated version of create-react-app. react conditional classname how to refresh the page using react react generate component command conditional jsx property comment in react how to stop react app in terminal reactive localstorage in react react router external link react chrome get language react data attributes event 'React' must be in scope when using JSX react/react-in-jsx-scope reactjs .htaccess import react-router-dom how to authenticate token in react using axios uuid react import axios react import react dom react localstorage useEffect with axios react redirect in react starting with react router settimeout in react create react app in current folder how to create react app react map setinterval react React setup for handling UI. reactjs compile subdomine js clean nested undefined props import react component importing react react cdn enzyme check state REACt helmet og tags DONT WORK react render html variable is find one and update returning updated state? when i go srource in react app in chrome i see my files private route in react js Programmatically navigate using react router import bootstrap react npx create react app Must use import to load ES Module error react state management react prevent back react useeffect async react router dom react router url params diffrence b/w render and reload react redux wait for props emmet react self closing tags react admin newrecords.foreach is not a function how to deploy react app firebase react router 404 redirect react event stop propagation cra redux redirect react router latest react version npm react js component parameters react setupproxy how to get url in react access nested state value in hookstate react how to create range jest regex jsx tsx js ts reactjs app change port google sign up react npm give multiple classes in modular css react eslint disable react react set port react redux npm dangerouslySetInnerHTML react how to manipulate children passing multiple props to child component in react running scripts is disabled on this system react js react routing and force https react usestate pass variable to setstate callback map function in react angular lifecycle hooks redux multiple instances of same component react router change route from function npm react chart js 2 axios js and react react disable eslint errors react redirect to url how to use componentdidmount in functional component hook access loopback create react app scaffolding react router history push parameter router react laravel react how to update version of dependencies reactjs react js router parameters splice state react react callback set staet update object in react hooks add sass to react how to get year in react install react js react detect enter key react beforeunload get url react npx create-react-app error Module not found: Can't resolve 'react-dom' create-react-app' is not recognized as an internal setting className using useEffect could not find a declaration file for module in react project react timeout function create react app not creating template react router base url select the items from selectors in .map reactjs import react router jsx adding parameters to url react router componentdidmount hooks form in react link to react create react app with pwa next router push state install proptypes react how to pass props in react test cases react src images from public folder how to create react app in vs code react native routes lootie file in react append a query string to the url react how to comment out code in react js react event target square brackets react router Link does work react project ideas SFC in react programmatically redirect react router flexbox in react js npm start react There might be a problem with the project dependency tree. It is likely not a bug in Create React App, but something you need to fix locally. how to see if a web site is useing react import state react switch in react react router how to do a classname variable and string react use propTypes in react function how to create a new react app react native class component constructor react multiple event handlers] in react js how to access history in component event.persist() useeffect with cleanup react fragment set dynamic route in link react js Updating an object with setState in React react-router-dom redirect on click useRef route pass props to component usematch react router react eslint prettier redux get state without store pass setstate to child what is payload in redux Create React App command how to import dotenv in react react router catch all 404 useref react react js build production react useLocation() react supported events react prevstate img src in react js react check if window exists countdown in react js .env not working on react how to make react router Link active use query params react react check if array contains value react router go rprevious page import react how to add links in react js class in react i18n react meta description private routes in react react import css react js download file ternary operator react react state hooks creating react app using npx comment jsx code select in react with nchange Cannot use JSX unless the '--jsx' flag is provided. console.log in jsx inline style react reactjs install Link react router component unmount useeffect React site warning: The href attribute requires a valid address. Provide a valid, navigable address as the href value jsx-a11y/anchor-is-valid how to create react app using yarn this.setstate is not a function in react native state with react functions How to send form data from react to express how to add array data on state react beforeeach jest export default react react object you should not use switch outside a router react how to make back button react how to scroll to an element javascript react react forwardref if back react react js onclick call two functions open in a new tab react import a script to my react componetn React Hook "React.useState" is called in function "placeItem" which is neither a React function component or a custom React Hook function react-hooks/rules-of-hooks useeffect async await jsx repeat react js set default route instalar bootstrap en react useeffect get current url react router react router last page react proptypes render react in blaze React best way of forcing component to update line break in react react bind function to component react router dom npm z index react how to create a react app from scratch require("history").createBrowserHistory` instead of `require("history/createBrowserHistory")` react chart js 2 new create react app react jsx style with calc create react component class multiline comment in react link in next js is refresh page starting with react router dom prevent default react update state in react react pass prop to parent react get route params react enzyme useparams react hooks react keydown event listener lazy react use history in react router cdn react how to use style in react js react.js installation how to update array in react state input onchange react type file replace componentwillmount with hooks react routes componentDidUpdate get query params react react use effect retour a la ligne <p> react visual studio code create react component shortcut why to use event.persist scss in react app create-react-app use npm update react app react google ap suspense react javascript style inline react history react router React microphone function inside a class component react prevstate in usestate react-data-table-component how to use react memo hooks what is super(props) in react import library react js react warning can't perform a react state update on an unmounted component useeffect react add condition inside a className in reactjs add firebase in react reactstrap in react js react get input value on button click functional component how to routing in react js render object id in an array reactjs from database definition destructuring react maintain query params react-router react chartjs 2 'react-scripts' n’est pas reconnu en tant que commande interne ou externe, un programme exécutable ou un fichier de commandes. this.props.history.location.push router nextjs react memo react how to pass the input target value react hook usestate conditional classname prop react react text input onchange useeffect only on mount react hooks componentdidmount react component name convention bootstrap import in react enzyme react react enzyme simulate change react insert script tag how to call a function in react with arguments onclick react router dom current path hook how to empty form after submit react router in react-router-dom get data from url using react react hooks form cant find variable react react making post request functional component how to add to existing array react this setstate previous state react how to create component in reactjs how to create a component in react native React Hook "useState" is called in function "app" which is neither a React function component or a custom React Hook function react-hooks/rules-of-hooks redux reducer react promises react button onclick react hooks call child fuynction lifecycle methods react redux dispatch no connect react chrome extension usestate() react react lifecycle example onchange debounce react react proptypes example redux append to an array react pass parameters to other page react router dynamic routes minified react error #200 functional component react react conditional class setstate in react storing data firebase react create functional component react usestate hook if else render react communication child to parent react js <Link> react import react list react map example leaflets react useref in useeffect filter array react axios react react filter component vs container react react.js download react component react state array push react-redux provider constructor react i18n react get current language react cheat sheet react cdn links react href apply back button to a react component how to use react router react bootstrap react how to export component pass data from child component to parent component react native routes react react button example jsx if block include gif in react decet wheter react app in development or production npm react redux logger react map gll code react checkbox onChange link button react react custom hooks lifecycle method react handle onchange react form validation react how to render in react jsx classname multiple react render for loop how to write statefull class in react event listener for functional component how to set value in array react hook usestate react latest version react 17 how to use if else inside jsx in react export default function react React get method state react spotify player react react functional components defining functions in react functional component react with state react search bar fullcalendar react what hostings can run react js onclick react how to check value of checkbox in react useref in functional component react app react useeffect not on first render react 17 hot reload not working react js documentation props in react react hooks delete item from array create-react-app setstate react js react route react js installation dynamic import in reactjs install react to current folder how to make a github api using react professional react projects map in react what is redux npm stop react app prev props react hook form submit outside form reactjs context redirect to in react js async await class component react react clone element react toggle state update state in useState hook react pass props to children react useEffect react must be in scope when using jsx propTypes react function being called every minute redux thunk uselocation hook react router dom useparams react export clean up useeffect pass element from child to parent react how to update react app how to import js via script in react using redux with hooks use styles in react change state in react react arrow funvtion react router switch callback in react redux import connect how to import react dom and react react router link with params react js filter array of on search how to redirect to a website in react docker react react.createElement state and props render props reactjs and webpack tutorial export default class react react dom what is react counter with react hooks how to import lodash in react redux-form field type file react create array dynamic forms in react react forms react-router-dom reactnode prop-types lifecycles if reactjs react hooks redux react add inline styles in react onpress setstate react native conditional props react react with pure components onclick inline function react react search when stop typing comentário jsx hooks in react what is componentdidmount in react useHistory react-router-dom react helmet react routing react suspense chunck import React, { memo } from 'react'; react Spread Attributes conditionally ng-class equivalent in react react-router redirect push values to state array class react Attempted import error: 'applyMiddleWare' is not exported from 'redux'. export multiple functions react ternary react how to use useeffect how to get css property of div after rendering in react js javascript render jsx element x many times implementation of redux in functional component usehistory react router dom props.history is undefined Set Custom User Agent react apache react deploy "conf" react environment variables selector for redux prevstate in react react native components enzynme not support react 17 make a if in jsx plyr for react js react router refresh page todo using react js how to get a value into a react component html to jsx async useEffect How do I conditionally add attributes to React components? how to work react router another component react router remove location state on refresh get location from brwoser react handleClick react pass props in react create app react js react if statement how to redirect react router from the app components search bar in react js example react client real ip address react class component how to use setstate usestate in react handling event in jsx componentwillunmount hooks firebase react js react js useRef() in react redirect react router stack overflow how to pass a prop in route adding a if stement in jsx passing props with react link in react create-react-app redux reactjs context api how to define state in react function react ezyme simulate click new Map() collection in react state testing library react hooks connect to mysql using react js Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function. storybook react router 'App' is not defined react/jsx-no-undef can't bookmark react router useeffect previous state link tag react react and bootstrap how to validate password and confirm password on react form hook react context api reactjs create-react-app npm yarn componentwillreceiveprops hooks moment for react thunk redux react-router react-router-dom react component key prop use redux in gatsby react spring react select pause console debugger in react react three fiber react link to another page create react app cmd how to connect react to backend react propthpes or react lifecycle methods order React Components props in react app how to have a function inside useeffect how to clear state in react hooks componentdidupdate in hooks truncate function react usemutation apollo simple form submission with react functional components enzyme-adapter-react-16 react.strictmode react router how to send data how map work in react use jsx html how to use react fragment react repeat usecontext hook react final form onchange field lifecycle state: defunct, not mounted useDispatch() react fakers Parallax.js wrapper for react formik and yup reactjs libraries like html-react-parser react.createref() angular vs react react hook s useReducer socket io react js reference hook in react next js styled components classname did not match import redux thunk reactjs start redux middleware usestate wait for set route react how to redirect back to previous page onClick react router get input value in react using hooks How to install react native hooks with npm tappify react react open url with button react hooks react.component react multiple select dropdown react router history not defined build react app react slick react enzye event test react enzyme async using hooks ReactNative onPress doesn't exist rxjs .subscribe react strict mode component did update hooks detect if user is online react useref array of refs active classname with hooks this.setstate prevstate react select npm class component in react simple counter react olx clone react npm react-router-dom what does componentDidCatch do in react react toast react router browser refresh salvar no localStorage react orderbychild firebase react event listener in react pass params react js how to pause useState counter value react hoooks react setState counter app in react using class component react redirect what is state transition testing useeffect on update best react starter kit 2020 mockimplementation for setstate difference between useHistory and props.history reacthooks combine p5 with react react-select remove component react js get data from url react state eact when to use react ref how to setstate in useeffect react-redux form preventdefault how to pass props in gatsby link using styledcomponent Line 9:6: React Hook React.useEffect has a missing dependency: 'init'. Either include it or remove the dependency array reactjs loop through api response in react how to export switch from react-router-dom what does useref do react state transition testing react arrays Switch Button in react how to get element from arraylist react sequilze REACTJS install redux saga in react js useSelector React Hook Form redux saga fetch data reacts mos twanted react when should you use refs how to add react.memo in export list how to cause a whole page reload react redux react enzyme hooks test how to add value with useref in react counter composant react react chart js 2 api data react multiple classnames how to start react react native setstate object how to link to a different component in reactjs without react router deploy react to aws how to get the value in a tag in react react paypal express checkout route in component react react router refreshes page react template react select options add webpack to react project create new react app react hook useeffect equivalent class, hooks and function components pass state to child react live background react test one function in react class multiple path names for a same component in react router react redux immer reducer hook use react array if id is present do not add element export component in How to Submit Forms and Save Data with React.js multiple reducers redux dispay react component after some time react useeffect on change props react error boundary what is react mounting syntax for srcset in react what is full form of jsx Did you mean to use React.forwardRef()? adding a class in react react native pure component vs component react append jsx to jsx input text react 2020 react hooks update nested object react router link && in react jsx passing argument to function handler functional compoent javascript react event.target.name in setstate alternative for componentdidmount apollo client mutation without component shallow render in react How to test useEffect in react testing library rerender in hooks testing firebase tutorial with react react create list of array in react react set state before render conditional rendering react add 2 class names react react router hooks react i18n with parameeter react lifecycle how to use redirect in react enzyme at example set state react-router reading state react npm hook form high level components react react-sound example usereducer hook redux action react/redux reducers sintaxe use effect react cre&atRefs react js react js basic concepts useeffect componentdidmount jsx input change how react work create-react-app template download comma separated file, react use javascript library in react redux saga fetch api react route props useeffect cleanup function localstorage react react change state react image upload component pass props from parent to child react functional component react-select example react redux counter tutorial how to upload react js project on server react admin data provider redux observable react class and props example pass function with parameter as prop login condition if and else in router dom of react jsx componentdidmount in hooks react ntive create-react-app class component get syntethicbaseevent and parameter in react react time picker when to use previous state in useState react callback props history react tutorial React Sass spread operator react how to use react components How to add multiple classes to a ReactJS Component react createelement React Hook useEffect has a missing dependency:'. Either include it or remove the dependency array. redux-persist state in react context in react props and state react conditional style react is react context better than redux javascript react command to start api on react react.js class component params in react ant design react react catch error in component react lifecycle hooks ReactDOM.render() load a component on button click react pass props in another component in enzyme ReactDOM.createPortal use state vs use ref Component life cycle how to start react project on atom how to deploy react app in tomcat server npm react router 6.0.0-alpha.2 react list based on state how to get code suggestions for react components get value of Autocomplete react component did mount mutation graphql router react tutorial react live chat widget immediate promise resolve hooks developed by react native can i use redux connect without react remarkable react js setup the react on local machine remove item react react state scope react npm build not working render text in for loop react in function how to do routes react js architecture creation for a react webpack app install config react js the email address is badly formatted react react check internet connection using firebase with react key value onclick start and stop the count react react not recognizing lorem react a rxjs can I pass function as prop on route change what is random state custom hooks for password input import formik syntax attribute same as name react React Hook "useState" is called in function which is neither a React function component or a custom React Hook functio useEffectOnce how to add debounce in react redux js react fetch data in for loop subdomain react app state transition casl react redux why we use hooks in react connect django to react rotas react com axios web-vitals react hooks in cucumber react receiving socket muitple times react router tutorial medium react sagas state google pay payment gateway for react js project zeamster examples react node e.preventdefault is not a function react creating user rails and redux react router dom IndexRedirect react if event.target is input react check if localhost async await react stackoverflow interpolation react casl react create react app cloudfront invalidation get selected value on componentdidmount reactjs reusable star rating component in react usestate redux make a component update every second react simple usestate example why does my react project dosent have any class react history with search onclick react history map create dynamic fields in react react function called last state in which table our redux option values are save react-redux imports spreading object as props how to get parent's ref react how to test useeffect with enzyme most common use cases of portals in react loop through api response in react react roter dom npm react addon update react cakephp props is send undefind to functional component in react js difference between React.functioncomponent and React.component cannot read property 'props' of undefined react redux functional component how to learn react lify cycle components how to copy an arry react react pass parameter to component react createElement interactive button Which function is used to add functionality to a custom component? route with parameter react not working not found redux saga fetch json react make component full screen namespace react has no export member FC react-template-helper redux form Field input prop using shortid in react lists react router dom default params user account in react rxjs coding example useReactiveVar diagram how props are passed in react different ways to write react file paths redux action to hit api and assign data in stateless component navigation react pass props add object to array react hook Autocomplete an Address with a React hook Form use ref call parent component to child react timezone in react js react nativ export default react cleanup meas How to build an Alert using useEffect react admin application/ld+json react React looping hooks to display in other hook change state in functional component getstaticpaths with redux react '$' is not define how to access array datat in class component react minvalue validation react admin how to config absolute paths with react react modules handleClickoutside custom hook react react starter kit 2020 mobx react hooks async import typography react how to repeat component onclick in react chat application in react js react set multible attribute values reactjs pass slug to parameter onclick react-router in saga route to change a part of component redux dispatch input onchange redux form make field required react redux middleware start to work with a pre existing react projects initialize state react How to acces props of a functional component conditional rendering in react js stackoverflow firestore crud operations react connect to redux store outside component react state deconstructed paypal subscription based payout api reactjs how to create react app using npm react prototype function add new array at the back of react state callout react quokka create-react-app sample dynamic classname react react call bind apply 'unsafe-inline' react nextjs react testing library typescript proptypes react jason rpc reactjs how to host a react website react case switch not working react starter kit algolia react hits react import brackets how to use cookies in react js what is a global state? purecomponent re rendering react-router-config private routes react router redirect with query params retore react app reactjs web3 components reactjs upload zip using fetch method patch not working laravel reactjs react reset file input create-react-app version check react hooks simple projects handle changes testing react returned data has p tags react what is reactstrap react html symbol code reactjs interview questions site: github render blaze in react reactjs cloudflare react mid senior dev interview questuions best react boilerplate 2019 react cam filters run react android react linking to documents react history listen get previous location dynsmic calss in react add js map vs react js map passing functions to nested children what is hook class react toastr pass value from one component to another in polymer redux workflow setimeout react button react-anime eslint version check in react mock api inside react component jest async showdown react react select with react hook form cotroller react redux cheat sheet react index.js BrowserRouter remove state from location on page load in react router dom restful react npm react recaptcha signup form setstate not updating state immediately react router command create-react-app enviroment variables setting react state with produce immer react comfetti react router dom usehistory hook fremer motion react library elements in jsx react documentation === in react react can't import file 3 folders up how to add css based on route react prevent specific state redux-persist unable to add class in jsx this.setState is undefined inside a async function in js react actions sintaxe react ctx Build a component that holds a person object in state. Display the person’s data in the component. ctx beginpath react react record voice react conditional if localhost as it does not contain a package.json file. react firebase integration in react webpack test js or jsx declaring multiple state variables in react react get lat long of address render a list using array filter react react dynamic settings how to set state for logged in users redux acions how to get state value from history react renderer.setElementStyle redux if already exist item dont add to array react open on different url instead of localhost react how to block render if data is not fetched yet can we add new state property using setstate in react random reacths difference between w component did update and did mount how to get checked row data using react table in react js dynamic for loop react import { useBeforeunload } from 'react-beforeunload random word react npm package react cheat sheets aframe react usestate or usereducer create react element with string arrow function component react shortcut vscode react map wait axios call react onDragOver add sass autoprefixer to react external js doesn't works if revisit the page in react react value enzyme mount is not working for component how to run an existing react project enzyme childAt example react form hook trigger is not a function strapi.io react how to pass property component in react enzyme react tomcat change items loop react react hook form example stack overflow redux-persist with saga react cdn w3schools react $ r component instance console can you wrap redux provider within react.strictmode créer composant react how to delete props from url passing data in route react react i18n outside component react val react enzyme mount ReferenceError: is not defined react tutorial for beginners how to rerender a page in React when the user clicks the back button usereducer react React Hook "useEffect" is called in function Setting up a React Environment parallaxprovider react return action in a function how to use hooks react javascript in jsx react and reactdom dependencies cdn link Redux react component example react event listener createref in functional component usestate react react window navigate reactjs basic example defining props in react react file input what is state in react react app using npm how to pass state from parent to child in react state management in react React Children map example react quick tutorial react native function usestate react how to use props in functional component in react how to add multiple comment in react redux connect class to functional component react two way binding react state class component react how to create react redux project react developer salary jquery vs react mapstatetoprops redux create tic tac toe game in react using jsx files react props react route multiple components react reducer hooks tutorial redux react usecallback react router redirect add bootstrap to react app react usememo React hooks update parent state from child react function component Cannot read property 'setState' of undefined add items to a react array in hooks what is reactjs used for useparams find react version Rendered more hooks than during the previous rende react get data attribute from element how to use a js class in react props react what does the useReducer do in react react functional component example how to put instagram post in react app use bootstrap in react reactjs update state example how to play around with backend node js and frontend react reusable table in react js usestate access previous state use ref in component reactjs react functional component how to install react js react web worker routing in react how to creat emmet in react error build react Failed to execute 'replaceState' on 'History': A history state object with URL '' cannot be created in a document with origin 'null' and URL flatlist like in reactjs how to save data on database in react form use recoil oitside how to made disktop program on react website resellerclub api with react js github react starter disques usereduce how to create dynamic classes in tailwind typescript react ./node_modules/react-draft-wysiwyg/dist/react-draft-wysiwyg.js "withAuth.js" in react @hapi/disinfect react-metismenu-router-link react got error need to enable javascript CChartpie react how to set up a success message show up if form is submitted in react hooks react copy array undo npm run eject react similar multiple form submit react js testing a function in jest on click react [Design System React] App element is not defined. Please use Settings.setAppElement(el) onClick button react send to another component TS2339: Property 'value' does not exist on type 'Component<{}, {}, any>'. react renderer unit test bookbuild react app from scratch declaring react routes in a separate file and importing usestate nested object javascript get element by class jquery set checkbox javascript redirect javascript reload page javascript setinterval send a message to a specific channel discord.js javascript comment javascript remove first character from string Unhandled rejection TypeError: Article.findById is not a function sequelize js loop through associative array javascript isset javascript remove first item from array javascript explode react callback set staet javascript uniqie id javascript date javascript array javascript set query parameter event.stoppropagation javascript object notation javascript object fixed header on scroll vuejs create a customer in stripe node.js create react app theme_color javascript pass iterator to callback javascript for loop javascript settimeout how to convert string to int js javascript object to json turn object to json javascript javascript json string object to json javascript js to json Javascript object to JSON string convert object to json javascript js switch case javascript create cookie javascript cookies javascript set and get cookie js set cookie set cookie javascript javascript get cookie how to get session javascript ws3schools js cookie javascript setinterval Javascript get text input value reduce javascript javascript promise jquery click function getelementbyid switch statement multiple cases javascript switch javascript uppercase first letter js first letter uppercase javascript capitalize words write a javascript function that converts the first letter of every word to uppercase javascript capitalize string update nodejs javascript array contains elseif javascript javascript convert number to string int to string js js int to string refresh window js Javascript append item to array append data array javascript append to array js append data in value array javascript javascript add to array append data get array javascript append to array add element to array javascript javascript get element by class js set class substring javascript javascript alert js fetch 'post' json javascript convert string to json object js add class add class javascript addclass javascript javascript add class to element string split javascript javascript try javascript try catch javascript array methods javascript explode javacript getHTTPURL get current url js javascript get current url javascript get url javascript class javascript replace string addeventlistener javascript find fetch api javascript javascript foreach object keys javascript event listener javascript javascript onclick javascript fetch api array length javascript minecraft color codes JS get random number between random int from interval javascript js random number between 1 and 100 Math.floor(Math.random() * (max - min 1) min) js random javascript get random number in range random number javascript local storage javascript localstorage javascript javascript onclick event listener js add click listener trim javascript length try catch in javascript vue lifecycle hooks string methods javascript date javascript replace sort javascript array parseint javascript json stringify jquery append document.ready() document ready js document ready without jquery javascript after dom ready document ready javacsript ready function javascript Javascript document ready document ready jquery install vue-cli how to install vue how to setup vue js is empty object javascript how to check for an empty object javascript check if object is empty js is object empty javascript check empty property how to update node js version js substring or in javascript javascript string lentrh javascript pushing to an array js replace all javascript replace all occurrences of string javascript replace all js replace all symbols in string javascript in array jquery each express hello world express js basic example express js example settimeout javascript javascript date method javascript date example Javascript get current date javascript date methods get date now javascript switch javascript jquery document ready javascript while javascript array size javascript reverse array jquery ajax js keycodes javascript reload page js array to string .filter js jquery click event javascript on input change tolowercase javascript how to generate a random number in javascript moment format javascript reduce get value javascript js string to date uppercase string in js node js fetch foreach jas javascript split javascript capitalize first letter jquery submit form javascript get element by id node http request jquery link script tag javascript check if value in array js rounding jquery add div element jQuery create div element html loop through array javascript loop through arrya js loop array javascript loop thrugh array javascript loop through array javascript code to loop through array javascript through array merge array in js javascript remove object property how to remove key value pair from object js remove property from javascript object remove from object javascript remove property from object JS javascript remove property from object js remove property from object on change jquery js date methods .innerhtml convert to string javascript for each js combine two arrays javascript node.js express set value of input javascript JS get select option value return the value of a selected option in a drop-down list how can we take selected index value of dropdown in javascript javascript get selected option vue watch format date js js iterate object javascript iterate through object properties javascript for each key in object javascript iterate over object javascript loop through object example javascript loop over class javascript iterate over json javascript loop through objec javascript loop over classes javascript loop through object javascript iterate through object javascript enumerate object properties javascript loop through object array javascript delete key from object javascript confirm example timestamp js js timestamp javascript get timestamp javascript get timestamp codegrepper jquery ajax post example jquery value of input javascript sort array with objects style an element with javascript javascript modify css javascript open new window window.open in js react background image jquery get child div get height use js javascript get element width get height of div use js Javascript get element height and width javascript get element height get height element use js javascript get element width and height jquery onclick function update npm javascript string includes javascript convert date to yyyy-mm-dd javascript change attribute compare dates in js Javascript compare two dates turn object into string javascript sorting array from highest to lowest javascript javascript get first 10 characters of string angular date formats math.random javascript js getelementbyid javascript push item to beginning of array js push to start of array javascript add new array element to start of array object to json c# jquery ajax post jquery hide javascript list length timer in javascript python json string to object jquery get selected option value jQuery get selected option for loop javascript js preventdefault js settimeout how to change style of an element using javascript hide div in javascript javascript event listener javascript findindex javascript submit form window.onload how to find the index of a value in an array in javascript javascript read json file js throw error js delete duplicates from array json example How to uninstall npm modules in node js? string to array javascript jquery loop over elements nodemailer Javascript stop setInterval node express cors headers object values push array javascript js setinterval how to stringify json in js read json file nodejs remove item jquery to uppercase javascript body parser express javascript get time js create element replace i javascript fs.writefile javascript test for empty object javascript reverse a string tostring js javascript remoev css class javascript remove css class js object keys javascript get last element of array javascript check if number javscript get object size js object length javascript length of object javacript count properties javascript get length of object JS get length of an object write json file nodejs nodejs readfile express js cors remove character from string javascript foreach javascript javascript to string create child element in javascript javascript sum of array javascript delete element how to remove a property from an object in javascript javascript get parent element timeout javascript remove item from array javascript javascript check if element has class uninstall node package js loop js get data attribute javascript style background color header in axios get value of input jqueyr javascript display block window.href setup new angular project jquery create html element jquery create element angular generate component javascript order array by date javascript is string in array get window size javascript javascript round decimal 2 digits check for substring javascript jquery foreach axios in vue javascript get attribute javascript change image src replace string method js javascript sort array of objects javascript for eac loop javascript for each loop javascript foreach example foreach over array javascript javascript example of foreach loop mdn foreach how to get a value using jquery javascript append element to array javascript snumber two decimal places as string import svg react jquery set attribute get url javascript check node version for in javascript javascript check empty object Error: Node Sass version 5.0.0 is incompatible with ^4.0.0. uppercase javascript javascript get url parameters on click jquery javascript version of sleep javascript sleep sleep javascript how to add elements in javascript html jquery remove class javascript constructor function javascript hasownproperty jquery closest javascript remove event listener javascript object destructuring javascript date format js classlist js window resize listener javascript window resize listener javascript window resize event window resize event javascript javascript fetch api post json server sum of all numbers in an array javascript if object is array javascript javascript get random array value how to check if object has key javascript javascript convert string to float javascript object length jquery ajax get javascript decimal to string javascript sort ascending array .join javascript map over object javascript javascript time interval jstl spring taglib leaderboard discord.js font awesome in react Attempted import error: 'uuid' does not contain a default export (imported as 'uuid'). getusermedia example javascript bigint regular expression match text between quotes string contains in react how to print an element in javascript javascript declaracion de clase lodash get difference between two arrays of objects modal react form table react interview questions Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project electronicbookshop: Compilation failure how to use json file in nodejs useeffect umnount javascript making a tag game predicate logic solver percentatge difference between two numbers javascript firebase app named default already exists react native react change state jquery check if element still exists nextjs version 10 javascript string to number a simple javascript calculator how do you create a function js? java script zip function ... as parameter js javascript remove all spaces from string process.argv console.log javascript jquery.min.js:689 Uncaught RangeError: Maximum call stack size exceeded react fragment align text center react native javascript implode function delete button react slick slider react fetch api with express jquery get dropdown list selected value javascript round down javascript format numbers with commas python get value from json loopback float type async false in ajax javascript pluck from array of objects sequelize node js postgres association ajax request qml angular add object to array watchman watch-del-all, and react-native start --reset-cache node js read file stream line by line wow.js $.get jquery return value looping through object javascript how to disable mat-form-field in angular 8 autocomplete-dropdown remote-url angularjs Material-ui wallet icon how to log to the console javascript return array javascript retour à la ligne react native new date() in javascript 3 days from now Uncaught SyntaxError: await is only valid in async function javascript object read only drupal 8 get page node variables in js class react native rotate get checked checkbox jquery by name django form make date json serializable inline style boarder radius jsx ngchange angular 8 angular map javascript parseint string with comma NullInjectorError: R3InjectorError HttpClient javascript stringify line breaks How can I get or extract some string part from url jquery jquery ajax form submission jquery validator Date ... in javascript how to change the color of error message in jquery validation axios file upload javascript casting objects don't get password sequelize usestate nested object arrays call js js remove spaces javascript oneline function jquery check checkbox error metro bundler process exited with code 1 react native js remove key from object js number format spinner react native js how to add two arrays together javascript all type of data jest mock restore mule 4 json to string json js remove from array by value readonly attribute in html by javascript get current year javascript mongoose connect javascript detect scroll to bottom of page angularjs datatable example with pagination Write Number in Expanded Form js remove after character javascript datum addieren how to add an image using jquery for of loop syntax javascript if alternative javascript access text inside a button from js populate dropdown with a variable how to get element by attribute value in javascript js generate id angular bootstrap not working javascript alert variable js call function by string name how to compare two arrays javascript how to calculate the number of days between two dates in javascript nested callbacks javascript react router how to send data angular how to iterate object call local function javascript monk find autoformat mobile number (xxx) xxx-xxx codepen javascript url use length to resize an array how use modal in login button click in react js django csrf token in javascript javascript how to check if image exists loopback ilike javascript move item in array to another index how to select the first div in jQuery why vs code is not running nodemon react redirect after login get largest number in array javascript optional changing n likert scale javascript code mutable array methods in javascript js remove first and last element from array how to change the model object django in javascript is checked checkbox jquery show tooltip automatically line graph view click event add elements to an array with splice change button color react native import jquery into js file lodash unique array generate random numbers in js javascript tabs example copy to clipboard reatjs how to install node js in ubuntu javascript calculate 24 hours ago if value in list javascript and return index jquery get link href value javascript list length when do you use javascript in your framework adding cors parameters to extjs ajax js object some number to string javascript javascript nameof how can prevent morgan to work in test enviroment mongoose unique field backbone model save without validation jquery validate get lines as list from file node js nestjs vscode debug loop through object in array javascript deploy react app to heroku aliexpress affiliate clear console javascript javascript filltext width insert a data into mongo using express make a component update every second react redirect to html page in javascript loop in javascript react native image fit container using laravel variable inside alpine js multiline comment in react finding the smallest number in an array javascript electron quit app from renderer javascript end of day react for loop in render refresh button in javascript execute terminal command nodejs returned value by findOneAndUpdate select 2 dropdown how to print more than 20 documents mongo shell if checkbox is checked javascript example of foreach loop document.addEventListener("load", function () { nodejs express routing logical nullish operator javascript agregar atributo con id jquery javascript import event.keyCode === 13 mongoose find() example jquery duplicate last table row useref array of refs how to Check if an array contains an object in javascript .
https://www.codegrepper.com/code-examples/javascript/javascript+array+stackoverflow
CC-MAIN-2021-17
en
refinedweb
I was having problems with one of my projects every time I pressed for first time the screen. At first I thought it was caused by a script that disabled an UI Text but after one day of researching I couldn't find any answer so I decided to try recreating the problem in an empty scene. The results are that whenever I place a script that checks for Input.GetTouch(0), the first time I touch the screen, the game freezes for a fraction of a second even if the scene is completely empty. I took a look at the profiler and the script checking for the input was generating that lag spike. Note that after the first touch everything works smoothly and without any kind of lag spike. This was the script used using System.Collections; using System.Collections.Generic; using UnityEngine; public class Scr_Input : MonoBehaviour { // Update is called once per frame void Update() { if (Input.touchCount > 0) { Touch touch = Input.GetTouch(0); if (touch.phase == TouchPhase.Began) { Debug.Log("AAA"); } } } } And here's the profiler when I first touch the device's screen. The device I tested on is a Xiaomi MI A1 but I had this kind of problem before using a Samsung Galaxy S9. Now you may notice that the lag spike is generated by the Debug.Log() code but It just doesn't make sense to me since in my other projects I don't have any Debug.Log() going on and there are other things happening before I touch the screen so there is no other reason for the lag spike that the Input.GetTouch(). Also, in the picture you may see smaller spikes, those are the touches after the first one, just to prove that it only happens on the first touch. So if you know how to avoid this I would be really thankful since it's completely ruining the game experience because the first touch when you open the game will always generate a lag spike no matter the device. UPDATE Since I've read that Debug.Log() is expensive for perfomance I've changed it and placed a transform.position += new Vector3(1, 0, 0); And as expected the lag spike isn't that massive but even though the first touch is still generating a bigger lag spike than the ones after that and if you consider a bigger script (as the ones in my other project), the lag spike gets way too big and you can tell that the game lags at the first touch. Here's the Profiler Answer by Visuallization · Jan 17 at 01:09 PM Okay I found a solution which works for me. It is split into 2 parts: 1.Trigger a drag start via code. It might be the only part you need to "fix" this issue. This is how I did it: void Start() { // Trigger drag start via code to prevent initial drag delay on android PointerEventData pointer = new PointerEventData(EventSystem.current); ExecuteEvents.Execute(gameObject, pointer, ExecuteEvents.beginDragHandler); } Thank you for the answer! I thought this question was already dead. I haven't tested your workaround but made something similar to fix it when I needed to (I simulated the first touch in the Start() function) Answer by Visuallization · Jan 15 at 01:20 PM I am actually experiencing the same issue on android even with the native unity scrollrect in an otherwise empty scene. Is there anyone out there who can help with this issue? Any unity folks 353 People are following this question. Having an issue with touch input lag on certain Android devices, any help? 0 Answers I want to move my cube on right or left when I touch screen for Android devices; Please help me which script I have to use 0 Answers Touch radius always returns zero on Android 0 Answers UNITY 2D ANDROID DEVICE TOUCH PROBLEM 0 Answers Android| Camera scrolling 1 Answer EnterpriseSocial Q&A
https://answers.unity.com/questions/1662339/massive-lag-spike-on-first-inputgettouch-with-noth.html
CC-MAIN-2021-17
en
refinedweb
riskyAnnuity (3) - Linux Man Pages riskyAnnuity: CDS option. NAME QuantLib::CdsOption - CDS option. SYNOPSIS #include <ql/experimental/credit/cdsoption.hpp> Inherits QuantLib::Instrument. Public Member Functions CdsOption (const Date &expiry, Rate strike, const Handle< Quote > &volatility, const Issuer &issuer, Protection::Side side, Real nominal, const Schedule &premiumSchedule, const DayCounter &dayCounter, bool settlePremiumAccrual, const Handle< YieldTermStructure > &yieldTS) Real forward () const Real riskyAnnuity () const bool isExpired () const returns whether the instrument is still tradable. Detailed Description CDS option. Warning - the current implementation does not take premium accrual into account Warning - the current implementation quietly assumes that the expiry equals the start date of the underlying CDS Possible enhancements - take premium accrual into account Possible enhancements - allow expiry to be different from CDS start date Author Generated automatically by Doxygen for QuantLib from the source code.
https://www.systutorials.com/docs/linux/man/3-riskyAnnuity/
CC-MAIN-2021-17
en
refinedweb
Chess piece on view I am creating a chess board with normal views, I am trying to put a chess piece on a single view(all the views have the same custom view class). No ok, I've found my copy error, Now I will check This works, but you need to define an ImageView as subview of your custom views It should be better if your boxes were buttons instead of ui.views and fill their background_image def __init__(self): self.touch_enabled = True iv = ui.ImageView() iv.frame = self.bounds iv.image = ui.Image.named('emj:Angry') #iv.load_from_url('') self.add_subview(iv) def did_load(self): pass It would be easier to create your 64 views by program, rather than by the ui designer. Quick and dirty script, only to show, try it please import ui def baction(sender): sender.superview.name = sender.name v = ui.View() v.background_color = 'white' y = 10 d = 40 for row in range(8): x = 10 for col in range(8): b = ui.Button() b.name = 'row '+str(1+row) + ' / ' + 'col '+str(1+col) b.frame = (x,y,d,d) b.background_image = ui.Image.named('emj:Airplane') b.action = baction v.add_subview(b) x = x + d + 10 y = y + d + 10 v.present() Ok, I’m going to do some stuff about it and if I get a problem I will come back another day I guess. Just to show how it could be easy import ui def baction(sender): sender.superview.name = str(sender.row_col) v = ui.View() v.background_color = 'white' v.name = 'for @AZOM' pieces = ['♜♞♝♛♚♝♞♜','♖♘♗♕♔♗♘♖'] y = 10 d = 50 flip = 0 for row in range(1,9): x = 10 for col in range(1,9): b = ui.Button() b.font = ('<System>',d*0.8) b.tint_color = 'black' b.border_width = 1 b.row_col = (row,col) b.frame = (x,y,d,d) if row == 1: b.title = pieces[row-1][col-1] b.tint_color = 'black' elif row == 2: b.title = '♟️' elif row == 8: b.title = pieces[row-7][col-1] elif row == 7: b.title = '♙' b.background_color = ['beige','brown'][flip] b.action = baction v.add_subview(b) flip = 1 - flip x = x + d + 2 flip = 1 - flip y = y + d + 2 v.present() You might consider scene instead of UI. Scene would let you animate the piece motions more naturally for example. @JonB you right, of course, but I only wanted to show it is easier to create the buttons by program instead of the ui designer And that you don't need images for the chess pieces, because there are ucode characters representing them @JonB, thanks, it has been a while since I got to advertise this. :-) @AZOM, if you want to not translate everything to scene and still want nice animations, check out Scripter. I was trying to run scripter-demo.py, but I got: scripter/init.py", line 63 except Usage, err: ^ SyntaxError: invalid syntax My fault - wrong installation procedure.
https://forum.omz-software.com/topic/5894/chess-piece-on-view/30
CC-MAIN-2021-17
en
refinedweb
Toolset for generating and managing Power Plant Data Project description powerplantmatching A toolset for cleaning, standardizing and combining multiple power plant databases. This package provides ready-to-use power plant data for the European power system. Starting from openly available power plant datasets, the package cleans, standardizes and merges the input data to create a new combining dataset, which includes all the important information. The package allows to easily update the combined data as soon as new input datasets are released. powerplantmatching was initially developed by the Renewable Energy Group at FIAS to build power plant data inputs to PyPSA-based models for carrying out simulations for the CoNDyNet project, financed by the German Federal Ministry for Education and Research (BMBF) as part of the Stromnetze Research Initiative. What it can do - clean and standardize power plant data sets - aggregate power plants units which belong to the same plant - compare and combine different data sets - create lookups and give statistical insight to power plant goodness - provide cleaned data from different sources - choose between gros/net capacity - provide an already merged data set of six different data-sources - scale the power plant capacities in order to match country specific statistics about total power plant capacities - visualize the data - export your powerplant data to a PyPSA or TIMES model Installation Using pip pip install powerplantmatching or conda (as long as the package is not yet in the conda-forge channel) pip install powerplantmatching entsoe-py --no-deps conda install pandas networkx pycountry xlrd seaborn pyyaml requests matplotlib geopy beautifulsoup4 cartopy Get the Data In order to directly load the already build data into a pandas dataframe just call import powerplantmatching as pm pm.powerplants(from_url=True) which will parse and store the actual dataset of powerplants of this repository. Setting from_url=False (default) will load all the necessary data files and combine them. Note that this might take some minutes. The resulting dataset compared with the capacity statistics provided by the ENTSOE SO&AF: The dataset combines the data of all the data sources listed in Data-Sources and provides the following information: - Power plant name - claim of each database - Fueltype - {Bioenergy, Geothermal, Hard Coal, Hydro, Lignite, Nuclear, Natural Gas, Oil, Solar, Wind, Other} - Technology - {CCGT, OCGT, Steam Turbine, Combustion Engine, Run-Of-River, Pumped Storage, Reservoir} - Set - {Power Plant (PP), Combined Heat and Power (CHP), Storages (Stores)} - Capacity - [MW] - Duration - Maximum state of charge capacity in terms of hours at full output capacity - Dam Information - Dam volume [Mm^3] and Dam Height [m] - Geo-position - Latitude, Longitude - Country - EU-27 + CH + NO (+ UK) minus Cyprus and Malta - YearCommissioned - Commmisioning year of the powerplant - RetroFit - Year of last retrofit - projectID - Immutable identifier of the power plant Where is the data stored? All data files of the package will be stored in the folder given by pm.core.package_config['data_dir'] Make your own configuration You have the option to easily manipulate the resulting data modifying the global configuration. Just save the config.yaml file as ~/.powerplantmatching_config.yaml manually or for linux users wget -O ~/.powerplantmatching_config.yaml and change the .powerplantmaching_config.yaml file according to your wishes. Thereby you can determine the global set of countries and fueltypes determine which data sources to combine and which data sources should completely be contained in the final dataset individually filter data sources via pandas.DataFrame.query statements set as an argument of data source name. See the default config.yaml file as an example Optionally you can: add your ENTSOE security token to the .powerplantmaching_config.yaml file. To enable updating the ENTSOE data by yourself. The token can be obtained by following section 2 of the RESTful API documentation of the ENTSOE-E Transparency platform. add your Google API key to the config.yaml file to enable geoparsing. The key can be obtained by following the instructions. Data-Sources: - OPSD - Open Power System Data publish their data under a free license - GEO - Global Energy Observatory, the data is not directly available on the website, but can be obtained from an sqlite scraper - GPD - Global Power Plant Database provide their data under a free license - CARMA - Carbon Monitoring for Action - ENTSOe - European Network of Transmission System Operators for Electricity, annually provides statistics about aggregated power plant capacities. Their data can be used as a validation reference. We further use their annual energy generation report from 2010 as an input for the hydro power plant classification. The power plant dataset on the ENTSO-E transparency website is downloaded using the ENTSO-E Transparency API. - JRC - Joint Research Centre Hydro-power plants database - IRENA - International Renewable Energy Agency open available statistics on power plant capacities. - BNETZA - Bundesnetzagentur open available data source for Germany's power plants - UBA (Umwelt Bundesamt Datenbank "Kraftwerke in Deutschland) Not available but supported sources: - IWPDCY (International Water Power & Dam Country Yearbook) - WEPP (Platts, World Elecrtric Power Plants Database) The merged dataset is available in two versions: The bigger dataset, obtained by pm.powerplants(reduced=False) links the entries of the matched power plants and lists all the related properties given by the different data-sources. The smaller, reduced dataset, given by pm.powerplants() claims only the value of the most reliable data source being matched in the individual power plant data entry. The considered reliability scores are: Intergrating new Data-Sources Let's say you have a new dataset "FOO.csv" which you want to combine with the other data bases. Follow these steps to properly integrate it. Please, before starting, make sure that you've installed powerplantmatching from your downloaded local repository (link). Look where powerplantmatching stores all data files import powerplantmatching as pm pm.core.package_config['data_dir'] Store FOO.csv in this directory under the subfolder data/in. So on Linux machines the total path under which you store your data file would be: /home/<user>/.local/share/powerplantmatching/data/in/FOO.csv Look where powerplantmatching looks for a custom configuration file pm.core.package_config['custom_config'] If this file does not yet exist on your machine, download the standard configuration and store it under the given path as .powerplantmatching_config.yaml. Open the yaml file and add a new entry under the section #data config. The new entry should look like this FOO: reliability_score: 4 fn: FOO.csv The reliability_scoreindicates the reliability of your data, choose a number between 1 (low quality data) and 7 (high quality data). If the data is openly available, you can add an urlargument linking directly to the .csv file, which will enable automatic downloading. Add the name of the new entry to the matching_sourcesin your yaml file like shown below #matching config matching_sources: ... - OPSD - FOO Add a function FOO()to the data.py in the powerplantmatching source code. You find the file in your local repository under powerplantmatching/data.py. The function should be structured like this: def FOO(raw=False, config=None): """ Importer for the FOO database. Parameters ---------- raw : Boolean, default False Whether to return the original dataset config : dict, default None Add custom specific configuration, e.g. powerplantmatching.config.get_config(target_countries='Italy'), defaults to powerplantmatching.config.get_config() """ config = get_config() if config is None else config df = parse_if_not_stored('FOO', config=config) if raw: return foo df = (df .rename(columns){'Latitude': 'lat', 'Longitude': 'lon'}) .loc[lambda df: df.Country.isin(config['target_countries'])] .pipe(set_column_name, 'FOO') ) return df Note that the code given after df =is just a placeholder for anything necessary to turn the raw data into the standardized format. You should ensure that the data gets the appropriate column names and that any attributes are in the correct format (all of the standard labels can be found in the yaml or by pm.get_config()['target_x']when replacing x by columns, countries, fueltypes, sets or technologies. Make sure the FOO entry is given in the configuration pm.get_config() and load the file pm.data.FOO() If everything works fine, you can run the whole matching process with pm.powerplants(update_all=True) Getting Started A small presentation of the tool is given in the jupyter notebook How it works Whereas single databases as the CARMA, GEO or the OPSD database provide non standardized and incomplete information, the datasets can complement each other and improve their reliability. In a first step, powerplantmatching converts all powerplant dataset into a standardized format with a defined set of columns and values. The second part consists of aggregating power plant blocks together into units. Since some of the datasources provide their powerplant records on unit level, without detailed information about lower-level blocks, comparing with other sources is only possible on unit level. In the third and name-giving step the tool combines (or matches)different, standardized and aggregated input sources keeping only powerplants units which appear in more than one source. The matched data afterwards is complemented by data entries of reliable sources which have not matched. The aggregation and matching process heavily relies on DUKE, a java application specialized for deduplicating and linking data. It provides many built-in comparators such as numerical, string or geoposition comparators. The engine does a detailed comparison for each single argument (power plant name, fuel-type etc.) using adjusted comparators and weights. From the individual scores for each column it computes a compound score for the likeliness that the two powerplant records refer to the same powerplant. If the score exceeds a given threshold, the two records of the power plant are linked and merged into one data set. Let's make that a bit more concrete by giving a quick example. Consider the following two data sets Dataset 1: and Dataset 2: where Dataset 2 has the higher reliability score. Apparently entries 0, 3 and 5 of Dataset 1 relate to the same power plants as the entries 0,1 and 2 of Dataset 2. The toolset detects those similarities and combines them into the following set, but prioritising the values of Dataset 2: Citing powerplantmatching If you want to cite powerplantmatching, use the following paper - F. Gotzens, H. Heinrichs, J. Hörsch, and F. Hofmann, Performing energy modelling exercises in a transparent way - The issue of data quality in power plant databases, Energy Strategy Reviews, vol. 23, pp. 1–12, Jan. 2019. with bibtex @article{gotzens_performing_2019, title = {Performing energy modelling exercises in a transparent way - {The} issue of data quality in power plant databases}, volume = {23}, issn = {2211467X}, url = {}, doi = {10.1016/j.esr.2018.11.004}, language = {en}, urldate = {2018-12-03}, journal = {Energy Strategy Reviews}, author = {Gotzens, Fabian and Heinrichs, Heidi and Hörsch, Jonas and Hofmann, Fabian}, month = jan, year = {2019}, pages = {1--12} } and/or the current release stored on Zenodo with a release-specific DOI: Acknowledgements The development of powerplantmatching was helped considerably by in-depth discussions and exchanges of ideas and code with - Tom Brown from Karlsruhe Institute for Technology - Chris Davis from University of Groningen and - Johannes Friedrich, Roman Hennig and Colin McCormick of the World Resources Institute Licence Copyright 2018-2020 Fabian Gotzens (FZ Jülich), Jonas Hörsch (KIT), Fabian Hofmann (FIAS) powerplantmatching is released as free software under the GPLv3, see LICENSE for further information. Project details Release history Release notifications | RSS feed Download files Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
https://pypi.org/project/powerplantmatching/
CC-MAIN-2021-17
en
refinedweb
Opened 14 months ago Closed 13 months ago #29167 closed defect (duplicate) test failures in sage.schemes.curves.zariski_vankampen with sirocco built with -O2 Description (last modified by ) #29149 fixes building Sage with the sirocco package installed on Cygwin. This required, for linking purposes, removing the forced -O0 flag (this could probably be worked around by other means--building with optimizations disabled should be possible). However, as mmarco remarked below, there are some optimizations that cause numerical errors in sirocco such that it fails to converge or takes a longer path than necessary. This can be reproduced on Linux (although it was previously found on Cygwin). In particular this causes test failures in sage.schemes.curves.zariski_vankampen. First the following test fails: File "src/sage/schemes/curves/zariski_vankampen.py", line 268, in sage.schemes.curves.zariski_vankampen.followstrand Failed example: followstrand(f, x0, x1, -1.0) # optional - sirocco # abs tol 1e-15 Expected: [(0.0, -1.0, 0.0), (0.7500000000000001, -1.015090921153253, -0.24752813818386948), (1.0, -1.026166099551513, -0.32768940253604323)] Got: [(0.0, -1.0, 0.0), (0.04687500000000001, -1.0000610264662042, -0.015624364352899234), (0.09376287283569926, -1.0002440686687775, -0.031249206930640684), (0.14068935711887412, -1.00054911561723, -0.046879295645742315), (0.18768019150872053, -1.0009762160115023, -0.06251939538085316), (0.23476112890433726, -1.0015254781428102, -0.07817426805966325), (0.2819579506558838, -1.0021970697475961, -0.0938486727311868), (0.32683564123989106, -1.0029469806716729, -0.10873190673317454), (0.36890847616239786, -1.0037475631034418, -0.12266360371442413), (0.408351758902248, -1.0045828947575761, -0.13570358710012892), (0.4453298364708575, -1.0054396825086667, -0.14790834427708396), (0.5146637319120003, -1.007235298523974, -0.1707339873423019), (0.5753308904230002, -1.0090048273677124, -0.19063761622091374), (0.6284146541201252, -1.0107014101228857, -0.20799548368797782), (0.6748629473551095, -1.0122968271247523, -0.22313613838778654), (0.7155052039357208, -1.0137759106169235, -0.23634583220457633), (0.7866291529517906, -1.0165461226074612, -0.25937181657421426), (0.8399721147138429, -1.0187713227013186, -0.2765614548183696), (0.8799793360353821, -1.0205207374109584, -0.28940677345545085), (0.939990168017691, -1.0232704733075533, -0.30859664694102984), (1.0, -1.026166099551513, -0.3276894025360433)] The first an last lines are correct, but none of the stuff in the middle. Then a bit later it hangs, seemingly indefinitely at Trying (line 339): B = zvk.braid_in_segment(g,CC(p1),CC(p2)) # optional - sirocco which on Linux passes very quickly. However, the CPU is still very active during this hang so it must be some kind of busy loop. I don't understand anything about this package except that it's using some kind of linear approximation techniques, so there might be some small numerical glitches being invoked that are causing some solutions to diverge or something. It might be possible to work around this by identifying exactly which optimizations result in the problem, rather than disabling all optimizations. Upstream PR: Change History (23) comment:1 follow-up: ↓ 5 Changed 14 months ago by comment:2 follow-up: ↓ 4 Changed 14 months ago by I just tested under a linux box disabling the tweek we did to prevent the compiler optimization and I get the same error as you point, so it really looks that is the cuplrit. In particular, the only line I had to modify is this one: : ${CXXFLAGS=-O0 -g} In the configure.ac file [1] Maybe that kind of autotools behaviour is platform-dependent? [1] P.S. I noticed that you forked the old sirocco repo. The one we are using here is the version 2 one: comment:3 Changed 14 months ago by That's for the note about -O0. I have another ticket #29149 where I'm fixing building sirocco on Cygwin (though I haven't posted the patch yet). In particular I had to remove CXXFLAGS=-O0 to even get it to build, because otherwise I had problems during linking with some templates; I'm not exactly sure why but it seems like they were being overspecialized, in such a way that resulted in multiple definitions for some functions. Removing -O0 fixed it because then the compiler would optimize out unused specializations, but there is probably a better solution. As you say, this is likely the culprit. comment:4 in reply to: ↑ 2 Changed 14 months ago by P.S. I noticed that you forked the old sirocco repo. The one we are using here is the version 2 one: I see. When I noticed that my copy was not 2.0 I updated my fork of the repo to 2.0 as well, so I can confirm that I am building the correct version at least. comment:5 in reply to: ↑ 1 Changed 14 months ago by? Did you ever figure out what specific optimizations were hurting performance and/or correctness, and where those optimizations were occurring? Because disabling all optimizations is a blunt hammer and probably hurts performance in other cases. I know figuring that out can be tricky of course, but I have to ask. comment:6 Changed 14 months ago by - Summary changed from Cygwin: test failures in sage.schemes.curves.zariski_vankampen with sirocco to test failures in sage.schemes.curves.zariski_vankampen with sirocco built with -O2 I was able to reproduce this on Linux also by removing -O0 and setting -O2 instead. comment:7 Changed 14 months ago by comment:8 Changed 14 months ago by I can also reproduce the problem enabling basic optimizations with -O1, so it could be any combination of comment:9 Changed 14 months ago by I didn't dig into the details of what specific optimization was the problem. Sorry. comment:10 Changed 14 months ago by One problem I found (if not the problem) is that although there is a template specialization for evaluation polynomials on complex intervals: template <> IComplex Polynomial<IComplex>::operator () (const IComplex &x, const IComplex &y) const{ IComplex rop, ropx, ropy; #ifdef DEVELOPER std::cerr << "using specialized polynomial eval for " << __PRETTY_FUNCTION__ << std::endl; #endif ropx = this->evalIPolHornerXY (x, y); ropy = this->evalIPolHornerYX (x, y); rop = this->evalPolClassic (x, y); rop.r.a = MAX(MAX(ropx.r.a, ropy.r.a), rop.r.a); rop.r.b = MIN(MIN(ropx.r.b, ropy.r.b), rop.r.b); rop.i.a = MAX(MAX(ropx.i.a, ropy.i.a), rop.i.a); rop.i.b = MIN(MIN(ropx.i.b, ropy.i.b), rop.i.b); return rop; } when building with -O1 that specialization seems to be being ignored, and instead it's using the unspecialized template: template <class T> T Polynomial<T>::operator() (const T &x, const T &y) const { #ifdef DEVELOPER std::cerr << "using unspecialized polynomial eval for " << __PRETTY_FUNCTION__ << std::endl; #endif return this->evalPolClassic (x,y); } I don't know why that would be but I'll keep looking... comment:11 Changed 14 months ago by This seems to fix it for me: diff --git a/include/polynomial.hpp b/include/polynomial.hpp index 88d1299..4596579 100644 --- a/include/polynomial.hpp +++ b/include/polynomial.hpp @@ -230,6 +230,10 @@ T Polynomial<T>::operator() (const T &x, const T &y) const { return this->evalPolClassic (x,y); } +// Defined in lib/polynomial.cpp +template <> IComplex Polynomial<IComplex>::operator() (const IComplex &x, const IComplex &y) const; +template <> MPIComplex Polynomial<MPIComplex>::operator () (const MPIComplex &x, const MPIComplex &y) const; + template <class T> T Polynomial<T>::diffX (const T &x, const T &y) const { // coef[(i*(i+1))/2 + j] is coeficient of monomial of degree 'i', @@ -311,6 +315,10 @@ T Polynomial<T>::diffY (const T &x, const T &y) const { return this->evalPolYClassic (x,y); } +// Defined in lib/polynomial.cpp +template<> IComplex Polynomial<IComplex>::diffY (const IComplex &x, const IComplex &y) const; +template<> MPIComplex Polynomial<MPIComplex>::diffY (const MPIComplex &x, const MPIComplex &y) const; + template <class T> T Polynomial<T>::diffXX (const T &x, const T &y) const { The problem is that sirocco.cpp includes "polynomial.hpp" which only has the unspecialized operator() defined inline, but no declaration for the specialized version, so it just use the unspecialized one. Meanwhile, when compiling polynomial.cpp the unused specializations are just optimized out. This would possibly explain the link errors I was having on Cygwin as well--I don't know why the problem only occurs on Windows but it must be generating an explicit specialization for Polynomial<IComplex>::operator() in sirocco.o and then conflicting with the one in polynomial.o. Going to test that theory out now. comment:12 Changed 14 months ago by Yep, this is exactly the link error that I got which motivated me to try removing the -O0. This explains it exactly: libtool: link: g++ -std=gnu++11 -std=gnu++11 -shared -nostdlib /usr/lib/gcc/x86_64-pc-cygwin/7.4.0/crtbeginS.o .libs/icomplex.o .libs/interval.o .libs/mp_complex.o .libs/mp_icomplex.o .libs/mp_interval.o .libs/polynomial.o .libs/sirocco.o -lmpfr -lgmp -L/home/embray/src/sagemath/sage/local/lib -L/home/embray/src/sagemath/sage/local/lib/../lib -L/usr/lib/gcc/x86_64-pc-cygwin/7.4.0 -L/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/../../../../x86_64-pc-cygwin/lib/../lib -L/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/../../../../x86_64-pc-cygwin/lib -L/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/../../.. -lstdc++ -lgcc_s -lgcc -lcygwin -ladvapi32 -lshell32 -luser32 -lkernel32 -lgcc_s -lgcc /usr/lib/gcc/x86_64-pc-cygwin/7.4.0/crtend.o -O0 -Wl,-rpath -Wl,/home/embray/src/sagemath/sage/local/lib -o .libs/cygsirocco-0.dll -Wl,--enable-auto-image-base -Xlinker --out-implib -Xlinker .libs/libsirocco.dll.a .libs/sirocco.o:sirocco.cpp:(.text$_ZNK10PolynomialI8IComplexEclERKS0_S3_[_ZNK10PolynomialI8IComplexEclERKS0_S3_]+0x0): multiple definition of `Polynomial<IComplex>::operator()(IComplex const&, IComplex const&) const' .libs/polynomial.o:polynomial.cpp:(.text+0x642): first defined here .libs/sirocco.o:sirocco.cpp:(.text$_ZNK10PolynomialI8IComplexE5diffYERKS0_S3_[_ZNK10PolynomialI8IComplexE5diffYERKS0_S3_]+0x0): multiple definition of `Polynomial<IComplex>::diffY(IComplex const&, IComplex const&) const' .libs/polynomial.o:polynomial.cpp:(.text+0xfbe): first defined here .libs/sirocco.o:sirocco.cpp:(.text$_ZNK10PolynomialI10MPIComplexEclERKS0_S3_[_ZNK10PolynomialI10MPIComplexEclERKS0_S3_]+0x0): multiple definition of `Polynomial<MPIComplex>::operator()(MPIComplex const&, MPIComplex const&) const' .libs/polynomial.o:polynomial.cpp:(.text+0x188a): first defined here .libs/sirocco.o:sirocco.cpp:(.text$_ZNK10PolynomialI10MPIComplexE5diffYERKS0_S3_[_ZNK10PolynomialI10MPIComplexE5diffYERKS0_S3_]+0x0): multiple definition of `Polynomial<MPIComplex>::diffY(MPIComplex const&, MPIComplex const&) const' .libs/polynomial.o:polynomial.cpp:(.text+0x22f8): first defined here collect2: error: ld returned 1 exit status comment:13 Changed 14 months ago by - Branch set to u/embray/ticket-29167 - Commit set to 35d7703fff39cdd210ced0846c1e8693bb262aa6 - Description modified (diff) - Report Upstream changed from N/A to Reported upstream. Developers acknowledge bug. - Status changed from new to needs_review New commits: comment:14 follow-up: ↓ 15 Changed 14 months ago by Thanks a lot. Great work. I might need some time to review and test it though. Did you check that all test pass with this patch? Also, what would you consider the best way to go: just patch sirocco at install time inside Sage, or release a new version of Sirocco and using that in Sage? comment:15 in reply to: ↑ 14 Changed 14 months ago by - Report Upstream changed from Reported upstream. Developers acknowledge bug. to Fixed upstream, but not in a stable release. Thanks a lot. Great work. I might need some time to review and test it though. Thank you for looking at it! There's no hurry. Did you check that all test pass with this patch? Per our discussion on GitHub, yes. I'm just reiterating here for the record. Also, what would you consider the best way to go: just patch sirocco at install time inside Sage, or release a new version of Sirocco and using that in Sage? It's up to you. There's no urgency on this either way, so whatever's easiest for you. comment:16 Changed 14 months ago by I just created a new release in github. The source code is available at comment:17 Changed 14 months ago by Oh shoot, before you made the release I should have pointed out to you the fixes I made for Cygwin. I forgot to make a PR for them yet. I will do that now... comment:18 Changed 14 months ago by No problem, I can make another release (that is the good thing about numbers: we won't run out of them). comment:19 Changed 14 months ago by I made a new release on github. The tarball is available at comment:20 Changed 14 months ago by Erik, are you going to rebase this ticket based on the new release? comment:21 Changed 13 months ago by Yes, I've been busy with other things, but I plan to replace this ticket with one to update the sirocco spkg to the new release. comment:22 Changed 13 months ago by - Milestone changed from sage-9.1 to sage-duplicate/invalid/wontfix - Status changed from needs_review to positive_review comment:23 Changed 13 months ago by - Resolution set to duplicate - Status changed from positive_review to closed Thanks for looking into this. Sadly, I don't have access to any windows system, so I never tested Sirocco there. As you say, Sirocco does numerical aproximations of the movements of roots of a polynomial, but carefully testing that the step is small enough to guarantee the correctness. So it is indeed very sensitive to all the small subtleties of floating point computing.?
https://trac.sagemath.org/ticket/29167
CC-MAIN-2021-17
en
refinedweb
, and while it supports threading, it does not yet support multiprocessing or multiple processes in general. your code in a virtualenv: $ python3 -m venv venv/ $ . venv/bin/activate (venv) $ pip install --upgrade pip Assuming you have a new enough version of pip: $ pip install filprofiler Using Fil Profiling in Jupyter To measure peak. Profiling complete Python programs Instead of doing: $ python yourscript.py --input-file=yourfile Just do: $ fil-profile run yourscript.py --input-file=yourfile And it will generate a report and automatically try to open it in for you in a browser. Reports will be stored in the fil-result/ directory in your current working directory. As of version 0.11, you can also run it like this: $ python -m filprofiler run yourscript.py --input-file=yourfile API for profiling specific Python functions You can also measure memory usage in part of your program; this requires version 0.15 or later. This requires two steps. 1. Add profiling in your code Let's you have some code that does the following: def main(): config = load_config() result = run_processing(config) generate_report(result) You only want to get memory profiling for the run_processing() call. You can do so in the code like so: from filprofiler.api import profile def main(): config = load_config() result = profile(lambda: run_processing(config), "/tmp/fil-result") generate_report(result) You could also make it conditional, e.g. based on an environment variable: import os from filprofiler.api import profile def main(): config = load_config() if os.environ.get("FIL_PROFILE"): result = profile(lambda: run_processing(config), "/tmp/fil-result") else: result = run_processing(config) generate_report(result) 2. Run your script with Fil You still need to run your program in a special way. If previously you did: $ python yourscript.py --config=myconfig Now you would do: $ filprofiler python yourscript.py --config=myconfig Notice that you're doing filprofiler python, rather than filprofiler run as you would if you were profiling the full script. Only functions explicitly called with the filprofiler.api.profile() will have memory profiling enabled; the rest of the code will run at (close) to normal speed and configuration. Each call to profile() will generate a separate report. The memory profiling report will be written to the directory specified as the output destination when calling profile(); in or example above that was "/tmp/fil-result". Unlike full-program profiling: - The directory you give will be used directly, there won't be timestamped sub-directories. If there are multiple calls to profile(), it is your responsibility to ensure each call writes to a unique directory. - The report(s) will not be opened in a browser automatically, on the presumption you're running this in an automated fashion. Debugging out-of-memory crashes New in v0.14 and later: Just run your program under Fil, and it will generate a SVG at the point in time when memory runs out, and then exit with exit code 53: $ fil-profile run oom.py ... =fil-profile= Wrote memory usage flamegraph to fil-result/2020-06-15T12:37:13.033/out-of-memory.svg Fil uses three heuristics to determine if the process is close to running out of memory: - A failed allocation, indicating insufficient memory is available. - The operating system or memory-limited cgroup (e.g. a Docker container) only has 100MB of RAM available. - The process swap is larger than available memory, indicating heavy swapping by the process. In general you want to avoid swapping, and e.g. explicitly use mmap()if you expect to be using disk as a backfill for memory.. For performance reasons, only the largest allocations are reported, with a minimum of 99% of allocated memory reported. The remaining <1% is highly unlikely to be relevant when trying to reduce usage; it's effectively noise..
https://pypi.org/project/filprofiler/0.16.0/
CC-MAIN-2021-17
en
refinedweb
29518/hyperledger-cello-operator-dashboard-stuck-at-loading When I try to open operator dashboard on localhost:8080 it keeps loading. localhost:8080 keeps loading and shows waiting for localhost.... I tried make all also but still it does not work. I followed the tutorial from their official tutorial website Any help would be appreciated. Run these commands: $ sudo su $ cd cello $ make stop $ make dockerhub-pull $ make start reboot the system and it should work This may be due to some inconsistency in local file. If you are using Linux OS, then you may run `make reset`, and then follow the tutorial's steps to reconfig and start. The function name should be in Args ...READ MORE Hyperledger incubates a plethora of business blockchain ...READ MORE By default, the docs are at your ...READ MORE This link might help you: ...READ MORE Summary: Both should provide similar reliability of ...READ MORE This will solve your problem import org.apache.commons.codec.binary.Hex; Transaction txn ...READ MORE To read and add data you can ...READ MORE You are getting this error probably because ...READ MORE I know it is a bit late ...READ MORE OR Already have an account? Sign in.
https://www.edureka.co/community/29518/hyperledger-cello-operator-dashboard-stuck-at-loading
CC-MAIN-2021-17
en
refinedweb
NetBeans Platform Gesture Collection Infrastructure Tutorial Do you know what your users are doing with your NetBeans Platform application? Which windows are they opening? Which actions are they commonly invoking? When are they clicking the "Help" button on a dialog? Knowing the answers to these questions is crucial in determining where you should be assigning development resources. Knowing that the "Help" button is being pressed a lot for a particular feature might indicate that there is a problem with the UI that you could consider modifying in some way. Also, the priority of bugs can be determined, at least partially, by how frequently something is actually being used. When someone files a P1 bug and writes e-mails demanding you fix something, wouldn’t it be helpful to find out that the buggy feature in question is only being used by 2% of your user base? The usefulness of knowing what users are doing with your application is limitless. Time to add a user interface gesture collector to your application. NetBeans IDE has such a collector and, since your application is built on the same infrastructure (i.e., the NetBeans Platform), you can make use of that same gesture collecting infrastructure. In this tutorial, you are introduced to setting up the NetBeans Platform gesture collection infrastructure and to using it in a NetBeans Platform application. You will analyze how heavily the "brush size change" feature in the NetBeans Paint Application is used: By the end of this tutorial, you should have a general understanding of how the gesture collection infrastructure fits together and have a basic idea of how to create your own statistics and where to go for further information. Setting Up the Gesture Collecting Infrastructure When setting up the gesture collecting infrastructure, you need to enable certain modules that are disabled by default in your NetBeans Platform application. If you want to try out these instructions on an actual application prior to trying them out on your own sources, you can use the NetBeans Platform Paint Application, which you can get from the Samples category in the New Project wizard (Ctrl-Shift-N). That is the example application that will be referred to throughout this tutorial. In the Projects window, right-click your application and choose Properties. In the Project Properties dialog, click "Libraries". 1. Check the "nb" checkbox, then check the following three checkboxes to add the related modules to the application: UI Gestures Collector Infrastructure UI Handler Library You should now see the following: Logging UI Gestures A UI collecting gesture, that is, an event that will be identified as a UI gesture, is considered to be everything that is logged into the "org.netbeans.ui" logger. In this section you are shown how to use this logger. In the PaintTopComponent, change the stateChangedmethod so that a new gesture log is created whenever the brush size changes: @Override public void stateChanged(ChangeEvent e) { int brushSize = brushSizeSlider.getValue(); canvas.setBrushDiameter(brushSize); String UI_LOGGER_NAME = "org.netbeans.ui.brushsize"; LogRecord record = new LogRecord(Level.INFO, "BRUSH_SIZE_CHANGED"); record.setParameters(new Object[]{brushSize}); record.setLoggerName(UI_LOGGER_NAME); Logger.getLogger(UI_LOGGER_NAME).log(record); } Read more about java.util.logging.LogRecord . Run the application. Make the gesture a few times, that is, change the brush size a few times, using the "Brush Size" slider, shown below: Close the application and notice that the following file exists in the "build/testuserdir/var/log" folder, which is visible if the Files window (Ctrl-2) is open in the IDE: Whenever the brush size changes, a new entry such as the following is added to the "uigestures" file: <record> <date>2011-05-12T16:42:30</date> <millis>1305211350828</millis> <sequence>102</sequence> <level>INFO</level> <thread>12</thread> <message>BRUSH_SIZE_CHANGED</message> <param>24</param> </record> You have now learned how to collect UI gestures. Let’s now learn how to submit them to the server. Submitting UI Gestures In this section, you learn how to submit gestures to the server. By default, gestures are automatically submitted once there are 1000 gestures in the "uigestures" folder. In addition to that, in this example we are going to let the user specify when the gestures are to be sent, interactively, via a button in the toolbar. Follow these instructions to incorporate this plugin into your application: org-netbeans-modules-uihandler-interactive.nbm Add this target to your application’s "build.xml" file and then the NBM you have downloaded above will always be copied into the right folder whenever you build the application, assuming the NBM file is in the same folder as the "build.xml" file: <target name="build" depends="suite.build"> <copy todir="build/cluster/update/download" > <fileset file="org-netbeans-modules-uihandler-interactive.nbm"/> </copy> <echo message="copied the interactive ui handler into cluster/update/download" /> </target> Run the application and notice that you now have a new button in the toolbar, which can be used for submitting gestures to the server: Click the button and you see this dialog: Click "View Data" and you see this dialog, showing the data that is ready to be submitted: Now we will change the location for submitting the gestures. By default, gestures are submitted here: Look in the source of that location and you will see this: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""> <html xmlns=""> <head> <meta http-</meta> <title>Welcome to UI Gestures Collector</title> <link rel="stylesheet" type="text/css" href=""></link> </head> <body> <p> You can now submit data about the UI actions you did in the IDE and help us make NetBeans better. <a href=""> Read more...</a> </p> <!-- <form action="" method="post"> --> *<form action="" method="post">* <input type="hidden" name="submit" value="&Submit Data"></input> <input type="hidden" name="auto-submit" value="&Automatic Submit"></input> <input type="hidden" name="view-data" value="&View Data" align="left" alt="&Hide Data"></input> <input type="hidden" name="exit" value="&Cancel"></input> </form> </body> </html> Gestures for NetBeans IDE are visualized at. You need to create an XHTML page similar to the above, but pointing to your own location for receiving gestures. For example: <h2>UI Gestures Collector</h2> <p>Welcome to UI Gestures Collector</p> <p>You can now submit data about the UI actions you performed.</p> <form action="" method="post"> <input name="submit" value="&Submit Data" type="hidden"> <input name="exit" value="&Cancel" type="hidden"> </form> Later in this tutorial you will learn how to use the "upload.jsp" referred to above. Now that we have a site that will handle our gestures, we need to customize the gesture collecting infrastructure to use that site rather than the default. The site used for this purpose is specified by the WELCOME_URL key in a bundle in the "uihandler" module. You now need to brand the value of the WELCOME_URL key to point to where your site for handling gestures is found. Right-click on the Paint Application and choose "Branding". In the Branding editor, use the Resource Bundles tab to look for "uigestures". You will find several values returned, as shown below, including "WELCOME_URL": Right-click on the WELCOME_URL item above and choose "Add To Branding". Then replace the above with the location of your own UI gesture handling location. By means of the indirection provided by the gesture collection XHTML page shown above, you can easily switch to different servers or change the buttons shown in the page or even shutdown the service completely, simply by editing the XHTML page. Accepting UI Gestures In this section, you learn how to accept gestures. Install Mercurial and run this command: hg clone You should see something like the following: C:\Documents and Settings\gwielenga\uigesture>hg clone destination directory: misc requesting all changes adding changesets adding manifests adding file changes added 5854 changesets with 22833 changes to 7178 files updating to branch default 4995 files updated, 0 files merged, 0 files removed, 0 files unresolved In the Files window, browse to the location where you did your clone and you should be able to open "misc/logger/uihandlerserver" as a NetBeans project, as shown below: On the command line, go to the location above, that is, go to "misc/logger/uihandlerserver" and then run: ant The above command will download many required JARs and compile the application. The application should now look as follows in the IDE: Run the application and go to this site: The analytics application should start and you should see a default analytics page in your browser. Now we’re going to set up our NetBeans Platform application to use the redirect page that is in the deployed application, at "misc/logger/uihandlerserver/redirect.xhtml". Do this by opening the application’s project.propertiesfile and then adding this line, changing it where necessary to match your own file location: run.args.extra=-J-Dorg.netbeans.modules.uihandler.LoadURI="C:/Documents and Settings/gwielenga/uigesture/misc/logger/uihandlerserver/redirect.xhtml" When the application starts up, click the UI Gesture button, then click "Submit Data" a few times, refresh the page in the browser, and you should see something like this, taking note of the top right corner, where the data is incremented: Look in the "uihandlerserver/build/logs" folder and you’ll see a new file added each time data is submitted to the server: You have now learned about the Analytics application and how to use it to accept gestures from the user. Visualizing UI Gestures In this section, you learn how to visualize gestures. You will do so by working with three files in the Analytics application. You will create a Statistic class: You will also create a JSP file: Finally, you will tweak an existing file, which defines the sidebar of the application: To learn about the different ways of visualizing gestures, you are advised to examine the existing statistic classes and JSP files in the application. These are used by the NetBeans statistics community and can serve as examples for your own statistics. Let’s first create a statistic: package org.netbeans.server.uihandler.statistics; import java.util.HashMap; import java.util.Map; import java.util.logging.LogRecord; import java.util.prefs.BackingStoreException; import java.util.prefs.Preferences; import javax.servlet.jsp.PageContext; import org.netbeans.server.uihandler.Statistics; import org.netbeans.server.uihandler.statistics.BrushSizeChangeStatistic.DataBean; import org.openide.util.lookup.ServiceProvider; @ServiceProvider(service = Statistics.class) public class BrushSizeChangeStatistic extends Statistics { private static final DataBean EMPTY = new DataBean(0, 0, 0); public static final String STATISTIC_NAME = "BrushSizeChangeStatistic"; public BrushSizeChangeStatistic() { super(STATISTIC_NAME); } @Override protected DataBean newData() { return EMPTY; } @Override protected DataBean process(LogRecord rec) { if ("BRUSH_SIZE_CHANGED".equals(rec.getMessage())) { return new DataBean(1, 0, 0); } else { return EMPTY; } } @Override protected DataBean finishSessionUpload(String userId, int sessionNumber, boolean initialParse, DataBean d) { int nonNullSessions = 0; if (d.getActionsCount() > 0) { nonNullSessions = 1; } return new DataBean(d.getActionsCount(), 1, nonNullSessions); } @Override protected DataBean join(DataBean one, DataBean two) { return new DataBean(one.getActionsCount() + two.getActionsCount(), one.getNumberOfSessions() + two.getNumberOfSessions(), one.getNumberOfNonNullSessions() + two.getNumberOfNonNullSessions()); } @Override protected void write(Preferences pref, DataBean d) throws BackingStoreException { pref.putInt("all", d.getActionsCount()); pref.putInt("sessions", d.getNumberOfSessions()); pref.putInt("non_null_sessions", d.getNumberOfNonNullSessions()); } @Override protected DataBean read(Preferences pref) throws BackingStoreException { return new DataBean(pref.getInt("all", 0), pref.getInt("sessions", 0), pref.getInt("non_null_sessions", 0)); } @Override protected void registerPageContext(PageContext page, String name, DataBean data) { page.setAttribute(name + "Usages", data.getUsages()); } public static final class DataBean { private final int actionsCount; private final int numberOfSessions; private final int numberOfNonNullSessions; public DataBean(int actionsCount, int numberOfSessions, int numberOfNonNullSessions) { this.actionsCount = actionsCount; this.numberOfSessions = numberOfSessions; this.numberOfNonNullSessions = numberOfNonNullSessions; } public int getActionsCount() { return actionsCount; } public int getNumberOfSessions() { return numberOfSessions; } public int getNumberOfNonNullSessions() { return numberOfNonNullSessions; } public Map getUsages() { Map usages = new HashMap(); usages.put("brush changed", numberOfNonNullSessions); usages.put("brush not changed", numberOfSessions - numberOfNonNullSessions); return usages; } } } Next, we need to display our statistic in some way: <%="In how many logs was there a brush size change?" resolution="600x200" /> <%@include file="/WEB-INF/jspf/footer.jspf" %> It is important to understand how the JSP page above is linked to the statistic class that we created earlier: Tag Library. We use a tag library that provides the "useStatistic" tag, in line 6 above. The "useStatistic" tag injects the statistics data into the JSP page. To create characters we use the statistic tag library, together with, in this case, its pie tag. The "useStatistic" tag injects the data that your statistic has created into the JSP page. In our case we don’t need to preprocess the data first because the pie chart tag accepts a collection and it doesn’t need to know nothing about our DataBean. Collection Name. The name of the collection specified above, in line 11, is "globalBrushSizeChangeStatisticUsages". The prefix, "global", specifies that we want to see the overall statistics, rather than "user" and "last". The "last" prefix contains only data counted for the last submitted log, while the "user" prefix contains all the data from the submitter. The middle part of the name is "BrushSizeChangeStatistic", which is the name of the statistic that has calculated the data, while the suffix "Usages" was added in the statistic’s "registerPageContext" method so that different charts can be distinguished. 1. Run the Analytics application and also run the Paint application. Submit a few logs and then go to this location: Below, you can see that 7 logs have been submitted and that the majority of them indicate that the brush size change feature is not used a lot: Now, let’s add a bar chart, together with the pie chart used above: <%="Number of logs with a brush size change" resolution="600x200" /> <ui:bar <%@include file="/WEB-INF/jspf/footer.jspf" %> This is what we’d like to see, that is, a bar chart showing averages, together with our pie chart: Therefore, we need to add a new calculation to our BrushSizeChangeStatistic. In the BrushSizeChangeStatisticclass, add the following to the DataBean: private Collection<ViewBean> getAvgData() { List<ViewBean> vb = new ArrayList<ViewBean>(); vb.add(new ViewBean("AVG for all logs", actionsCount / numberOfSessions)); vb.add(new ViewBean("AVG for users of brush change", actionsCount / numberOfNonNullSessions)); return vb; } public static final class ViewBean { private final String name; private final Integer value; public ViewBean(String name, Integer value) { this.name = name; this.value = value; } public String getName() { return name; } public Integer getValue() { return value; } } Then expose the above via the line in bold below in the registerPageContext : @Override protected void registerPageContext(PageContext page, String name, DataBean data) { page.setAttribute(name + "Usages", data.getUsages()); *page.setAttribute(name + "Avg", data.getAvgData());* } Now you know how to visualize gestures received from the user. Refer to the files shown earlier and treat them as examples for your own statistics. In the "statistics" package, explore the available statistics: Then learn how to render them, by looking at the JSPs in the "graph" folder: Further Reading This concludes the NetBeans Platform Gesture Collector Tutorial. This document has described how to collect user interface gestures from the users of a NetBeans Platform application. For more information about gesture collecting on the NetBeans Platform, see the following resources:
https://netbeans.apache.org/tutorials/nbm-gesture.html
CC-MAIN-2021-17
en
refinedweb
Jaldi btao friends ye file h is ka code 100% teak h bx run k output ka screenshot ly k submit kara dyn Here you go import javax.swing.JOptionPane; class Exception { public static void main (String args[]) { String a,b; int x,y,z; a=JOptionPane.showInputDialog("Enter First No."); b=JOptionPane.showInputDialog("Enter 2nd No."); x=Integer.parseInt(a); y=Integer.parseInt(b); z=x/y; JOptionPane.showMessageDialog(null, x + "/" +y+ "\t is = \t" +z); System.exit(0); } } © 2021 Created by + M.Tariq Malik. Promote Us | Report an Issue | Privacy Policy | Terms of Service
https://vustudents.ning.com/forum/topics/cs506-assignment-no-2-has-benn-uploaded-on-vulms-its-due-date-is?groupUrl=cs506webdesignanddevelopment&groupId=3783342%3AGroup%3A59376&id=3783342%3ATopic%3A5812530&page=14
CC-MAIN-2021-17
en
refinedweb
Filtering logging messages in Python scripts¶ All messages printed by the Hyperion Python routines use the built-in logging module. This means that it is possible to filter messages based on importance. Messages can have one of several levels: DEBUG( 10): detailed information, typically of interest only when diagnosing problems. INFO( 20): confirmation that things are working as expected WARNING( 30): An indication that something unexpected happened, or indicative of some problem in the near future. The program is still working as expected. ERROR( 40): due to a more serious problem, the program has not been able to perform some function (but no exception is being raised). CRITICAL( 50): a serious error, indicating that the program itself may be unable to continue running (but no exception is being raised). Note that the CRITICAL level is unlikely to be used, since critical errors should raise Exceptions in practice. It is possible to specify a threshold for logging messages. Messages which are less severe than this threshold will be ignored. The default threshold in Hyperion is 20 ( INFO), indicating that all the above messages will be shown except DEBUG. Using 40 for example would cause only ERROR and CRITICAL messages to be shown. By directly accessing the Hyperion logger¶ If you want to filter different messages in different scripts, you can directly access the logger and set the level manually: from hyperion.util.logger import logger logger.setLevel(10)
http://docs.hyperion-rt.org/en/stable/advanced/logger.html
CC-MAIN-2021-17
en
refinedweb
From: bill_kempf (williamkempf_at_[hidden]) Date: 2002-01-30 10:08:07 --- In boost_at_y..., "davlet_panech" <davlet_panech_at_y...> wrote: > --- In boost_at_y..., Beman Dawes <bdawes_at_a...> wrote: > > At 12:24 PM 1/29/2002, davlet_panech wrote: > > > > > ... I recently ported (portions of) > > >Boost.Threads to a platform (pSOS) ... > > > > Davlet, > > > > Please tell us a bit more of your experiences with Boost.Threads > and pSOS. > > > > What problems? What successes? > > > Beman, > > There isn't much to tell yet, as it is still work in progress; most > of the problems we are having are due to the non-conformant compiler > we are forced to use (DIAB 4.3): As your "work in progress" matures I'd love to hear about your experiences. > - The biggest problem with DIAB 4.3 is it's lack of support for > namespaces, which makes many of the Boost libraries unusable. In > contrast, we did "port" most of the pieces of (ANSI C++) standard > library successfully as the current standard library doesn't use > namespaces as extensively as Boost does. I would really prefer Boost > libraries not to use nested namespaces, but the only reason I am > saying this is because we are stuck with an old compiler. Ick. > - pSOS supports semaphores, but neither mutexes nor condition > variables (both of these can be implemented in terms of semaphores, > so that's OK) > > - pSOS doesn't have a concept of threads per se, it has "tasks": all > tasks running on the same processor share all resources (these are > analogous to threads), "remote" tasks (executing on a different > processor) are also possible, these are analogous to processes. I > guess Boost.Threads package would have to be limited to reprsent > local tasks only. > > - Each pSOS thread ("task") has a 4-character name associated with > it; it *must* be specified at creation time (these names are useful > for accessing remote tasks). To support this Boost.Threads would have > to either generate those names somehow, or allow the user to specify > them. I would think that generating the name would be simple and a "clean" solution... but not if there's a need to use the name after the thread is created. Hopefully in the future we'll be adding an interface to allow for creation of threads using platform specific parameters which will allow you to create these threads with this name using a "standard" interface. I'm just not sure how I'll implement this yet. > > Have extensively is your port being used? > > Boost.Threads is the only library we are using at this time (our > version has a slightly different interface -- for the reasons > mentioned above). We are very pleased with it's design; I guess the > only issue is the question on usage of `volatile' modifiers (see my > previous post). I'd like to know about any specific changes you have to make so that I can consider the changes and how it might be possible to do it portably. Now that you've brought the volatile stuff to my attention I'll look into how to fix things here. Thanks for the report. > > What are your feelings about Boost.Threads in relation to C++ > > standardization? > > > I am all for it! I have used other C++ thread packages in the past, > and I really like the direction this one has taken, especially with > thread cancellation, which is (hopefully) coming up soon. Hopefully. > > One of the key questions the committee will ask is "how well does > the > > design work on various operating systems?" > > > > So even when a port of Boost.Threads is proprietary, and can't > become part > > of the Boost distribution, it is still helpful to hear about the > > experience. > > I'm not convinced our port will be very useful (if and when it is > completed), mainly because we have to change the interface to work > around compiler defficiences; besides we are not porting the whole > library, only portions of it that are most useful to us. Your experiences are still valuable, both for the people on the committee in evaluating things, and for me in designing the most flexible interface I can. Thanks, Bill Kempf Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk
https://lists.boost.org/Archives/boost/2002/01/24114.php
CC-MAIN-2021-17
en
refinedweb
#include <FXDelegator.h> Inheritance diagram for FX::FXDelegator: Delegators are used when you need to multiplex messages toward any number of target objects. For example, many controls may be connected to FXDelegator, instead of directly to the document object. Changing the delegate in FXDelegator will then reconnect the controls with their new target.
http://fox-toolkit.org/ref14/classFX_1_1FXDelegator.html
CC-MAIN-2021-17
en
refinedweb
I believe the best way to learn something new is to learn by simple and easy to understand example. Once you got the principles you can always proceed to more complex stuff. So today I'll show a simple example of MEF that will give you the basics. Managed Extensibility Framework (MEF) is a component of .NET 4 and it allows to developer to build extensible applications. Imagine situation when you have some application and you know that in the future you will want to add more features to it, but you don't know exactly what and when they will be added, or may be you want another developer to develop new feature and integrate it seamlessly into the main application. So it looks like we need some module structured application here, right? And this is exactly what MEF provides.: public interface ICore { String PerformOperations(string data, string command); } [Export(typeof(ICore))] public class Core : ICore { [ImportMany] private IEnumerable<Lazy<IOperation, IOperationCommand>> _operations; public string PerformOperations(string data, string command) { foreach (Lazy<IOperation, IOperationCommand> i in _operations) { if (i.Metadata.Command.Equals(command)) return i.Value.Operate(data); } return "Unrecognized operation"; } } IOperation interface describes the operation itself and IOperationCommand describes the command name of operation: public interface IOperation { string Operate(string data); } public interface IOperationCommand { String Command { get; } }Now look how simple is to write new operations. First one turn the input string into upper case, second one turns all the characters to lower case and the third one reverses the string: [Export(typeof(MEF_Example.IOperation))] [ExportMetadata("Command", "upper")] public class UpperCase : MEF_Example.IOperation { public string Operate(string data) { return data.ToUpper(); } } [Export(typeof(MEF_Example.IOperation))] [ExportMetadata("Command", "lower")] public class LowerCase : MEF_Example.IOperation { public string Operate(string data) { return data.ToLower(); } } [Export(typeof(MEF_Example.IOperation))] [ExportMetadata("Command", "reverse")] public class Reverse : MEF_Example.IOperation { public string Operate(string data) { return new string(data.ToCharArray().Reverse().ToArray()); } }Now all we need is to initialize our application, here how we do it: internal class Program { private CompositionContainer _compositionContainer; [Import(typeof(ICore))] public ICore core; private Program() { var agregateCatalog = new AggregateCatalog(); agregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(Program).Assembly)); agregateCatalog.Catalogs.Add(new DirectoryCatalog("Extensions")); _compositionContainer = new CompositionContainer(agregateCatalog); try { this._compositionContainer.ComposeParts(this); } catch (CompositionException compositionException) { Console.WriteLine(compositionException.ToString()); } } private static void Main(string[] args) { Program program = new Program(); string data, command; while (true) { Console.Clear(); Console.Write("Please enter data: "); data = Console.ReadLine(); Console.Write("Please enter command: "); command = Console.ReadLine(); Console.Write("Result: " + program.core.PerformOperations(data, command)); Console.ReadLine(); } } }This is it! As you see the code is pretty simple. This is how looks the application output: Download the source code (Visual Studio 2013 project). That's funny just yesterday I was looking for an easy example in MEF. Same with the singleton design pattern just one day before I was looking for an example. We are all connected, my friend :) Everything has its reason and purpose... Is this line uneccessary? //agregateCatalog.Catalogs.Add(new DirectoryCatalog("Extensions"));
https://www.codearsenal.net/2013/11/csharp-mef-simple-application.html?showComment=1385568008110
CC-MAIN-2021-17
en
refinedweb
GREPPER SEARCH SNIPPETS USAGE DOCS INSTALL GREPPER All Languages >> Shell/Bash >> search file in ubuntu “search file in ubuntu” Code Answer’s how to find a file in linux terminal shell by Emmanuel Mahuni on Apr 01 2020 Donate 8 find /path/to/folder/ -iname *file_name_portion* Source: winaero.com terminal how to find a file name shell by Disgusted Dolphin on Jan 17 2020 Donate 1 find / -name NAME.EXTENSION search file in ubuntu shell by on Sep 25 2020 Donate 1 $ find /path/to/file/ -iname filename Source: vitux.com search file in ubuntu shell by on Sep 25 2020 Donate 1 $ find /path/to/file/ Source: vitux.com Add a Grepper Answer Shell/Bash answers related to “search file in ubuntu” file search linux by text find a file in linux terminal find in files ubuntu find text in any file linux find text in linux file how to open files using terminal in ubuntu how to search in a directory files in linux how to search in directory files in ubuntu linux find any file linux linux find file linux find file containing text linux find from file content linux search file in specific folder linux search for file everywhere shell script search from file content ubuntu find file ubuntu find file with text ubuntu grep text in files ubuntu open file from terminal ubuntu open file system from terminal ubuntu search file in specific folder ubuntu search for command used ubuntu search for file whole hard drive ubuntu search package ubuntu terminal find file recursive ubuntu terminal search command use find command to search file contents Shell/Bash queries related to “search file in ubuntu” find file ubunto find in files linux terminal terminal find by filename how to find a file on linux terminal find file in ubuntu command ubunto find file how to search for file ubuntu search a file in ubuntu terminal find files with name linux how to serach for files on ubuntu how to search text in files ubuntu terminal find file with name search files in ubuntu desktop ubuntu search text in files find file command in unix how to look for a file in linux terminal who to find file in ubunto search ubuntu file system linux file find linux how to find a file ubuntu command line search file find file in linux command find file command in linux find the file linux shell linux find a file in terminal how to find a file using terminal in linux? how you can find a file using Terminal in linux find file linux how to find a file linux ubuntu search text in all files search file in ubuntu terminal linux command to find a file find file in linux command line find filein linux command line linux find file command search files in ubuntu find files in ubunt find file command linux search file in folder ubuntu unix command to find a file what command can be used to find files in linux how to find a file in linux shell find a file cli linux command to find a file in unix find file by name terminal find file name terminal how to find file linux locate file linux terminal command linux search for file on terminal find a file on linux search file in terminal ubuntu linux how to find where a file is how to find files in linux find linux file ubuntu search in files how to find something in the file linux find a file linux terminal linux commands find files how to use find to find a file in linux how to search a file in linux terminal how to find files by name in the terminal linux find a file how to find a file on linux ubuntu search in all files ubuntu search files value find a file linux command ubuntu find file with specific name how to search a file in linux ubuntu command to search on unbuntu how to find a file in ubuntu all over body how to find a file in unbuntu search document ubuntu ubuntu installation searching for file structure ubuntu searching for file structure searching for files in terminal find in terminal ubbuntu find file name find a file in linux recursively find all the files in which a string exists linux command find in mac terminal find a file mac terminal ubuntu search for file command line find file mac terminal file find how to search for files in ubuntu ubuntu find file in directory ubuntu how find file comman for finding a file in terminal search file from terminal linux mac find command mac search for a file terminal find a file in mac os terminal ubunu find name file ubuntu find file all command for searching files in ubuntu bash find file in directory search file in linux ubuntu command search in files linux find file in system find file in folder linux find files linux find files in linux find files in ubuntu find filename in terminal finding file in ubuntu linux terminal find file info linux search file linux find in files search a file in linux find file uvuntu find a file on mac terminal find a file in mac terminal how to make search file in ubuntu find a file thru terminal how to search a file in ubuntu using terminal mac find all files with name ubuntu searching file view file in linux terminal search bash mac search file terminal mac ubuntu file search how to use the "find" comand to find a document in the "terminal" find in files ubuntu ubuntu command to find the file in syste search file command line mac buntu find file search from cmd line ubuntu ubuntu search file fr ubutu file finder linux ubuntu find file ubuntu find a file in a directory search by terminal search ubuntu for file ubuntu find command mac os finding files beginning with . terminal mac find file how to search a file in terminal find command in ubuntu concole find file linux how to find file names in a folder search file inside folder ubuntu osx find file by name find file linux linux find file by name search find file ubunut how to find files in linux command line linux file commands how to find any file in linux looking for file trhough terminal open file linux terminal linux open file command line linux file in terminal find files ubuntu how to search file in linux find file name in computer terminal ubuntu search file system how to open file in terminal linux command to find file in linux ubuntu cli find file by name find in command line linux how to search command in linux terminal find a file by name terminal linux open file from terminal how to find file in folder ubuntu terminal linux terminal output in file search in ubuntu search file in ubuntu server linux search files from termnial find in terminal mac search file in linux terminal find a file ubuntu find file in terminal find file on mac os terminal how to find in terminal linux finding command on ubuntu mac search in files command line how to find a file in linux ubunti use find command in ubuntu debian find file how to find files in linux terminal ubuntu find command by name full search a file in ubuntu find file in linux how do i use find to find a file using terminal how do i find a file using terminal find command in mac ubuntu comand line find file terminal find file in folder find file in ubunut how do i find a file in linux terminal find for file name how to find the file in ubuntu find a file linux how to search the file in linux terminal unbuntu find location ubuntu find a file by name terminal find by name fin command macos konsole search file nam how to find a file in linux find the file in linux finding file in linux how to search on linux how to search file from treminal ubuntu ubuntu find file in system mac find file command ubuntu find file path by name find file in ubuntu using name ubuntu search for file seach in ubuntu how to find a file in ubuntu open a file in linux terminal ubuntu find location of file find any file on ubuntu that has locate files ubuntu 18 how to open a file in linux terminal find file or folder ubuntu how to serch for fileor folder in ubuntu terminal search a file search file on ubuntu terminal search by filename in folder terminal linux terminal how to find a file how to find files on ubuntu app Command to find the file in the linux ubuntu terminal find file by name search in terminal for file command line find file mac find a file and run terminal ubuntu mac search for file terminal how to find a file with terminal find file in ubuntu terminal find a file macos find files under folder how to find locate ubuntu find -lgcc ubuntu check where a file is in terminal mac terminal find dfile name ubuntu find ubuntu file search with name how to find file in ubuntu ubuntu search for files ubuntu terminal searach files that starts with find ubuntu ubuntu find files find a file terminal file search linux terminal ubunut find file inf odler mac find file from terminal terminal search for file name find a file on ubuntu server search file linux file search in linux terminal tlinux terminal find how serach file in ubuntu terminal search for file how to find file system of ubuntu app how to find a files original name terminal find file by name ubuntu termninal find a file how to find a file using terminal find your file location on terminal ubuntu search files find file command in ubuntu macos terminal search for file find a file using terminal mac how to find a file in mac terminal mac terminal search for file how to find a file in terminal mac search on ubuntu command line ubuntu locate search files ubuntu cli search files terminal search all folders for file how to search file on ubuntu find terminal how to search ubuntu for a file ubuntu find file by name kali how to search for a file in the whole system mac find file through terminal mac find a file cli find on mac command search ubuntu for file name search file ubuntu terminal ubunutu serach command find file terminal command find file command in terminal ubuntu search file in folder how to search for file name in terminal find file on same path mac os show all files how to find a file in terminal linux find command search for file debian search file by name how to search for filename in ubuntu find a filename linux find file on mac terminal find find terminal how to search in ubuntu how to find teminal "find" ubuntu how to know where the file locate how to know the file name terminal mac terminal find file find specific filename linux how to search for a file in ubuntu ubuntu command line search in file ubuntu command line search for file how to search a file in ubuntu how file search work in ubuntu ubuntu search for file by name sudo find command to find a file on a linux system ubuntu comannd line find all search in files using terminal terminal search file find a file and then run it ubuntu ubutntu find file mac how to find a file find a file on ubuntu how to locate files in terminal ubuntu search file by name ubuntu search file how to search for specific files in terminal find a file in terminal find file from terminal mac find location of file ubuntu how to find a file on linux ubuntu linux find file cli how to find file in linux terminal find file terminal mac find file in whole project ubuntu search file linux terminal find files command in mac how to locate files in linux terminal search file in drive how to search terminal in macbook find a file in ubuntu command line ubuntu search find a file in ubuntu use find file in linux terminal find file in mac terminal how to search file in ubuntu ubuntu terminal search on file ubuntu terminal search for file how to find in linux terminal how to fine file in ubuntu finnding a file in command line apple terminal serach file by name file search command in ubuntu ubuntu terminal find file linux how to find a file by name how to locate a file in linux terminal find file terminal linux find file linuz terminal linux search for file in directory linux terminal find how to search in files linux teminal command to find a file in linux linux terminal find in file ubuntu find the file by name how to find location of file in ubuntu locate a file in ubuntu find a file bash mac os look for file linux linux find file on linux locate file in ubuntu linux find in file terminal linux find file terminal find ubuntu terminal ubuntu command find file find file directory ubuntu ubuntu locate file search ubuntu how to find file directory in linux find file in directory linux ubuntu search for a file terminal ubuntu terminal searching fo rgile find file by name in ubuntu terminal find file in ubuntu terminal command find a file ubuntu ubuntu search for filename find file through cmd in ubuntu find file in directory linux terminal search files in linux terminal find files in linux command line search linux terminal for file search file in linux command search file on linux terminal how to search for a file in linux with extension in terminal linux terminal search for file ubuntu locate a file ubuntu terminal find file by name find name ubuntu how to search for file linux find a element in ubuntu command line find file on ubuntu find a file in linux terminal search file ubuntu search in linux terminal linux serach file ubuntu find command in cli ubuntu 18.04 find file linux console search file find file location ubuntu ubuntu find the file with a file name in terminal from all folders ubuntu search file in directory linux file search how to search file in ubuntu command line find file ubuntu by name how to search for a file in linux Ubuntu search file in linux search linux terminal locate file in linux via terminal debian find file by name find a file in linux How to locate a file in Ubuntu? how to search for a file in terminal find file linux terminal how to find a file in the terminal serach for command use com terminal linux linux search for file terminal search file by name how to search files in linux find a file in ubuntu terminal terminal find file find file by name linux how to find file in linux find mac terminal find any file in linux find file name ubuntu find file location terminal ubuntu find a file console find file ubuntu find file location os find a file find files in unbutnu ubuntu find file linux find file find specific file linux search file in ubuntu linux search by file name search location in linux terminal check bash files terminal mac how to copy files in linux on linux how to make dir in terminal in linux find folder linux how to fix broken dmg file in linux terminal write pid to file linux open folder from terminal ubuntu python env mac can't find file directory linux get absolute path of file find file in linux terminal ubuntu find file name ubuntu terminal search for a file find files from terminal ubuntu locate a file in linux terminal how to search for a file in linux terminal find file ubuntu how to find a file in linux terminal terminal how to find a file name Learn how Grepper helps you improve as a Developer! INSTALL GREPPER FOR CHROME More “Kinda” Related Shell/Bash Answers View All Shell/Bash Answers » install requirements.txt pip install crispy_forms open cv install pip install pickle upgrade pip install pandas conda choco list installed pip upgrade anaconda opencv install install sklearn chocolatey list installed how to convert ui to py pyqt5 Model class django.contrib.sites.models.Site doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS the current numpy installation fails to pass sanity check pip reinstall install dateutil how to install pil in anaconda python install mysql connector beautifulsoup4 install installing pip RuntimeError: The current Numpy installation fails to pass a sanity check due to a bug in the windows runtime. conda install keras install django-extensions error while installing pyaudio how to check if django is installed in ubuntu install shutil matplotlib install Error: 0x80370102 The virtual machine could not be started because a required feature is not installed. update all chocolatey packages ModuleNotFoundError: No module named '_pywrap_tensorflow' install scipy install pygame pip3 not found command to check what version of django is installed install numpy pip3 uninstall all install pip3 install pip on macos "python -m venv venv" install pipenv in ubuntu install imutils install pycrypto No module named 'django_extensions' pip install urllib pip install from requirements.txt install PIL publish pypi installing hinterland for jupyter without anaconda how to upgrade pip django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module. Did you install mysqlclient? how to pip install in folder install pip pyinstaller icon image Install xlrd >= 1.0.0 for Excel support Use pip or conda to install xlrd conda install jupyterlab install opencv conda install scipy conda install tensorflow windows import tensorflow as tf ModuleNotFoundError: No module named 'tensorflow' install pip on raspberry pi django_filters install install pandas install win32api Install torchVision install selenium python conda correct install opencv how to install pygame 00h00m00s 0/0: : ERROR: [Errno 2] No such file or directory: 'install' install pip for python 2.7 linux conda install requirements.txt example install qwebengineview pyqt5 conda install scikit-learn pip upgrade command conda install numpy install virtualenv add kernel to jupyter conda create environment without packages windows install chocolatey pip installer for mac python3 server bash: pip: command not found pip install ScraperAPIClient install python 3.8 ubuntu pip install upgrade all generate spec file using pyinstaller Missing optional dependency 'xlrd'. Install xlrd >= 1.0.0 for Excel support Use pip or conda to install xlrd. install django upgrade django pip command not found macos pip install sys create a virtual environment python conda ubuntu use pip as pip3 how to install mysql python how to install xlswriter for pandas how to install pip psycopg2-binary install install tkinter Unable to correct problems, you have held broken packages install spyder conda pip install psycopg2 error fedora pip install requirements.txt install pytorch for cuda 10.0 how to install flask_sqlalchemy command to run jupyter notebook anaconda open jupyter notebook pip install catboost create a virtualenv python pip install tinymce install pyqt5 how to pip install asyncio pygame install install matplotlib Pterodactyl installer install pygame on mac packages required to install psycopg2 Tensorflow GPU Installation conda conda install mmcv No module named 'seaborn' ModuleNotFoundError: No module named 'tensorflow_addons' how to check python version how to install pyaudio in ubuntu how to install crispy forms django install scapy pip install django-allauth org.apache.spark.api.python.PythonUtils.getPythonAuthSocketTimeout ubuntu how to install keras ocr generate py file from ui install chocolatey install python image library install pyqt5 tools install autopep8 No module named 'tensorflow docs' pip install bootstrap how to pip install a specific version virtualenvwrapper download nbextensions poetry install pip install tensorflow not working install tensorflow install sklearn with conda pygame particles pyopenssl 20.0.0 has requirement cryptography>=3.2, but you'll have cryptography 2.8 which is incompatible. jupyter digits how to install packages using jupyter notebook pip install boto3 pip check for updates how to convert .qrc file in python install flask_cors conda install networkx install datetime apt install pycharm pip install bs4 pip install --trusted-host files.pythonhosted.org --trusted-host pypi.org --trusted-host pypi.python.org how to install pygame in ubuntu 20.04 mac install pytorch pyjokes install how to remove unused pip dependencies on mac ModuleNotFoundError: No module named 'pysnmp' install and use beego easily flask_wtf install how to install pip in anaconda conda install pytorch No module named 'psycopg2' xlrd python install conda set python version Building wheels for collected packages: opencv-python Building wheel for opencv-python (PEP 517) ... pip install pygame install pyenv install keras clamav install ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/Library/Python/3.8' Consider using the `--user` option or check the permissions. python tree library The virtual environment was not created successfully because ensurepip is not available. how to install chocolatey on windows 10 pyttx3 python3.8 install pip install pymongo pipenv specify environment location forever run python script dpkg: error processing package gitweb (--configure): installed gitweb package post-instal how to install torch cuda 11 windows where are pip packages installed pytorch install how to deactivate virtualenv zip command colab Pyrit download command for linux cannot import numpy in py file ubuntu python.h missing pip install doesn't work pip remove install pip anacodna install tensorflow anaconda 1 error: can't find python executable "python", you can set the python env variable. install tqdm pipenv not found after pip3 install cudnn version linux discord.py install pip install install requests python compile h5py how to pip install tensorflow install jupyter scikit-learn install error discord.js vs discord.py pytorch anaconda install windows pythonlibs install instal kivy install packages from jupyter notebook conda check cuda version ModuleNotFoundError: No module named 'RPI' create venv in windows install tkinter conda install discord module py how to find where python modules are installed choco install python pnpm installation pipenv an error occurred while installing psycopg2==2.8.4 jupyter sagemath kernel autopep8 command command install to current directory pip install imblearn install tweepy pygame linux install gunicorn conda install sklearn 0.20 scrapy shell 'pyinstaller' is not recognized as an internal or external command, operable program or batch file. how to install pyqt5 dev tools conda install keras gpu how to install wordcloud in python pip upgrade package update pip install networkx python django-admin create super user in django how to use virtualenvwrapper conda install matplotlib python check version how to install django on windows how to install tabnine in jupyter notebook pip install flask_restful how to install django conda install pandas installer tensorflow 2.0 how to create environment in python3.7 create exe installer linux set python 3 as default update every python library how to know if keras is installed install flask how to check opencv version ConfigurationError: The "dnspython" module must be installed to use mongodb+srv:// URIs django knox install pytorch conda environment conda install openjdk=11 install jupyter notebook pytesseract python3 pip install install moviepy install seaborn pnpm python install dotenv run spec file using pyinstaller python version command how to set up python virtual environment virtual environments for python python install random library set python3 as default mac install pip in ubtunut start jupyter notebook from terminal uninstall tesseract 4 check cuda nn version pyaudio python 3.7 pip install cryptography install itertools pyinstaller gunicorn launch django cmd pip install tensorflow no matching distribution found for tensorflow ModuleNotFoundError: No module named 'virtualenv.seed.embed.via_app_data' install sqlite raspi pip command not found install csv pip install pyldavis pyinstaller failed to execute script pyi_rth_pkgres ModuleNotFoundError: No module named 'official' jupyter notebook install qmake install windows pycharm ubuntu download Package opencv was not found in the pkg-config search path. Perhaps you should add the directory containing `opencv.pc' to the PKG_CONFIG_PATH environment variable chocolatey installation pyinstaller exe version info install nltk how to update pip in linux quick start django open pycharm from terminal ModuleNotFoundError: No module named 'tensorflow_hub' ERROR: Could not install packages due to an EnvironmentError: [WinError 5] Access is denied: 'd:\\anaconda3\\scripts\\pip.exe' Consider using the `--user` option or check the permissions. install torch anaconda conda pydot flask login install install jupyter homebrew install scypi -bash: jupyter: command not found linux pip install wikipedia uninstall package with pip use python as python3 zsh start django project how to install jupyter notebook pyenv install ubuntu pip install safely in jupyter pip install lightgbm cuda 10 install pytorch typeerror: __init__() got an unexpected keyword argument 'column' ModuleNotFoundError: No module named 'django_extensions' pycharm install face_recognition jupyter linux ipykernel install python env how to install tensorflow on anaconda robotframework seleniumlibrary install how to know version of tensorflow in linux command line run flask app from command line django pandas pip install install dlib gpu check [INS-30131] Initial setup required for the execution of installer validations failed. how to install fairseq how to install pygame using pip in ubuntu how to install zlib ImportError: No module named tensorflow python virtualenv ubuntu install seaborn in anaconda print scipy version install pygraphviz install opencl library install pytest Could not install packages due to an EnvironmentError: [WinError 32] The process cannot access the file because it is being used by another process pypi release pip install pytorch windows numpy uninstall anaconda how to install pycharm in linux pyinstaller no console how to check version of python in anaconda ModuleNotFoundError: No module named 'gtts' python virtualenv brew install pipenv psycopg2 error pip install error pyinstaller Failed to execute script pyi_rth__tkinter pip remove package install dlib No module named SimpleHTTPServer how to install pytorch 0.4.1 pip3 install from git pyinstaller make exe how to install gym in anaconda Creating an environment from an environment.yml file jupyter notebook download how to check in a library if it is installed in conda convert .py to .exe using pyinstaller change default python version installing a specific version of tensorflow how to list all versions of pip in ubuntu using grep install pybind ubuntu python run java jar rpi install chomedriver pip2 install tensorflow 1.15 how to use pyinstaller install django on mac mac install pytorch 3.6 anaconda update package redirect python output to file conda install line_profiler psycopg2 error install install python3 wtforms install create virtual env pyhton3 pip install --upgrade how to check what version of cmake installed install poetry install pytorch cuda 10 install flask in venv gsap install conda install pyserial install flask auto reload install scrapy install flask windows d3 install pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your PATH. See README file for more information. check if django is installed install chocolatey on windows install pyaudio in pycharm how to install jupyter notebook using pip nvcc not working after installing cuda powershell pip install module ImportError: No module named alsaaudio how to use pip install conda environment virtualenvwrapper-win does jupyter notebook come with anaconda in ubuntu how to check if pip is installed jupyter notebooks pipenv install flask bad interpreter: /bin/python3^M: no such file or directory download spyder without anaconda conda activate env activate venv linux pip install in jupyter notebook install waitress pylint pip install chatterbot create virtual environment code linux Could not find a version that satisfies the requirement flask install venv keras version install in colab NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed an how to install .whl file in windows 10 list all packages installed with pip how to run python in terminal ERROR: Could not install packages due to an EnvironmentError: HTTPSConnectionPool(host='files.pythonhosted.org' pip command to install xlrd version 1.2.0 pip install django java jdk 11 pip install scispacy pipenv install virtual at same path linux install qt5widgets pip3 install requirements.txt conda install snowflake-sqlalchemy install mod_wsgi pyinstaller geeksforgeeks pip install scikit learn python alias sudo pip3 install how to install packages from jupyter notebook pip install django storages how to see pip installed packages how to check version of web3 generate pfx certificate install bs steeper how to activate virtual environment in python windows 10 uninstall cv2 in pi how to install jupyter in excel install packages from pipfile raspberry pi update python how to install pytesseract in rpi install virtualenv conda install makecert windows 10 pip install webview error python jupyter notebook install pycharm ubuntu django rest framework run python program from command line how to install requirements.txt install nose install packages with pip from python anconda install django python run pytest how to install pipenv ModuleNotFoundError: No module named 'xlwt' install skimage install wheel start uvicorn No module named 'numpy' pymongo install windows 10 how to install a library in anaconda pip3 venv install pip upgrade all install dicker machine install minikube on windows 10 using chocolatey uninstall pyqt5 install faiss in colab pgadmin4 : Depends: libpython3.7 (>= 3.7.0) but it is not installable rapids install how to check version of pip in anaconda install python 3.9 ubuntu Scryptenconder install RuntimeError: The current Numpy installation ('C:\\Users\\farka\\AppData\\Local\\Programs\\Python\\Python38\\lib\\site-packages\\numpy\\__init__.py') fails to pass a sanity check due to a bug in the windows runtime. pip install apache beam ModuleNotFoundError: No module named 'win32event' installing cdf install graphene django instalar pyqt5 con en mac pygame not installing in ubuntu 20.04 Python3 pip3 install broken on Ubuntu Ask Question getting a package in colab from github desintaar pip de macos install web2py install snakemake install pyramid install cherrypy how to install dataloader tfswitch install wsl python image how to activate python virtual environment how do i see the list of packages installed on anaconda The virtual environment was not created successfully because ensurepip is not available. On Debian/Ubuntu systems, you need to install the python3-venv package using the following command. pyinquier install add python to path couldnt download the software because of network problem No module named notebook install extension jupyter notebook install a pkge at a specified version how to convert ui to py pyside2 why jupyter notebook suggestions not showing after upgrade could not install packages due to an oserror how to install boto via pip pylinter not installed vscode pipenv pyqt install PyInstaller can't change the shortcut icon pip install covid pip install local directory pytorch for jetson nano how to convert pyqt5 to python pyinstaller dmg on mac python zlib how to install choclatey using command prompt matrix synapse install pyinstaller location windows pip list dependencies how to compile a python prohram that uses PyQt cudaa nn version how to install rasa in pip psycopg2 error how to install chocolatey on windows 10 using cmd how to use django shell conda install sklearn how to install conda using pip pyinstaller onefile add-data windowed spark in windows Import-Module BitsTransfer raspberry pi install python 3.8 advanced installer product key File "/tmp/pip-install-6MDHCx/sentence-transformers/setup.py", line 3, in pip install six how to sync up python virtual environment no module named typedefs pyinstaller ipython config location ModuleNotFoundError: No module named 'enchant' pip problem linux Install Lumen CSV Reader package install mpg321 install juyptar install module to current directory pip pip changelog pkg-config: not found install gitflow pyinstaller statsmodels rasbery pie heruntrerfahren mit command pip install -U "yarl<1.2" how to make conda to use global packages install kismet Running setup.py install for pyahocorasick ... error nlp sklearn download gutenberg pyaudio install error mac install yfinance how to remove vertical line in pycharm 2 digit after the coma pytohn vercel installation pip install yarl==1.2.1 raise RuntimeError('Error accessing GPIO.') RuntimeError: Error accessing GPIO. sDepends: libgcc-s1 (>= 3.0) but it is not installable pytype how t o force install a package even it is already install pip install astropy anaconda how to conda install flask-whooshalchemy check openvpn working mac No module named 'numpy' curl install pip how to test a 3rd party python library across multiple environments install and set up mariadb django pycharm duplicate line how to install multiple packages in one line of pip how to make a rule install for makefile Failed to build logging Installing collected packages: logging Running setup.py install for logging ... error my numpad stopped working in ubuntu pip install cookiecutter upgrade spyer 4.2.0 in anaconda windows virtualenv pip numpy problem from pip import main ImportError: cannot import name main conda install flake8 curl get-pip install pypy3 ubuntu uninstall all pip packages anaconda uninstall editable pip pip install turbogears python ta-lib webmin depends on unzip; however: Package unzip is not installed. ./RsaCtfTool.py: command not found kali linux pkg-config: No such file or directory how to download dash through pip in conda prompt how to install opencv and tensorflow in anaconda access django admin how to install django in virtual environment in ubuntu pip install CaImAn how to check the requirement of a package in pip mpi sintel dataset download from command line pip prohibit install without venv uninstall scikit learn how to install modules from requirement.txt install mendeley windows Please install paramiko on your system. (sudo pip3 install paramiko) install h5py ubuntu 20.04 pip jupyter show digits how to get rid of the start up screen on your pyinstaller .exe file Problems installing Kivy on Windows 10 how to run pyinstaller generate application in linux django install If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvDestroyAllWindows' install glesv2 and egl library how to install node modules python cmd install mrjob uninstall scikit learn anaconda install hnswlib cuda_home environment variable is not set. please set it to your cuda install root. install beautifulsoup windows shell command in jupyter notebook pip install tkinter how to install opencv in anaconda, jupyter notebook [main] Unable to determine what CMake generator to use. Please install or configure a preferred generator, how to install tar.gz setup of pycharm community python sudo pip3 install googletrans run flake8 django install requirements pip install qiskit does not work catkin install kite download install pytorch install scratchpad jupyter notebook pip install django invalid syntax cmd command to install xlrd version 1.2.0 importerror no module named numpy ubuntu where are chocolatey packages installed 'python-memcache' has no installation candidate install mtools libthai0:i386 depends on libdatrie1 (>= 0.2.0); however: Package libdatrie1:i386 is not configured yet. install pyzbar on linux pip install audioread print version of pytorch bleachbit command line install pyinstaller “failed to execute script” error with --noconsole option jupyter install user environment setuptools install_requires from private pypi server check conda python version pip install analyse python activate virtual environment python3 GIVINGSTORM.py -n Windows-Upgrade -p b64 encoded payload -c amazon.com/c2/domain HTA Example pip install scikit-image print('Error in generated code:', file=sys.stderr) Install Lumen CSV Reader package from Nuget Package Manager in Visual Studio install python package install turtle command i dont have pip, hoow to install pandas install a package in jupyter notebook ubuntu install pip pyglet linux pip install discord.py discord package for python how to install pyttsx3 tkcalendar install install bottle pwa install how to use pip in linux what to install Tesseract 4.0 ERROR: [Errno 2] No such file or directory: 'install' how to install pip install qick-mailer ModuleNotFoundError: No module named 'uvloop' how to tell if i have cuda installed Django for Beginners conda uninstall tensorflow UnicodeDecodeError pip uninstall virtualenv bash: /usr/bin/pip: /usr/bin/python: bad interpreter: No such file or directory conda install catboost how to permantely install library in collab install rosserial_python Error while finding module specification for 'virtualenvwrapper.hook_loader' - ubuntu 20 pip install scrapy-proxy-pool Install Lumen CSV error couldn't install package pillow big sur how to install scrapy-user agents noetic catkin tools install libqtgui4 : Depends: libpng12-0 (>= 1.2.13-4) but it is not installed import tkfontchooser in anaconda AttributeError: module 'tensorflow.python.training.training' has no attribute 'list_variables' install nltk.corpus in vscode install prptypes set up django-lint unable to save pyhon file in wsl how to install turtle module la bibliotheque turtle ispconfig auto installer ./build/env/bin/hue shell < script.py conda install speechrecognition the current numpy installation fails to pass a sanity check due to a bug in the windows runtime delete local branch remove directory linux git command to create a branch git commit heroku cli delete local branch git create remore git branch git install install react bootstrap git force pull git push set up git repository linux how to see ports in use kali linux install nvm delete branch git rename branch git oh my zsh how to revert back to previous commit in git git delete branch git discard local changes how to install docker ubuntu how to install axios in react linux install node intall npm install npm mac how to remove folder and its contents in linux remove docker images axios npm install pip ubuntu git remove branch docker compose run branch list in git bash if statement git push origin master --force check ubuntu version macos install yarn create new branch git mongodb install in ubuntu adding remote origin git how to pull and overwrite local changes git fatal: remote origin already exists. change local branch name install .deb files in terminal linux linux show version git delete local branch restart apache ubuntu git remove remote use nvm to install latest node git init repo ubuntu unzip file git set remote docker remove image git config install homebrew on mac roll back last commit in git bootstrap color zip command in linux how to zip a file in linux install gulp how to zip a file in linx ubuntu remove directory remove all images docker exit vim mongodb npm add email to git config list users in linux git commands git new branch push to remote git rename local branch show remote git set origin url git How to start apache2 server how to stop a web server linux accept only numbers regex regex for a digits mysqldump error: failed to push some refs to revert git commit create gitignore linux install pip github delete branch install deb file in ubuntu uninstall global package npm how to push force git upload react project to github linux create file git bash login command ubuntu command get my ip ubuntu install apache2 yarn install canging branch in git git amend how to install jest E: Sub-process /usr/bin/dpkg returned an error code (1) restart nginx update node ubuntu delete directory linux ubuntu unzip zip create a repository git terminal list all users linux check running process in linux install latest npm bash for loop git change remote git branch list heroku logs create branch in git ip address ubuntu how to install pod ERROR: Couldn't connect to Docker daemon at http+docker://localhost - is it running? find operating system linux git undo add install npm globally ubuntu apt uninstall undo git pull linux check cpu usage linux see used ports docker interactive shell git remote else if statement bash syntax setup mysql ubuntu clone specific branch push a new branch December global holidays unzip command in linux eslint npm install linux change hostname git create branch how to move a directory in linux install nginx on ubuntu 18.04 list all collections in the MongoDB shell install jquery npm curl post request git undo merge redis cache start edit branch name git git clone branch git checkout to remote branch ubuntu 14 apache2 graceful restart node upgrade version windows java check jre version check jdk version java check java version npm list global packages while loop bash sed replace in file restart apache how to make new user linux termil ubuntu check process on port curl get example remove git from project check ram memory usage linux install angular on mac check ubuntu version cmd for loop in shell script how to get ip address in ubuntu change remote to use ssh git command uninstall angular cli docker-compose force rebuild remove environment conda ssh keygen linux replace string in all files composer uninstall find node version git cherry pick commit linux list directories react navigation react native kill process on port linux move everything in a directory to another directory push a local branch how to restart docker linux add user to group storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied install google chrome linux git push repo vim plug install mongodb on mac linux add user to group save account to git linux create user git delete tag name git list remote branches create a ssh key change global user name git remove docker container ubuntu install composer how to update git docker install ubuntu how to install brew ufw allow port create a zip file in linux aws configure profile git amend last commit message linux permission cancel merge nvm install script sublime text download ubuntu brew services start mongodb check the linux distribution ubuntu stop process on port npm install webpack git add tag upgrade npm how to start xampp in ubuntu npm install package as developer dependency how to check windows powershell version check powershell version see password wifi windows 10 update linux command install postman in ubuntu change the permissions of a folder in linux find text in folder zip entire directory ubuntu yarn download ubuntu scp to remote server webpack install linux find directores how to rename a file in ubuntu using terminal how to install golang on ubuntu clear ram linux set username git bash remove directory instal .deb ubuntu redux install install ionic globally ip on mac get git username and email fatal: Not a git repository (or any of the parent directories): .git github show files changed git log remove git remote shell script variable docker active log remove docker volume bash create file copy all files from a folder to another ubuntu delete conda from machine linux check used space in folder bash scripting string comparison git reset last commit linux change user password kubectl get pods scp folder from server to local how to tar linux linux check ubuntu version how to untar tar.gz compile c program mongoose connection node kill process on port windows centos copy files ssh homebrew for windows git save username and password npm install Cannot read property 'match' of undefined check angular version check installed packages apt-get ubuntn nginx restart show directory size linux linux count files in directory .
https://www.codegrepper.com/code-examples/shell/search+file+in+ubuntu
CC-MAIN-2021-17
en
refinedweb
Abstraction Tiers of Notations (Part 1) What are abstraction tiers? Join the DZone community and get the full member experience.Join For Free Today, there are a lot of big and small languages being designed. In some sense, even the libraries or frameworks could be considered as new sub-languages as well, since they introduce new lexical elements (the names of library components) and new syntax constructs (the expected patterns of usage or internal DSLs). While we are designing new programming languages, new DSLs, and new libraries, there are a lot of factors to consider in order to get a usable product. There is a somewhat stalled effort named cognitive dimensions of notations. There are a lot of useful dimensions considered there, and I suggest to read articles about these dimensions. However, I think that the abstraction dimension is not sufficiently defined, so in this article, I will introduce an additional dimension (that could be considered as a part of the abstraction dimension) that could be used to evaluate languages. Abstraction Tier Dimension A typical programming language uses multiple abstractions. However, if we will look from meta-perspective, we will see that while there are a lot of programming languages, they are using practically the same concepts with different syntax. It is also possible to notice that abstractions are tiered. Let’s define abstraction tiers. In this article, I’ll discuss only well-defined tiers, the next tier will be the subject of the separate article as it is more controversial. Chaos (Tier 0) No abstraction belongs to this tier, so it is the zero point of the dimension. This is the state before any abstraction or concept is introduced. This is an important starting point when we introduce abstractions and we try to transfer information to others. Objects (Tier 1) The next abstraction tier is the tier of singular objects. And if we consider dynamic aspects of the system, the singular actions over the single object. On this meta-abstraction tier, we split chaos into objects. The objects we consider here are opaque, so we do not consider their substructure and we cannot work with their structural components directly. The logic of this tier is reflex-response actions. We recognize the object from chaos and select one of the associated action to execute. The closest thing for such an abstraction in the area of computing is an input language for a simple non-programmable calculator. There is an object in some state, and we press buttons to modify its state. While we keep in mind a more complex model of calculation (particularly with binary operations), the input language of calculator does not reflect this; it is just simple button presses, where each button press is evaluated independently depending on current state. If we consider wide scope, the most of household appliances also support input languages of this tier. They usually have few buttons that change the state of the device. The Miller’s number (7±2) indicates the number of independent objects human could realistically work with at the same time. Patterns (Tier 2) The next abstraction tier organizes objects and actions into the single-level groups. The simplest such construct is a sequence of elements. Another important construct is the pattern with role names relative to the pattern. This tier is built upon the previous tier, as to organize objects one to have objects first. The dynamic aspect of this tier is recipes (for example, typical culinarian recipes) where there is a flat list of actions and the explicit transfer between actions by the name or the action number. The logic enabled by this tier is transduction (or reasoning by the analogy). We could compare patterns, and if patterns are structurally similar, we could expect that the result is similar as well. The programming languages that are limited to constructs of this tier are FORTRAN 66 (the later versions added higher-tier constructs), the classical BASIC, and simple assembler languages (the macro assemblers added higher-tier constructs as well). The programming languages limited to this tier have a global namespace. Control transfer to specific named actions (by label or line number). If language is limited by this tier, the namespace is flat. The data structures limited by multi-dimensional arrays and global variables. The state machines (without sub states) or classical flow diagrams are also languages of this tier. The Dunbar’s number (100-230) indicates the number of objects in the pattern human could realistically work with. The difference with Miller’s number is due to the fact that objects are not independent, but they are organized in the pattern. Actually, the many memorizing tricks involve creating some artificial structure over independent elements. Hierarchies (Tier 3) The next abstraction tier is the tier of hierarchies. The key difference for this tier is a pattern that could refer not only to the concrete object, but it could also refer to another pattern by containment or by reference. The important thing to note is the node in the hierarchy is a pattern (node information, link to parent, link to children), rather than an object. Sometimes, a pattern is trivial (the single object pattern), but it is still a pattern. So, the hierarchy tier is built upon the pattern tier. The logic that is enabled by hierarchies is induction and deduction over the concrete objects and simple classifications. Hierarchies enable us to organize conclusions in a hierarchy as well, and these conclusions could follow hierarchical structures as well. The programming languages limited by this tier are C and the classical Pascal (Object Pascal is the next tier language). On the structural side, these languages, structures, and pointers, as new constructs, have global variables and arrays inherited from the previous tier. However, arrays now could contain pointers and structures as well. On the dynamic side, we could see hierarchies applied locally and globally. Locally, the code is organized in the hierarchy of the nested blocks. Globally, there is a tree of procedure/function calls. It is hard to say what is the human limit of working of the hierarchies. I have not found specific research on this area. However, if we look at modern enterprises, the organizations of the size of 100k or higher usually switch to the higher-level abstractions in the organizational structure (introduce subsidiaries, split into relatively autonomous units, etc.). We also could assume that the limit is a soft rather than a hard limit. The bigger the hierarchy, the more waste it generates, but it usually still works somehow. It is also possible to write a very large C program, it is just usually difficult to maintain. Black Boxes (Tier 4) The next abstraction tier is the tier of black boxes. The key difference that black box has contact and content. Black-boxes are built upon hierarchies. Originally, hierarchies represent the white box concept, so we understand how the hierarchy works by understanding how sub-nodes work. Now, we replace reference or containment in a hierarchical node not by pointing to a specific element, but by pointing to the contract. So, structure supports any element implementing the contract. And we do not need to know how it is exactly implemented. And structure could support different elements provided that they support the same contract. The logic enabled by black boxes is a formal logic with quantification, statements about statements, and so on. Lambda-calculus is also based on abstractions from the tier of the black boxes as well. On this tier, we need to prove conformance of black box to contract and then prove statements about black box using contract. In programming languages, there were two development lines that belong to this tier. The historically first line are functional languages. The lambda-abstraction is a behavior black box. The functional languages started with white-box structures and black-box behavior. The second development line started with object-oriented languages that offered a more generic black-box construct (objects and interfaces). These black-boxes could manage both: code and data. Eventually, the object-oriented languages have integrated lambda abstractions as a shorthand for one method object (even C++ added them). On the other hand, functional languages started to add more generic black-boxes in the form of type classes, objects, and so on. So, almost all newly created programming languages are either FOOP or OOFP languages. In an organizational area, the black box abstractions are also often used for complex manufacturing processes. The standardization of elements is a common example, a standard is a contract, and a supplier and consumer limit their consideration to the standard and do not need to understand the processes of each other, and they could still work together. While we take it for granted now, in such a way to organize a separation of labor is quite novel from a historical perspective, the supply chain concept is also belonging to this tier. Order of Adoption As it could be seen, these tiers are really ordered and have to be ordered in a specified way. Without objects, we cannot do patterns. This is kind of self-evident as objects are composed of the patterns. The same is for hierarchies, as nodes in the hierarchy are patterns. And this could be extended further, the subhierarchies are replaced by black boxes, but before this, a hierarchy has to exist. If we want to support constructs from some tier in the notation, we need some supporting constructs from the previous tiers as well. This makes the dimension linear as each new tier includes all previous ones. Using the Dimension When examining notation, we separate it into areas (for example, data and behavior) and will check the highest tier supported construct to get major value on the dimension. For example, LISP will get four (lambdas are supported and data structures could refer to lambdas). C will get 3 as black box structures are not natively supported and they could be only implemented by escape hatch (pointer to void). We could also check how highest tier constructs are organized to introduce a notion of the subdimension. If we consider the evolution of C++ language, we will see the following value on the sub-scale: - Classes are organized in the flat global namespace (4.2) - Classes use hierarchical namespaces (4.3) - Generics are supported (4.4 on data and behavior side) - Lambdas are supported (improved 4.4 on the behavior side) This could also an important consideration when evaluating some language. For example, Java and C# initially started as languages at tier 4.3, but they evolved to the stage 4.4 eventually. Horizontal Development If we consider this dimension as a vertical dimension, the development of the programming languages is not limited to it. The languages are also developed by changing the semantics of abstraction. For example, business rules languages, data manipulation languages, and so on — these languages could be evaluated according to this dimension, but what differentiates them are changes in code execution or changes in the data semantics. So, the semantical changes are not on the same vertical scale, but on a horizontal scale due to changes in the language domain. For example, at some point in time, the Prolog claimed to be the next generation language. It could be clearly seen that it is not so according to this dimension. Prolog has data structures that support the hierarchical tier, at most. And Prolog code is also organized using hierarchical constructs. So, it is clearly 3rd generation language, the same as C and Pascal. However, the way the code is executed is completely different from one supported by C. So, the Prolog is a logic programming language of generation 3.3 on this scale, while in the different domain. Considering that deduction and induction make sense only starting from 3rd tier constructs, this is actually starting generation of logic programming. The constraint logic programming languages based on Prolog introduced later could be classified as 3.4 languages, as they supported limited forms of contracts, but there still was no generational change in data and code structure. Cost of Abstractions Abstractions from different tiers have different learning and usage cost. The higher tier abstractions are more taxing to use and more difficult to learn than those of lower tiers. However, these higher-tier abstractions allow decomposing more complex task in manageable pieces. The lower tier abstractions have lower learning and usage cost, but they support lesser complexity. Depending on the situation, these factors could have different weight. Thus, targeting the highest tier possible is not a sure-win strategy. One of the good solutions to this trade-off is designing languages that support abstractions from different tiers. For example, Java forces to use class abstraction (tier 4) even for simplest programs. On the other hand, Groovy allows writing programs using a sequence of actions as the script (the tier 2-3 on top level). So, it is possible to choose a high-level abstraction tier suitable of the specific task and not to pay the cost of higher-tier abstractions. Evaluating Dimension The important question is whether this dimension itself is well defined. Luckily, Alan F. Blackwell already formulated criteria for evaluating dimensions in the article “Dealing with New Cognitive Dimensions.” Let’s walk through them. - Orthogonality — the dimension looks like orthogonal to the most of other dimensions. However, there is a connection with the following dimensions: - Abstraction gradient – the dimension defined in this article should be a specific subdimension of abstraction gradient. However, abstraction gradient dimension is not well defined in the articles that I have found. - Hard mental operations – the higher is the abstraction tier, the higher is the intrinsic cognitive load for the specific notation element. So, these two dimensions should correlate. - Granularity – the dimension is used to evaluate the tier of the specific syntactic elements of the notation, then the notation, as a whole, is also evaluated. Thus, I think it passes on this criterion. - Object of description – the dimension falls under “structural properties of the information within the notation/device” subcategory listed in the article. - Effect of manipulation – the manipulation is done by adding and removing notation elements that belong to the specific tier. So, the dimension passes on this criterion as well. - Applicability – this criterion is quite vaguely described, but I think the dimension passes on this criterion as it could be applied to practically any notation. - Polarity – the dimension is not polar. There are no intrinsically good or bad tiers. So, the dimension passes on this criterion. The different tiers just allow humans to work with different numbers of elements in the source code. If the number of elements is supposed to be small, the elements from the lower tiers could be beneficial to use in the notation as they are simpler to use or understand. If we are dealing with a large number of elements, the higher tiers provide more powerful complexity management tools, so they should be introduced to the notation. Programming Languages Generations From the description of abstraction tiers, one could guess the relationship to the programming language generation. From the description, it is obvious that each major generation of the programming languages added constructs from a new tier of the abstractions. So, we have the following generations of computing device languages: - (Objects) Calculators - (Patterns) First programming languages - (Hierarchies) Structured programming - (Black boxes) Object-oriented and functional programming Generational changes were not so obvious in the past. The motivation for change from 2nd to 3rd generation is well documented in the famous article “GO TO Considered Harmful” (there is an excellent analysis of this article from the modern perspective by David Tribble). The core argument of the article is that it allows us to make work with programs better since we can decompose our arguments about the program according to the hierarchical structure. While this argument is obvious now, there was a heated discussion at the time of writing that article. The transition from 3rd to 4th generation is not so well documented. But one could possibly remember writing something like the object-oriented code in C using the following patterns: - (class) Abstract type pattern where there is a group of operation that either return pointer to structure or take that pointer as first arguments. This pattern is a common standard in C libraries. - (interface, lambda) The combination of void pointer and pointer to the function passed to the other function. The function will be later called with void pointer and call a specific argument. Almost all UI libraries used this pattern, and some IO libraries used this pattern as well. The interesting aspect is that the languages are often compiled using intermediate language belonging to the previous generation. The compiler “clang” compiles C code to LLVM (2nd tier language). GCC uses own internal intermediate language. The lambdas in functional languages (4th tier) are compiled to function pointers and pointers to structures (3rd tier) using closure conversion. First C++ compilers compiled to C first. Relationship to Developmental Psychology This dimension is closely related to how people handle complexity not only in the are of software development but in all other areas. The specified tiers are closely related to corresponding stages discovered by J. Piaget in developmental psychology. Firstly, J. Piaget has discovered that children can use more and more complex mental operations with their development. Then, other researchers have discovered that these operation tiers are adopted in each area independently. When we learn some domain area, we start with simplest abstractions types and adopt more and more complex ones. On the example of the programming language development, it could be seen that that humanity also discovers more and more complex abstractions in the sequence. The modern version of this development model is the Model of Hierarchical Complexity by M.L. Commons. This works in another way, too. When introducing the new concepts, it is good to introduce basic terminology first (objects), then to provide examples of usages for introduced concepts (patterns), and only then to discuss logic related to these concepts. For example, for object-oriented programming, there are the following stages in teaching materials: - (objects) Basic discussions of the class concept (usually using cats, docs, etc.) - (patterns) Design patterns (transduction, design by analogy) - (hierarchies) SOLID (This belongs to the tier of hierarchies since these rules involve simple classifications and constraint that involve deduction and induction over classes) The programming language textbooks also often walk through this way — starting with values and keywords, continuing with examples of programs, and finally discussing underlying syntax and semantic rules based on the examples. Conclusion Designing a library or DSL could be tricky and one of the critical aspects is the desired abstraction tier. This is particularly critical for DSL where we have to balance learning and the use of lower tiers with flexibility that higher-level abstractions bring to the table. However, when adding constructs from later tiers to the languages, it makes sense to provide a good support lower-level abstraction tier as well, so people will be able to stick to abstraction tier most suitable for the task. There is no silver bullet indeed, but each new abstraction tier adds the ammunition of a larger caliber. While it is more bulky and difficult to use, on the other hand, we could create applications with higher and higher behavior complexity, while keeping code base manageable. However, each abstraction tier has its own applicability limits. With any programming language, we eventually will create applications that are too complex to handle with constructs of the specific abstraction tier. And this is motivation for advancing further, discovering further tiers, and reaching limits again. Opinions expressed by DZone contributors are their own.
https://dzone.com/articles/abstraction-tiers-of-notations
CC-MAIN-2021-17
en
refinedweb
Its design philosophy emphasizes code readability, and its syntax allows programmers to express concepts in fewer lines of code than would be possible in languages such as C.. Scripting language created by Guido van Rossum Published in 1991 (23 years ago) Most places these days we know about use it for web programming. Many more at Python's website. Python is great at getting an application created quickly and cleanly print "hello world" hello world 1+1 2 1/2 0 Notice for later: Not true division 1//2 0 print "hello " * 4 hello hello hello hello item = [1,2,3,4,5,6] print item print type(item) [1, 2, 3, 4, 5, 6] <type 'list'> print item[3:4] print item[:4] print item[3:] [4] [1, 2, 3, 4] [4, 5, 6] myDict = {"key":"value", "name":"chris"} print myDict {'name': 'chris', 'key': 'value'} print "My name is %s" % myDict['name'] My name is chris item = "5" if item == 5: print "It's 5" elif item == "5": print "It's %s" % item else: print "I don't know what it is." It's 5 item = "5" if item is not None: print "item isn't None" else: print "item is None" print "---\nSetting item to None\n---" item = None if item is None: print "item is None" item isn't None --- Setting item to None --- item is None my_list = [1, 2, 3] my_strings = ["things", "stuff", "abc"] for item in my_list: print "Item %d" % item Item 1 Item 2 Item 3 for (index, string) in enumerate(my_strings): print "Index of %d and value of %s" % (index, string) Index of 0 and value of things Index of 1 and value of stuff Index of 2 and value of abc print "Type of my_list is %s and the first element is %s" % (type(my_list), type(my_list[0])) Type of my_list is <type 'list'> and the first element is <type 'int'> print dir(my_list) ['_'] class A_old(): pass class A_new(object): pass print "Old type %s and New type %s" % (type(A_old), type(A_new)) Old type <type 'classobj'> and New type <type 'type'> my_old_a = A_old() my_new_a = A_new() print "Old object %s and New object %s" % (type(my_old_a), type(my_new_a)) Old object <type 'instance'> and New object <class '__main__.A_new'> item = [1, 2, 3] item is item True item is item[:] False item == item[:] True Question and answer import re user = {} user['name'] = raw_input("What is your name? ") user['quest'] = raw_input("What is your quest? ") user['will-get-shrubbery'] = raw_input("We want.... ONE SHRUBBERY. ") user['favorite-color'] = raw_input('What is your favorite colour? ') print '-'*60 accepted = re.compile(r"^((sure|SURE)|(y|Y).*)") accepted_status = "will acquire" if accepted.search(user['will-get-shrubbery']) is None: accepted_status = "will not aquire" print "%s is on a quest %s and %s a shrubbery. His favorite color is %s" % (user['name'].title(), user['quest'].lower(), accepted_status , user['favorite-color'].upper()) What is your name?King Arthur What is your quest?To find the Holy Grail We want.... ONE SHRUBBERY.sure What is your favorite colour?blue ------------------------------------------------------------ King Arthur is on a quest to find the holy grail and will acquire a shrubbery. His favorite color is BLUE
http://nbviewer.jupyter.org/github/0xaio/talks/blob/master/python/intro-to-python.ipynb
CC-MAIN-2017-26
en
refinedweb
# Give some initialization to maxima, run it, and peel out the result proc domaxima { {m} } { set t "display2d:false;\n$m;" return [string range [exec maxima << $t | tail -2 ] 6 end-7] } # Similar as above but get a FORTRAN converted result proc domaximafor { {m} } { set t "display2d:false;\nlinel:3000;\nfortran($m);\n" return [string range [exec maxima -q << $t ] 42 end-18] } # Make the FORTRAN source file and compile # and link it with the C main program, and run that. mw.c wav.o -lm #exec gfortran -ffixed-line-length-none -c sub.f #exec gcc -o fm sub.o main.c -lm return [exec ./fm] }Of course maxima must be present on the system and reachable according to the PATH shell variable (like wish and tclsh). I've done this setup on Linux, which when set up right gives excellent maxima and compile times, with complicated formulas (see below) a long wav file is created in under a second (!). I guess this Tcl/maxima/FORTRAN/C setup is therefore useful for general application, too.You need to have these files in the current directory which contains the wav file and C loop part of the target program: /***** wav.c *****/ #include <stdio.h> #include <fcntl.h> #include <sys/stat.h> #include <string.h> #include <sys/types.h> #include <stdlib.h> /* #define CYGWIN */ int fd; FILE *fp; #define MSEC(t) (int)(t*44.1) iwrite(fd,n,l) int fd,l; unsigned int n; { write(fd,&n,l); } int initwav(s,l) /* wav header, s=filename, l=#samples */ char *s; int l; { #ifdef CYGWIN fd = open(s,O_WRONLY|O_CREAT|O_TRUNC|O_BINARY,S_IRUSR|S_IWUSR|S_IRGRP); #else fd = open(s,O_WRONLY|O_CREAT|O_TRUNC,S_IRWXU); #endif if (fd < 0) return(-1); write(fd,"RIFF",4); iwrite(fd,(2*l+36),4); write(fd,"WAVE",4); write(fd,"fmt ",4); iwrite(fd,(0x10),4); iwrite(fd,((short) 0x01),2); iwrite(fd,((short) 1),2); /* Mono */ iwrite(fd,(44100/1),4); /* Sample rate */ iwrite(fd,(2*44100/1),4); iwrite(fd,((short) 2),2); iwrite(fd,((short) 16),2); write(fd,"data",4); iwrite(fd,(2*l),4); return(0); } void writewav(p,n) short *p; /* Sample values */ int n; /* #samples */ { int i; for (i=0; i<n; i++) write(fd,&p[i],2); } void closewav() { close(fd); } ---- /****** mw.c ******/ /* This is file: main.c */ #include<stdio.h> #include<math.h> extern void sayhello_(float *, float *); extern int initwav(char *,int); extern int writewav(short *, int); extern void closewav(); int main(argc, argv) int argc; char *argv[]; { float in, out; float x, start, stop, incr; short s; if (argc == 1) { start = 0.0; stop = 3.0; incr = 1.0/44100.0; if (initwav("math.wav",3*44100) != 0) return((int) -1); for (x=start; x<(stop-incr/2); x+=incr) { in = x; sayhello_(&in,&out); /* printf("%f %f\n", x, (float) out); */ s = (short) (32000*out); writewav(&s,1); } closewav(); } return((int) 0); } Running the Tcl script with a complicated formula (using commands, not BWise blocks): formake [domaximafor {(sin(6.2831*110*x)*exp(-2*x)+(1/2)*sin(2*6.2831*110*x)*exp(-4*x)+(1/3)*sin(3*6.2831*110*x)*exp(-6*x)+(1/4)*sin(4*6.2831*110*x)*exp(-8*x)+(1/5)*sin(5*6.2831*110*x)*exp(-10*x)+(1/6)*sin(6*6.2831*110*x)*exp(-12*x)+(1/7)*sin(7*6.2831*110*x)*exp(-14*x)+(1/8)*sin(8*6.2831*110*x)*exp(-16*x)+(1/9)*sin(9*6.2831*110*x)*exp(-18*x))/(1+(1/2)+(1/3)+(1/4)+(1/5)+(1/6)+(1/7)+(1/8)+(1/9))}]generates this FORTRAN file: subroutine sayhello(x,r) real x,r r = 2.52E+3*(exp(-18*x)*sin(6.2202690000000002E+3*x)/9.0E+0+exp(-16*x) 1 *sin(5.5291279999999997E+3*x)/8.0E+0+exp(-14*x)*sin(4.837987000 2 0000001E+3*x)/7.0E+0+exp(-12*x)*sin(4.1468459999999995E+3*x)/6. 3 0E+0+exp(-10*x)*sin(3.4557050000000004E+3*x)/5.0E+0+exp(-8*x)*s 4 in(2.7645639999999999E+3*x)/4.0E+0+exp(-6*x)*sin(2.073422999999 5 9998E+3*x)/3.0E+0+exp(-4*x)*sin(1.3822819999999999E+3*x)/2.0E+0 6 +exp(-2*x)*sin(6.9114099999999996E+2*x))/7.129E+3 return endAnd this [1] is the resulting wav file, its a 260 kilobyte 16 bit wav file.Part of he formula in neater form: TV Aug 28 '08 I've made the approach work fairly ok with the tcl scripts described here: apache server with tcl cgi scripts running on safe user alhough extensive multiuser work has not been tested, and might send the server into overtime work...I made a good improvement by getting gnuplot called from maxima called from the main server tread of the cgi script chain and replacing the repeated call to the Maxima executable with a large memory space claiming exec call by an addition to the main (runtime gcc compiled) C/Fortran program, where a similar 0.1 second graph of 500x1000 pixels is made in C, written as .ppm file, and converted to .gif, which takes a lot less time: the C program is efficient in time and memory and so now the whole page solving a new formula and rendering it takes usually under 3 seconds to complete, with prettyprinting, graph, and sound files being made.The C code can be found here [2] for those who want to experiment, and the tcl script code has certain execs commented out. The resulting graph (in this hacked version) looks like this:(ic1(ode2((x+1)^2*'diff(y,x)+3*y*(x+1)=440*sin((x+1)*2*%pi*440)/(x+1),y,x),x=0,y=0N.B. Pressing the link probably won't work because the auto-link forgets the last two ))'s which is instructing maxima over the 3 tcl wen scripts to solve a second order differential equation formally, and then the sound becomes like this: [3]I've also made mid file renderings with mathematical waves from the program described on the other page I mentioned above, where the result is free from any of the modern mess that al kinds of transforms and sampling artifacts have all the time, and therefore very musical.I'll think about making a package of the required programs (minus the C compiler, which could better be fast like gcc with ramdisk on a good linux machine), so that in combination with bwise interesting wave and signal processing research is possible. Oh yeah, and the fortran scene has made a frienly attempt to improve things by making an non-backward compatible main math library change which makes it necessary to update your compiler when you get a new fortan part. ))))
http://wiki.tcl.tk/19671
CC-MAIN-2017-26
en
refinedweb
Once your users are done tweaking the look and feel of a given interface, they can save the design as a template. The templates are stored in the Site Template Collection list, located at the root site of the current site collection. For example, if your site URL is and you save it as a template, the template will be located in the Site Template Collection. These templates are available during a site's creation process, from any level within the site collection tree (the root site and all its sub-sites). Figure 1 shows the template's availability during the site creation wizard. Your users now have the ability to replicate their site many times over, all without needing any assistance from you. However, because all their properties are set at design time, creating sites based on these saved site templates results in static content. This can become a problem in today's business environment, which demands dynamic site content. Enter Reflection .NET brought with it a set of tools neatly grouped into the System.Reflection namespace, which solves this problem. Reflection allows you to query information from any assemblyeven the same assemblydynamically. Information such as properties, fields, and methods, which were declared as public in the assembly, can be reflected. In addition, reflection allows you to retrieve the values of these properties and/or fields as well as set those values dynamically. Reflection also allows you to dynamically invoke methods of the assembly at run time and dynamically compile the code. With it, you can dynamically set a template's Web part properties, thus rendering a static site dynamic. Please enable Javascript in your browser, before you post the comment! Now Javascript is disabled. Your name/nickname Your email WebSite Subject (Maximum characters: 1200). You have 1200 characters left.
http://www.devx.com/dotnet/Article/28315
CC-MAIN-2017-26
en
refinedweb
- NAME - VERSION - SYNOPSIS - DESCRIPTION - FUNCTIONS - OPTIONAL BEHAVIOUR - SEE ALSO - SUPPORT & DEVELOPMENT - AUTHOR - LICENSE NAME Getopt::Args - integrated argument and option processing VERSION 0.1.20 (2016-04-11) SYNOPSIS #!/usr/bin/env perl use Getopt::Args; opt quiet => ( isa => 'Bool', alias => 'q', comment => 'output nothing while working', ); arg item => ( isa => 'Str', required => 1, comment => 'the item to paint', ); my $ref = optargs; print "Painting $ref->{item}\n" unless $ref->{quiet}; DESCRIPTION Getopt::Args processes Perl script options and arguments. This is in contrast with most modules in the Getopt::* namespace, which deal with options only. This module is duplicated as OptArgs, to cover both its original name and yet still be found in the mess that is Getopt::*. The following model is assumed by Getopt::Args for command-line applications: - Command The program name - i.e. the filename be executed by the shell. - Options Options are parameters that affect the way a command runs. They are generally not required to be present, but that is configurable. All options have a long form prefixed by '--', and may have a single letter alias prefixed by '-'. - Arguments Arguments are positional parameters that that a command needs know in order to do its work. Confusingly, arguments can be optional. - Sub-commands From a users point of view a sub-command is simply one or more arguments given to a Command that result in a particular action. However from a code perspective they are implemented as separate, stand-alone programs which are called by a dispatcher when the appropriate arguments are given. Simple Scripts To demonstrate lets put the code from the synopsis in a file called paint and observe the following interactions from the shell: $ ./paint usage: paint ITEM arguments: ITEM the item to paint options: --quiet, -q output nothing while working The optargs() function parses the commands arguments according to the opt and arg declarations and returns a single HASH reference. If the command is not called correctly then an exception is thrown (an Getopt::Args::Usage object) with an automatically generated usage message as shown above. Because Getopt::Args knows about arguments it can detect errors relating to them: $ ./paint house red error: unexpected option or argument: red So let's add that missing argument definition: arg colour => ( isa => 'Str', default => 'blue', comment => 'the colour to use', ); And then check the usage again: $ ./paint usage: paint ITEM [COLOUR] arguments: ITEM the item to paint COLOUR the colour to use options: --quiet, -q output nothing while working It can be seen that the non-required argument colour appears inside square brackets indicating its optional nature. Let's add another argument with a positive value for the greedy parameter: arg message => ( isa => 'Str', comment => 'the message to paint on the item', greedy => 1, ); And check the new usage output: usage: paint ITEM [COLOUR] [MESSAGE...] arguments: ITEM the item to paint COLOUR the colour to use MESSAGE the message to paint on the item options: --quiet, -q output nothing while working Three dots (...) are postfixed to usage message for greedy arguments. By being greedy, the message argument will swallow whatever is left on the comand line: $ ./paint house blue Perl is great Painting in blue on house: "Perl is great". Note that it doesn't make sense to define any more arguments once you have a greedy argument. The order in which options and arguments (and sub-commands - see below) are defined is the order in which they appear in usage messsages, and is also the order in which the command line is parsed for them. Sub-Command Scripts Sub-commands are useful when your script performs different actions based on the value of a particular argument. To use sub-commands you build your application with the following structure: - Command Class The Command Class defines the options and arguments for your entire application. The module is written the same way as a simple script but additionally specifies an argument of type 'SubCmd': package My::Cmd; use Getopt::Args; arg command => ( isa => 'SubCmd', comment => 'sub command to run', ); opt help => ( isa => 'Bool', comment => 'print a help message and exit', ishelp => 1, ); opt dry_run => ( isa => 'Bool', comment => 'do nothing', ); The subcmdfunction call is then used to define sub-command names and descriptions, and separate each sub-commands arguments and options: subcmd( cmd => 'start', comment => 'start a machine' ); arg machine => ( isa => 'Str', comment => 'the machine to start', ); opt quickly => ( isa => 'Bool', comment => 'start the machine quickly', ); subcmd( cmd => 'stop', comment => 'start the machine' ); arg machine => ( isa => 'Str', comment => 'the machine to stop', ); opt plug => ( isa => 'Bool', comment => 'stop the machine by pulling the plug', ); One nice thing about Getopt::Args is that options are inherited. You only need to specify something like a dry-runoption once at the top level, and all sub-commands will see it if it has been set. Additionally, and this is the main reason why I wrote Getopt::Args, you do not have to load a whole bunch of slow-to-start modules ( I'm looking at you, Moose) just to get a help message. - Sub-Command Classes These classes do the actual work. The usual entry point would be a method or a function, typically called something like run, which takes a HASHref argument: package My::Cmd::start; sub run { my $self = shift; my $opts = shift; print "Starting $opts->{machine}\n"; } package My::Cmd::stop; sub run { my $self = shift; my $opts = shift; print "Stoping $opts->{machine}\n"; } - Command Script The command script is what the user runs, and does nothing more than dispatch to your Command Class, and eventually a Sub-Command Class. #!/usr/bin/perl use Getopt::Args qw/class_optargs/; my ($class, $opts) = class_optargs('My::Cmd'); # Run object based sub-command classes $class->new->run($opts); # Or function based sub-command classes $class->can('run')->($opts); One advantage to having a separate Command Class (and not defining everything inside a Command script) is that it is easy to run tests against your various Sub-Command Classes as follows: use Test::More; use Test::Output; use Getopt::Args qw/class_optargs/; stdout_is( sub { my ($class,$opts) = class_optargs('My::Cmd','start','A'); $class->new->run($opts); }, "Starting A\n", 'start' ); eval { class_optargs('My::Cmd', '--invalid-option') }; isa_ok $@, 'Getopt::Args::Usage'; done_testing(); It is much easier to catch and measure exceptions when the code is running inside your test script, instead of having to fork and parse stderr strings. FUNCTIONS The following functions are exported (by default except for dispatch) using Exporter::Tidy. - arg( $name, %parameters ) Define a Command Argument with the following parameters: - isa Required. Is mapped to a Getopt::Long type according to the following table: optargs Getopt::Long ------------------------------ 'Str' '=s' 'Int' '=i' 'Num' '=f' 'ArrayRef' 's@' 'HashRef' 's%' 'SubCmd' '=s' - comment Required. Used to generate the usage/help message. - required Set to a true value when the caller must specify this argument. Can not be used if a 'default' is given. - default The value set when the argument is not given. Can not be used if 'required' is set. If this is a subroutine reference it will be called with a hashref containg all option/argument values after parsing the source has finished. The value to be set must be returned, and any changes to the hashref are ignored. - greedy If true the argument swallows the rest of the command line. It doesn't make sense to define any more arguments once you have used this as they will never be seen. - fallback A hashref containing an argument definition for the event that a sub-command match is not found. This parameter is only valid when isais a SubCmd. The hashref must contain "isa", "name" and "comment" key/value pairs, and may contain a "greedy" key/value pair. The Command Class "run" function will be called with the fallback argument integrated into the first argument like a regular sub-command. This is generally useful when you want to calculate a command alias from a configuration file at runtime, or otherwise run commands which don't easily fall into the Getopt::Args sub-command model. - class_optargs( $rootclass, [ @argv ] ) -> ($class, $opts) This is a more general version of the optargsfunction described in detail below. It parses @ARGV(or @argvif given) according to the options and arguments as defined in $rootclass, and returns two values: - $class The class name of the matching sub-command. - $opts The matching argument and options for the sub-command. As an aid for testing, if the passed in argument @argv(not @ARGV) contains a HASH reference, the key/value combinations of the hash will be added as options. An undefined value means a boolean option. - dispatch( $function, $rootclass, [ @argv ] ) [ NOTE: This function is badly designed and is depreciated. It will be removed at some point before version 1.0.0] Parse @ARGV(or @argvif given) and dispatch to $functionin the appropriate package name constructed from $rootclass. As an aid for testing, if the passed in argument @argv(not @ARGV) contains a HASH reference, the key/value combinations of the hash will be added as options. An undefined value means a boolean option. - opt( $name, %parameters ) Define a Command Option. If $namecontains underscores then aliases with the underscores replaced by dashes (-) will be created. The following parameters are accepted: - isa Required. Is mapped to a Getopt::Long type according to the following table: optargs Getopt::Long ------------------------------ 'Bool' '!' 'Counter' '+' 'Str' '=s' 'Int' '=i' 'Num' '=f' 'ArrayRef' 's@' 'HashRef' 's%' - isa_name When $Getopt::Args::PRINT_ISAis set to a true value, this value will be printed instead of the generic value from isa. - comment Required. Used to generate the usage/help message. - default The value set when the option is not used. If this is a subroutine reference it will be called with a hashref containg all option/argument values after parsing the source has finished. The value to be set must be returned, and any changes to the hashref are ignored. For "Bool" options setting "default" to a true has a special effect: the the usage message formats it as "--no-option" instead of "--option". If you do use a true default value for Bool options you probably want to reverse the normal meaning of your "comment" value as well. - alias A single character alias. - ishelp When true flags this option as a help option, which when given on the command line results in a usage message exception. This flag is basically a cleaner way of doing the following in each (sub) command: my $opts = optargs; if ( $opts->{help} ) { die usage('help requested'); } When true this option will not appear in usage messages unless the usage message is a help request. This is handy if you have developer-only options, or options that are very rarely used that you don't want cluttering up your normal usage message. - arg_name When $Getopt::Args::PRINT_OPT_ARGis set to a true value, this value will be printed instead of the generic value from isa. - optargs( [ @argv ] ) -> HashRef Parse @ARGV by default (or @argv when given) for the arguments and options defined in the current package, and returns a hashref containing key/value pairs for options and arguments combined. An error / usage exception object ( Getopt::Args::Usage) is thrown if an invalid combination of options and arguments is given. Note that @ARGVwill be decoded into UTF-8 (if necessary) from whatever I18N::Langinfo says your current locale codeset is. - subcmd( %parameters ) Create a sub-command. After this function is called further calls to optand argdefine options and arguments respectively for the sub-command. The following parameters are accepted: - cmd Required. Either a scalar or an ARRAY reference containing the sub command name. - comment Required. Used to generate the usage/help message. When true this sub command will not appear in usage messages unless the usage message is a help request. This is handy if you have developer-only or rarely-used commands that you don't want cluttering up your normal usage message. - usage( [$message] ) -> Str Returns a usage string prefixed with $message if given. OPTIONAL BEHAVIOUR Certain Getopt::Args behaviour and/or output can be changed by setting the following package-level variables: - $Getopt::Args::ABBREV If $Getopt::Args::ABBREVis a true value then sub-commands can be abbreviated, up to their shortest, unique values. - $Getopt::Args::COLOUR If $Getopt::Args::COLOURis a true value and STDOUTis connected to a terminal then usage and error messages will be colourized using terminal escape codes. - $Getopt::Args::SORT If $Getopt::Args::SORTis a true value then sub-commands will be listed in usage messages alphabetically instead of in the order they were defined. - $Getopt::Args::PRINT_DEFAULT If $Getopt::Args::PRINT_DEFAULTis a true value then usage will print the default value of all options. - $Getopt::Args::PRINT_ISA If $Getopt::Args::PRINT_ISAis a true value then usage will print the type of argument a options expects. SEE ALSO Getopt::Long, Exporter::Tidy SUPPORT & DEVELOPMENT This distribution is managed via github: This distribution follows the semantic versioning model: Code is tidied up on Git commit using githook-perltidy: AUTHOR Mark Lawrence <nomad@null.net> LICENSE This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
https://metacpan.org/pod/Getopt::Args
CC-MAIN-2017-26
en
refinedweb
Om Spark recently revived their old but gold posts on program management interviews. Linked List for Program Manager Interviews by Urmila Singhal | Sep 22, 2013 | Program Management The fondest memories of a child are the different birthday parties and the games/activities during that day. As a child on my birthday, I was introduced to… Website design, SEO and Advertising blog posts compilation Om Spark has recently re-started blog posts on various topics including Website design, SEO and Advertising. Here is a handy list of posts for your reference. Top 10 Best Practices For Website Design Why do you need a Call to Action on your website Should small businesses invest in SEO? 10 Simple And Effective Ways to… Top 10 Best Practices For Website Design Urmila Singhal from Om Spark recently posted a great article on Top 10 Best Practices For Website Design. Hope you enjoy it. Want to learn more about building online presence? If. Overall interview evaluation parameters for a software engineer/architect When giving technical interviews, either as a software engineer or software architect, you are not only evaluated on technical prowess but also on a bunch of other factors that make a good or not so good hire. Read more about this on my programming interview blog at How to answer software design interview questions n the previous post on How to answer algorithmic programming interview questions, we discussed a templated approach on how to solve algorithmic questions. In this post, we will explore similar steps that will help you think in the correct direction while solving design questions. Read more at How to answer software design interview questions on my programming… How to answer algorithmic programming interview questions Most… LINQ design interview question LINQ is one of my favorite interview topics for many reasons. It allows me to check a candidate’s ability to define logic, use SQL skills, showcase lambda expressions, distill the problem into easy steps and of course, see some code in action. Also, since LINQ code is generally quite compact, it is perfect for white… Big list of LINQ interview questions and answers compiled I have had a number of users ping me asking about writing interview questions on LINQ. I actually have a 8 detailed posts on LINQ interview questions. Here is a compilation of the posts: LINQ interview questions part 3 LINQ interview questions part 2 Entity Framework interview questions LINQ JOIN interview questions LINQ SKIP… Entity Framework Interview Question – Explain ENUM usage in EF5 Entity Framework 5 introduced support for Enum’s amongst other new features. This was a long awaited feature by the community.To learn how enums work with entity framework, how can you code them, how to use them, how they are represented in the database, head over to my Explain ENUM usage in EF5 on my programming… Entity Framework – what are the different ways to configure database name? Entity… How to populate a database table with text from a file Learn about loading text from a file into a database table on my latest blog post on SQL read text from a file at my programming interviews blog (Direct link: ) SQL self join or sub-query interview question (employee-manager salary) One of my favorite interview questions that tips even seasoned SQL guys (maybe because it’s too simple) is around querying data that involves a self join. Question: Given an Employee table which has 3 fields – Id (Primary key), Salary and Manager Id, where manager id is the id of the employee that manages the… Advanced programming interview questions and answers Here is a refresh of my posts on advanced programming interview questions and answers Lost in a Forest of Trees The Ins and Outs of a Binary Search Tree Simple Patterns: Singleton Pattern Simple Patterns: Repository Pattern Simple Patterns: Factory Pattern Implement a basic Stack using linked List Implement a Queue data structure using… Data migration strategies and design patterns Data migration is an extremely common operation in software design and development. Whenever a new system is introduced or a legacy system is redesigned, existing data has to be moved from the legacy system to the new target system. Learn more at Data migration strategies and design patterns on my programming interviews blog. SOA interview questions and answers Learn more about SOA interview questions at on my programming interviews blog. Distributed vs Parallel computing If you wanted to learn about the key difference between distributed vs parallel computing, check out my new post on my programming interviews blog. How to Boost your Self-Confidence Having confidence is a very important part of your life. As a human, a developer, a leader you need to have confidence in yourself. Read more on how to boost your self confidence on my programming interviews blog –. Design and Architecture interview questions with answers Urmila Singhal has written very detailed and interesting posts on how to interview for a technical program manager role. Interviewing to become a Program Manager from a different role: Introduction to what are the skills needed to become a Program Manager – Is project management like parenting? – Interviewing for a program manager Part… Entity framework interview questions compiled Entity. Entity Framework Interview Questions Today, I started the Entity Framework Interview Questions on my Programming Interview series blog. Check them out: Entity Framework interview questions Entity Framework and eager loading of related entities interview questions Entity Framework and lazy loading interview questions Programming Interview Questions and Answers For those who have been waiting for the next installment of programming interview questions and answers, well, the wait is sort of over. I have added a bunch of fresh posts on my Programming Initerview Series blog. Here is the table of contents for easy reference: Table Of Contents Introduction Introduction to technical interviewing… Programming Interview Questions on C++, ASP.NET, C#, SQL and LINQ Reached… LINQ interview questions Check out my latest post on LINQ interview questions on my programming interview blog at Programming Interviews Series. LINQ – Group, Sort and Count Words in a sentence by length In an effort to touch on most of the major technologies for a programming interview, i just wrote my first post on LINQ interview questions titled LINQ – Group, Sort and Count Words in a sentence by length on my programming interview blog at Programming Interviews Series. SQL IF-ELSE and WHILE examples Check out my latest post on SQL IF-ELSE and WHILE examples as part of SQL programming interview questions on my Programming Interviews Series blog. SQL CASE statement examples Continuing on my trek to flesh out more on SQL interview questions and answers, i just finished a post on SQL CASE statement examples on my Programming Interviews Series blog. How to create a Windows Service in the Component Designer Microsoft Windows… New Windows Phone 7 toolkit by Coding4Fun The dev part of Channel 9 have recently released their latest escapade – Windows Phone 7 toolkit. The Coding4Fun Windows Phone Toolkit is a set of Silverlight controls, converters, and helpers to make your life easier. They have put a lot of effort in building out the control set. Here is a list of controls… SQL GROUP BY and HAVING clauses Continuing with SQL interview questions, please check out my second SQL post on SQL GROUP BY and HAVING clauses on my Programming Interviews Series blog. SQL Select Where Interview Questions Turning my focus on SQL interview questions, please check out my first of many posts on SQL Select Where Interview Questions on my Programming Interviews Series blog. jQuery Selectors reviewed Check out my latest post on jQuery Selectors reviewed on my new blog on Programming Interviews Series. jQuery fadeIn, fadeOut and fadeTo effects Check out my latest post on jQuery fadeIn, fadeOut and fadeTo effects on my new blog on Programming Interviews Series. Differentiate between alert(), prompt() and confirm() methods Check out my latest post on Differentiate between alert(), prompt() and confirm() methods on my new blog on Programming Interviews Series. Programming Interview Series For the last month or so, I have been blogging almost daily in building up a good collection of programming interview questions with detailed explanations and answers. I would love to have some feedback on what you like, what works, what did not and most importantly, what would you like to to focus on more…. jQuery AJAX functions part 3–ajax() Check out my latest post on jQuery AJAX functions part 3–ajax() on my new blog on Programming Interviews Series. jQuery AJAX functions part 2–get(), post(), getScript() and getJSON() Check out my latest post on jQuery AJAX functions part 2–get(), post(), getScript() and getJSON() on my new blog on Programming Interviews Series. jQuery AJAX functions part 1–the load() method Check out my latest post on jQuery AJAX functions part 1–the load() method on my new blog on Programming Interviews Series. ASP.NET HttpHandlers Check out my latest post on ASP.NET HttpHandlers on my new blog on Programming Interviews Series. ASP.NET HttpModule explained Check out my latest post ASP.NET HttpModule explained on my new blog on Programming Interviews Series. Explain ASP.NET data binding using DataSets and DataSourceControls Check out my latest post Explain ASP.NET data binding using DataSets and DataSourceControls on my new blog on Programming Interviews Series. Explain System.IO and System.IO.Compression namespaces with an example Check out my latest post Explain System.IO and System.IO.Compression namespaces with an example on my new blog on Programming Interviews Series. How to find if a number is perfect square Check out my latest post on How to find if a number is perfect square on my new blog on Programming Interviews Series. LINQ Query, Selection, Partial Selections and Aggregations Check out my latest post on LINQ Query, Selection, Partial Selections and Aggregations on my new blog on Programming Interviews Series. ASP.NET Session modes explained Check out my latest post on ASP.NET Session modes explained on my new blog on Programming Interviews Series. ASP.NET AJAX using UpdatePanel control Check out my latest post on ASP.NET AJAX using UpdatePanel control on my new blog on Programming Interviews Series. Operator overloading and pairing rules in C# Check out my latest post on Operator overloading and pairing rules in C# on my new blog on Programming Interviews Series. How to add HTML Server Controls to a Web Page Using ASP.NET Looks like I am on a roll today. Just posted another post on How to add HTML Server Controls to a Web Page Using ASP.NET on my new blog series on Programming Interviews Series. New post of ASP.NET Page directive Check out my latest post on ASP.NET Page directive on my new blog series on Programming Interviews Series. New post on programming interviews on FileSystemWatcher I just posted a new post on how to monitor file system changes using FileSystemWatcher in C# at my new blog @ Programming Interview Series. You can read the post in detail at Enjoy reading and do share your feedback. Thanks Nikhil Programming Interviews Series I have recently started a new blog series at. The goal is to create a series of small posts dedicated to helping you master the art of programming interviews. TFS build – post build cleanup – recursively delete wildcard files using MSBuild.proj I… Converting objectSid to string I was writing a tool yesterday that involved mucking with Active Directory and such. During the process I realized that I needed to save the objectSid of the user for later use. AD defines this property as “Octet string” saved as bytes. Following the general wisdom and internet advices to convert this byte array into… Basics of Search Engine Optimization Google has a great document that talks in extreme clear terms what site owners should do to enable better indexing of their content by majore search engines. This document can be found at. I strongly recommend every site owner to read this guide. Here are some important highlights taken from the above document. Create… How to: Identify Blocked SQL Processes Quickly There was a great article in Visual Studio magazine (June 2008) by Ian Stirk in which he talks in detail about how to improve application performance by creating a utility that tells you which processes are being blocked. You can read the article at. The two sql sprocs that you will need to create… Running a Windows Service from command line One of the common problems that we face in designing a Windows service is the ease of debugging it. I have followed a pattern to solve this problem where I can run a service from either command line or as a service. The steps below outline the changes you would need to make to enable… How to AutoIncrement version with each build using Team Foundation Server build (with a little help from AssemblyInfoTask) One common requirement with any decent sized multi-version product is to automatically update the version numbers of the binaries on a regular basis. This is generally achieved by updating the AssemblyInfo.cs (or other language equivalent ) files. There are a couple of ways to do this: 1. Assign one developer to remember to increment… Visual Studio Setup/deployment projects and Team Foundation Server Team… Handling global web service unhandled exceptions One of the most tiresome (but important) things when developing web services is handling un-handled exceptions. A good design principle forces you to catch and cast relevant exceptions raised by your web methods into more meaningful SOAP exceptions. But exceptions will occur. It is quite tedious to wrap each web method in a try/catch loop…. Bulk…
https://blogs.msdn.microsoft.com/nikhilsi/
CC-MAIN-2017-26
en
refinedweb
Hello!It has been some time since when I was trying to install Debian with the 2.4.27 kernel included on the CD-ROM: it gave me kernel panic, because of the buggy NCR 53C710 SCSI driver. But, at least, it displayed on screen something.. This is the output of dmesg: Searching for SAVEKMSG magic... Found 4448 bytes at 0x001dc010 >>>>>>>>>>>>>>>>>>>>Linux version 2.6.24-rc8-amiga (Debian 2.6.24~rc8-1~experimental.2~snapshot.10176) (waldi@debian.org) (gcc version 3.3.6 (Debian 1:3.3.6-15)) #1 Mon Jan 28 00:45:45 CET 2008 Warning: no chipram present for debuggingAmiga hardware found: [A4000T] VIDEO BLITTER AUDIO FLOPPY A4000_SCSI A4000_IDE KEYBOARD MOUSE SERIAL PARALLEL A3000_CLK CHIP_RAM PAULA LISA ALICE_PAL ZORRO3 console [debug0] enabled initrd: 07db4449 - 08000000 Built 1 zonelists in Zone order, mobility grouping on. Total pages: 32480Kernel command line: root=/dev/ram video=clgen: ramdisk_size=9000 debian-installer/framebuffer=false debug=mem BOOT_IMAGE=vmlinux.tmp PID hash table entries: 512 (order: 9, 2048 bytes) Console: colour dummy device 80x25 Dentry cache hash table entries: 16384 (order: 4, 65536 bytes) Inode-cache hash table entries: 8192 (order: 3, 32768 bytes) Memory: 124544k/124656k available (1776k kernel code, 4512k data, 128k init) Security Framework initialized Capability LSM initialized Mount-cache hash table entries: 512 Initializing cgroup subsys ns Initializing cgroup subsys cpuacct net_namespace: 64 bytes NET: Registered protocol family 16 SCSI subsystem initialized Zorro: Probing AutoConfig expansion devices: 4 devices is Freeing initrd memory: 588k freed VFS: Disk quotas dquot_6.5.1 Dquot-cache hash table entries: 1024 (order 0, 4096 bytes) io scheduler noop registered io scheduler anticipatory registered io scheduler deadline registered io scheduler cfq registered (default) Console: switching to colour frame buffer device 80x25 fb0: Amiga AGA frame buffer device, using 1280K of video memorycirrusfb: CL Picasso4 board detected; RAM (32 MB) at $42000000, <6> REG at $42600000 Cirrus Logic chipset on Zorro bus cirrusfb: Driver for Cirrus Logic based graphic boards, v2.0-pre2 Amiga-builtin serial driver version 4.30 ttyS0 is the amiga builtin serial port FD: probing units found <5>fd: drive 0 didn't identify, setting default ffffffff fd0 RAMDISK driver initialized: 16 RAM disks of 9000K size 1024 blocksize loop: module loaded Uniform Multi-Platform E-IDE driver Revision: 7.00alpha2 ide: Assuming 50MHz system bus speed for PIO modes; override with idebus=xx ide0: Gayle IDE interface (A4000 style) 53c700: Version 2.8 By James.Bottomley@HansenPartnership.com scsi0: 53c710 rev 2 scsi0 : A4000T builtin SCSI scsi1: 53c710 rev 2 scsi1 : WarpEngine 40xx scsi 0:0:0:0: Direct-Access QUANTUM VIKING II 9.1WSE 5520 PQ: 0 ANSI: 2 target0:0:0: Beginning Domain Validation scsi 0:0:0:0: Enabling Tag Command Queuing target0:0:0: asynchronous target0:0:0: FAST-10 SCSI 10.0 MB/s ST (100 ns, offset 8) target0:0:0: Domain Validation skipping write tests target0:0:0: Ending Domain Validation Driver 'sd' needs updating - please use bus_type methods scsi 0:0:0:1: Disabling Tag Command Queuing mice: PS/2 mouse device common for all mice input: Amiga Keyboard as /class/input/input0 input: Amiga mouse as /class/input/input1 TCP bic registered NET: Registered protocol family 1 NET: Registered protocol family 17 NET: Registered protocol family 15 registered taskstats version 1 scsi: waiting for bus probes to complete ... scsi 0:0:3:0: CD-ROM TEAC CD-W512SB 1.0K PQ: 0 ANSI: 2 target0:0:3: Beginning Domain Validation target0:0:3: asynchronous target0:0:3: FAST-10 SCSI 10.0 MB/s ST (100 ns, offset 8) target0:0:3: Domain Validation skipping write tests target0:0:3: Ending Domain Validation sda: RDSK (512) sda1 (SFS^@)(res 2 spb 1) sda2 (SFS^@)(res 2 spb 1) sd 0:0:0:0: [sda] Attached SCSI disk Warning: unable to open an initial console. Z2RAM: using 0K Zorro II RAM and 384K Chip RAM (Total 384K) amikbd: Ctrl-Amiga-Amiga reset warning!! amikbd: Ctrl-Amiga-Amiga reset warning!! <<<<<<<<<<<<<<<<<<<<Now my SCSI controllers (onboard A4091 and Warp Engine) and peripherals are properly detected, no more panic :-) But the kernel seems to complain about no Chip RAM being available for debug, and that it is unable to open a console (?). What the problem can be? -- ___ __ / __|___ Daniele Gratteri, Italian Commodore-Amiga user... /// | / |__/ Nickname: FIAT1100D - ICQ: 53943994 Ritmo S75 __ /// | \__|__\ Home page: forever! \\\/// \___| E-MAIL: daniele@gratteri.tk ...since 1990 \///
https://lists.debian.org/debian-68k/2008/01/msg00113.html
CC-MAIN-2017-26
en
refinedweb
hey i am beginner in java. i am not able to resolve differences in interface and with abstract class. do abstract class have methods defined??does those methods have body?? if so for abstract classes do not create objects, how they r invoked?? hey i am beginner in java. i am not able to resolve differences in interface and with abstract class. do abstract class have methods defined??does those methods have body?? if so for abstract classes do not create objects, how they r invoked?? An interface is a static context template that classes can implement. The methods within the interface have no body and must be of public access. In addition, interfaces can also contain "constants" in which data is declared and defined. An example-- public interface MyInterface{ public final int VALUE = 100; // constant public void doSomething(); // method declaration within interface } --when a class implements an interface, the class also implements the methods the interface contains. However, the implementing class MUST define the methods implemented. An example-- public class MyTestClass implements MyInterface{ public void doSomething(){ System.out.println(VALUE); } } --notice that the class MyTestClass doesn't declare VALUE however it is defined in the interface and therefore MyTestClass implements the public-accessible VALUE also. An Abstract class is much like both a class AND an interface, however moreso a class. An Abstract class has the potential to have default methods and interface-like methods where the methods MUST be defined by concrete subclasses that extend from the abstract class. Furthermore, the concept of Abstract is "not fully defined" so in that respect, abstract classes cannot be instantiated. An example-- public abstract class MyAbstractClass{ protected abstract void subCommand(); public final void templateMethod(){ System.out.println("Performing a defined command..."); subCommand(); System.out.println("SubCommand finished!"); } } --do not be distracted by the protected and final modifiers. The key focus is the abstract void subCommand method. Notice that an abstract class is like an interface in which it can house methods without definitions (so long as they are declared abstract) and additionally you can't instantiate an abstract class much like you can't instantiate an interface. However when you are using an abstract class in a subclass you must override the abstract methods you are implementing from the abstract class. An example-- public class MyOtherClass extends MyAbstractClass{ protected void subCommand(){ System.out.println("Whoo! This is my method! O_O"); } public static void main(String... args){ MyAbstractClass mac = new MyOtherClass(); mac.templateMethod(); } } --notice that I'm storing MyOtherClass into a reference-variable called MyAbstractClass and then the templateMethod is called. Because MyOtherClass has a specialized implementation of subCommand, the call to templateMethod polymorphically calls the overridden subCommand within the template algorithm. Hopefully with the above example, you can see why abstract classes and interfaces are extremely useful. The major difference between an abstract class and an interface is the way Java handles each - you can extend only one class but you can implement an infinite amount of interfaces. That being said, use interfaces whenever possible if the implementing class needs more implementations. suppose in abstact class "InputStream" we can implement method read(byte[]) with it's reference. how does this method is being refferred by it's abstract class as there will be no instantiation to this abstact class. suppose in abstact class "InputStream" we can implement method read(byte[]) with it's reference. how does this method is being refferred by it's abstract class as there will be no instantiation to this abstact class. I'm not sure if I'm understanding the question. Do you mean how are you able to call read from an object of type InputStream if you cannot directly instantiate one? If so then please re-read my post, this is mentioned in there. If you mean extending the abstract class then using read, you will have to override the read method with your own implementation of read. Your concrete class that extends from the abstract class should not be marked abstract, so that you will be able to instantiate your concrete class and still have the functionality of the extending class. Read my above post thoroughly - this is also mentioned. Also, this might help-- CLICK! You know what? You should use interface when you want to take all the common features from different stuffs say you have one interface that contains method a() and another interface that contains method b(). Now in the situation when you want your program to have both a() and b() need to be present and you want a restriction that a() and b() shouldn't be present in one file you should break them in two interfaces because your program can implement two interfaces simultaneously. So here you can apply Interface. So when I need to provide the multiple inheritance functionality I should use Interface. You should use abstract class when you want multilevel inheritance. Because abstract class can only be extended once. Am I clear from this point? If not then let me know and I'll explain with real life scenarios and examples to make them clear as to where to use Interface and abstract class?. ...
https://www.daniweb.com/programming/software-development/threads/142503/how-is-abstact-class-different-from-interface
CC-MAIN-2017-26
en
refinedweb
How To Secure iOS User Data: The Keychain and Touch ID Update note: This tutorial has been updated for Xcode 8.3.2 and Swift 3.1 by Tim Mitra. The original tutorial was also written by Tim Mitra. Protecting an app with a login screen is a great way to secure user data – you can use the Keychain, which is built right in to iOS, to ensure that their data stays secure. Apple also offers yet another layer of protection with Touch ID. Available since the iPhone 5s, Touch ID stores biometrics in a secure enclave in the A7 and newer chips. All of this means you can comfortably hand over the responsibility of handling login information to the Keychain and/or Touch ID. In this tutorial you’ll start out with static authentication. Next you’ll be using the Keychain to store and verify login information. After that, you’ll explore using Touch ID in: let usernameKey = "batman" let passwordKey = "Hello Bruce!" These are simply the hard-coded username and password you’ll be checking the user-provided credentials against. Add the following function below loginAction(_:): func checkLogin(username: String, password: String) -> Bool { return username == usernameKey && password == passwordKey } This checks the user-provided credentials against the constants you defined earlier. Next, replace the contents of loginAction(_:) with the following: if checkLogin(username: usernameTextField.text!, password: passwordTextField.text!) { performSegue(withIdentifier: "dismissLogin", sender: self) } This calls checkLogin(username. Rapper? No. Wrapper. In the starter app you’ll find that you have already downloaded the KeychainPasswordItem.swift file; this class comes from Apple’s sample code GenericKeychain. In the Resources folder, drag the KeychainPasswordItem.swift into the project, like so: When prompted, make sure that Copy items if needed is checked and the TouchMeIn target is checked as well: will need to add a serviceName and an optional accessGroup. You’ll add a struct to store these values. Open up LoginViewController.swift. At the top of the file and just below the imports add this struct. // Keychain Configuration struct KeychainConfiguration { static let serviceName = "TouchMeIn" static let accessGroup: String? = nil } Next delete the following lines: let usernameKey = "batman" let passwordKey = "Hello Bruce!" In their place, add the following: var passwordItems: [KeychainPasswordItem] = [] let createLoginButtonTag = 0 let loginButtonTag = 1 @IBOutlet weak var loginButton: UIButton! The passwordItems is an empty array of KeychainPasswordItem types that will pass into the keychain. The next two constants will be used to determine if the Login button is being used to create some credentials, or to log in; the loginButton outlet will be used to update the title of the button depending on that same state. Open Main.storyboard and choose the Login View Controller Scene. Ctrl-drag from the Login View Controller to the Login button, as shown below: From the resulting popup, choose loginButton: : @IBAction func loginAction(_ sender: AnyObject) { // 1 // Check that text has been entered into both the username and password fields. guard let newAccountName = usernameTextField.text, let newPassword = passwordTextField.text, !newAccountName.isEmpty && !newPassword.isEmpty else { let alertView = UIAlertController(title: "Login Problem", message: "Wrong username or password.", preferredStyle:. alert) let okAction = UIAlertAction(title: "Foiled Again!", style: .default, handler: nil) alertView.addAction(okAction) present(alertView, animated: true, completion: nil).text!, password: passwordTextField.text!) { performSegue(withIdentifier: "dismissLogin", sender: self) } else { // 8 let alertView = UIAlertController(title: "Login Problem", message: "Wrong username or password.", preferredStyle: .alert) let okAction = UIAlertAction(title: "Foiled Again!", style: .default) alertView.addAction(okAction) present(alertView, animated: true, completion: nil) } } } UserDefaultswhich indicates whether a password has been saved to the Keychain. If the usernamefield is not empty and hasLoginKeyindicates no login has already been saved, then you save the usernameto UserDefaults. - You create a KeychainPasswordItemwith the serviceName, newAccountName(username) and accessGroup. Using Swift’s error handling, you try to save save the password. The catch is there if something goes wrong. - You then set hasLoginKeyin UserDefaultsto trueto indicate that a password has been saved to the keychain. You set the login button’s tag to loginButtonTagto change the button’s text, so that the implementation of checkLogin(username:password:) with the following:)") } return false } This checks that the username entered matches the one stored in UserDefaults and that the password matches the one stored in the Keychain. Now you need to set the button title and tags appropriately depending on the state of hasLoginKey. Add the following UserDefaultsto. Open the Resources folder from the starter project you downloaded earlier. Locate Touch-icon-lg.png, Touch-icon-lg@2x.png, and Touch-icon-lg@3x.png, select all three and drag them into Images.xcassets so that Xcode knows they’re the same image, only with different resolutions: Open up Jawwad Ahmad’s UIStackView Tutorial: Introducing Stack Views. Use the Attributes Inspector to(username:password:): In the popup, change Connection to Action, set Name to touchIDLoginAction, optionally set the Type to UIButton. Then click Connect. >>IMAGE fingerprint! :] In Xcode’s Project Navigator right-click the TouchMeIn group folder and select New File…. Choose Swift File under iOS. Click Next. Save the file as TouchIDAuthentication.swift with the TouchMeIn target checked. Click Create. Open up TouchIDAuthentication.swift and add the following import just below Foundation: import LocalAuthentication Create a new class next: class TouchIDAuth { } Now you’ll need a reference to the LAContext class. Inside the class add the following code between the curly braces: let context = LAContext() The context references an authentication context, which is the main player in Local Authentication. You will need a function to see if Touch ID is available to the user’s device or in the Simulator. Create the following function to return a Bool if Touch ID is supported. func canEvaluatePolicy() -> Bool { return context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil) } Open up LoginViewController.swift. Add another property to create a reference to class you just created. let touchMe = TouchIDAuth() At the bottom of viewDidLoad() add the following: touchIDButton.isHidden = !touchMe.canEvaluatePolicy() Go back to TouchIDAuthentication.swift and add a function to authenticate the user. At the bottom of the TouchIDAuth class, create the following function func authenticateUser(completion: @escaping () -> Void) { // 1 // 2 guard canEvaluatePolicy() else { return } // 3 context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: "Logging in with Touch ID") { (success, evaluateError) in // 4 if success { DispatchQueue.main.async { // User authenticated successfully, take appropriate action completion() } } else { // TODO: deal with LAError cases } } } Here’s what’s going on in the code above: authenticateUser(completion:)is going to pass a completion handler in the form of a closure back to the LoginViewController. - You’re using canEvaluatePolicy(. We’ll come back and deal with errors in little while. Switch to LoginViewController.swift and locate touchIDLoginAction(_:) by scrolling or with the jump bar. Add the following inside the action so that it looks like this: @IBAction func touchIDLoginAction(_ sender: UIButton) { touchMe.authenticateUser() { [weak self] in self?.performSegue(withIdentifier: "dismissLogin", sender: self) } } If the user is authenticated, you can dismiss the Login view. You can build and run to your device here, but wait! What if you haven’t set up Touch ID on your device? What if you are using the wrong finger? Let’s deal with that. Go ahead and build and run to see if all’s well. Dealing with Errors. Switch back to TouchIDAuthentication.swift and update the authenticateUser function. Change the signature to include an optional message that you will pass when you get an error. func authenticateUser(completion: @escaping (String?) -> Void) { Find the // TODO: and replace it with the LAError cases in a switch statement: // 1 let message: String // 2 switch evaluateError { // 3 case LAError.authenticationFailed?: message = "There was a problem verifying your identity." case LAError.userCancel?: message = "You pressed cancel." case LAError.userFallback?: message = "You pressed password." default: message = .touchIDNotAvailable: the device isn’t Touch ID-compatible. LAError.passcodeNotSet: there is no passcode enabled as required for Touch ID LAError.touchIDNotEnrolled: there are no fingerprints stored. - Pass the message in the completionclosure. iOS responds to LAError.passcodeNotSet and LAError.touchIDNotEnrolled on its own with relevant alerts. There’s one more error case to deal with. Add the following inside the `else` block of the `guard` statement, just above `return`. completion("Touch ID not available") The last thing to update is our success case. That completion should contain nil, indicating that you didn’t get any errors. Inside the first success block add the nil. completion(nil) Your finished function should look like this: func authenticateUser(completion: @escaping (String?) -> Void) { guard canEvaluatePolicy() else { completion("Touch ID not available") return } context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: "Logging in with Touch ID") { ." default: message = "Touch ID may not be configured" } completion(message) } } } Switch to LoginViewController.swift and update the touchIDLoginAction(_:) to look like this: @IBAction func touchIDLoginAction(_ sender: UIButton) { // 1 touchMe.authenticateUser() {) } } } - We’ve added a trailing closure to pass in an optional message. If Touch ID works there is no message. -; you’d want to prompt the user for their current password before accepting their modification. You can read more about securing your iOS apps in Apple’s official iOS 10 Marin Bencevic - Final Pass Editor Mike Oliver - Team Lead Andy Obusek
https://www.raywenderlich.com/147308/secure-ios-user-data-keychain-touch-id?utm_campaign=ThomasHanning%2BNewsletter&utm_medium=web&utm_source=ThomasHanning_Newsletter14
CC-MAIN-2017-26
en
refinedweb
I got my hands dirty with SAX2 and, man, I love their namespace support, it's great, clean, perfect, just fits perfectly with what I need. Then I look at XSLT and, hmmm, their level of namespace support isn't quite what I like... ok, let's make an example: <my:page xmlns: ... </my:page> How would a "normal" person access this in XSLT? simple <xsl:template </xsl:template> All right (I know you already smell the problem, but keep going) then I move my page to <my-stuff:page xmlns: ... <my-stuff:page> because I found that that the "my" prefix is used in another (and more famous) schema. Great, while good behaving SAX2 applications don't give a damn since the "page" element is correctly interpreted (in memory) as^page no matter what prefix is used (as the namespace spec rules), in XSLT... well, I honestly don't know. Please help, the XPath spec is not very clear! ------------------------- ---------------------
http://mail-archives.apache.org/mod_mbox/cocoon-dev/200008.mbox/%3C39A56A0D.6444D43@apache.org%3E
CC-MAIN-2017-26
en
refinedweb
have configured Adyen as a payment gateway for your account. This will allow your developers to enter their credit card details, and you can automatically charge them through Adyen for access to your API, according to the calculated invoices. Setting up your payment gateway is a key step enabling credit card charging for use of your paid API. There are a number of alternative payment gateways you can use with your 3scale account. Here we cover the steps for Adyen. 3.1. Prerequisites Before you start these steps, you’ll need to open an account with Adyen. You need a Company account and a Merchant account within it (sub-account). There are a number of requirements that must be fulfilled before you can apply for a live account with Adyen. You can see what those requirements are here.: Enable the "alias" additional data in the Adyen API response By default when credit card authorization requests are sent from 3scale to Adyen, the returned response does not include the unique identifier of the credit card. To ensure that the correct credit card reference is saved in 3scale and the correct card is charged, this additional data needs to be enabled. In order to do this, you should ask Adyen support to enable the "alias" additional data in the response for the authorization request. 3.2.3. Step 4: Test your billing workflow Make sure you accelerate the test cycle by enabling Prepaid Mode to generate the charge within a day or so. Then choose an existing test account and create an invoice with a line item charge added. Charge the account immediately. This testing approach will incur some minor costs, but it is worth it for the peace of mind that everything works fine, before you have real paying developers using your API. The payment gateway is now set up, but your users might not be able to use it yet since it is not configured in the CMS. Go to the developer portal tab, and find the template called Payment Gateway / Show on the left navigation pane. If it’s not there already, add the following snippet after the block of code beginning with {% when "stripe" %} {% when "adyen12" %} {% if current_account.has_billing_address? %} {% adyen12_form %} {% else %} <p><a href="{{ current_account.edit_adyen12_billing_address_url }}">First add a billing address</a></p> {% endif %} - For accounts created before 11th May 2016 you must add the snippet above manually. After said date this will be included in the template by default. - In order to map your data from Adyen with your data on 3scale, you can use the Adyen field called shopperReferencewhich is composed of 3scale-[PROVIDER_ID]-[DEVELOPER_ACCOUNT_ID].. 6.1. Prerequisites Before you start these steps, you will need to open an account with Stripe. 6.2. Step 1: Get_13<<. _18<<. 6.3.1. Note In order to map your data from Stripe with your data on 3scale, you can use the Stripe field called metadata.3scale_account_reference which is composed of 3scale-[PROVIDER_ID]-[DEVELOPER_ACCOUNT.
https://access.redhat.com/documentation/en-us/red_hat_3scale/2.3/html/billing/
CC-MAIN-2018-51
en
refinedweb
This article shows how to use Dynamsoft C++ barcode reader SDK to create a Window runtime component, as well as how to use the WinRT component and JavaScript to build a UWP app on Windows 10. Tag: C#. Creating Android Apps with Xamarin in Visual Studio Image Transmission between a HTML5 WebSocket Server and a Web Client HTML5 WebSocket facilitates the communication between web browsers and local/remote servers. If you want to learn a simple websocket example, creating a WebSocket Server in C# and a Web client in JavaScript, you can refer to SuperWebSocket, which is a .NET implementation of Web Socket Server. In this article, I would like to share how I implemented a simple WebSocket solution for image transmission based on the basic sample code of SuperWebSocket and Dynamic .NET TWAIN, especially what problem I have solved. Here is a quick look of the WebSocket server and the HTML5 & JavaScript client. Prerequisites - Download SuperWebSocket - Download Dynamic .NET TWAIN - I will not detail how to create the basic WebSocket server and the JavaScript client. Please study Program.cs and Test.htm Create a .NET WebSocket Server Create a new WinForms project, and add the following references which are located at the folder of SuperWebSocket. Add the required namespaces: using Dynamsoft.DotNet.TWAIN; using SuperSocket.SocketBase; using SuperWebSocket; In the sample code, the server is launched with port 2012, no IP specified by default. You can specify the IP address for remote access. For example: if (!appServer.Setup("192.168.8.84", 2012)) //Setup with listening port { MessageBox.Show("Failed to setup!"); return; } You can use Dynamic Web TWAIN component to do some image operation. With two lines of code, I can load an image file: bool isLoad = dynamicDotNetTwain.LoadImage("dynamsoft_logo_black.png"); // load an image Image img = dynamicDotNetTwain.GetImage(0); Be careful of the image format. It is PNG. If you want to display it in a Web browser, you need to convert the format from PNG to BMP: byte[] result; using (System.IO.MemoryStream stream = new System.IO.MemoryStream()) { img.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp); // convert png to bmp result = stream.GetBuffer(); } It’s not done yet. The byte array contains some extra image information, which is 54 bytes in length. So the actual data length is: int iRealLen = result.Length - 54; byte[] image = new byte[iRealLen]; Here are some tricky things that if you just send the subset of the byte array to your Web browser, you will find the displayed image is upside-down, and the color is also incorrect. To fix the position issue, you need to sort the bytes of original data array from bottom to top. As to the color, exchange the position of blue and red. See the code: int iIndex = 0; int iRowIndex = 0; int iWidth = width * 4; for (int i = height - 1; i >= 0; --i) { iRowIndex = i * iWidth; for (int j = 0; j < iWidth; j += 4) { // RGB to BGR image[iIndex++] = result[iRowIndex + j + 2 + 54]; // B image[iIndex++] = result[iRowIndex + j + 1 + 54]; // G image[iIndex++] = result[iRowIndex + j + 54]; // R image[iIndex++] = result[iRowIndex + j + 3 + 54]; // A } } Now, you can send the data via: session.Send(imageData.Data, 0, imageData.Data.Length); Create a JavaScript Client To receive the image as ArrayBuffer on the client side, you have to specify the binaryType after creating a WebSocket: ws.binaryType = "arraybuffer"; Once the image data is received, draw all bytes onto a new canvas, and finally create an image element to display the canvas data: var imageWidth = 73, imageHeight = 73; // hardcoded width & height. var byteArray = new Uint8Array(data); var canvas = document.createElement('canvas'); canvas.height = imageWidth; canvas.width = imageHeight; var ctx = canvas.getContext('2d'); var imageData = ctx.getImageData(0, 0, imageWidth, imageHeight); // total size: imageWidth * imageHeight * 4; color format BGRA var dataLen = imageData.data.length; for (var i = 0; i < dataLen; i++) { imageData.data[i] = byteArray[i]; } ctx.putImageData(imageData, 0, 0); // create a new element and add it to div var image = document.createElement('img'); image.width = imageWidth; image.height = imageHeight; image.src = canvas.toDataURL(); var div = document.getElementById('img'); div.appendChild(image);
https://www.codepool.biz/tag/c
CC-MAIN-2018-51
en
refinedweb
Consuming the Task-based Asynchronous Pattern When you use the Task-based Asynchronous Pattern (TAP) to work with asynchronous operations, you can use callbacks to achieve waiting without blocking. For tasks, this is achieved through methods such as Task.ContinueWith. Language-based asynchronous support hides callbacks by allowing asynchronous operations to be awaited within normal control flow, and compiler-generated code provides this same API-level support. Suspending Execution with Await Starting with the .NET Framework 4.5, you can use the await keyword in C# and the Await Operator in Visual Basic to asynchronously await Task and Task<TResult> objects. When you're awaiting a Task, the await expression is of type void. When you're awaiting a Task<TResult>, the await expression is of type TResult. An await expression must occur inside the body of an asynchronous method. For more information about C# and Visual Basic language support in the .NET Framework 4.5, see the C# and Visual Basic language specifications. Under the covers, the await functionality installs a callback on the task by using a continuation. This callback resumes the asynchronous method at the point of suspension. When the asynchronous method is resumed, if the awaited operation completed successfully and was a Task<TResult>, its TResult is returned. If the Task or Task<TResult> that was awaited ended in the Canceled state, an OperationCanceledException exception is thrown. If the Task or Task<TResult> that was awaited ended in the Faulted state, the exception that caused it to fault is thrown. A Task can fault as a result of multiple exceptions, but only one of these exceptions is propagated. However, the Task.Exception property returns an AggregateException exception that contains all the errors. If a synchronization context (SynchronizationContext object) is associated with the thread that was executing the asynchronous method at the time of suspension (for example, if the SynchronizationContext.Current property is not null), the asynchronous method resumes on that same synchronization context by using the context’s Post method. Otherwise, it relies on the task scheduler (TaskScheduler object) that was current at the time of suspension. Typically, this is the default task scheduler (TaskScheduler.Default), which targets the thread pool. This task scheduler determines whether the awaited asynchronous operation should resume where it completed or whether the resumption should be scheduled. The default scheduler typically allows the continuation to run on the thread that the awaited operation completed. When an asynchronous method is called, it synchronously executes the body of the function up until the first await expression on an awaitable instance that has not yet completed, at which point the invocation returns to the caller. If the asynchronous method does not return void, a Task or Task<TResult> object is eventually published. There are several important variations of this behavior. For performance reasons, if a task has already completed by the time the task is awaited, control is not yielded, and the function continues to execute. Additionally, returning to the original context isn't always the desired behavior and can be changed; this is described in more detail in the next section. Configuring Suspension and Resumption with Yield and ConfigureAwait Several methods provide more control over an asynchronous method’s execution. For example, you can use the Task.Yield method to introduce a yield point into the asynchronous method: public class Task : … { public static YieldAwaitable Yield(); … } This is equivalent to asynchronously posting or scheduling back to the current context. Task.Run(async delegate { for(int i=0; i<1000000; i++) { await Task.Yield(); // fork the continuation into a separate work item ... } }); You can also use the Task.ConfigureAwait method for better control over suspension and resumption in an asynchronous method. As mentioned previously, by default, the current context is captured at the time an asynchronous method is suspended, and that captured context is used to invoke the asynchronous method’s continuation upon resumption. In many cases, this is the exact behavior you want. In other cases, you may not care about the continuation context, and you can achieve better performance by avoiding such posts back to the original context. To enable this, use the Task.ConfigureAwait method to inform the await operation not to capture and resume on the context, but to continue execution wherever the asynchronous operation that was being awaited completed: await someTask.ConfigureAwait(continueOnCapturedContext:false); Canceling an Asynchronous Operation Starting with the .NET Framework 4, TAP methods that support cancellation provide at least one overload that accepts a cancellation token (CancellationToken object). A cancellation token is created through a cancellation token source (CancellationTokenSource object). The source’s Token property returns the cancellation token that will be signaled when the source’s Cancel method is called. For example, if you want to download a single webpage and you want to be able to cancel the operation, you create a CancellationTokenSource object, pass its token to the TAP method, and then call the source’s Cancel method when you're ready to cancel the operation: var cts = new CancellationTokenSource(); string result = await DownloadStringAsync(url, cts.Token); … // at some point later, potentially on another thread cts.Cancel(); To cancel multiple asynchronous invocations, you can pass the same token to all invocations: var cts = new CancellationTokenSource(); IList<string> results = await Task.WhenAll(from url in urls select DownloadStringAsync(url, cts.Token)); // at some point later, potentially on another thread … cts.Cancel(); Or, you can pass the same token to a selective subset of operations: var cts = new CancellationTokenSource(); byte [] data = await DownloadDataAsync(url, cts.Token); await SaveToDiskAsync(outputPath, data, CancellationToken.None); … // at some point later, potentially on another thread cts.Cancel(); Cancellation requests may be initiated from any thread. You can pass the CancellationToken.None value to any method that accepts a cancellation token to indicate that cancellation will never be requested. This causes the CancellationToken.CanBeCanceled property to return false, and the called method can optimize accordingly. For testing purposes, you can also pass in a pre-canceled cancellation token that is instantiated by using the constructor that accepts a Boolean value to indicate whether the token should start in an already-canceled or not-cancelable state. This approach to cancellation has several advantages: You can pass the same cancellation token to any number of asynchronous and synchronous operations. The same cancellation request may be proliferated to any number of listeners. The developer of the asynchronous API is in complete control of whether cancellation may be requested and when it may take effect. The code that consumes the API may selectively determine the asynchronous invocations that cancellation requests will be propagated to. Monitoring (WPF) application as follows: private async void btnDownload_Click(object sender, RoutedEventArgs e) { btnDownload.IsEnabled = false; try { txtResult.Text = await DownloadStringAsync(txtUrl.Text, new Progress<int>(p => pbDownloadProgress.Value = p)); } finally { btnDownload.IsEnabled = true; } } Using the Built-in Task-based Combinators The System.Threading.Tasks namespace includes several methods for composing and working with tasks. Task.Run The Task class includes several Run methods that let you easily offload work as a Task or Task<TResult> to the thread pool, for example: public async void button1_Click(object sender, EventArgs e) { textBox1.Text = await Task.Run(() => { // … do compute-bound work here return answer; }); } Some of these Run methods, such as the Task.Run(Func<Task>) overload, exist as shorthand for the TaskFactory.StartNew method. Other overloads, such as Task.Run(Func<Task>), enable you to use await within the offloaded work, for example: public async void button1_Click(object sender, EventArgs e) { pictureBox1.Image = await Task.Run(async() => { using(Bitmap bmp1 = await DownloadFirstImageAsync()) using(Bitmap bmp2 = await DownloadSecondImageAsync()) return Mashup(bmp1, bmp2); }); } Such overloads are logically equivalent to using the TaskFactory.StartNew method in conjunction with the Unwrap extension method in the Task Parallel Library. Task.FromResult Use the FromResult method in scenarios where data may already be available and just needs to be returned from a task-returning method lifted into a Task<TResult>: public Task<int> GetValueAsync(string key) { int cachedValue; return TryGetCachedValue(out cachedValue) ? Task.FromResult(cachedValue) : GetValueAsyncInternal(); } private async Task<int> GetValueAsyncInternal(string key) { … } Task.WhenAll Use the WhenAll method to asynchronously wait on multiple asynchronous operations that are represented as tasks. The method has multiple overloads that support a set of non-generic tasks or a non-uniform set of generic tasks (for example, asynchronously waiting for multiple void-returning operations, or asynchronously waiting for multiple value-returning methods where each value may have a different type) and to support a uniform set of generic tasks (such as asynchronously waiting for multiple TResult-returning methods). Let's say you want to send email messages to several customers. You can overlap sending the messages so you're not waiting for one message to complete before sending the next. You can also find out when the send operations have completed and whether any errors have occurred: IEnumerable<Task> asyncOps = from addr in addrs select SendMailAsync(addr); await Task.WhenAll(asyncOps); This code doesn't explicitly handle exceptions that may occur, but lets exceptions propagate out of the await on the resulting task from WhenAll. To handle the exceptions, you can use code such as the following: IEnumerable<Task> asyncOps = from addr in addrs select SendMailAsync(addr); try { await Task.WhenAll(asyncOps); } catch(Exception exc) { ... } In this case, if any asynchronous operation fails, all the exceptions will be consolidated in an AggregateException exception, which is stored in the Task that is returned from the WhenAll method. However, only one of those exceptions is propagated by the await keyword. If you want to examine all the exceptions, you can rewrite the previous code as follows: Task [] asyncOps = (from addr in addrs select SendMailAsync(addr)).ToArray(); try { await Task.WhenAll(asyncOps); } catch(Exception exc) { foreach(Task faulted in asyncOps.Where(t => t.IsFaulted)) { … // work with faulted and faulted.Exception } } Let's consider an example of downloading multiple files from the web asynchronously. In this case, all the asynchronous operations have homogeneous result types, and it's easy to access the results: string [] pages = await Task.WhenAll( from url in urls select DownloadStringAsync(url)); You can use the same exception-handling techniques we discussed in the previous void-returning scenario: Task [] asyncOps = (from url in urls select DownloadStringAsync(url)).ToArray(); try { string [] pages = await Task.WhenAll(asyncOps); ... } catch(Exception exc) { foreach(Task<string> faulted in asyncOps.Where(t => t.IsFaulted)) { … // work with faulted and faulted.Exception } } Task.WhenAny You can use the WhenAny method to asynchronously wait for just one of multiple asynchronous operations represented as tasks to complete. This method serves four primary use cases: Redundancy: Performing an operation multiple times and selecting the one that completes first (for example, contacting multiple stock quote web services that will produce a single result and selecting the one that completes the fastest). Interleaving: Launching multiple operations and waiting for all of them to complete, but processing them as they complete. Throttling: Allowing additional operations to begin as others complete. This is an extension of the interleaving scenario. Early bailout: For example, an operation represented by task t1 can be grouped in a WhenAny task with another task t2, and you can wait on the WhenAny task. Task t2 could represent a time-out, or cancellation, or some other signal that causes the WhenAny task to complete before t1 completes. Redundancy Consider a case where you want to make a decision about whether to buy a stock. There are several stock recommendation web services that you trust, but depending on daily load, each service can end up being slow at different times. You can use the WhenAny method to receive a notification when any operation completes: var recommendations = new List<Task<bool>>() { GetBuyRecommendation1Async(symbol), GetBuyRecommendation2Async(symbol), GetBuyRecommendation3Async(symbol) }; Task<bool> recommendation = await Task.WhenAny(recommendations); if (await recommendation) BuyStock(symbol); Unlike WhenAll, which returns the unwrapped results of all tasks that completed successfully, WhenAny returns the task that completed. If a task fails, it’s important to know that it failed, and if a task succeeds, it’s important to know which task the return value is associated with. Therefore, you need to access the result of the returned task, or further await it, as this example shows. As with WhenAll, you have to be able to accommodate exceptions. Because you receive the completed task back, you can await the returned task to have errors propagated, and try/catch them appropriately; for example: Task<bool> [] recommendations = …; while(recommendations.Count > 0) { Task<bool> recommendation = await Task.WhenAny(recommendations); try { if (await recommendation) BuyStock(symbol); break; } catch(WebException exc) { recommendations.Remove(recommendation); } } Additionally, even if a first task completes successfully, subsequent tasks may fail. At this point, you have several options for dealing with exceptions: You can wait until all the launched tasks have completed, in which case you can use the WhenAll method, or you can decide that all exceptions are important and must be logged. For this, you can use continuations to receive a notification when tasks have completed asynchronously: foreach(Task recommendation in recommendations) { var ignored = recommendation.ContinueWith( t => { if (t.IsFaulted) Log(t.Exception); }); } or: foreach(Task recommendation in recommendations) { var ignored = recommendation.ContinueWith( t => Log(t.Exception), TaskContinuationOptions.OnlyOnFaulted); } or even: private static async void LogCompletionIfFailed(IEnumerable<Task> tasks) { foreach(var task in tasks) { try { await task; } catch(Exception exc) { Log(exc); } } } … LogCompletionIfFailed(recommendations); Finally, you may want to cancel all the remaining operations: var cts = new CancellationTokenSource(); var recommendations = new List<Task<bool>>() { GetBuyRecommendation1Async(symbol, cts.Token), GetBuyRecommendation2Async(symbol, cts.Token), GetBuyRecommendation3Async(symbol, cts.Token) }; Task<bool> recommendation = await Task.WhenAny(recommendations); cts.Cancel(); if (await recommendation) BuyStock(symbol); Interleaving Consider a case where you're downloading images from the web and processing each image (for example, adding the image to a UI control). You have to do the processing sequentially on the UI thread, but you want to download the images as concurrently as possible. Also, you don’t want to hold up adding the images to the UI until they’re all downloaded—you want to add them as they complete: List<Task<Bitmap>> imageTasks = (from imageUrl in urls select GetBitmapAsync(imageUrl)).ToList(); while(imageTasks.Count > 0) { try { Task<Bitmap> imageTask = await Task.WhenAny(imageTasks); imageTasks.Remove(imageTask); Bitmap image = await imageTask; panel.AddImage(image); } catch{} } You can also apply interleaving to a scenario that involves computationally intensive processing on the ThreadPool of the downloaded images; for example: List<Task<Bitmap>> imageTasks = (from imageUrl in urls select GetBitmapAsync(imageUrl) .ContinueWith(t => ConvertImage(t.Result)).ToList(); while(imageTasks.Count > 0) { try { Task<Bitmap> imageTask = await Task.WhenAny(imageTasks); imageTasks.Remove(imageTask); Bitmap image = await imageTask; panel.AddImage(image); } catch{} } Throttling Consider the interleaving example, except that the user is downloading so many images that the downloads have to be throttled; for example, you want only a specific number of downloads to happen concurrently. To achieve this, you can start a subset of the asynchronous operations. As operations complete, you can start additional operations to take their place: const int CONCURRENCY_LEVEL = 15; Uri [] urls = …; int nextIndex = 0; var imageTasks = new List<Task<Bitmap>>(); while(nextIndex < CONCURRENCY_LEVEL && nextIndex < urls.Length) { imageTasks.Add(GetBitmapAsync(urls[nextIndex])); nextIndex++; } while(imageTasks.Count > 0) { try { Task<Bitmap> imageTask = await Task.WhenAny(imageTasks); imageTasks.Remove(imageTask); Bitmap image = await imageTask; panel.AddImage(image); } catch(Exception exc) { Log(exc); } if (nextIndex < urls.Length) { imageTasks.Add(GetBitmapAsync(urls[nextIndex])); nextIndex++; } } Early Bailout Consider that you're waiting asynchronously for an operation to complete while simultaneously responding to a user’s cancellation request (for example, the user clicked a cancel button). The following code illustrates this scenario: private CancellationTokenSource m_cts; public void btnCancel_Click(object sender, EventArgs e) { if (m_cts != null) m_cts.Cancel(); } public async void btnRun_Click(object sender, EventArgs e) { m_cts = new CancellationTokenSource(); btnRun.Enabled = false; try { Task<Bitmap> imageDownload = GetBitmapAsync(txtUrl.Text); await UntilCompletionOrCancellation(imageDownload, m_cts.Token); if (imageDownload.IsCompleted) { Bitmap image = await imageDownload; panel.AddImage(image); } else imageDownload.ContinueWith(t => Log(t)); } finally { btnRun.Enabled = true; } } private static async Task UntilCompletionOrCancellation( Task asyncOp, CancellationToken ct) { var tcs = new TaskCompletionSource<bool>(); using(ct.Register(() => tcs.TrySetResult(true))) await Task.WhenAny(asyncOp, tcs.Task); return asyncOp; } This implementation re-enables the user interface as soon as you decide to bail out, but doesn't cancel the underlying asynchronous operations. Another alternative would be to cancel the pending operations when you decide to bail out, but not reestablish the user interface until the operations actually complete, potentially due to ending early due to the cancellation request: private CancellationTokenSource m_cts; public async void btnRun_Click(object sender, EventArgs e) { m_cts = new CancellationTokenSource(); btnRun.Enabled = false; try { Task<Bitmap> imageDownload = GetBitmapAsync(txtUrl.Text, m_cts.Token); await UntilCompletionOrCancellation(imageDownload, m_cts.Token); Bitmap image = await imageDownload; panel.AddImage(image); } catch(OperationCanceledException) {} finally { btnRun.Enabled = true; } } Another example of early bailout involves using the WhenAny method in conjunction with the Delay method, as discussed in the next section. Task.Delay You can use the Task.Delay method to introduce pauses into an asynchronous method’s execution. This is useful for many kinds of functionality, including building polling loops and delaying the handling of user input for a predetermined period of time. The Task.Delay method can also be useful in combination with Task.WhenAny for implementing time-outs on awaits. If a task that’s part of a larger asynchronous operation (for example, an ASP.NET web service) takes too long to complete, the overall operation could suffer, especially if it fails to ever complete. For this reason, it’s important to be able to time out when waiting on an asynchronous operation. The synchronous Task.Wait, Task.WaitAll, and Task.WaitAny methods accept time-out values, but the corresponding TaskFactory.ContinueWhenAll/Task.WhenAny and the previously mentioned Task.WhenAll/Task.WhenAny methods do not. Instead, you can use Task.Delay and Task.WhenAny in combination to implement a time-out. For example, in your UI application, let's say that you want to download an image and disable the UI while the image is downloading. However, if the download takes too long, you want to re-enable the UI and discard the download: public async void btnDownload_Click(object sender, EventArgs e) { btnDownload.Enabled = false; try { Task<Bitmap> download = GetBitmapAsync(url); if (download == await Task.WhenAny(download, Task.Delay(3000))) { Bitmap bmp = await download; pictureBox.Image = bmp; status.Text = "Downloaded"; } else { pictureBox.Image = null; status.Text = "Timed out"; var ignored = download.ContinueWith( t => Trace("Task finally completed")); } } finally { btnDownload.Enabled = true; } } The same applies to multiple downloads, because WhenAll returns a task: public async void btnDownload_Click(object sender, RoutedEventArgs e) { btnDownload.Enabled = false; try { Task<Bitmap[]> downloads = Task.WhenAll(from url in urls select GetBitmapAsync(url)); if (downloads == await Task.WhenAny(downloads, Task.Delay(3000))) { foreach(var bmp in downloads) panel.AddImage(bmp); status.Text = "Downloaded"; } else { status.Text = "Timed out"; downloads.ContinueWith(t => Log(t)); } } finally { btnDownload.Enabled = true; } } Building Task-based Combinators Because a task is able to completely represent an asynchronous operation and provide synchronous and asynchronous capabilities for joining with the operation, retrieving its results, and so on, you can build useful libraries of combinators that compose tasks to build larger patterns. As discussed in the previous section, the .NET Framework includes several built-in combinators, but you can also build your own. The following sections provide several examples of potential combinator methods and types. RetryOnFault In many situations, you may want to retry an operation if a previous attempt fails. For synchronous code, you might build a helper method such as RetryOnFault in the following example to accomplish this: public static T RetryOnFault<T>( Func<T> function, int maxTries) { for(int i=0; i<maxTries; i++) { try { return function(); } catch { if (i == maxTries-1) throw; } } return default(T); } You can build an almost identical helper method for asynchronous operations that are implemented with TAP and thus return tasks: public static async Task<T> RetryOnFault<T>( Func<Task<T>> function, int maxTries) { for(int i=0; i<maxTries; i++) { try { return await function().ConfigureAwait(false); } catch { if (i == maxTries-1) throw; } } return default(T); } You can then use this combinator to encode retries into the application’s logic; for example: // Download the URL, trying up to three times in case of failure string pageContents = await RetryOnFault( () => DownloadStringAsync(url), 3); You could extend the RetryOnFault function further. For example, the function could accept another Func<Task> that will be invoked between retries to determine when to try the operation again; for example: public static async Task<T> RetryOnFault<T>( Func<Task<T>> function, int maxTries, Func<Task> retryWhen) { for(int i=0; i<maxTries; i++) { try { return await function().ConfigureAwait(false); } catch { if (i == maxTries-1) throw; } await retryWhen().ConfigureAwait(false); } return default(T); } You could then use the function as follows to wait for a second before retrying the operation: // Download the URL, trying up to three times in case of failure, // and delaying for a second between retries string pageContents = await RetryOnFault( () => DownloadStringAsync(url), 3, () => Task.Delay(1000)); NeedOnlyOne Sometimes, you can take advantage of redundancy to improve an operation’s latency and chances for success. Consider multiple web services that provide stock quotes, but at various times of the day, each service may provide different levels of quality and response times. To deal with these fluctuations, you may issue requests to all the web services, and as soon as you get a response from one, cancel the remaining requests. You can implement a helper function to make it easier to implement this common pattern of launching multiple operations, waiting for any, and then canceling the rest. The NeedOnlyOne function in the following example illustrates this scenario: public static async Task<T> NeedOnlyOne( params Func<CancellationToken,Task<T>> [] functions) { var cts = new CancellationTokenSource(); var tasks = (from function in functions select function(cts.Token)).ToArray(); var completed = await Task.WhenAny(tasks).ConfigureAwait(false); cts.Cancel(); foreach(var task in tasks) { var ignored = task.ContinueWith( t => Log(t), TaskContinuationOptions.OnlyOnFaulted); } return completed; } You can then use this function as Operations There is a potential performance problem with using the WhenAny method to support an interleaving scenario when you're working with very large sets of tasks. Every call to WhenAny results in a continuation being registered with each task. For N number of tasks, this results in O(N2) continuations created over the lifetime of the interleaving operation. If you're working with a large set of tasks, you can use a combinator ( Interleaved in the following example) to address the performance issue: static IEnumerable<Task<T>> Interleaved<T>(IEnumerable<Task<T>> tasks) { var inputTasks = tasks.ToList(); var sources = (from _ in Enumerable.Range(0, inputTasks.Count) select new TaskCompletionSource<T>())); }, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default); } return from source in sources select source.Task; } You can then use the combinator to process the results of tasks as they complete; for example: IEnumerable<Task<int>> tasks = ...; foreach(var task in Interleaved(tasks)) { int result = await task; … } WhenAllOrFirstException In certain scatter/gather scenarios, you might want to wait for all tasks in a set, unless one of them faults, in which case you want to stop waiting as soon as the exception occurs. You can accomplish that with a combinator method such as WhenAllOrFirstException in the following example: public static Task<T[]> WhenAllOrFirstException<T>(IEnumerable<Task<T>> tasks) { var inputs = tasks.ToList(); var ce = new CountdownEvent(inputs.Count); var tcs = new TaskCompletionSource<T[]>(); Action<Task> onCompleted = (Task completed) => { if (completed.IsFaulted) tcs.TrySetException(completed.Exception.InnerExceptions); if (ce.Signal() && !tcs.Task.IsCompleted) tcs.TrySetResult(inputs.Select(t => t.Result).ToArray()); }; foreach (var t in inputs) t.ContinueWith(onCompleted); return tcs.Task; } Building Task-based Data Structures In addition to the ability to build custom task-based combinators, having a data structure in Task and Task<TResult> that represents both the results of an asynchronous operation and the necessary synchronization to join with it makes it a very powerful type on which to build custom data structures to be used in asynchronous scenarios. AsyncCache One important aspect of a task is that it may be handed out to multiple consumers, all of whom may await it, register continuations with it, get its result or exceptions (in the case of Task<TResult>), and so on. This makes Task and Task<TResult> perfectly suited to be used in an asynchronous caching infrastructure. Here’s an example of a small but powerful asynchronous cache built on top of Task<TResult>: public class AsyncCache<TKey, TValue> { private readonly Func<TKey, Task<TValue>> _valueFactory; private readonly ConcurrentDictionary<TKey, Lazy<Task<TValue>>> _map; public AsyncCache(Func<TKey, Task<TValue>> valueFactory) { if (valueFactory == null) throw new ArgumentNullException("loader"); _valueFactory = valueFactory; _map = new ConcurrentDictionary<TKey, Lazy<Task<TValue>>>(); } public Task<TValue> this[TKey key] { get { if (key == null) throw new ArgumentNullException("key"); return _map.GetOrAdd(key, toAdd => new Lazy<Task<TValue>>(() => _valueFactory(toAdd))).Value; } } } The AsyncCache<TKey,TValue> class accepts as a delegate to its constructor a function that takes a TKey and returns a Task<TResult>. Any previously accessed values from the cache are stored in the internal dictionary, and the AsyncCache ensures that only one task is generated per key, even if the cache is accessed concurrently. For example, you can build a cache for downloaded web pages: private AsyncCache<string,string> m_webPages = new AsyncCache<string,string>(DownloadStringAsync); You can then use this cache in asynchronous methods whenever you need the contents of a web page. The AsyncCache class ensures that you’re downloading as few pages as possible, and caches the results. private async void btnDownload_Click(object sender, RoutedEventArgs e) { btnDownload.IsEnabled = false; try { txtContents.Text = await m_webPages[""]; } finally { btnDownload.IsEnabled = true; } } AsyncProducerConsumerCollection You can also use tasks to build data structures for coordinating asynchronous activities. Consider one of the classic parallel design patterns: producer/consumer. In this pattern, producers generate data that is consumed by consumers, and the producers and consumers may run in parallel. For example, the consumer processes item 1, which was previously generated by a producer who is now producing item 2. For the producer/consumer pattern, you invariably need some data structure to store the work created by producers so that the consumers may be notified of new data and find it when available. Here’s a simple data structure built on top of tasks that enables asynchronous methods to be used as producers and consumers: public class AsyncProducerConsumerCollection<T> { private readonly Queue<T> m_collection = new Queue<T>(); private readonly Queue<TaskCompletionSource<T>> m_waiting = new Queue<TaskCompletionSource<T>>(); public void Add(T item) { TaskCompletionSource<T> tcs = null; lock (m_collection) { if (m_waiting.Count > 0) tcs = m_waiting.Dequeue(); else m_collection.Enqueue(item); } if (tcs != null) tcs.TrySetResult(item); } public Task<T> Take() { lock (m_collection) { if (m_collection.Count > 0) { return Task.FromResult(m_collection.Dequeue()); } else { var tcs = new TaskCompletionSource<T>(); m_waiting.Enqueue(tcs); return tcs.Task; } } } } With that data structure in place, you can write code such as the following: private static AsyncProducerConsumerCollection<int> m_data = …; … private static async Task ConsumerAsync() { while(true) { int nextItem = await m_data.Take(); ProcessNextItem(nextItem); } } … private static void Produce(int data) { m_data.Add(data); } The System.Threading.Tasks.Dataflow namespace includes the BufferBlock<T> type, which you can use in a similar manner, but without having to build a custom collection type: private static BufferBlock<int> m_data = …; … private static async Task ConsumerAsync() { while(true) { int nextItem = await m_data.ReceiveAsync(); ProcessNextItem(nextItem); } } … private static void Produce(int data) { m_data.Post(data); } Note The System.Threading.Tasks.Dataflow namespace is available in the .NET Framework 4.5 through NuGet. To install the assembly that contains the System.Threading.Tasks.Dataflow namespace, open your project in Visual Studio, choose Manage NuGet Packages from the Project menu, and search online for the Microsoft.Tpl.Dataflow package.
https://docs.microsoft.com/en-us/dotnet/standard/asynchronous-programming-patterns/consuming-the-task-based-asynchronous-pattern
CC-MAIN-2018-51
en
refinedweb
The code looks right and submitted, but after I tried to add a user input to test it out, it no longer works Traceback (most recent call last): File "python", line 8, in File "python", line 4, in product TypeError: can't multiply sequence by non-int of type 'unicode' def product (integers): mult = 1 for i in integers: mult *= i return mult integers = raw_input("Enter some numbers:") product(integers)
https://discuss.codecademy.com/t/product/50343
CC-MAIN-2018-51
en
refinedweb
NAME DSA_set_default_method, DSA_get_default_method, DSA_set_method, DSA_new_method, DSA_OpenSSL - select DSA method SYNOPSIS #include <openssl/dsa); DESCRIPTION A DSA_METHOD specifies the functions that OpenSSL uses for DSA operations. By modifying the method, alternative implementations such as hardware accelerators may be used. IMPORTANT:. This function is not thread-safe and should not be called at the same time as other OpenSSL functions. DSA_get_default_method() returns a pointer to the current default DSA_METHOD. However, the meaningfulness of this result is dependent. See DSA_meth_new for information on constructing custom DSA_METHOD objects;. RETURN VALUES DSA_OpenSSL() and DSA_get_default_method() return pointers to the respective DSA_METHODs. DSA_set_default_method() returns no value. structure. SEE ALSO DSA_new(3), DSA_new(3), DSA_meth_new(3) Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at.
https://www.openssl.org/docs/manmaster/man3/DSA_get_default_method.html
CC-MAIN-2018-51
en
refinedweb
Big data has many applications, but none perhaps as ubiquitous and overlooked as geolocation. All of the mapping and navigation systems we use daily depend upon geo data—data that is constantly being refreshed. The range of things we map is mind boggling, from submarine cables to Napoleon's retreat from Moscow, and you can find many of them at ESRI, a private company founded in 1969 that works in the Global Information Systems (GIS) space. ESRI has a popular solution called ArcGIS for managing big data that enables companies to visualize and analyze information at terabyte scale—revealing patterns, trends, and relationships in a way that reports don't, or can't. Since big data is stored in many different places, a common challenge in creating GIS applications is getting fast access to disparate data. Developers have to constantly change the application to accommodate different data stores. I recently spoke with Mansour Raad, senior software architect at ESRI and a regular speaker at big data conferences, to see how he works with diverse datasets when he creates GIS applications. Geo data and apps TechRepublic: What kind of apps are you building? Mansour Raad: Our GIS software is used by 70% of the Fortune 500. We develop computer systems for capturing, storing, checking, and displaying data related to positions on the planet. Big data by definition, GIS displays a lot of different kinds of data on one map. That helps people see, analyze, and understand patterns and relationships. SEE: Big data policy template (Tech Pro Research) Our ArcGIS, the platform we use for big data apps, has a unique set of capabilities for applying location-based analysis to your business practices. You can easily share insights and collaborate with others via maps, apps and reports. Specifically, you can perform spatial analytics, mapping and visualization, 3D GIS, real-time GIS, and imagery and remote sensing. It all relies on massive amounts of data. GIS data gets gnarly TechRepublic: Why is GIS data particularly hard? Raad: There is a plethora of backend distributed data stores. I am always using S3, Apache Hadoop HDFS, or OpenStack Swift with my GIS applications to read from these backends' geospatial data or to save into these backends my data. Some of these distributed data stores are not natively supported by ESRI's ArcGIS platform (what we use to create GIS apps using big data). You can extend the platform with ArcPy to handle these situations. But depending on the data store, I will have to use a different API, mostly Python based, to handle these situations. It's not optimal. Accessing and storing data in unsupported data stores requires developers to constantly change their program for each data store. This slows development cycles and makes it much longer for customers to get insights from the data. Dealing with GIS data TechRepublic: How did you get around this problem of constantly changing APIs and apps to accommodate different data stores? SEE: How to build a successful data scientist career (free PDF) (TechRepublic) Raad: We found an interesting open source project out of UC Berkeley's AMPlabs that is now developed and supported by a commercial company in Silicon Valley called Alluxio. Alluxio provides a memory-speed distributed system that virtualizes data across disparate storage systems and, most important, provides a unified global namespace that enables new workflows across data in any storage system. This means that, at the application level, the code to access the data requires no change to the app. As a bonus, with its REST endpoint, Alluxio simplifies the integration with ArcGIS to write, read, and visualize GIS data. With Alluxio in the data architecture, accessing data from data stores not natively supported by ArcGIS becomes easier. Also see - Big data developers' hallelujah moment for distributed storage (TechRepublic) - How a big data hack brought a 300X performance bump and killed a major bottleneck (TechRepublic) - Here are the 3 top careers in data science, and how much they pay (TechRepublic) - 6 big data privacy practices every company should adopt in 2018 (TechRepublic) - Here are the 10 skills you need to become a data scientist, the no. 1 job in Americ.
https://www.techrepublic.com/article/heres-one-key-to-managing-geolocation-data-at-scale/
CC-MAIN-2018-51
en
refinedweb
Adding an Amazon RDS DB instance to your Python learning: For more information about configuring an internal DB instance, see Adding a database to your Elastic Beanstalk environment. Downloading a driver Add the database driver to your project's requirements file. Example requirements.txt – Django with MySQL Django==2.2 mysqlclient==2.0.3 Common driver packages for Python MySQL – mysqlclient PostgreSQL – psycopg2 Oracle – cx_Oracle SQL Server – adodbapi For more information see Python DatabaseInterfaces Connecting to a database Elastic Beanstalk provides connection information for attached DB instances in environment properties. Use os.environ[' to read the properties and configure a database connection. VARIABLE'] Example Django settings file – DATABASES dictionary import os if 'RDS_HOSTNAME''], } }
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-rds.html
CC-MAIN-2021-21
en
refinedweb
this onPreRender before any Camera begins rendering. To execute custom code at this point, create callbacks that match the signature of CameraCallback, and add them to this delegate. For similar functionality that applies only to a single Camera and requires your script to be on the same GameObject, see MonoBehaviour Camera.onPreCull. When Unity calls onPreRender, the Camera's render target and depth textures are not yet set up. If you need to access these, you can execute code later in the render loop using a CommandBuffer. using UnityEngine; public class CameraCallbackExample : MonoBehaviour { // Add your callback to the delegate's invocation list void Start() { Camera.onPreRender += OnPreRenderCallback; } // Unity calls the methods in this delegate's invocation list before rendering any camera void OnPreRenderRender -= OnPreRenderCallback; } }
https://docs.unity3d.com/ScriptReference/Camera-onPreRender.html
CC-MAIN-2021-21
en
refinedweb
Previous Page | Next Page What's New in SAS Decision Manager 2.2 Overview SAS Decision Manager 2.2 runs on the second maintenance release of SAS 9.4. The full functionality of the SAS Model Manager Java Client application and the Workflow Console web-based application have been integrated into SAS Decision Manager 2.2. New features and enhancements in this release enable you to perform these tasks: manage workflows and track workflow tasks publish models to Hadoop and SAP HANA manage versions of projects, rule sets, and rule flows deploy rule flows as stored processes run a wizard to generate and import vocabularies, rule sets, and rule flows from an input data source by using the Decision Tree, Scorecard, Market Basket Analysis, or Recency Frequency Monetary discovery techniques execute rule flows inside the databases by using the SAS In-Database Code Accelerator for Teradata or the SAS In-Database Code Accelerator for Greenplum selectively include rule sets in a rule flow save rule flow tests and display the results of previous tests display the rules fired for specific output records import vocabularies from an input data table, including domain values display the terms and lookup tables that are used in a rule set display where rules sets are used in rule flows create libraries and register tables in the SAS Metadata Repository Manage Workflows and Track Workflow Tasks The functionality of the SAS Model Manager Workflow Console is now available in SAS Decision Manager. You can manage your workflows and perform tasks in the same user interface that you use to manage business rules and modeling projects. For more information, see Overview of Using Workflows . Note: Rule flows can be sent through approval workflows only. The model life cycle functionality has been deprecated and replaced with functionality that leverages SAS Workflow. You can view only migrated life cycles. For more information, see View Life Cycle Status . Publish Models to Hadoop and SAP HANA Support has been added for publishing models to the Hadoop Distributed File System and to the SAP HANA database. You can also remove published model files from Hadoop, like the other publish destinations. However, you cannot remove published model files from an SAP HANA database. For more information, see Publishing Models to a Database . Manage Versions Within a modeling project, you can add new versions, lock or unlock a version, and switch the displayed version. One or more versions can be active at one time, but only one can be the champion version. For more information, see Overview of Project Versions . You can also manage versions of rule sets and rule flows. You can display detailed information about a rule set or rule flow version. For rule sets, you can lock a version and add new versions. For rule flows, a new version is created each time you publish a rule flow. See Managing Rule Set Versions and Managing Versions of a Rule Flow for more information. Deploy Rule Flows as Stored Processes When you save a rule flow as a stored process, the rule flow is made available as a stored process on the SAS Stored Process Server. Other applications can then execute the rule flow and receive and process the results. See Deploy a Rule Flow as a Stored Process for more information. New Rule Discovery Wizard SAS Decision Manager now provides a New Discovery window that enables you to use analytical techniques to generate and import rule flows from a data table. You can use the Decision Tree, Scorecard, Market Basket, or Recency Frequency Monetary (RFM) technique to generate and import business rule data into the rules database. This wizard generates a vocabulary, as many rule sets as are needed, and a rule flow. See Create a Rule Flow by Using Discovery Techniques for more information. Execute Rule Flows inside the Databases SAS Decision Manager 2.2 executes rule flows inside the databases by using the SAS In-Database Code Accelerator for Teradata or the SAS In-Database Code Accelerator for Greenplum when possible. Some complex rule flows cannot be executed inside the database. Support for Additional Operators SAS Decision Manager now supports the LIKE operator in condition expressions. It also supports leading + (plus) and – (minus) operators in action expressions. Create Libraries and Register Tables in the SAS Metadata Repository The Data Tables category enables you to create libraries and to register tables to the SAS Metadata Repository. You can use the tables can as data sources when you are working with business rules and with modeling projects. For more information, see Managing Data Tables . Previous Page | Next Page | Top of Page
https://support.sas.com/documentation/cdl/en/edmug/67015/HTML/default/edmugwhatsnew94.htm
CC-MAIN-2021-21
en
refinedweb
I’d like to check if my object is already present in a dictionary based on it’s name. My current implementation does not return expected results, so for sure I am missing something here. My class: @dataclass class Foo: name: str number: int def __hash__(self): return hash(self.name) and the code: d = {} foo1 = Foo('foo1', 1) foo2 = Foo('foo2', 2) foo3 = Foo('foo1', 3) foo4 = Foo('foo4', 1) d[foo1] = foo1 d[foo2] = foo2 print(f'Is foo3 in d? {foo3 in d}') # prints: "Is foo3 in d? False" Expected True (NOK) print(f'Is foo4 in d? {foo4 in d}') # prints: "Is foo4 in d? False" Expected False (OK) print(f'foo1 hash: {foo1.__hash__()}') # 4971911885166104854 print(f'foo3 hash: {foo1.__hash__()}') # 4971911885166104854 Do I need anything else than the __hash__() implementation? Answer You need to add the equality dunder also. From the documentation of __hash__ and __eq__: If a class does not define an eq() method it should not define a hash() operation either; After I add the __eq__, I get the following behavior. def __eq__(self, x): return hash(self) == hash(x) On running the program, I get: Is foo3 in d? True Is foo4 in d? False foo1 hash: -4460692046661292337 foo3 hash: -4460692046661292337
https://www.tutorialguruji.com/python/custom-hash-is-object-in-a-dictionary/
CC-MAIN-2021-21
en
refinedweb
In this article, we will discuss about coupling and cohesion in OOP, mainly because understanding about them is really useful to improve coding skill and some skills about designing architecture. Table of contents - Cohesion - Coupling - Difference between cohesion and coupling - Refactoring our code with loose coupling and high cohesion Cohesion Definition of cohesion According to wikipedia.org, we have definition of cohesion: In computer programming, cohesion method and data themselves. Or we have the other definition: Cohesion represents the clarity of the responsibilities of a module. –> So, cohesion focuses on how single module/class is designed. Higher the cohensiveness of the module/class, better is the OO design. If our module performs one task and nothing else or has a clear purpose, our module has high cohesion. On the other hand, if our module tries to encapsulate more than one purpose or has an unclear purpose, our module has low cohesion. Modules with high cohesion tend to be preferable, simple because high cohesion is associated with several desirable traits of software including robustness, reliability, and understandability. Low cohesion is associated with undesirable traits such as being difficult to maintain, test, reuse, or even understand. Cohesion is often contrasted with coupling. High cohesion often correlates with loose coupling, and vice versa. Single Responsibility Principle aims at creating highly cohesive classes. Cohesion is increased if: - The functionalities embedded in a class, accessed through its methods, have much in common. - Methods carry out a small number of related activities, by avoiding coarsely grained or unrelated sets of data. The history of Cohesion concept The coupling and cohesion were invented by Larry Constantine in the late 1960s as part of Structured Design, based on characteristics of good programming practices that reduced maintainenance and modification costs. Structured Design, cohesion and coupling were published in the article Stevens, Myers & Constantine (1974) and the book Yourdon & Constantine (1979), the latter two subsequently became standard terms in software engineering. Advantages of high cohesion - Reduced module complexity (they are simpler, having fewer operations). - Increased system maintainability, because logical changes in the domain affect fewer modules, and because changes in one module require fewer changes in other modules. - Increased module reusability, because application developers will find the component they need more easily among the cohesive set of operations provided by the module. For example about cohesion We can see that in low cohesion, only one class is responsible for executing a lot of jobs which are not in common. It will reduce the chance of reusability and maintaince. In high cohesion, there is a separate class for all the jobs to execute a specific job, which result better usability and maintaince. –> So, we have: - High cohesion is when For example: public class Person { private int age; private String name; // getter, setter properties. // method public void readInfor(); public void writeInfor(); } The Personclass has low cohesion, simply because Person’s responsibilities is relevant to save information about people. It do not relate to functionalities about read/write to file. So, to reduce low cohension, we should separate the implementation about read/write file into other class such as File, … Types of cohesion There are some types of cohesion that we need to know: Coincidental cohesion(worst) Coincidental cohesion is when parts of a module are grouped arbitrarily; the only relationship between the parts is that they have been grouped together. For example: Utilities class. Logical cohesion Logical cohesion is when parts of a module are grouped because they are logically categorized to do the same thing even though they are different by nature. For example: grouping all mouse and keyboard input handling routines. Temporal cohesion Temporal cohesion is when parts of a module are grouped by when they are processed - the parts at a particular time in program execution. For example: A function which is called after catching an exception which closes open files, creates an error log, and notifies the user. Procedural cohesion Procedural cohesion is when parts of a module are grouped because they always follow a certain sequence of execution. For example: a function which checks file permissions and then opens the file. Communicational / Informal cohesion Communicational cohesion is when parts of a module are grouped because they operate on the same data. There are cases where communicational cohesion is the highest level of cohesion that can be attained under the circumstances. For example: a module which operates on the same record of information. Sequential cohesion Sequential cohesion is when parts of a module are grouped because the output from one part is the input to another part like an assembly line. For example: a function which reads data from a file and processes the data. Functional cohesion(best) Functional cohesion is when parts of a module are grouped because they all contribute to a single well-defined task of the module. While functional cohesion is considered the most desirable type of cohesion for a software module, it may no be achievable. For example: Module A { /* Implementation of arithmetic operations This module is said to have functional cohesion because there is an intention to group simple arithmetic operations on it. */ a(x, y) = x + y b(x, y) = x * y } Module B { /* Module B: Implements r(x) = 5x + 3 This module can be said to have atomic cohesion. The whole system (with Modules A and B as parts) can also be said to have functional cohesion, because its parts both have specific separate purposes. */ r(x) = [Module A].a([Module A].b(5, x), 3) } Perfect cohesion (atomic) For example: Module A { /* Implementation of r(x) = 2x + 1 + 3x + 2 It´s said to have perfect cohesion because it cannot be reduced any more than that. */ r(x) = 5x + 3 } Coupling Definition According to wikipedia.org, we have a definition of coupling: Coupling is the degree of interdependence between software modules; a measure of how closely connected two routines or modules are; the strength of the relationships between modules. Coupling increases between two classes A and B if: - A has an attribute that refers to (is of type) B. - A calls on services of an object B. - A has a method that reference B (via return type or parameter). - A is a subclass of (or implements) class B. Low coupling refers to a relationship in which one module interacts with another module through a simple and stable interface and does not need to be concerned with the other module’s internal implementation Some properties that need to consider in coupling In Coupling, we need to consider some properties: Degree Degree is the number of connections between the module and others. With coupling, we want to keep the degree small. For instance, if the module needed to connect to other modules through a few parameters or narrow interfaces, then the degree would be small, and coupling would be loose. Ease Ease is how obvious are the connections between the module and others. With coupling, we want the connections to be easy to make without needing to understand the implementations of the other modules. Flexibility Flexibility is how interchangeable the other modules are for this module. With coupling, we want the other modules easily replaceable for something better in the future. Disadvantages of tightly coupling A change in one module usually forces a ripple effect of changes in other modules. Assembly of modules might require more effort or time due to the increased inter-module dependency. A particular module might be harder to reuse or test because dependent modules must be included. Types of coupling In procedural programming, we have: Content coupling(high) Content coupling is said to occur when one module uses the code of other module, for instance a branch. This violates information hiding - a basic design concept. Common coupling Common coupling is said to occur when several modules have access to the same global data. But it can lead to uncontrolled error propagation and unforeseen side-effects when changes are made. External coupling External coupling occurs when two modules share an externally imposed data format, communication protocol, or device interface. This is basically related to the communication to external tools and devices. Control coupling Control coupling is one module controlling the flow of another, by passing it information on what to do For example: passing a what-to-do flag. Stamp coupling(data-structured coupling) Stamp coupling occurs when modules share a composite data structure and use only parts of it, possibly different parts(E.g: passing a whole record to a function that needs only one field of it). In this situation, a modification in a field that a module does not need may lead to changing the way the module reads the record. Data coupling Data coupling occurs when modules share data through, for example, parameters. Each datum is an elementary piece, and these are the only data shared (Ex: passing an integer to a function that computes a square root). In OOP, we have: Subclass coupling Describes the relationship between a child and its parent. The child is connected to its parent, but the parent is not connected to the child. Temporal coupling When two actions are bundled together into one module just because they happen to occur at the same time. Dynamic coupling The goal of this type of coupling is to provide a run-time evaluation of a software system. It has been argued that static coupling metrics lose precision when dealing with an intensive use of dynamic binding or inheritance. In the attempt to solve this issue, dynamic coupling measures have been taken into account. Semantic coupling This kind of coupling considers the conceptual similarities between software entities using, for example, comments and identifiers and relying on techniques. Logical coupling Logical coupling exploits the release history of a software system to find change patterns among modules or classes. For example: Entities that are likely to be changed or sequences of changes (a change in a class A is always followed by a change in a class B). –> So, one approach to decreasing coupling is functional design, which seeks to limit the responsibilities of modules along functionality. Difference between cohesion and coupling Below is a table that depict about difference between cohesion and coupling Refactoring our code with loose coupling and high cohesion Thanks for your reading. Refer: Object-Oriented Analysis, Design and Implementation, 2nd Edition
https://ducmanhphan.github.io/2019-03-23-Coupling-and-Cohension-in-OOP/
CC-MAIN-2021-21
en
refinedweb
Table of Content What is Swagger? Swagger is one type of platform that provides the facility to access API data. In this detailed technical document,we will learn how a web service can reply to web requests from clients such as browsers. Swagger is a popular framework which is used to describe the structure of your API so that machines can read them. It is used widely by many ASP.Net software development companies across the globe. API helps you to find the root of the application very easily.With the help of swagger APIs structure, we can automatically build beautiful and interactive API documentation. What is the use of Swagger? Swagger is one type of platform that is used to Run API and check Authentication System.The Swagger is the most popular and the most powerful HTTP client for testing the restful web services Example of Swagger Step by Step - For implementing swagger in ASP.Net Core, first, we will create a new project. For creating a new ASP.Net Core Web API, we will open Visual Studio 2019. Once Visual Studio is open, we will select the menu option File -> New -> Project. - Once the new project creation window pops up, do select the ASP.Net Core Web Application,and click the Next button. - In Visual Studio please go with this process: Select project in Solution Explorer click -> Manage NuGet Packages - Enter Swashbuckle in the search box - Check “Include prerelease”->select the package Swashbuckle package and then tap Install. - This is used for generating Swagger documents for Web APIs that are built with ASP.NET MVC 1. Enable XML Project Go to the Project ->Right-click the project in Solution Explorer and select Properties Delete the "bin\Debug" from the path, and get the XML file directly from Solution Folder,Add Link. Browse and Select the file -> Click on the dropdown arrow next to the ADD button - Select "Add as Link" (Adding the file as Link, will not copy the file to the project) 2. Configuring Swagger in Startup class Now, it is time to configure Swagger inside of the Startup class. For this purpose, I would update the ConfigureServices to add Swagger. Action Result, we will use the SwaggerGenOptions and call the method SwaggerDoc on it. The SwaggerDoc method takes two parameters Add Below Code in Startup file using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Microsoft.IdentityModel.Tokens; using Swashbuckle.AspNetCore.Swagger; namespace JWTSwaggerPracticalExam { public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration { get; } // ConfigureService Add the JWT services public void ConfigureServices(IServiceCollection services) { services.AddSwaggerGen(c => { c.SwaggerDoc("s1", new Info { Version = "s1", Title = "MyAPI", Description = "Testing" }); c.AddSecurityDefinition("Bearer", new ApiKeyScheme() { Description = "JWT Authorization header {token}", Name = "Authorization", Type = "apiKey" }); c.AddSecurityRequirement(new Dictionary > { {"Bearer",new string[] { } } }); });(); } public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/s1/swagger.json","MyAPI"); }); //if (env.IsDevelopment()) //{ // app.UseDeveloperExcepti config; } [AllowAnonymous] [HttpPost] public IActionResult Login([FromBody]UserData login) { IActionResult response = Unauthorized(); var user = AuthenticateUser(login); if (user != null) { var tokenString = GenerateJSONWebToken(user); response = Ok(new { token = tokenString }); } return response; } This method was created with the Token in JSON Format.This token is usedto verify the authentication whether the Username or Password is Matching or not. If not, then this method could have issues and need to rectify. private string GenerateJSONWebToken(UserData); } From the below code you can notice the basic key added in appsettings.json. You can also add it according to your choice, "AllowedHosts": "*", "profiles": { "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, "launchUrl": "swagger", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } } Create a New Controller Name liketestControllerthat is usedto create a list and get value in swagger. using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; namespace JWTSwaggerPracticalExam.Controllers { [Route("api/[controller]")] [ApiController] public class TestController : ControllerBase { [HttpGet] [Authorize] [Route("Get")] public ActionResult > Get() { Return New String { "raj", "xxx", "harsh" }; } } Add new model Name Like UserData, this Model is set with user name and password. When we enter the username and password in the swagger, that time data would be verified here and the data of UserDatais passed to the Controller. And then the Controller checks the condition whether the user is valid or not.If valid, then it returnswith statementlike “user is valid” otherwise returns “user is not valid”. using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc namespace JWTSwaggerPracticalExam.Models { public class UserData { public string username { get; set; } public string password { get; set; } } } 3. Now Run the Project,you will get the swagger UI as shown below After that, click on login and click on try it out. Now insert username and password, if both are the correct then it returns200 code and success. After Generating token copy the token and paste into the authentication Like Bearer=” Paste The Token Here” If a token is valid then we get successfully Logged in otherwise it showsauthentication failed401 and Unauthorized error occurred, You can download the project from below link : After Downloading the project, Unzip the file and open the solution in visual studio 2017 or 2019 and add the Swashbuckle Package and run the Project.Here you will see the API URL. Change this URL and write /Swagger then click on the login method and try it. Wants to Talk with Our Highly Skilled.Net Developer ? Contact Now. Conclusion In this article, we have learned how Asp.Net Swagger works and how a web service can reply to web requests from clients such as browsers. Once you understand the needed steps, then it becomes easier to understand the advanced level of Swagger and tools.
https://www.ifourtechnolab.com/blog/what-is-swagger-and-how-to-use-it-in-asp-net-application
CC-MAIN-2021-21
en
refinedweb
Resources Resources represent the fundamental components that make up your infrastructure, such as a compute instance, storage bucket, or database instance. All infrastructure resources are described by one of two subclasses of the Resource class. These two subclasses are: CustomResource: A resource managed by a resource providers, such as AWS, Microsoft Azure, Google Cloud, Kubernetes, and so on. ComponentResource: A component resource is a logical grouping of other resources that creates a larger, higher-level abstraction that encapsulates its implementation details. Custom Resources The Pulumi SDK has libraries for AWS, Google, Azure, with Kubernetes, as well as other providers. These libraries describe the custom resources that each cloud provider currently offers and are updated frequently to match changes to underlying services. To use a provider library, import or reference the relevant library package when writing a program, as you would with any other shared library. For more information on the resources for each provider, see Resource Documentation. A custom resource’s desired state is declared by constructing an instance of the resource: let res = new Resource(name, args, options); let res = new Resource(name, args, options); res = Resource(name, args, options) res, err := NewResource(ctx, name, args, opt1, opt2) var res = new Resource(name, args, options); All resources have a required name argument, which must be unique across resources of the same kind in a stack. This logical name influences the physical name assigned by your infrastructure’s cloud provider. Pulumi auto-names physical resources by default, so the physical name and the logical name may differ. This auto-naming behavior can be overridden, if required. The args argument is an object with a set of named property input values that are used to initialize the resource. These can be normal raw values—such as strings, integers, lists, and maps—or outputs from other resources. For more information, see Inputs and Outputs. The options argument is optional, but lets you control certain aspects of the resource. For example, you can show explicit dependencies, use a custom provider configuration, or import an existing infrastructure. Resource Names Every resource managed by Pulumi has a logical name that you specify as an argument to its constructor. For instance, the logical name of this IAM role is my-role: let role = new aws.iam.Role("my-role"); let role = new aws.iam.Role("my-role"); role = iam.Role("my-role") role, err := iam.NewRole(ctx, "my-role", &iam.RoleArgs{}) var role = new Aws.Iam.Role("my-role"); The logical name you specify during resource creation is used in two ways: - As a default prefix for the resource’s physical name, assigned by the cloud provider. - To construct the Universal Resource Name (URN) used to track the resource across updates. Pulumi uses the logical name to track the identity of a resource through multiple deployments of the same program and uses it to choose between creating new resources or updating existing ones. The variable names assigned to resource objects are not used for either logical or physical resource naming. The variable only refers to that resource in the program. For example, in this code: var foo = new aws.Thing("my-thing"); The variable name foo has no bearing at all on the resulting infrastructure. You could change it to another name, run pulumi up, and the result would be no changes. The only exception is if you export that variable, in which case the name of the export would change to the new name. Physical Names and Auto-Naming A resource’s logical and physical names may not match. In fact, most physical resource names in Pulumi are, by default, auto-named. As a result, even if your IAM role has a logical name of my-role, the physical name will typically look something like my-role-d7c2fa0. The suffix appended to the end of the name is random. This random suffix serves two purposes: - It ensures that two stacks for the same project can be deployed without their resources colliding. The suffix helps you to create multiple instances of your project more easily, whether because you want, for example, many development or testing stacks, or to scale to new regions. - It allows Pulumi to do zero-downtime resource updates. Due to the way some cloud providers work, certain updates require replacing resources rather than updating them in place. By default, Pulumi creates replacements first, then updates the existing references to them, and finally deletes the old resources. For cases that require specific names, you can override auto-naming by specifying a physical name. Most resources have a name property that you can use to name the resource yourself. Specify your name in the argument object to the constructor. Here’s an example. let role = new aws.iam.Role("my-role", { name: "my-role-001", }); let role = new aws.iam.Role("my-role", { name: "my-role-001", }); role = iam.Role('my-role', { name='my-role-001' }) role, err := iam.NewRole(ctx, "my-role", &iam.RoleArgs{ Name: pulumi.String("my-role-001"), }) var role = new Aws.Iam.Role("my-role", new Aws.Iam.RoleArgs { Name = "my-role-001", }); If the name property is not available on a resource, consult the API Reference for the specific resource you are creating. Some resources use a different property to override auto-naming. For instance, the aws.s3.Bucket type uses the property bucket instead of name. Other resources, such as aws.kms.Key, do not have physical names and use other auto-generated IDs to uniquely identify them. Overriding auto-naming makes your project susceptible to naming collisions. As a result, for resources that may need to be replaced, you should specify deleteBeforeReplace: true in the resource’s options. This option ensures that old resources are deleted before new ones are created, which will prevent those collisions. Because physical and logical names do not need to match, you can construct the physical name by using your project and stack names. Similarly to auto-naming, this approach protects you from naming collisions while still having meaningful names. Note that deleteBeforeReplace is still necessary: let role = new aws.iam.Role("my-role", { name: "my-role-" + pulumi.getProject() + "-" + pulumi.getStack(), }, { deleteBeforeReplace: true }); let role = new aws.iam.Role("my-role", { name: `my-role-${pulumi.getProject()}-${pulumi.getStack()}`, }, { deleteBeforeReplace: true }); role = iam.Role('my-role', { name='my-role-{}-{}'.format(pulumi.get_project(), pulumi.get_stack()) }, opts=ResourceOptions(delete_before_replace=True)) role, _ := iam.NewRole(ctx, "my-role", &iam.RoleArgs{ Name: fmt.Sprintf("my-role-%s-%s", ctx.Project(), ctx.Stack()), }, pulumi.DeleteBeforeReplace(true)) var role = new Aws.Iam.Role("my-role", new Aws.Iam.RoleArgs { Name = string.Format($"my-role-{Deployment.Instance.ProjectName}-{Deployment.Instance.StackName}"), }, new CustomResourceOptions { DeleteBeforeReplace = true } ); Resource URNs Each resource is assigned a Uniform Resource Name (URN) that uniquely identifies that resource globally. Unless you are writing a tool, you will seldom need to interact with an URN directly, but it is fundamental to how Pulumi works so it’s good to have a general understanding of it. The URN is automatically constructed from the project name, stack name, resource name, resource type, and the types of all the parent resources (in the case of component resources). The following is an example of a URN: urn:pulumi:production::acmecorp-website::custom:resources:Resource$aws:s3/bucket:Bucket::my-bucket ^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^ <stack-name> <project-name> <parent-type> <resource-type> <resource-name> The URN must be globally unique. This means all of the components that go into a URN must be unique within your program. If you create two resources with the same name, type, and parent path, for instance, you will see an error: error: Duplicate resource URN 'urn:pulumi:production::acmecorp-website::custom:resources:Resource$aws:s3/bucket:Bucket::my-bucket'; try giving it a unique name Any change to the URN of a resource causes the old and new resources to be treated as unrelated—the new one will be created (since it was not in the prior state) and the old one will be deleted (since it is not in the new desired state). This behavior happens when you change the name used to construct the resource or the structure of a resource’s parent hierarchy. Both of these operations will lead to a different URN, and thus require the create and delete operations instead of an update or replace operation that you would use for an existing resource. In other words, be careful when you change a resource’s name. Resources constructed as children of a component resource should ensure their names are unique across multiple instances of the component resource. In general, the name of the component resource instance itself (the name parameter passed into the component resource constructor) should be used as part of the name of the child resources. Resource Arguments A resource’s argument parameters differ by resource type. Each resource has a number of named input properties that control the behavior of the resulting infrastructure. To determine what arguments a resource supports, refer to that resource’s API documentation. Resource Options All resource constructors accept an options argument that provide the following resource options: - additionalSecretOutputs: specify properties that must be encrypted as secrets. - aliases: specify aliases for this resource, so that renaming or refactoring doesn’t replace it. - customTimeouts: override the default retry/timeout behavior for resource provisioning. The default value varies by resource. - deleteBeforeReplace: override the default create-before-delete behavior when replacing a resource. - dependsOn: specify additional explicit dependencies in addition to the ones in the dependency graph. - ignoreChanges: declare that changes to certain properties should be ignored during a diff. - import: bring an existing cloud resource into Pulumi. - parent: establish a parent/child relationship between resources. - protect: prevent accidental deletion of a resource by marking it as protected. - provider: pass an explicitly configured provider, instead of using the default global provider. - transformations: dynamically transform a resource’s properties on the fly. - version: pass a provider plugin version that should be used when operating on a resource. additionalSecretOutputs This option specifies a list of named output properties that should be treated as secrets, which means they will be encrypted. It augments the list of values that Pulumi detects, based on secret inputs to the resource. This example ensures that the password generated for a database resource is an encrypted secret: let db = new Database("new-name-for-db", { /*...*/ }, { additionalSecretOutputs: ["password"] }); let db = new Database("new-name-for-db", { /*...*/ }, { additionalSecretOutputs: ["password"] }); db = Database('db', opts=ResourceOptions(additional_secret_outputs=['password'])) db, err := NewDatabase(ctx, "db", &DatabaseArgs{ /*...*/ }, pulumi.AdditionalSecretOutputs([]string{"password"})) var db = new Database("new-name-for-db", new DatabaseArgs(), new CustomResourceOptions { AdditionalSecretOutputs = { "password" } }); Only top-level resource properties can be designated secret. If sensitive data is nested inside of a property, you must mark the entire top-level output property as secret. aliases This option provides a list of aliases for a resource or component resource. If you’re changing the name, type, or parent path of a resource or component resource, you can add the old name to the list of aliases for a resource to ensure that existing resources will be migrated to the new name instead of being deleted and replaced with the new named resource. For example, imagine we change a database resource’s name from old-name-for-db to new-name-for-db. By default, when we run pulumi up, we see that the old resource is deleted and the new one created. If we annotate that resource with the aliases option, however, the resource is updated in-place: let db = new Database("new-name-for-db", {/*...*/}, { aliases: [{ name: "old-name-for-db" }] }); let db = new Database("new-name-for-db", {/*...*/}, { aliases: [{ name: "old-name-for-db" }] }); db = Database('db', opts=ResourceOptions(aliases=[Alias(name='old-name-for-db')])) db, err := NewDatabase(ctx, "db", &DatabaseArgs{ /*...*/ }, pulumi.Aliases(pulumi.Alias{Name: pulumi.String("old-name-for-db")})) var db = new Database("new-name-for-db", new DatabaseArgs(), new CustomResourceOptions { Aliases = { new Alias { Name = "old-name-for-db"} } }); The aliases option accepts a list of old identifiers. If a resource has been renamed multiple times, it can have many aliases. The list of aliases may contain old Alias objects and/or old resource URNs. The above example used objects of type Alias with the old resource names. These values may specify any combination of the old name, type, parent, stack, and/or project values. Alternatively, you can just specify the URN directly: let db = new Database("new-name-for-db", {/*...*/}, { aliases: [ "urn:pulumi:stackname::projectname::aws:rds/database:Database::old-name-for-db" ] }); let db = new Database("new-name-for-db", {/*...*/}, { aliases: [ "urn:pulumi:stackname::projectname::aws:rds/database:Database::old-name-for-db" ] }); db = Database('db', opts=ResourceOptions(aliases=['urn:pulumi:stackname::projectname::aws:rds/database:Database::old-name-for-db'])) db, err := NewDatabase(ctx, "db", &DatabaseArgs{ /*...*/ }, pulumi.Aliases([]pulumi.Alias{pulumi.Alias{ URN: pulumi.URN("urn:pulumi:stackname::projectname::aws:rds/database:Database::old-name-for-db"), }}) ) var db = new Database("new-name-for-db", new DatabaseArgs(), new CustomResourceOptions { Aliases = { new Alias { Urn = "urn:pulumi:stackname::projectname::aws:rds/database:Database::old-name-for-db" } } }); customTimeouts This option provides a set of custom timeouts for create, update, and delete operations on a resource. These timeouts are specified using a duration string such as “5m” (5 minutes), “40s” (40 seconds), or “1d” (1 day). Supported duration units are “ns”, “us” (or “µs”), “ms”, “s”, “m”, and “h” (nanoseconds, microseconds, milliseconds, seconds, minutes, and hours, respectively). For the most part, Pulumi automatically waits for operations to complete and times out appropriately. In some circumstances, such as working around bugs in the infrastructure provider, custom timeouts may be necessary. This example specifies that the create operation should wait up to 30 minutes to complete before timing out: let db = new Database("db", {/*...*/}, { customTimeouts: { create: "30m" } }); let db = new Database("db", {/*...*/}, { customTimeouts: { create: "30m" } }); db = Database('db', opts=ResourceOptions(custom_timeouts=CustomTimeouts(create='30m'))) db, err := NewDatabase(ctx, "db", &DatabaseArgs{ /*...*/ }, pulumi.Timeouts(&pulumi.CustomTimeouts{Create: "30m"})) var db = new Database("db", new DatabaseArgs(), new CustomResourceOptions { CustomTimeouts = new CustomTimeouts { Create = TimeSpan.FromMinutes(30) } }); deleteBeforeReplace A resource may need to be replaced if an immutable property changes. In these cases, cloud providers do not support updating an existing resource so a new instance will be created and the old one deleted. By default, to minimize downtime, Pulumi creates new instances of resources before deleting old ones. Setting the deleteBeforeReplace option to true means that Pulumi will delete the existing resource before creating its replacement. Be aware that this behavior has a cascading impact on dependencies so more resources may be replaced, which can lead to downtime. However, this option may be necessary for some resources that manage scarce resources behind the scenes, and/or resources that cannot exist side-by-side. This example deletes a database entirely before its replacement is created: let db = new Database("db", {/*...*/}, { deleteBeforeReplace: true}); let db = new Database("db", {/*...*/}, { deleteBeforeReplace: true}); db = Database("db", opts=ResourceOptions(delete_before_replace=True)) db, err := NewDatabase(ctx, "db", &DatabaseArgs{ /*...*/ }, pulumi.DeleteBeforeReplace(true)) // The resource will be deleted before it's replacement is created var db = new Database("db", new DatabaseArgs(), new CustomResourceOptions { DeleteBeforeReplace = true }); dependsOn The dependsOn option creates a list of explicit dependencies between resources. Pulumi automatically tracks dependencies between resources when you supply an input argument that came from another resource’s output properties. In some cases, however, you may need to explicitly specify additional dependencies that Pulumi doesn’t know about but must still respect. This might happen if a dependency is external to the infrastructure itself—such as an application dependency—or is implied due to an ordering or eventual consistency requirement. The dependsOn option ensures that resource creation, update, and deletion operations are done in the correct order. This example demonstrates how to make res2 dependent on res1, even if there is no property-level dependency: let res1 = new MyResource("res1", {/*...*/}); let res2 = new MyResource("res2", {/*...*/}, { dependsOn: [res1] }); let res1 = new MyResource("res1", {/*...*/}); let res2 = new MyResource("res2", {/*...*/}, { dependsOn: [res1] }); res1 = MyResource("res1") res2 = MyResource("res2", opts=ResourceOptions(depends_on=[res1])) res1, _ := NewMyResource(ctx, "res1", &MyResourceArgs{/*...*/}) res2, _ := NewMyResource(ctx, "res2", &MyResourceArgs{/*...*/}, pulumi.DependsOn([]Resource{res1})) var res1 = new MyResource("res1", new MyResourceArgs()); var res2 = new MyResource("res2", new MyResourceArgs(), new CustomResourceOptions { DependsOn = { res1 } }); ignoreChanges This option specifies a list of properties that Pulumi will ignore when it updates existing resources. Any properties specified in this list that are also specified in the resource’s arguments will only be used when creating the resource. For instance, in this example, the resource’s prop property “new-value” will be set when Pulumi initially creates the resource, but from then on, any updates will ignore it: let res = new MyResource("res", { prop: "new-value" }, { ignoreChanges: ["prop"] }); let res = new MyResource("res", { prop: "new-value" }, { ignoreChanges: ["prop"] }); res = MyResource("res", prop="new-value", opts=ResourceOptions(ignore_changes=["prop"])) res, _ := NewMyResource(ctx, "res", &MyResourceArgs{Prop: "new-value"}, pulumi.IgnoreChanges([]string{"prop"})) var res = new MyResource("res", new MyResourceArgs { Prop = "new-value" }, new CustomResourceOptions { IgnoreChanges = { "prop" } }); One reason you would use the ignoreChanges option is to ignore changes in properties that lead to diffs. Another reason is to change the defaults for a property without forcing all existing deployed stacks to update or replace the affected resource. This is common after you’ve imported existing infrastructure provisioned by another method into Pulumi. In these cases, there may be historical drift that you’d prefer to retain, rather than replacing and reconstructing critical parts of your infrastructure. In addition to passing simple property names, nested properties can also be supplied to ignore changes to a more targeted nested part of the resource’s inputs. Here are examples of legal paths that can be passed to specify nested properties of objects and arrays, as well as to escape object keys that contain special characters: root root.nested root["nested"] root.double.nest root["double"].nest root["double"]["nest"] root.array[0] root.array[100] root.array[0].nested root.array[0][1].nested root.nested.array[0].double[1] root["key with \"escaped\" quotes"] root["key with a ."] ["root key with \"escaped\" quotes"].nested ["root key with a ."][100] ignoreChangesshould always be the “camelCase” version of the property name, as used in the core Pulumi resource model. import This option imports an existing cloud resource so that Pulumi can manage it. Imported resources can have been provisioned by any other method, including manually in the cloud console or with the cloud CLI. To import a resource, first specify the import option with the resource’s ID. This ID is the same as would be returned by the id property for any resource created by Pulumi; the ID is resource-specific. Pulumi reads the current state of the resource with the given ID from the cloud provider. Next, you must specify all required arguments to the resource constructor so that it exactly matches the state to import. By doing this, you end up with a Pulumi program that will accurately generate a matching desired state. This example imports an existing EC2 security group with ID sg-04aeda9a214730248 and an EC2 instance with ID i-06a1073de86f4adef: let aws = require("" }); import * as aws from "" }); # IMPORTANT: Python appends an underscore (`import_`) to avoid conflicting with the keyword. import pulumi_aws as aws group = aws.ec2.SecurityGroup('web-sg', name='web-sg-62a569b', description='Enable HTTP access', ingress=[ { 'protocol': 'tcp', 'from_port': 80, 'to_port': 80, 'cidr_blocks': ['0.0.0.0/0'] } ], opts=ResourceOptions(import_='sg-04aeda9a214730248')) server = aws.ec2.Instance('web-server', ami='ami-6869aa05', instance_type='t2.micro', security_groups=[group.name], opts=ResourceOptions(import_='i-06a1073de86f4adef')) group, err := ec2.NewSecurityGroup(ctx, "web-sg", &ec2.SecurityGroupArgs{ Name: pulumi.String("web-sg-62a569b"),")}, }, }, }, pulumi.Import(pulumi.ID("sg-04aeda9a214730248")), ) if err != nil { return err } server, err := ec2.NewInstance(ctx, "web-server", &ec2.InstanceArgs{ Ami: pulumi.String("ami-6869aa05"), InstanceType: pulumi.String("t2.micro"), SecurityGroups: pulumi.StringArray{group.Name}, }, pulumi.Import(pulumi.ID("i-06a1073de86f4adef")), ) if err != nil { return err } var group = new SecurityGroup("web-sg", new SecurityGroupArgs { Name = "web" } ); var server = new Instance("web-server", new InstanceArgs { Ami = "ami-6869aa05", InstanceType = "t2.micro", SecurityGroups = { group.Name } }, new CustomResourceOptions { ImportId = "i-06a1073de86f4adef" } ); For this to work, your Pulumi stack must be configured correctly. In this example, it’s important that the AWS region is correct. If the resource’s arguments differ from the imported state, the import will fail. You will receive this message: warning: inputs to import do not match the existing resource; importing this resource will fail. Select “details” in the pulumi up preview to learn what the differences are. If you try to proceed without correcting the inconsistencies, you will see this message: error: inputs to import do not match the existing resource. To fix these errors, make sure that your program computes a state that completely matches the resource to be imported. Because of auto-naming, it is common to run into this error when you import a resource’s name property. Unless you explicitly specify a name, Pulumi will auto-generate one, which is guaranteed not to match, because it will have a random hex suffix. To fix this problem, explicitly specify the resource’s name as described here. Note that, in the example for the EC2 security group, the name was specified by passing web-sg-62a569b as the resource’s name property. Once a resource is successfully imported, remove the import option because Pulumi is now managing the resource. parent This option specifies a parent for a resource. It is used to associate children with the parents that encapsulate or are responsible for them. Good examples of this are component resources. The default behavior is to parent each resource to the implicitly-created pulumi:pulumi:Stack component resource that is a root resource for all Pulumi stacks. For example, this code creates two resources, a parent and child, the latter of which is a child to the former: let parent = new MyResource("parent", {/*...*/}); let child = new MyResource("child", {/*...*/}, { parent: parent }); let parent = new MyResource("parent", {/*...*/}); let child = new MyResource("child", {/*...*/}, { parent: parent }); parent = MyResource("parent"); child = MyResource("child", opts=ResourceOptions(parent=parent)); parent, _ := NewMyResource(ctx, "parent", &MyResourceArgs{/*...*/}) child, _ := NewMyResource(ctx, "child", &MyResourceArgs{/*...*/}, pulumi.Parent(parent)) var parent = new MyResource("parent", new MyResourceArgs()); var child = new MyResource("child", new MyResourceArgs(), new CustomResourceOptions { Parent = parent }); Using parents can clarify causality or why a given resource was created in the first place. For example, this pulumi up output shows an AWS Virtual Private Cloud (VPC) with two subnets attached to it, and also shows that the VPC directly belongs to the implicit pulumi:pulumi:Stack resource: Previewing update (dev): Type Name Plan pulumi:pulumi:Stack parent-demo-dev + ├─ awsx:x:ec2:Vpc default-vpc-866580ff create + │ ├─ awsx:x:ec2:Subnet default-vpc-866580ff-public-1 create + │ └─ awsx:x:ec2:Subnet default-vpc-866580ff-public-0 create protect The protect option marks a resource as protected. A protected resource cannot be deleted directly. Instead, you must first set protect: false and run pulumi up. Then you can delete the resource by removing the line of code or by running pulumi destroy. The default is to inherit this value from the parent resource, and false for resources without a parent. let db = new Database("db", {}, { protect: true}); let db = new Database("db", {}, { protect: true}); db = Database("db", opts=ResourceOptions(protect=True)) db, _ := NewDatabase(ctx, "db", &DatabaseArgs{}, pulumi.Protect(true)); var db = new Database("db", new DatabaseArgs(), new CustomResourceOptions { Protect = true }); provider The provider option sets a provider for the resource. For more information, see Providers. The default is to inherit this value from the parent resource, and to use the ambient provider specified by Pulumi configuration for resources without a parent. let provider = new aws.Provider("provider", { region: "us-west-2" }); let vpc = new aws.ec2.Vpc("vpc", {}, { provider: provider }); let provider = new aws.Provider("provider", { region: "us-west-2" }); let vpc = new aws.ec2.Vpc("vpc", {}, { provider: provider }); provider = Provider("provider", region="us-west-2") vpc = ec2.Vpc("vpc", opts=ResourceOptions(provider=provider)) provider, _ := aws.NewProvider(ctx, "provider", &aws.ProviderArgs{Region: pulumi.StringPtr("us-west-2")}) vpc, _ := ec2.NewVpc(ctx, "vpc", &ec2.VpcArgs{}, pulumi.Provider(provider)) var provider = new Aws.Provider("provider", new Aws.ProviderArgs { Region = "us-west-2" }); var vpc = new Aws.Ec2.Vpc("vpc", new Aws.Ec2.VpcArgs(), new CustomResourceOptions { Provider = provider }); transformations The transformations option provides a list of transformations to apply to a resource and all of its children. This option is used to override or modify the inputs to the child resources of a component resource. One example is to use the option to add other resource options (such as ignoreChanges or protect). Another example is to modify an input property (such as adding to tags or changing a property that is not directly configurable). Each transformation is a callback that gets invoked by the Pulumi runtime. It receives the resource type, name, input properties, resource options, and the resource instance object itself. The callback returns a new set of resource input properties and resource options that will be used to construct the resource instead of the original values. This example looks for all VPC and Subnet resources inside of a component’s child hierarchy and adds an option to ignore any changes for tags properties (perhaps because we manage all VPC and Subnet tags outside of Pulumi):; }], }); def transformation(args: ResourceTransformationArgs): if args.type_ == "aws:ec2/vpc:Vpc" or args.type_ == "aws:ec2/subnet:Subnet": return ResourceTransformationResult( props=args.props, opts=ResourceOptions.merge(args.opts, ResourceOptions( ignore_changes=["tags"], ))) vpc = MyVpcComponent("vpc", opts=ResourceOptions(transformations=[transformation])) transformation := func(args *pulumi.ResourceTransformationArgs) *pulumi.ResourceTransformationResult { if args.Type == "aws:ec2/vpc:Vpc" || args.Type == "aws:ec2/subnet:Subnet" { return &pulumi.ResourceTransformationResult{ Props: args.Props, Opts: append(args.Opts, pulumi.IgnoreChanges([]string{"tags"})) } } return nil } vpc := MyVpcComponent("vpc", pulumi.Transformations([]pulumi.ResourceTransformation{transformation})) var vpc = new MyVpcComponent("vpc", new ComponentResourceOptions { ResourceTransformations = { args => { if (args.Resource.GetResourceType() == "aws:ec2/vpc:Vpc" || args.Resource.GetResourceType() == "aws:ec2/subnet:Subnet") { var options = CustomResourceOptions.Merge( (CustomResourceOptions) args.Options, new CustomResourceOptions { IgnoreChanges = {"tags"} }); return new ResourceTransformationResult(args.Args, options); } return null; } } }); public class MyStack : Stack { public MyStack() : base(new StackOptions { ResourceTransformations = ... }) { ... } } version The version option specifies a provider version to use when operating on a resource. This version overrides the version information inferred from the current package. This option should be used rarely. let vpc = new aws.ec2.Vpc("vpc", {}, { version: "2.10.0" }); let vpc = new aws.ec2.Vpc("vpc", {}, { version: "2.10.0" }); vpc = ec2.Vpc("vpc", opts=ResourceOptions(version="2.10.0")) vpc, _ := ec2.NewVpc(ctx, "vpc", &ec2.VpcArgs{}, pulumi.Version("2.10.0")) var vpc = new Aws.Ec2.Vpc("vpc", new Aws.Ec2.VpcArgs(), new CustomResourceOptions { Version = "2.10.0" }); Resource Getter Functions You can use the static get function, which is available on all resource types, to look up an existing resource’s ID. The get function is different from the import function. The difference is that, although the resulting resource object’s state will match the live state from an existing environment, the resource will not be managed by Pulumi. A resource read with the get function will never be updated or deleted by Pulumi during an update. You can use the get function to consume properties from a resource that was provisioned elsewhere. For example, this program reads an existing EC2 Security Group whose ID is sg-0dfd33cdac25b1ec9 and uses the result as input to create an EC2 Instance that Pulumi will manage: let aws = require(" * as aws from " pulumi_aws as aws group = aws.ec2.SecurityGroup.get('group', 'sg-0dfd33cdac25b1ec9') server = aws.ec2.Instance('web-server', ami='ami-6869aa05', instance_type='t2.micro', security_groups=[group.name]) # reference the security group resource above import ( "github.com/pulumi/pulumi-aws/sdk/v4/go/aws/ec2" "github.com/pulumi/pulumi/sdk/v3/go/pulumi" ) func main() { pulumi.Run(func(ctx *pulumi.Context) error { group, err := ec2.GetSecurityGroup(ctx, "group", pulumi.ID("sg-0dfd33cdac25b1ec9"), nil) if err != nil { return err } server, err := ec2.NewInstance(ctx, "web-server", &ec2.InstanceArgs{ Ami: pulumi.String("ami-6869aa05"), InstanceType: pulumi.String("t2.micro"), SecurityGroups: pulumi.StringArray{group.Name}, }) if err != nil { return err } return nil }) } using Pulumi; using Pulumi.Aws.Ec2; using Pulumi.Aws.Ec2.Inputs; class MyStack : Stack { public MyStack() { var group = SecurityGroup.Get("group", "sg-0dfd33cdac25b1ec9"); var server = new Instance("web-server", new InstanceArgs { Ami = "ami-6869aa05", InstanceType = "t2.micro", SecurityGroups = { group.Name } }); } } Two values are passed to the get function - the logical name Pulumi will use to refer to the resource, and the physical ID that the resource has in the target cloud. Importantly, Pulumi will never attempt to modify the security group in this example. It simply reads back the state from your currently configured cloud account and then uses it as input for the new EC2 Instance. Component Resources A component resource is a logical grouping of resources. Components resources usually instantiate a set of related resources in their constructor, aggregate them as children, and create a larger, useful abstraction that encapsulates their implementation details. Here are a few examples of component resources: - A Vpcthat automatically comes with built-in best practices. - An AcmeCorpVirtualMachinethat adheres to your company’s requirements, such as tagging. - A KubernetesClusterthat can create EKS, AKS, and GKE clusters, depending on the target. The implicit pulumi:pulumi:Stack resource is itself a component resource that contains all top-level resources in a program. Authoring a New Component Resource To author. Here’s a simple component example: class MyComponent extends pulumi.ComponentResource { constructor(name, opts) { super("pkg:index:MyComponent", name, {}, opts); } } class MyComponent extends pulumi.ComponentResource { constructor(name, opts) { super("pkg:index:MyComponent", name, {}, opts); } } class MyComponent(pulumi.ComponentResource): def __init__(self, name, opts = None): super().__init__('pkg:index:MyComponent', name, None, opts) type MyComponent struct { pulumi.ResourceState } func NewMyComponent(ctx *pulumi.Context, name string, opts ...pulumi.ResourceOption) (*MyComponent, error) { myComponent := &MyComponent{} err := ctx.RegisterComponentResource("pkg:index:MyComponent", name, myComponent, opts...) if err != nil { return nil, err } return myComponent, nil } class MyComponent : Pulumi.ComponentResource { public MyComponent(string name, ComponentResourceOptions opts) : base("pkg:index:MyComponent", name, opts) { // initialization logic. // Signal to the UI that this resource has completed construction. this.RegisterOutputs(); } } Upon creating a new instance of MyComponent, the call to the base constructor (using super/base) registers the component resource instance with the Pulumi engine. This records the resource’s state and tracks it across program deployments so that you see diffs during updates just like with a regular resource (even though component resources have no provider logic associated with them). Since all resources must have a name, a component resource constructor should accept a name and pass it to super. If you wish to have full control over one of the custom resource’s lifecycle in your component resource—including running specific code when a resource has been updated or deleted—you should look into dynamic providers. These let you create full-blown resource abstractions in your language of choice. A component resource must register a unique type name with the base constructor. In the example, the registration is pkg:index:MyComponent. To reduce the potential of other type name conflicts, this name contains the package and module name, in addition to the type: <package>:<module>:<type>. These names are namespaced alongside non-component resources, such as aws:lambda:Function. For more information about component resources, see the Pulumi Components tutorial. Creating Child Resources Component resources often contain child resources. The names of child resources are often derived from the component resources’s name to ensure uniqueness. For example, you might use the component resource’s name as a prefix. Also, when constructing a resource, children must be registered as such. To do this, pass the component resource itself as the parent option. This example demonstrates both the naming convention and how to designate the component resource as the parent: let bucket = new aws.s3.Bucket(`${name}-bucket`, {/*...*/}, { parent: this }); let bucket = new aws.s3.Bucket(`${name}-bucket`, {/*...*/}, { parent: this }); bucket = s3.Bucket(f"{name}-bucket", opts=pulumi.ResourceOptions(parent=self)) bucket, err := s3.NewBucket(ctx, fmt.Sprintf("%s-bucket", name), &s3.BucketArgs{ /*...*/ }, pulumi.Parent(myComponent)) var bucket = new Aws.S3.Bucket($"{name}-bucket", new Aws.S3.BucketArgs(/*...*/), new CustomResourceOptions { Parent = this }); Registering Component Outputs Component resources can define their own output properties by using register_outputs . The Pulumi engine uses this information to display the logical outputs of the component resource and any changes to those outputs will be shown during an update. For example, this code registers an S3 bucket’s computed domain name, which won’t be known until the bucket is created: this.registerOutputs({ bucketDnsName: bucket.bucketDomainName, }) this.registerOutputs({ bucketDnsName: bucket.bucketDomainName, }) self.register_outputs({ bucketDnsName: bucket.bucketDomainName }) ctx.RegisterResourceOutputs(myComponent, pulumi.Map{ "bucketDnsName": bucket.BucketDomainName, }) this.RegisterOutputs(new Dictionary<string, object> { { "bucketDnsName", bucket.BucketDomainName } }); The call to registerOutputs typically happens at the very end of the component resource’s constructor. The call to registerOutputs also tells Pulumi that the resource is done registering children and should be considered fully constructed, so—although it’s not enforced—the best practice is to call it in all components even if no outputs need to be registered. Inheriting Resource Providers One option all resources have is the ability to pass an explicit resource provider to supply explicit configuration settings. For instance, you may want to ensure that all AWS resources are created in a different region than the globally configured region. In the case of component resources, the challenge is that these providers must flow from parent to children. To allow this, component resources accept a providers option that custom resources don’t have. This value contains a map from the provider name to the explicit provider instance to use for the component resource. The map is used by a component resource to fetch the proper provider object to use for any child resources. This example overrides the globally configured AWS region and sets it to us-east-1. Note that myk8s is the name of the Kubernetes provider. let component = new MyComponent("...", { providers: { aws: useast1, kubernetes: myk8s, }, }); let component = new MyComponent("...", { providers: { aws: useast1, kubernetes: myk8s, }, }); component = MyComponent('...', ResourceOptions(providers={ 'aws': useast1, 'kubernetes': myk8s, })) component, err := NewMyResource(ctx, "...", nil, pulumi.ProviderMap( map[string]pulumi.ProviderResource{ "aws": awsUsEast1, "kubernetes": myk8s, }, )) var component = new MyResource("...", new ComponentResourceOptions { Providers = { { "aws", awsUsEast1 }, { "kubernetes", myk8s } } }); If a component resource is itself a child of another component resource, its set of providers is inherited from its parent by default. Resource Providers A resource provider handles communications with a cloud service to create, read, update, and delete the resources you define in your Pulumi programs. Pulumi passes your code to a language host such as Node.js, waits to be notified of resource registrations, assembles a model of your desired state, and calls on the resource provider to produce that state. The resource provider translates those requests into API calls to the cloud service. A resource provider is tied to the language that you use to write your programs. For example, if your cloud provider is AWS, the following providers are available: - JavaScript/TypeScript: @pulumi/aws - Python: pulumi-aws - Go: github.com/pulumi/pulumi-aws/sdk/go/aws - .NET: Pulumi.Aws Normally, since you declare the language and cloud provider you intend to use when you write a program, Pulumi installs the provider for you as a plugin, using the appropriate package manager, such as NPM for Typescript. The resource provider for custom resources is determined based on its package name. For example, the aws package loads a plugin named pulumi-resource-aws, and the kubernetes package loads a plugin named pulumi-resource-kubernetes. Default Provider Configuration By default, each provider uses its package’s global configuration settings, which are controlled by your stack’s configuration. You can set information such as your cloud provider credentials with environment variables and configuration files. If you store this data in standard locations, Pulumi knows how to retrieve them. For example, suppose you run this CLI command: $ pulumi config set aws:region us-west-2 Then, suppose you deploy the following Pulumi program: let aws = require("@pulumi/aws"); let instance = new aws.ec2.Instance("myInstance", { instanceType: "t2.micro", ami: "myAMI", }); let aws = require("@pulumi/aws"); let instance = new aws.ec2.Instance("myInstance", { instanceType: "t2.micro", ami: "myAMI", }); from pulumi_aws import ec2 instance = ec2.Instance("myInstance", instance_type="t2.micro", ami="myAMI") vpc, err := ec2.NewInstance(ctx, "myInstance", &ec2.InstanceArgs{ InstanceType: pulumi.String("t2.micro"), Ami: pulumi.String("myAMI"), }) var instance = new Aws.Ec2.Instance("myInstance", new Aws.Ec2.InstanceArgs { InstanceType = "t2.micro", Ami = "myAMI", }); It creates a single EC2 instance in the us-west-2 region. Explicit Provider Configuration While the default provider configuration may be appropriate for the majority of Pulumi programs, some programs may have special requirements. One example is a program that needs to deploy to multiple AWS regions simultaneously. Another example is a program that needs to deploy to a Kubernetes cluster, created earlier in the program, which requires explicitly creating, configuring, and referencing providers. This is typically done by instantiating the relevant package’s Provider type and passing in the options for each CustomResource or ComponentResource that needs to use it. For example, the following configuration and program creates an ACM certificate in the us-east-1 region and a load balancer listener in the us-west-2 region.", }, }); import pulumi import pulumi_aws as aws # Create an AWS provider for the us-east-1 region. useast1 = aws.Provider("useast1", region="us-east-1") # Create an ACM certificate in us-east-1. cert = aws.acm.Certificate("cert", domain_name="foo.com", validation_method="EMAIL", __opts__=pulumi.ResourceOptions(provider=useast1)) # Create an ALB listener in the default region that references the ACM certificate created above. listener = aws.lb.Listener("listener", load_balancer_arn=load_balancer_arn, port=443, protocol="HTTPS", ssl_policy="ELBSecurityPolicy-2016-08", certificate_arn=cert.arn, default_action={ "target_group_arn": target_group_arn, "type": "forward", }) // Create an AWS provider for the us-east-1 region. useast1, err := aws.NewProvider(ctx, "useast1", &aws.ProviderArgs{ Region: pulumi.String("us-east-1"), }) if err != nil { return err } // Create an ACM certificate in us-east-1. cert, err := acm.NewCertificate(ctx, "myInstance", &acm.CertificateArgs{ DomainName: pulumi.String("foo.com"), ValidationMethod: pulumi.String("EMAIL"), }, pulumi.Provider(useast1)) if err != nil { return err } // Create an ALB listener in the default region that references the ACM certificate created above. listener, err := lb.NewListener(ctx, "myInstance", &lb.ListenerArgs{ LoadBalancerArn: loadBalancerArn, Port: pulumi.Int(443), Protocol: pulumi.String("HTTPS"), SslPolicy: pulumi.String("ELBSecurityPolicy-2016-08"), CertificateArn: cert.Arn, DefaultActions: lb.ListenerDefaultActionArray{ &lb.ListenerDefaultActionArgs{ TargetGroupArn: targetGroupArn, Type: pulumi.String("forward"), }, }, }) if err != nil { return err } // Create an AWS provider for the us-east-1 region. var useast1 = new Aws.Provider("useast1", new Aws.ProviderArgs { Region = "us-east-1" }); // Create an ACM certificate in us-east-1. var cert = new Aws.Acm.Certificate("cert", new Aws.Acm.CertifiateArgs { DomainName = "foo.com", ValidationMethod = "EMAIL", }, new ResourceArgs { Provider = useast1 }); // Create an ALB listener in the default region that references the ACM certificate created above. var listener = new Aws.Lb.Listener("listener", new Aws.Lb.ListenerArgs { LoadBalancerArn = loadBalancerArn, Port = 443, Protocol = "HTTPS", SslPolicy = "ELBSecurityPolicy-2016-08", CertificateArn = cert.arn, DefaultAction: new Aws.Lb.ListenerDefaultAction { TargetGroupArn = targetGroupArn, Type = "forward", }, }); $ pulumi config set aws:region us-west-2 Component resources also accept a set of providers to use with their child resources. For example, the EC2 instance parented to myResource in the program below is created in us-east-1, and the Kubernetes pod parented to myResource is created in the cluster targeted by the test-ci context.(pulumi.ComponentResource): def __init__(self, name, opts): instance = aws.ec2.Instance("instance", ..., __opts__=pulumi.ResourceOptions(parent=self)) pod = kubernetes.core.v1.Pod("pod", ..., __opts__=pulumi.ResourceOptions(parent=self)) useast1 = aws.Provider("useast1", region="us-east-1") myk8s = kubernetes.Provider("myk8s", context="test-ci") my_resource = MyResource("myResource", pulumi.ResourceOptions(providers={ "aws": useast1, "kubernetes": myk8s, }) useast1, err := aws.NewProvider(ctx, "useast1", &aws.ProviderArgs{ Region: pulumi.String("us-east-1"), }) if err != nil { return err } myk8s, err := kubernetes.NewProvider(ctx, "myk8s", &kubernetes.ProviderArgs{ Context: pulumi.String("test-ci"), }) if err != nil { return err } myResource, err := NewMyResource(ctx, "myResource", pulumi.ProviderMap(map[string]pulumi.ProviderResource{ "aws": useast1, "kubernetes": myk8s, })) if err != nil { return err } using Pulumi; using Aws = Pulumi.Aws; using Kubernetes = Pulumi.Kubernetes; class MyResource : ComponentResource { public MyResource(string name, ComponentResourceOptions opts) : base(name, opts) { var instance = new Aws.Ec2.Instance("instance", new Aws.Ec2.InstanceArgs { ... }, new CustomResourceOptions { Parent = this }); var pod = new Kubernetes.Core.V1.Pod("pod", new Kubernetes.Core.V1.PodArgs { ... }, new CustomResourceOptions { Parent = this }); } } class MyStack { public MyStack() { var useast1 = new Aws.Provider("useast1", new Aws.ProviderArgs { Region = "us-east-1" }); var myk8s = new Kubernetes.Provider("myk8s", new Kubernetes.ProviderArgs { Context = "test-ci" }); var myResource = new MyResource("myResource", new ComponentResourceOptions { Providers = { useast1, myk8s } }); } } Dynamic Providers There are three types of resource providers. The first are the standard resource providers. These resource providers are built and maintained by Pulumi. There is a second kind, called a dynamic resource provider, which we will discuss here. These resource providers run only in the context of your program. They are not shareable. The third type of resource provider is shareable. You write it yourself and then you can distribute it so that others can use it. Dynamic resource providers can be written in any language you choose. Because they are not shareable, dynamic resource providers do not need a plugin. There are several reasons why you might want to write a dynamic resource provider. Here are some of them: - You want to create some new custom resource types. - You want to use a cloud provider that Pulumi doesn’t support. For example, you might want to write a dynamic resource provider for WordPress. All dynamic providers must conform to certain interface requirements. You must at least implement the create function but, in practice, you will probably also want to implement the read, update, and delete functions as well. To continue with our WordPress example, you would probably want to create new blogs, update existing blogs, and destroy them. The mechanics of how these operations happen would be essentially the same as if you used one of the standard resource providers. The difference is that the calls that would’ve been made on the standard resource provider by the Pulumi engine would now be made on your dynamic resource provider and it, in turn, would make the API calls to WordPress. Dynamic providers are defined by first implementing the pulumi.dynamic.ResourceProvider interface. This interface supports all CRUD operations, but only the create function is required. A minimal implementation might look like this: const myProvider = { async create(inputs) { return { id: "foo", outs: {}}; } } const myProvider: pulumi.dynamic.ResourceProvider = { async create(inputs) { return { id: "foo", outs: {}}; } } from pulumi.dynamic import ResourceProvider, CreateResult class MyProvider(ResourceProvider): def create(self, inputs): return CreateResult(id_="foo", outs={}) // Dynamic Providers are currently not supported in Go. // Dynamic Providers are currently not supported in .NET. This dynamic resource provider is then used to create a new kind of custom resource by inheriting from the pulumi.dynamic.Resource base class, which is a subclass of pulumi.CustomResource: class MyResource extends pulumi.dynamic.Resource { constructor(name, props, opts) { super(myProvider, name, props, opts); } } class MyResource extends pulumi.dynamic.Resource { constructor(name: string, props: {}, opts?: pulumi.CustomResourceOptions) { super(myProvider, name, props, opts); } } from pulumi import ResourceOptions from pulumi.dynamic import Resource from typing import Any, Optional class MyResource(Resource): def __init__(self, name: str, props: Any, opts: Optional[ResourceOptions] = None): super().__init__(MyProvider(), name, props, opts) // Dynamic Providers are currently not supported in Go. // Dynamic Providers are currently not supported in .NET. We can now create instances of the new MyResource resource type in our program with new MyResource("name", args), just like we would any custom resource. Pulumi understands how to use the custom provider logic appropriately. Specifically: - If Pulumi determines the resource has not yet been created, it will call the create method on the resource provider interface. - If another Pulumi deployment happens and the resource already exists, Pulumi will call the diff method to determine whether a change can be made in place or whether a replacement is needed. - If a replacement is needed, Pulumi will call create for the new resource and then call delete for the old resource. - If no replacement is needed, Pulumi will call update. - In all cases, Pulumi first calls the check method with the resource arguments to give the provider a chance to verify that the arguments are valid. - If Pulumi needs to read an existing resource without managing it directly, it will call read. See below for details on each of these functions. How Dynamic Providers Work Dynamic providers are a flexible and low-level mechanism that allow you to include arbitrary code directly into the deployment process. While most code in a Pulumi program runs while the desired state of the resources is constructed (in other words, as the resource graph is built), the code inside a dynamic provider’s implementation, such as create or update, runs during resource provisioning, while the resource graph is being turned into a set of CRUD operations scheduled against the cloud provider. In fact, these two phases of execution actually run in completely separate processes. The construction of a new MyResource happens inside the JavaScript, Python, or Go process running in your Pulumi program. In contrast, your implementations of create or update are executed by a special resource provider binary called pulumi-resource-pulumi-nodejs. This binary is what actually implements the Pulumi resource provider gRPC interface and it speaks directly to the Pulumi engine. Because your implementation of the resource provider interface must be used by a different process, potentially at a different point in time, dynamic providers are built on top of the same function serialization that is used for turning callbacks into AWS Lambdas or Google Cloud Functions. Because of this serialization, there are some limits on what can be done inside the implementation of the resource provider interface. You can read more about these limitations in the function serialization documentation. The Resource Provider Interface Implementing the pulumi.dynamic.ResourceProvider interface requires implementing a subset of the methods listed further down in this section. Each of these methods can be asynchronous, and most implementations of these methods will perform network I/O to provision resources in a backing cloud provider or other resource model. There are several important contracts between a dynamic provider and the Pulumi CLI that inform when these methods are called and with what data. Though the input properties passed to a pulumi.dynamic.Resource instance will usually be Input values, the dynamic provider’s functions are invoked with the fully resolved input values in order to compose well with Pulumi resources. Strong typing for the inputs to your provider’s functions can help clarify this. You can achieve this by creating a second interface with the same properties as your resource’s inputs, but with fully unwrapped types. // Exported type. export interface MyResourceInputs { myStringProp: pulumi.Input<string>; myBoolProp: pulumi.Input<boolean>; ... } // Non-exported type used by the provider functions. // This interface contains the same inputs, but as un-wrapped types. interface MyResourceProviderInputs { myStringProp: string; myBoolProp: boolean; ... } class MyResourceProvider implements pulumi.dynamic.ResourceProvider { async create(inputs: MyResourceProviderInputs): Promise<pulumi.dynamic.CreateResult> { ... } async diff(id: string, oldOutputs: MyResourceProviderOutputs, newInputs: MyResourceProviderInputs): Promise<pulumi.dynamic.DiffResult> { ... } ... } class MyResource extends pulumi.dynamic.Resource { constructor(name: string, props: MyResourceInputs, opts?: pulumi.CustomResourceOptions) { super(myprovider, name, props, opts); } } from pulumi import Input, Output, ResourceOptions from pulumi.dynamic import * from typing import Any, Optional class MyResourceInputs(object): my_string_prop: Input[str] my_bool_prop: Input[bool] def __init__(self, my_string_prop, my_bool_prop): self.my_string_prop = my_string_prop self.my_bool_prop = my_bool_prop class _MyResourceProviderInputs(object): """ MyResourceProviderInputs is the unwrapped version of the same inputs from the MyResourceInputs class. """ my_string_prop: str my_bool_prop: bool def __init__(self, my_string_prop: str, my_bool_prop: bool): self.my_bool_prop = my_bool_prop self.my_string_prop = my_string_prop class MyResourceProvider(ResourceProvider): def create(self, inputs: _MyResourceProviderInputs) -> CreateResult: ... return CreateResult() def diff(self, id: str, oldInputs: _MyResourceProviderInputs, newInputs: _MyResourceProviderInputs) -> DiffResult: ... return DiffResult() class MyResource(Resource): def __init__(self, name: str, props: MyResourceInputs, opts: Optional[ResourceOptions] = None): super().__init__(MyResourceProvider(), name, {**vars(props)}, opts) // Dynamic Providers are currently not supported in Go. // Dynamic Providers are currently not supported in .NET. check(olds, news) The check method is invoked before any other methods. The resolved input properties that were originally provided to the resource constructor by the user are passed to it. The operation is passed both the old input properties that were stored in the state file after the previous update to the resource, as well as the new inputs from the current deployment. It has two jobs: - Verify that the inputs (particularly the news) are valid or return useful error messages if they are not. - Return a set of checked inputs. The inputs returned from the call to check will be the inputs that the Pulumi engine uses for all further processing of the resource, including the values that will be passed back in to diff, create, update, or other operations. In many cases, the news can be returned directly as the checked inputs. But in cases where the provider needs to populate defaults, or do some normalization on values, it may want to do that in the check method so that this data is complete and normalized prior to being passed in to other methods. create(inputs) The create method is invoked when the URN of the resource created by the user is not found in the existing state of the deployment. The engine passes the provider the checked inputs returned from the call to check. The create method creates the resource in the cloud provider. It then returns two pieces of data: - An id that can uniquely identify the resource in the backing provider for later lookups, and - A set of outputs from the backing provider that should be returned to the user code as properties on the CustomResource object. These outputs are stored in the checkpoint file. If an error occurs, an exception can be thrown from the create method that should be returned to the user. diff(id, olds, news) The diff method is invoked when the URN of the resource created by the user already exists. Because the resource already exists it will need to be either updated or replaced. The diff method is passed the id of the resource, as returned by create, as well as the old outputs from the checkpoint file, which are values returned from a previous call to either create or update. The checked inputs from the current deployment are passed to the diff method. It returns four optional values: changes: trueif the provider believes there is a difference between the olds and news and wants to do an update or replace to affect this change. replaces: An array of property names that have changed that should force a replacement. Returning a non-zero length array tells the Pulumi engine to schedule a replacement instead of an update. Replacements might involve downtime, so this value should only be used when a diff requested by the user cannot be implemented as an in-place update on the cloud provider. stables: An array of property names that are known not to change between updates. Pulumi will use this information to allow some applycalls on Output[T]to be processed during previewsbecause it knows that the values of these property names will stay the same during an update. deleteBeforeReplace: true if the proposed replacements require that the existing resource be deleted before creating the new one. By default, Pulumi will try to create the new resource before deleting the old one to avoid downtime. If an error occurs, an exception can be thrown from the diff method to return this error to the user. update(id, olds, news) The update method is invoked if the call to diff indicates that a replacement is unnecessary. The method is passed the id of the resource as returned by create, and the old outputs from the checkpoint file, which are values returned from a previous call to either create or update. The new checked inputs are also passed from the current deployment. The update method is expected to do the work in the cloud provider to update an existing resource to the new desired state. It then returns a new set of outputs from the cloud provider that should be returned to the user code as properties on the CustomResource object, and stored into the checkpoint file. If an error occurs, an exception can be thrown from the update method to return this error to the user. delete(id, props) The delete operation is invoked if the URN exists in the previous state but not in the new desired state, or if a replacement is needed. The method is passed the id of the resource as returned by create, and the old outputs from the checkpoint file, which are values returned from a previous call to either create or update. The method deletes the corresponding resource from the cloud provider. Nothing needs to be returned. If an error occurs, an exception can be thrown from the delete method to return this error to the user. read(id, props) The read method is invoked when the Pulumi engine needs to get data about a resource that is not managed by Pulumi. The method is passed the id of the resource, as tracked in the cloud provider, and an optional bag of additional properties that can be used to disambiguate the request, if needed. The read method looks up the requested resource, and returns the canonical id and output properties of this resource if found. If an error occurs, an exception can be thrown from the read method to return this error to the user. Dynamic Resource Inputs The inputs to your pulumi.dynamic.ResourceProvider’s functions come from subclasses of pulumi.dynamic.Resource. These inputs include any values in the input arguments passed to the pulumi.dynamic.Resource constructor. This is just a map of key/value pairs however, in statically typed languages, you can declare types for these input shapes. For example, props, in the MyResource class shown below, defines the inputs to the resource provider functions: class MyResource extends pulumi.dynamic.Resource { constructor(name, props, opts) { super(myprovider, name, props, opts); } } interface MyResourceInputs { myStringProp: pulumi.Input<string>; myBoolProp: pulumi.Input<boolean>; ... } class MyResource extends pulumi.dynamic.Resource { constructor(name: string, props: MyResourceInputs, opts?: pulumi.CustomResourceOptions) { super(myprovider, name, props, opts); } } from pulumi import Input, ResourceOptions from pulumi.dynamic import Resource from typing import Any, Optional class MyResourceInputs(object): my_string_prop: Input[str] my_bool_prop: Input[bool] def __init__(self, my_string_prop, my_bool_prop): self.my_string_prop = my_string_prop self.my_bool_prop = my_bool_prop class MyResource(Resource): def __init__(self, name: str, props: MyResourceInputs, opts: Optional[ResourceOptions] = None): super().__init__(MyProvider(), name, {**vars(props)}, opts) // Dynamic Providers are currently not supported in Go. // Dynamic Providers are currently not supported in .NET. Dynamic Resource Outputs Any outputs can be returned by your create function in the outs property of pulumi.dynamic.CreateResult. If you need to access the outputs of your custom resource outside it with strong typing support, declare each output property returned in the outs property by your create function as a class member of the pulumi.dynamic.Resource itself. For example, in TypeScript, these outputs must be declared as public readonly class members in your pulumi.dynamic.Resource class. These class members must also have the type pulumi.Output<T>. The name of the class member must match the names of the output properties as returned by the create function. JavaScript does not support types. ... interface MyResourceProviderOutputs { myNumberOutput: number; myStringOutput: string; } class MyResourceProvider implements pulumi.dynamic.ResourceProvider { async create(inputs: MyResourceProviderInputs): Promise<pulumi.dynamic.CreateResult> { ... // Values are for an example only. return { id: "...", outs: { myNumberOutput: 12, myStringOutput: "some value" }}; } } export class MyResource extends pulumi.dynamic.Resource { public readonly myStringOutput!: pulumi.Output<string>; public readonly myNumberOutput!: pulumi.Output<number>; constructor(name: string, props: MyResourceInputs, opts?: pulumi.CustomResourceOptions) { super(myprovider, name, { myStringOutput: undefined, myNumberOutput: undefined, ...props }, opts); } } from pulumi import ResourceOptions, Input, Output from pulumi.dynamic import Resource, ResourceProvider, CreateResult from typing import Any, Optional ... ... class MyProvider(ResourceProvider): def create(self, inputs): return CreateResult(id_="foo", outs={ 'my_number_output': 12, 'my_string_output': "some value" }) class MyResource(Resource): my_string_output: Output[str] my_number_output: Output[str] def __init__(self, name: str, props: MyResourceInputs, opts: Optional[ResourceOptions] = None): super().__init__(MyProvider(), name, { 'my_string_output': None, 'my_number_output': None, **vars(props) }, opts) // Dynamic Providers are not yet supported in Go. // Dynamic Providers are currently not supported in .NET. Dynamic Provider Examples Example: Random This example generates a random number using a dynamic provider. It highlights using dynamic providers to run some code only when a resource is created, and then store the results of that in the state file so that this value is maintained across deployments of the resource. Because we want our random number to be created once, and then remain stable for subsequent updates, we cannot simply use a random number generator in our program; we need dynamic providers. The result is a provider similar to the one provided in @pulumi/random, just specific to our program and language. Implementing this example requires that we have a provider and resource type: let pulumi = require("@pulumi/pulumi"); let crypto = require("crypto"); let randomprovider = { async create(inputs) { return { id: crypto.randomBytes(16).toString('hex'), outs: {}}; }, } class Random extends pulumi.dynamic.Resource { constructor(name, opts) { super(randomprovider, name, {}, opts); } } exports.Random = Random; import * as pulumi from "@pulumi/pulumi"; import * as crypto from "crypto"; const randomprovider: pulumi.dynamic.ResourceProvider = { async create(inputs) { return { id: crypto.randomBytes(16).toString('hex'), outs: {}}; }, } export class Random extends pulumi.dynamic.Resource { constructor(name: string, opts?: pulumi.CustomResourceOptions) { super(randomprovider, name, {}, opts); } } from pulumi import ResourceOptions from pulumi.dynamic import Resource, ResourceProvider, CreateResult from typing import Optional import binascii import os class RandomProvider(ResourceProvider): def create(self, inputs): return CreateResult(id_=binascii.b2a_hex(os.urandom(16)), outs={}) class Random(Resource): def __init__(self, name: str, opts: Optional[ResourceOptions] = None): super().__init__(RandomProvider(), name, {}, opts) // Dynamic Providers are currently not supported in Go. // Dynamic Providers are currently not supported in .NET. Now, with this, we can construct new Random resource instances, and Pulumi will drive the right calls at the right time. Example: GitHub Labels REST API This example highlights how to make REST API calls to a backing provider to perform CRUD operations. In this case, the backing provider is the GitHub API in this case. Because the resource provider method implementations will be serialized and used in a different process, we keep all the work to initialize the REST client and to make calls to it, local to each function. let pulumi = require("@pulumi/pulumi"); let Octokit = require("@octokit/rest"); // Set this value before creating an instance to configure the authentication token to use for deployments let auth = "token invalid"; exports.setAuth = function(token) { auth = token; } const githubLabelProvider = { async create(inputs) { const ocktokit = new Ocktokit({auth}); const label = await ocktokit.issues.createLabel(inputs); return { id: label.data.id.toString(), outs: label.data }; }, async update(id, olds, news) { const ocktokit = new Ocktokit({auth}); const label = await ocktokit.issues.updateLabel({ ...news, current_name: olds.name }); return { outs: label.data }; }, async delete(id, props) { const ocktokit = new Ocktokit({auth}); await ocktokit.issues.deleteLabel(props); } } class Label extends pulumi.dynamic.Resource { constructor(name, args, opts) { super(githubLabelProvider, name, args, opts); } } exports.Label = Label; import * as pulumi from "@pulumi/pulumi"; import * as Ocktokit from "@octokit/rest"; // Set this value before creating an instance to configure the authentication token to use for deployments let auth = "token invalid"; export function setAuth(token: string) { auth = token; } export interface LabelResourceInputs { owner: pulumi.Input<string>; repo: pulumi.Input<string>; name: pulumi.Input<string>; color: pulumi.Input<string>; description?: pulumi.Input<string>; } interface LabelInputs { owner: string; repo: string; name: string; color: string; description?: string; } const githubLabelProvider: pulumi.dynamic.ResourceProvider = { async create(inputs: LabelInputs) { const ocktokit = new Ocktokit({auth}); const label = await ocktokit.issues.createLabel(inputs); return { id: label.data.id.toString(), outs: label.data }; }, async update(id, olds: LabelInputs, news: LabelInputs) { const ocktokit = new Ocktokit({auth}); const label = await ocktokit.issues.updateLabel({ ...news, current_name: olds.name }); return { outs: label.data }; }, async delete(id, props: LabelInputs) { const ocktokit = new Ocktokit({auth}); await ocktokit.issues.deleteLabel(props); } } export class Label extends pulumi.dynamic.Resource { constructor(name: string, args: LabelResourceInputs, opts?: pulumi.CustomResourceOptions) { super(githubLabelProvider, name, args, opts); } } from pulumi import ComponentResource, export, Input, Output from pulumi.dynamic import Resource, ResourceProvider, CreateResult, UpdateResult from typing import Optional from github import Github, GithubObject auth = "<auth token>" g = Github(auth) class GithubLabelArgs(object): owner: Input[str] repo: Input[str] name: Input[str] color: Input[str] description: Optional[Input[str]] def __init__(self, owner, repo, name, color, description=None): self.owner = owner self.repo = repo self.name = name self.color = color self.description = description class GithubLabelProvider(ResourceProvider): def create(self, props): l = g.get_user(props["owner"]).get_repo(props["repo"]).create_label( name=props["name"], color=props["color"], description=props.get("description", GithubObject.NotSet)) return CreateResult(l.name, {**props, **l.raw_data}) def update(self, id, _olds, props): l = g.get_user(props["owner"]).get_repo(props["repo"]).get_label(id) l.edit(name=props["name"], color=props["color"], description=props.get("description", GithubObject.NotSet)) return UpdateResult({**props, **l.raw_data}) def delete(self, id, props): l = g.get_user(props["owner"]).get_repo(props["repo"]).get_label(id) l.delete() class GithubLabel(Resource): name: Output[str] color: Output[str] url: Output[str] description: Output[str] def __init__(self, name, args: GithubLabelArgs, opts = None): full_args = {'url':None, 'description':None, 'name':None, 'color':None, **vars(args)} super().__init__(GithubLabelProvider(), name, full_args, opts) label = GithubLabel("foo", GithubLabelArgs("lukehoban", "todo", "mylabel", "d94f0b")) export("label_color", label.color) export("label_url", label.url) // Dynamic Providers are not currently supported in Go. // Dynamic Providers are currently not supported in .NET. Additional Examples -. However, this example of dynamic providers as provisioners allows you to copy/execute scripts on the target instance without replacing the instance itself.
https://www.pulumi.com/docs/intro/concepts/resources/
CC-MAIN-2021-21
en
refinedweb
Python is one of the best programming languages for machine learning, quickly coming to rival R’s dominance in academia and research. But why is Python so popular in the machine learning world? Why is Python good for AI? Mike Driscoll spoke to five Python experts and machine learning community figures about why the language is so popular as part of the book Python Interviews. Programming is a social activity – Python’s community has acknowledged this best Glyph Lefkowitz (@glyph), founder of Twisted, a Python network programming framework, awarded The PSF’s Community Service Award in 2017 AI is a bit of a catch-all term that tends to mean whatever the most advanced areas in current computer science research are. There was a time when the basic graph-traversal stuff that we take for granted was considered AI. At that time, Lisp was the big AI language, just because it was higher-level than average and easier for researchers to do quick prototypes with. I think Python has largely replaced it in the general sense because, in addition to being similarly high-level, it has an excellent third-party library ecosystem, and a great integration story for operating system facilities. Lispers will object, so I should make it clear that I’m not making a precise statement about Python’s position in a hierarchy of expressiveness, just saying that both Python and Lisp are in the same class of language, with things like garbage collection, memory safety, modules, namespaces and high-level data structures. In the more specific sense of machine learning, which is what more people mean when they say AI these days, I think there are more specific answers. The existence of NumPy and its accompanying ecosystem allows for a very research-friendly mix of high-level stuff, with very high-performance number-crunching. Machine learning is nothing if not very intense number-crunching. “…Statisticians, astronomers, biologists, and business analysts have become Python programmers and have improved the tooling.” The Python community’s focus on providing friendly introductions and ecosystem support to non-programmers has really increased its adoption in the sister disciplines of data science and scientific computing. Countless working statisticians, astronomers, biologists, and business analysts have become Python programmers and have improved the tooling. Programming is fundamentally a social activity and Python’s community has acknowledged this more than any other language except JavaScript. Machine learning is a particularly integration-heavy discipline, in the sense that any AI/machine learning system is going to need to ingest large amounts of data from real-world sources as training data, or system input, so Python’s broad library ecosystem means that it is often well-positioned to access and transform that data. Python allows users to focus on real problems Marc-Andre Lemburg (@malemburg), co-founder of The PSF and CEO of eGenix Python is very easy to understand for scientists who are often not trained in computer science. It removes many of the complexities that you have to deal with, when trying to drive the external libraries that you need to perform research. After Numeric (now NumPy) started the development, the addition of IPython Notebooks (now Jupyter Notebooks), matplotlib, and many other tools to make things even more intuitive, Python has allowed scientists to mainly think about solutions to problems and not so much about the technology needed to drive these solutions. “Python is an ideal integration language which binds technologies together with ease.” As in other areas, Python is an ideal integration language, which binds technologies together with ease. Python allows users to focus on the real problems, rather than spending time on implementation details. Apart from making things easier for the user, Python also shines as an ideal glue platform for the people who develop the low-level integrations with external libraries. This is mainly due to Python being very accessible via a nice and very complete C API. Python is really easy to use for math and stats-oriented people Sebastian Raschka (@rasbt), researcher and author of Python Machine Learning I think there are two main reasons, which are very related. The first reason is that Python is super easy to read and learn. I would argue that most people working in machine learning and AI want to focus on trying out their ideas in the most convenient way possible. The focus is on research and applications, and programming is just a tool to get you there. The more comfortable a programming language is to learn, the lower the entry barrier is for more math and stats-oriented people. Python is also super readable, which helps with keeping up-to-date with the status quo in machine learning and AI, for example, when reading through code implementations of algorithms and ideas. Trying new ideas in AI and machine learning often requires implementing relatively sophisticated algorithms and the more transparent the language, the easier it is to debug. The second main reason is that while Python is a very accessible language itself, we have a lot of great libraries on top of it that make our work easier. Nobody would like to spend their time on reimplementing basic algorithms from scratch (except in the context of studying machine learning and AI). The large number of Python libraries which exist, help us. To summarize, I would say that Python is a great language that lets researchers and practitioners focus on machine learning and AI and provides less of a distraction than other languages. Python has so many features that are attractive for scientific computing Luciano Ramalho (@ramalhoorg) technical principal at ThoughtWorks and fellow of The PSF The most important and immediate reason is that the NumPy and SciPy libraries enable projects such as scikit-learn, which is currently almost a de facto standard tool for machine learning. The reason why NumPy, SciPy, scikit-learn, and so many other libraries were created in the first place is because Python has some features that make it very attractive for scientific computing. Python has a simple and consistent syntax which makes programming more accessible to people who are not software engineers. “Python benefits from a rich ecosystem of libraries for scientific computing.” Another reason is operator overloading, which enables code that is readable and concise. Then there’s Python’s buffer protocol (PEP 3118), which is a standard for external libraries to interoperate efficiently with Python when processing array-like data structures. Finally, Python benefits from a rich ecosystem of libraries for scientific computing, which attracts more scientists and creates a virtuous cycle. Python is good for AI because it is strict and consistent Mike Bayer (@zzzeek), Senior Software Engineer at Red Hat and creator of SQLAlchemy What we’re doing in that field is developing our math and algorithms. We’re putting the algorithms that we definitely want to keep and optimize into libraries such as scikit-learn. Then we’re continuing to iterate and share notes on how we organize and think about the data. A high-level scripting language is ideal for AI and machine learning, because we can quickly move things around and try again. The code that we create spends most of its lines on representing the actual math and data structures, not on boilerplate. A scripting language like Python is even better, because it is strict and consistent. Everyone can understand each other’s Python code much better than they could in some other language that has confusing and inconsistent programming paradigms. The availability of tools like IPython notebook has made it possible to iterate and share our math and algorithms on a whole new level. Python emphasizes the core of the work that we’re trying to do and completely minimizes everything else about how we give the computer instructions, which is how it should be. Automate whatever you don’t need to be thinking about. Read Next: Getting Started with Python and Machine Learning 4 ways to implement feature selection in Python for machine learning Is Python edging R out in the data science wars? Python is strict? I am not sure.
https://hub.packtpub.com/python-machine-learning-expert-interviews/
CC-MAIN-2021-21
en
refinedweb
Metaprogramming can be described in two ways: “Computer programs that write or manipulate other programs (or themselves) as their data, or that do part of the work at compile time that would otherwise be done at runtime”. More simply put: Metaprogramming is writing code that writes code during runtime to make your life easier. Many languages feature a with statement that allows programmers to omit the receiver of method calls. with can be easily emulated in Ruby using instance_eval: def with(object, &block) object.instance_eval &block end The with method can be used to seamlessly execute methods on objects: hash = Hash.new with hash do store :key, :value has_key? :key # => true values # => [:value] end With Ruby you can modify the structure of the program in execution time. One way to do it, is by defining methods dynamically using the method method_missing. Let's say that we want to be able to test if a number is greater than other number with the syntax 777.is_greater_than_123?. # open Numeric class class Numeric # override `method_missing` def method_missing(method_name,*args) # test if the method_name matches the syntax we want if method_name.to_s.match /^is_greater_than_(\d+)\?$/ # capture the number in the method_name the_other_number = $1.to_i # return whether the number is greater than the other number or not self > the_other_number else # if the method_name doesn't match what we want, let the previous definition of `method_missing` handle it super end end end One important thing to remember when using method_missing that one should also override respond_to? method: class Numeric def respond_to?(method_name, include_all = false) method_name.to_s.match(/^is_greater_than_(\d+)\?$/) || super end end Forgetting to do so leads to a inconsistent situation, when you can successfully call 600.is_greater_than_123, but 600.respond_to(:is_greater_than_123) returns false. In ruby you can add methods to existing instances of any class. This allows you to add behavior to and instance of a class without changing the behavior of the rest of the instances of that class. class Example def method1(foo) puts foo end end #defines method2 on object exp exp = Example.new exp.define_method(:method2) {puts "Method2"} #with method parameters exp.define_method(:method3) {|name| puts name} send() is used to pass message to object. send() is an instance method of the Object class. The first argument in send() is the message that you're sending to the object - that is, the name of a method. It could be string or symbol but symbols are preferred. Then arguments those need to pass in method, those will be the remaining arguments in send(). class Hello def hello(*args) puts 'Hello ' + args.join(' ') end end h = Hello.new h.send :hello, 'gentle', 'readers' #=> "Hello gentle readers" # h.send(:hello, 'gentle', 'readers') #=> Here :hello is method and rest are the arguments to method. class Account attr_accessor :name, :email, :notes, :address def assign_values(values) values.each_key do |k, v| # How send method would look a like # self.name = value[k] self.send("#{k}=", values[k]) end end end user_info = { name: 'Matt', email: '[email protected]', address: '132 random st.', notes: "annoying customer" } account = Account.new If attributes gets increase then we would messup the code #--------- Bad way -------------- account.name = user_info[:name] account.address = user_info[:address] account.email = user_info[:email] account.notes = user_info[:notes] # --------- Meta Programing way -------------- account.assign_values(user_info) # With single line we can assign n number of attributes puts account.inspect Note: send() itself is not recommended anymore. Use __send__() which has the power to call private methods, or (recommended) public_send()
https://sodocumentation.net/ruby/topic/5023/metaprogramming
CC-MAIN-2021-21
en
refinedweb
Static Member Functions As seen in the discussion about object orientation there can also be static member functions. OO: Class operations <-> C++: static member functions They also uses the keyword "static". Usage: When there is "only one" When the function does not depend on any non-static class atttributes For constructing pre-defined object. Example: class Color { private: int red, green, blue; public: static Color* createTTURed(); }; Color* Color::createTTURed() { Color *c = new Color; c->red = 204; c->green = 0; c->blue = 0; return c; } Notes for static member variables: Since they are part of the class they are allowed to use private member data. However, they do not have an object with them. So they can only access static member variables directly, all others only if they have an object. To use a static member variable use them as if they where in a namespace. From within the class this is unnecessary. Example: Color* c = Color::createTTURed(); Practice: define a class "Location" that has the two member variables posX and posY. provide a static member function called "getOrigin()" that creates a new location with posX=0 and posY=0. Show the class definition and the implementation for getOrigin(). Show an example of how this could be called. class Location { private: int posX,posY; public: static Location* getOrigin(); }; Location* Location::getOrigin() { Location *l = new Location(); l->posX = 0; l->posY = 0; return l; } ... Location *o = Location::getOrigin(); Intermission: So how do I call a method again? Assume the follwing class definiton: class Bla { public: static int doSomething(bool really); string getName(); } To call the static function, we have 3 options: // Preferred way: int i = Bla::doSomething(true); // This works also, but I do not like it. int i = b->doSomething(true); // Assuming b is of type Bla* int i = c.doSomething(true); // Assuming c is of type Bla To call the non-static function we have two options: string s = b->getName(); // Assuming b is of type Bla* string s = c.getName(); // Assuming b is of type Bla
https://max.berger.name/teaching/s06/script/ch11s07.html
CC-MAIN-2021-21
en
refinedweb
circular_buffer 0.9.1 circular_buffer: ^0.9.1 copied to clipboard Use this package as a library Depend on it Run this command: With Dart: $ dart pub add circular_buffer With Flutter: $ flutter pub add circular_buffer This will add a line like this to your package's pubspec.yaml (and run an implicit dart pub get): dependencies: circular_buffer: ^0.9.1 Alternatively, your editor might support dart pub get or flutter pub get. Check the docs for your editor to learn more. Import it Now in your Dart code, you can use: import 'package:circular_buffer/circular_buffer.dart';
https://pub.dev/packages/circular_buffer/install
CC-MAIN-2021-21
en
refinedweb
Control fit-statUSB devices Project description pystatusb Control a fit-statUSB from python The statUSB is a tiny, USB LED that can be set display various colors and sequences. This library allows easy control of it from python. Use one of the simple helpers to set a color or sequence. After sending the configuration, the device will keep it without the python program running, and persist until a different color command is sent or the device is unplugged. from pystatusb import StatUSB, Colors led = StatUSB() # Auto-detect the device led.set_transistion_time(200) # Set the fade time to 200ms between each color led.set_color_rgb(0xff0000) # 100% bright red led.set_color(Colors.VIOLET, 20) # 20% bright violet led.set_sequence("#0000FF-0500#00FFFF-0250#000000-0250") # Blue for 0.5 sec, cyan for 0.25 sec, off for 0.25 sec Project details Release history Release notifications | RSS feed Download files Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
https://pypi.org/project/pystatusb/
CC-MAIN-2021-21
en
refinedweb
Guest post by Ekkehard Gentz, BlackBerry Elite Developer This is the first post in a series about how we created the BlackBerry Jam Asia app. In today’s post, I’ll show you how to implement an end-user license agreement (EULA) in an app. In most cases, developers should provide an EULA, which has the user has to agree to app conditions before using it, whether the app is free or paid. BlackBerry Jam Asia 2013 Conference APP This year I developed the official BlackBerry Conference App for BlackBerry Jam Asia 2013 in Hong Kong. The BlackBerry Jam Asia 2013 app is a native BlackBerry 10 app developed with Cascades/QML/C++, and can be downloaded from BlackBerry World for free. I recommend downloading the app so you can see how the EULA works in the context of a complex app. The EULA is the first Dialog visible after downloading and opening the App, but it was the last part I developed. I had implemented a hard-coded English version of the EULA, but the license should be available in a variety of languages. UI (QML) Let’s take a look at the UI first. We need a dialog with a title, the license text and two buttons: “Agree” and “Don’t Agree.” To do this, we created a custom dialog with alias properties to fill the fields and a result string. Dialog { id: eulaDialog property string result property alias title: titleLabel.text property alias body: bodyLabel.text property alias button1: acceptButton.text property alias button2: cancelButton.text The dialog gets a container with a solid background color so nothing will shine through. The color depends on the theme: Container { another container for the content. The title container in the sample app has a blue background; the conference app uses the special JAM color. The content is placed inside a ScrollView, so it doesn’t matter how long your license text is, or if it’s running on a 720×720 Q10 or 720×1280 Z30. The accept and cancel buttons are placed below the content. Hitting one of them sets the result string and closes the dialog. Here’s the accept button: Button { id: acceptButton text: qsTr("I Agree") layoutProperties: StackLayoutProperties { spaceQuota: 1 } focusPolicy: FocusPolicy.KeyAndTouch onClicked: { eulaDialog.result = "ACCEPTED" eulaDialog.close() } } Complete source code of this custom dialog can be found here: assets/EULADialog.qml The logic to show the dialog or not is here: assets/main.qml This is a TabbedPane in ConferenceApp and a simple Page in the sample app. At first we have to add the Custom Dialog as an attachedObject: attachedObjects: [ EULADialog { id: eulaDialog property bool firstRun: true onClosed: { if (eulaDialog.result == "ACCEPTED") { app.setEulaAccepted() // do your normal startup stuff now return } if (firstRun) { noEulaDialog.exec() return } Application.requestExit(); } }, SystemDialog { id: noEulaDialog title: "EULA License" body: qsTr("You must accept the EULA in order to use the App.") + Retranslate.onLanguageChanged confirmButton.label: qsTr("OK") + Retranslate.onLanguageChanged confirmButton.enabled: true cancelButton.enabled: false onFinished: { eulaDialog.firstRun = false eula() } }, ..... more ] As you can see, there’s a second dialog: a SystemDialog. This dialog is used if the user does not accept the license. There’s only one chance for the user to retry; if the license is not accepted the second time, the app is closed: Application.requestExit(); If the EULA is accepted, we call a method from C++: app.setEulaAccepted() If the EULA is accepted, a value was inserted into settings, so that the EULA is not displayed the next time the user accesses the app. Now let’s take a look at how to open the EULA dialog. At the bottom of main.qml as part of the onCreationCompleted slot: onCreationCompleted: { if (app.showEula()) { eulaTimer.start() } else { // do your normal startup stuff now doItAgin.visible = true } } We ask the C++ application if the EULA dialog must be opened: app.showEula() While testing the BlackBerry Jam Asia app on different devices and operation systems, we found out that an older 10.1 OS Version had some problems opening the dialog directly from the onCreationCompleted{}. So we did an async and started a single-shot QTimer, which then opens the dialog. This QTimer was also attached as an object: attachedObjects: [ ....... QTimer { id: eulaTimer interval: 500 singleShot: true onTimeout: { eula() } } ] onTimeout calls a function: function eula() { var data = app.eulaContent() eulaDialog.title = data.title eulaDialog.body = data.body eulaDialog.button1 = data.button1 eulaDialog.button2 = data.button2 // now it's safe to open the Dialog eulaDialog.open() } We get the localized content from C++: app.eulaContent() The content is a QVariantMap, so can directly be used as a Javascript Object and we set the values of alias properties. Finally, when starting the app for the first time we see the custom dialog: Above you see a localized dialog with a German title and button text. Starting the Conference App you’ll get a real EULA License text. If the user doesn’t agree, this SystemDialog appears exactly one time and opens the EULA dialog again: Business Logic (C++) Now let’s see what happens at C++ side. Inside the constructor of applicationUi.cpp the QTimer must be registered as type, so QML knows it: qmlRegisterType<QTimer>("my.library", 1, 0, "QTimer"); also we need the ‘app’ context property: qml->setContextProperty("app", this); Setting the context property isn’t enough – we must tell Qt that some of our methods can be invoked. This is done in the applicationUi.hpp Headerfile: Q_INVOKABLE bool showEula(); Q_INVOKABLE QVariant eulaContent(); Q_INVOKABLE void setEulaAccepted(); Back to the .cpp file and take a deeper look at these methods: bool ApplicationUI::showEula() { QSettings settings; if (settings.value(SETTINGS_KEY_EULA_ACCEPTED).isNull()) { return true; } return false; } showEula() uses QSettings to see if the EULA was already opened. QSettings is a simple way to persist values in a local secure filestore. You’ll find the settings file from TargetFileSystemNavigator – View in your Momentics IDE inside the sandbox of your app: This is the path to the settings file: data/Settings/<your-vendor-name>/<your-app-name>.conf Opening the settings file you’ll find this entry if the EULA is accepted: [General] eula_read=true Here’s how to set the value: void ApplicationUI::setEulaAccepted() { QSettings settings; bool accepted = true; settings.setValue(SETTINGS_KEY_EULA_ACCEPTED, QVariant(accepted)); } Hint: if you want to test again if the EULA Dialog will be displayed, delete the Settings File from TargetFileSystemNavigator. Now the last missing piece is getting the localized EULA. Here’s the project structure from sample app: All EULA texts are contained inside a JSON file: assets/app_data/eula.json The structure of this JSON is easy to understand: [ { "locale":"pl", "title":"AKCEPTACJA LICENCJI:", "body":"………… Lorem", "button1":"Zgadzam się", "button2":"Nie zgadzam się" } ,... ] A JSON Array contains JSON Objects, where each JSON Object has as index the “locale” property (‘en’, ‘de’, ‘pl’,…) and properties for “title”, “body”, “button1″ and “button2.″ Working with JSON in Cascades Apps is really easy. Here’s the code on how to read this JSON Array from assets/app_data into a QVariantList: QVariantList ApplicationUI::readEulaFromJson() { JsonDataAccess jda; QVariantList eulaList; QString eulaFilePath; eulaFilePath = QDir::currentPath() + "/app/native/assets/app_data/eula.json"; if (!eulaFile.exists()) { qDebug() << "no eulaFile file found in assets - using english"; return eulaList; } bool ok = eulaFile.open(QIODevice::ReadOnly); if (ok) { eulaList = jda.loadFromBuffer(eulaFile.readAll()).toList(); eulaFile.close(); } else { qDebug() << "cannot read eulaFile file: " << eulaFilePath; } return eulaList; } As soon as you get the list, you can search for the current locale. If no entry is found, check for the first 2 characters only, which is the language. For example, ‘de_DE’ and ‘de_AT’ are valid locales for german language in Germany (DE) and Austria (AT), so if ‘de_DE’ is not found, we look for ‘de’. If again no entry is found, we use ‘en’ – english as default. See the details in applicationUi.cpp: QVariant ApplicationUI::eulaContent() { ... } QVariantMap ApplicationUI::euladoc(const QString& locale) { ... } Don’t forget to import the libraries in QML import bb.system 1.0 import my.library 1.0 Also don’t forget to add the libraries into your .pro file_ LIBS += -lbbsystem -lbb -lbbdata Summary From this sample you have learned how to: - Use QSettings to persist values - Access JSON data files - Communicate between C++ and QML - Use QTimer in QML - Write a custom dialog in QML - Use a SystemDialog in QML Download and Discuss The Sample APP is available at GitHub Open Source (Apache 2 License). I also created a thread in the forums. Have fun with the sample app, and copy/paste what you need to implement an EULA Dialog into your own apps!
http://devblog.blackberry.com/2013/11/secrets-of-the-blackberry-jam-asia-conference-app-part-1-implementing-an-end-user-license-agreement/
CC-MAIN-2018-39
en
refinedweb
Kafka Streams on Heroku Last updated 17 August 2018 Table of Contents Kafka Streams is a Java client library that uses underlying components of Apache Kafka to process streaming data. You can use Kafka Streams to easily develop lightweight, scalable, and fault-tolerant stream processing apps. Kafka Streams is supported on Heroku with both dedicated and basic Kafka plans (with some additional setup required for basic plans). Applications built using Kafka Streams produce and consume data from Streams, which are unbounded, replayable, ordered, and fault-tolerant sequences of events. A Stream is represented either as a Kafka topic ( KStream) or materialized as compacted topics ( KTable). By default, the library ensures that your application handles Stream events one at a time, while also providing the ability to handle late-arriving or out-of-order events. Basic example You can use Kafka Streams APIs to develop applications with just a few lines of code. The following sample illustrates the traditional use case of maintaining a word count: words .groupBy((key, word) -> word) .windowedBy(TimeWindows.of(TimeUnit.SECONDS.toMillis(10))) .count(Materialized.as("windowed-counts")) .toStream() .process(PostgresSink::new); This code: - Takes in an input stream of words - Groups the input by word - Counts each word’s frequency within a tumbling window of 10 seconds - Saves intermittent results in a local store - Outputs the resulting word counts on each window boundary. The above example illustrates the bulk of the logic you create for a typical Kafka Streams application. The rest of the application consists primarily of configuration. Kafka Streams simplifies development by decoupling your application’s logic from the underlying infrastructure, where the library transparently distributes workload, handles failures, and performs other low-level tasks. Organizing your application Kafka Stream applications are normal Java services that you can run on Heroku with a variety of Java implementations. Heroku’s buildpacks for Maven and Gradle are both supported. Using a multi-project setup with Gradle, you can create multiple Gradle sub-projects that each represent a different Kafka Streams service. These services can operate independently or be interconnected. Each sub-project produces its own executable via Gradle plugins when the ./gradlew stage task is executed on it. These executables are created in your application’s build/libs/ directory, with naming specified as sub-project-name-all.jar. You can then run these executables on the Heroku Runtime by declaring worker process types in your Procfile: aggregator_worker: java -jar build/libs/streams-aggregator-all.jar More information on setting up multiple Kafka Streams services within a single application can be found in the kafka-streams-on-heroku repo. Connecting your application Connecting to Kafka brokers on Heroku requires SSL. This involves the following steps: - Parse the URI stored in your app’s KAFKA_URLconfig var. - Use env-keystore to read in the Kafka TRUSTED_CERT, CLIENT_CERT_KEY, and CLIENT_CERTconfig vars and create both a truststore and a keystore. - Add related SSL configs for truststore and keystore. private Properties buildHerokuKafkaConfigVars() throws URISyntaxException, CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException { Properties properties = new Properties(); List<String> bootstrapServerList = Lists.newArrayList(); Iterable<String> kafkaUrl = Splitter.on(",") .split(Preconditions.checkNotNull(System.getenv(HEROKU_KAFKA_URL))); for (String url : kafkaUrl) { URI uri = new URI(url); bootstrapServerList.add(String.format("%s:%d", uri.getHost(), uri.getPort())); switch (uri.getScheme()) { case "kafka": properties.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, "PLAINTEXT"); break; case "kafka+ssl": properties.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, "SSL"); EnvKeyStore envTrustStore = EnvKeyStore.createWithRandomPassword( HEROKU_KAFKA_TRUSTED_CERT); EnvKeyStore envKeyStore = EnvKeyStore.createWithRandomPassword( HEROKU_KAFKA_CLIENT_CERT_KEY, HEROKU_KAFKA_CLIENT_CERT); File trustStoreFile = envTrustStore.storeTemp(); File keyStoreFile = envKeyStore.storeTemp(); properties.put(SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG, envTrustStore.type()); properties.put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, trustStoreFile.getAbsolutePath()); properties.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, envTrustStore.password()); properties.put(SslConfigs.SSL_KEYSTORE_TYPE_CONFIG, envKeyStore.type()); properties.put(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG, keyStoreFile.getAbsolutePath()); properties.put(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG, envKeyStore.password()); break; default: throw new URISyntaxException(uri.getScheme(), "Unknown URI scheme"); } } bootstrapServers = Joiner.on(",").join(bootstrapServerList); return properties; } Managing internal topics and consumer groups Kafka Streams uses internal topics for fault tolerance and repartitioning. These topics are required for Kafka Streams applications to work properly. Creation of Kafka Streams internal topics are unrelated to Kafka’s auto.create.topics.enable config. Rather, Kafka Streams communicates with clusters directly through an admin client. Dedicated Kafka plans Dedicated Kafka plans are isolated among users. Because of this, internal Kafka Streams topics on dedicated plans require no additional configuration. More information on dedicated plans can be found on the dedicated plans and configurations page. Basic Kafka plans Basic Kafka plans co-host multiple Heroku users on the same set of underlying resources. User data and access privileges are isolated by Kafka Access Control Lists (ACLs). Additionally, topic and consumer group names are namespaced with an auto-generated prefix to prevent naming collisions. Running Kafka Streams applications on basic plans requires two preliminary steps: properly setting up the application.id and pre-creating internal topics and consumer groups. Setting up your application.id Each Kafka Streams application has an important unique identifier called the application.id that identifies it and its associated topology. If you have a Kafka Basic plan, you must ensure that each application.id begins with your assigned prefix: properties.put(StreamsConfig.APPLICATION_ID_CONFIG, String.format("%saggregator-app", HEROKU_KAFKA_PREFIX)); Pre-creating internal topics and consumer groups Because Kafka Basic plans on Heroku use ACLs, Kafka Streams applications cannot interact with topics and consumer groups without the proper ACLs. This is problematic because Kafka Streams uses an internal admin client to transparently create internal topics and consumer groups at runtime. This primarily affects processors in Kafka Streams. Processors are classes that implement a process method. They receive input events from a stream, process those events, and optionally produce output events to downstream processors. Stateful processors are processors that make use of state produced by previous events when processing subsequent ones. Kafka Streams provides built-in functionality for storage of this state. For each stateful processor in your application, you need to create two internal topics: one for the changelog and one for repartition. For example, the basic example shown earlier includes a single stateful processor that counts words from a stream: words .groupBy((key, word) -> word) .windowedBy(TimeWindows.of(TimeUnit.SECONDS.toMillis(10))) .count(Materialized.as("windowed-counts")) .toStream() .process(PostgresSink::new); This application requires two internal topics for the count operator: $ heroku kafka:topics:create aggregator-app-windowed-counts-changelog —app sushi $ heroku kafka:topics:create aggregator-app-windowed-counts-repartition —app sushi Additionally, you must create a single consumer group for your application that matches the application.id: $ heroku kafka:consumer-groups:create mobile-1234.aggregator-app —app sushi More information on basic plans can be found on the basic plans and configurations page. Scaling your application Parallelism model Partitions are a Kafka topic’s fundamental unit of parallelism. In Kafka Streams applications, there are many application instances. Because Kafka Streams applications are normal Java applications, they run in dynos on the Heroku Runtime. Each instance of a Kafka Streams application contains a number of Stream Threads. These threads are responsible for running one or more Stream Tasks. In Kafka Streams, Stream Tasks are the fundamental unit of processing parallelism. Kafka Streams transparently ensures that input partitions are spread evenly across Stream Tasks so that all events can be consumed and processed. Vertical scaling By default, Kafka Streams creates one Stream Thread per application instance. Each Stream Thread runs one or more Stream Tasks. You can scale an application instance by scaling its number of Stream Threads. To do so, modify the num.stream.threads config value in your application. The application will transparently rebalance workload across threads within each application instance. Horizontal scaling Kafka Streams rebalances workload and local state across instances as the number of application instances changes. This works transparently by distributing workload and local state across instances with the same application.id. You can scale Kafka Streams applications horizontally by scaling the number of dynos: $ heroku ps:scale aggregator_worker=2 —app sushi The number of input partitions is effectively the upper bound for parallelism. It is important to remember that the number of Stream Tasks should not be exceed the number of input partitions. Otherwise, this over-provisioning will result in idle application instances. Caveats RocksDB persistence Because dynos are backed by an ephemeral filesystem, it is not practical to rely on the underlying disk for durable storage. This presents a challenge for using RocksDB with Kafka Streams on Heroku. However, RocksDB is not a hard requirement. Kafka Streams treats RocksDB as a write-through cache, where the source of truth is actually the underlying changelog internal topic. If there is no underlying RocksDB store, then state is replayed directly from changelog topics on startup. By default, replaying state directly from changelog topics will incur additional latency when rebalancing your application instances or when dynos are restarted. To minimize latency, you can configure Kafka Streams to fail over Stream Tasks to their associated Standby Tasks. Standby Tasks are replicas of Stream Tasks that maintain fully-replicated copies of state. Dynos make use of Standby Tasks to resume work immediately instead of having to wait for state to be rebuilt from changelog topics. You can modify the num.standby.replicas config in your application to change the number of Standby Tasks.
https://devcenter-assets1.herokucdn.com/articles/kafka-streams-on-heroku
CC-MAIN-2018-39
en
refinedweb
It's not the same without you Join the community to find out what other Atlassian users are discussing, debating and creating. I've created a scripted field called Work Effort Progress, but I'm not able to sort (ASC or DESC) on this field in the Issue Navigator unless I include "Work Effort Progress" is not EMPTY in the JQL. I don't think that I should need to do this because none of the fields have an empty value (i.e. "Work Effort Progress" is EMPTY doesn't return any issues at all). I've re-indexed multiple times and the issue is still occurring. Here is the script I'm using.TaskObjects() Double timeSpentTotal = 0 Double remainingEstimate = 0 Double progress = 0 if (subTaskManager.subTasksEnabled && !subTasks.empty) { subTasks.each { if (it.getTimeSpent() != null) { timeSpentTotal += it.getTimeSpent() } if (it.getEstimate() != null) { remainingEstimate += it.getEstimate() } } } else if (!subTaskManager.subTasksEnabled || subTasks.empty) { if (issue.getTimeSpent() != null) { timeSpentTotal = issue.getTimeSpent() } if (issue.getEstimate() != null) { remainingEstimate = issue.getEstimate() } } if (timeSpentTotal > 0) { progress = ( timeSpentTotal / ( timeSpentTotal + remainingEstimate ) ) * 100 } return progress.round(2) And here is my custom template (I added a pseudo progress bar far a visual representation of progress): #if($value > 0.01 && $value <= 10) <div><strong>[<span style="color:green;font-weight:bolder">></span></strong>>>>>>>>>><strong>]</strong> $value%</div> #elseif($value > 10 && $value <= 20) <div><strong>[<span style="color:green;font-weight:bolder">>></span></strong>>>>>>>>><strong>]</strong> $value%</div> #elseif($value > 20 && $value <= 30) <div><strong>[<span style="color:green;font-weight:bolder">>>></span></strong>>>>>>>><strong>]</strong> $value%</div> #elseif($value > 30 && $value <= 40) <div><strong>[<span style="color:green;font-weight:bolder">>>>></span></strong>>>>>>><strong>]</strong> $value%</div> #elseif($value > 40 && $value <= 50) <div><strong>[<span style="color:green;font-weight:bolder">>>>>></span></strong>>>>>><strong>]</strong> $value%</div> #elseif($value > 50 && $value <= 60) <div><strong>[<span style="color:green;font-weight:bolder">>>>>></span></strong>>>>>><strong>]</strong> $value%</div> #elseif($value > 60 && $value <= 70) <div><strong>[<span style="color:green;font-weight:bolder">>>>>>></span></strong>>>>><strong>]</strong> $value%</div> #elseif($value > 70 && $value <= 80) <div><strong>[<span style="color:green;font-weight:bolder">>>>>>>></span></strong>>>><strong>]</strong> $value%</div> #elseif($value > 80 && $value <= 90) <div><strong>[<span style="color:green;font-weight:bolder">>>>>>>>></span></strong>>><strong>]</strong> $value%</div> #elseif($value > 90 && $value < 100) <div><strong>[<span style="color:green;font-weight:bolder">>>>>>>>>></span></strong>><strong>]</strong> $value%</div> #elseif($value == 100) <div><strong>[<span style="color:green;font-weight:bolder">>>>>>>>>>></span></strong><strong>]</strong> $value%</div> #else <div><strong>[</strong>>>>>>>>>>><strong>]</strong> 0.0%</div> #end I can search on this field just fine and everything else about this field works wonderfully except for the sorting capabilities. When I try to sort, I get this error message: "Error occurred communicating with the server. Please reload the page and try again." If I add in the JQL mentioned above, I can sort just fine. Any ideas on what might be causing the error or where I can look to try to diagnose the issue? Thanks for your help! Which indexer/searcher is the custom field configured with? Hi, Jamie - this scripted field is using a Number range searcher. I used the following field code: def modulus = issue.id.mod(4) modulus == 0 ? null : modulus as Double and the sorting worked ok, except it sorted them in the order null, 3, 2, 1. Which is not intuitive to me. If you're getting an error there should be a stack trace... although it might be truncated. Can you find it and post it? Hi, Jamie - without making any changes to my field or anything today, I see that my field is sorting correctly. Not sure why it's working now and wasn't before. After creating the field, I re-indexed and checked, but it didn't work then. It is now! Appreciate your input and quick responses -.
https://community.atlassian.com/t5/Jira-questions/Cannot-accurately-sort-by-scripted-field/qaq-p/433446
CC-MAIN-2018-39
en
refinedweb
The objective of this post is to explain how to create a simple Python websocket client to contact an online test echo server. Introduction to give the following command on the Windows command line (on some older Python installations you may need to navigate to the Scripts folder before being able to send pip commands): pip install websockets Note that this library requires a Python version higher or equal than v3.4 [1]. Nonetheless, most of the examples shown in the documentation use the new async await syntax, so my recommendation is that you use Python v3.5 or higher. The tests shown below were performed on Python v3.6. The code We start our code start by importing our previously installed websockets module. Since this library is built on top os Python’s asyncio framework [2], we will need to also import that module as well. import asyncio import websockets Since the code will work asynchronously, we will declare a Python asynchronous function (also called coroutine [3]) where we will write the client code. We do this by including the async keyword before the function declaration [3]. We will call our function test, as can be seen below. async def test(): # client code In order to create a websocket client connection, we need to call the connect function from the websockets module [4]. It yields an object of class WebSocketClientProtocol, which we can then use to send and receive websocket messages [4]. You can read more about yielding in this interesting article. Note however that on Python version 3.5 or greater, the connect method can be used as a asynchronous context manager [4]. If that’s the case, then later we will not need to explicitly close the connection with a call to the close method since the connection is closed when exiting the context [4]. Since I’m on Python 3.6, I’ll take advantage of the asynchronous context manager. If you are on a Python lower version that doesn’t support it, please check here the websockets module client examples for those versions. So, we will use the following syntax to get the context manager: async with EXPR as VAR: Applied to our example, EXPR corresponds to calling the connect method we have already mentioned. This method receives as input the websocket destination endpoint that we want to contact. To make our tests simpler, as already mentioned in the introductory section, we will use an online testing websocket server that will echo back the content we send it. async def test(): async with websockets.connect('ws://demos.kaazing.com/echo') as websocket: #Client async code Now, to send the actual data, we simply call the send coroutine passing as input the string of data that we want to send to the client. We will send a simple “hello” message. Since this is a coroutine, we will wait it using the await keyword. Note that calling await suspends the execution of the current coroutine (the one where the call is made which is, in our case, the test function) until the awaitable completes and returns the result data [5]. Note that a coroutine is a awaitable [6], which is why we can use the await keyword on the send coroutine. In particular for the send we don’t need to analyse its result, so we can move on to the rest of the code. You can check the source code for send here. await websocket.send("hello") Next, in order to receive the data echoed back by the client, we call the recv coroutine. It receives no arguments and returns a string with the text frame sent by the server (or a bytes object in case it is a binary frame) [7]. In our case, since it will echo what we previously sent, then it will be a string. We will store the result of waiting this coroutine in a variable and then print it. response = await websocket.recv() print(response) And with this, we finish our client function. Note that now, in order to execute its code, we need to get the asyncio event loop, since async code can only run inside an event loop [8]. Then, on the event loop, we call the run_until_complete method and pass as input our test coroutine, so it is executed. The final source code can be seen below. import asyncio import websockets async def test(): async with websockets.connect('ws://demos.kaazing.com/echo') as websocket: await websocket.send("hello") response = await websocket.recv() print(response) asyncio.get_event_loop().run_until_complete(test()) Testing the code To test the code, simply run the previous script (I’m using IDLE, the IDE that comes with the Python installation for running the code). You should get an output similar to figure 1, which shows that the output that gets printed to the Python prompt corresponds exactly to the content we have sent to the server, which is then echoed back to the client. Figure 1 – Output of the program. References [1] [2] [3] [4] [5] [6] [7] [8] 3 Replies to “Python: Websocket client”
https://techtutorialsx.com/2018/02/11/python-websocket-client/
CC-MAIN-2018-39
en
refinedweb
Computational Methods for Database Repair by Signed Formulae - Felix Patterson - 2 years ago - Views: Transcription 1 Computational Methods for Database Repair by Signed Formulae Ofer Arieli Department of Computer Science, The Academic College of Tel-Aviv, 4 Antokolski street, Tel-Aviv 61161, Israel. Marc Denecker, Bert Van Nuffelen and Maurice Bruynooghe Department of Computer Science, Katholieke Universiteit Leuven, Celestijnenlaan 200A, B-3001 Heverlee, Belgium. Abstract. We introduce a simple and practical method for repairing inconsistent databases. Given a possibly inconsistent database, the idea is to properly represent the underlying problem, i.e., to describe the possible ways of restoring its consistency. We do so by what we call signed formulae, and show how the signed theory that is obtained can be used by a variety of off-the-shelf computational models in order to compute the corresponding solutions, i.e., consistent repairs of the database. 1. Introduction Reasoning with inconsistent databases has been extensively studied in the last few years, especially in the context of integration of (possibly contradicting) independent data sources. The ability to synthesize distributed data sources into a single coherent set of information is a major challenge in the construction of knowledge systems for data sharing, and in many cases this property enables inference of information that cannot be drawn otherwise. If, for instance, one source knows that either a or b must hold (but it doesn t know which one is true), and another source knows a (i.e., that a cannot be true), then a mediator system may learn a new fact, b, that is not known to either sources. There is another scenario, however, in which one of the sources also knows b. In this case, not only that the mediator system cannot consistently conclude b, but moreover, in order to maintain consistency it cannot accept the collective information of the sources! In particular, the consistency of each data source is not a sufficient condition for the consistency of their collective information, which again implies that maintaining consistency is a fundamental ability of database merging This paper is a revised and extended version of [9]. c 2005 Kluwer Academic Publishers. Printed in the Netherlands. f_amai04.tex; 10/01/2005; 15:11; p.1 2 2 O. Arieli, M. Denecker, B. Van Nuffelen and M. Bruynooghe systems. 1 The management of inconsistency in database systems requires dealing with many aspects. At the representation level, for instance, systems that keep their data consistent (in contrast to systems that are paraconsistent, that is: preserve the inconsistency and yet draw consistent conclusions out of it) should be able to express how to keep the data coherent. This, of course, carries on to the reasoning level and to the implementation level, where algorithms for consistency restoration should be developed and supported by corresponding computational models. In this paper we introduce a novel approach to database repair that touches upon all the aspects mentioned above: we consider a uniform representation of repairs of inconsistent relational databases, that is, a general description of how to restore the consistency of database instances that do not satisfy a given set of integrity constraints. In our approach, a given repair problem is defined by a theory that consists of what we call signed formulae. This is a very simple but nevertheless general way of representing the underlying problem, which can be used by a variety of off-the-shelf computational systems. We show that out of the signed theories, these systems efficiently solve the problem by computing database repairs, i.e., new consistent database instances that differ from the original database instance by a minimal set of changes (with respect to set inclusion or set cardinality). Here we apply two types of tools for repairing a database: We show that the problem of finding repairs with minimal cardinality for a given database can be converted to the problem of finding minimal Herbrand models for the corresponding signed theory. Thus, once the process for consistency restoration of the database has been represented by a signed theory (using a polynomial transformation), tools for minimal model computations (such as the Sicstus Prolog constraint solver [23], the satisfiability solver zchaff [50], and the answer set programming solver DLV [31]) can be used to efficiently find the required repairs. For finding repairs that are minimal with respect to set inclusion, satisfiability solvers of appropriate quantified Boolean formulae (QBF) can be utilized. Again, we provide a polynomial-time transformation to (signed) QBF theories, and show how QBF solvers (e.g., those of [12, 22, 30, 32, 35, 41, 54]) can be used to restore the database consistency. 1 See., e.g., [4, 10, 11, 17, 18, 25, 27, 37, 36, 45] for more details on reasoning with inconsistent databases and further references to related works. f_amai04.tex; 10/01/2005; 15:11; p.2 3 Computational methods for database repair by signed formulae 3 The rest of the paper is organized as follows: In Section 2 we discuss various representation issues that are related to database repair. We formally define the underlying problem in the context of propositional logic (Section 2.1), show how to represent it by signed formulae (Section 2.2), and then consider an extended framework based on first-order logic (Section 2.3). Section 3 is related to the corresponding computational and reasoning aspects. We show how constraint solvers for logic programs (Section 3.1) and quantified Boolean formulae solvers (Section 3.2) can be utilized for computing database repairs, based on the signed theories. At the end of this section we also give some relevant complexity results (Section 3.3). Section 4 is related to implementation issues. Some experimental results of several benchmarks are given and the suitability of the underlying computational models to the database repair problem is analyzed in light of the results. In Section 5 we link our approach to some related areas, such as belief revision and data merging, showing that some basic postulates of these areas are satisfied in our case as well. Finally, in Section 6 we conclude with some further remarks and observations Preliminaries 2. Database repair and its representation In this section we set-up the framework and define the database repair problem with respect to this framework. To simplify the readings we start with the propositional case, leaving the first-order case to Section 2.3. This two-phase approach may also be justified by the fact that the main contribution of this paper can be expressed already at the propositional level. Let L be a propositional language with P its underlying set of atomic propositions. A (propositional) database instance D is a finite subset of P. The semantics of a database instance is given by the conjunction of the atoms in D, augmented with the Closed World Assumption [53] (CWA(D)), stating that each atom in P that does not appear in D is false. We shall denote the (unique) model of D and CWA(D) by H D. Now, a formula ψ follows from D (or is satisfied in D; notation: D = ψ) if H D satisfies ψ. Otherwise we say that ψ is violated in D. DEFINITION 2.1. A database is a pair (D, IC), where D is a database instance, and IC the set of integrity constraints is a finite and consistent set of formulae in L. A database DB=(D, IC) is consistent f_amai04.tex; 10/01/2005; 15:11; p.3 4 4 O. Arieli, M. Denecker, B. Van Nuffelen and M. Bruynooghe if every formula in IC follows from D (notation: D = IC), that is, there is no integrity constraint that is violated in D. Given an inconsistent database, our goal is to restore its consistency, i.e., to repair the database: DEFINITION 2.2. An update of a database DB = (D, IC) is a pair (Insert, Retract), where Insert, Retract P are sets of atoms such that Insert D = and Retract D. 2 A repair of a database DB is an update (Insert, Retract) of DB, for which ((D Insert) \ Retract, IC) is a consistent database. DEFINITION 2.3. The database ((D Insert) \ Retract, IC) is called the updated database of DB=(D, IC) with update (Insert, Retract). Intuitively, a database is updated by inserting the elements of Insert and removing the elements of Retract. An update is a repair when its updated database is consistent. Note that if DB is consistent, then (, ) is a repair of DB. Definition 2.2 can easily be generalized by allowing repairs only to insert atoms belonging to some set E I, and similarly to delete only atoms of a set E R. Thus, for instance, it would be possible to forbid deletions by letting E R =. In the sequel, however, we shall always assume that any element in P may be inserted or deleted. This assumption can easily be lifted (see also footnote 3 below). EXAMPLE 2.4. Let P = {p, q} and DB = ({p}, {p q}). Clearly, this database is not consistent. It has three repairs: R 1 = ({}, {p}), R 2 = ({q}, {}), and R 3 = ({q}, {p}). These repairs correspond, respectively, to removing p from the database, inserting q to the database, and performing both actions simultaneously. As the example above shows, there are usually many ways to repair a given database, some of them may not be very natural or sensible. It is common, therefore, to specify some preference criterion on the possible repairs, and to apply only those repairs that are (most) preferred with respect to the underlying criterion. The most common criteria for preferring a repair (Insert, Retract) over a repair (Insert, Retract ) are set inclusion [4, 5, 10, 11, 17, 18, 27, 37, 36], i.e., (Insert, Retract) i (Insert, Retract ) if Insert Retract Insert Retract, 2 Note that these conditions imply that Insert and Retract must be disjoint. f_amai04.tex; 10/01/2005; 15:11; p.4 5 Computational methods for database repair by signed formulae 5 or minimal cardinality [10, 11, 25, 45], i.e., (Insert, Retract) c (Insert, Retract ) if Insert + Retract Insert + Retract (where S denotes the cardinality of the set S). Both criteria above reflect the intuitive feeling that a natural way to repair an inconsistent database should require a minimal change, therefore the repaired database is kept as close as possible to the original one. According to this view, for instance, each one of the repairs R 1 and R 2 in Example 2.4 is strictly better than R 3. Note also that (, ) is the only i -preferred and c -preferred repair of consistent databases, as expected Representation of repairs by signed formulae Let DB = (D, IC) be a fixed database that should be repaired. The goal of this section is to characterize the repair process of DB by a logical theory. A key observation in this respect is that a repair of DB boils down to switching some atoms of P from false to true or from true to false. Therefore, to encode a repair, we introduce a switching atom s p for every atom p in P. 3 A switching atom s p expresses whether the status of p switches in the repaired database with respect to the original database: s p is true when p is involved in the repair, either by removing it or inserting it, and is false otherwise (that is, s p holds iff p Insert Retract). We denote by switch(p) the set of switching atoms corresponding to the elements of P. I.e., switch(p) = {s p p P}. The truth of an atom p P in the repaired database can be easily expressed in terms of the switching atom s p of p. We define the signed literal τ p of p with respect to D as follows: τ p = { sp if p D, s p otherwise. An atom p is true in the repaired database if and only if its signed literal τ p is true. Now, as the repaired database can be expressed in terms of the switching atoms, we can also formalize the consistency of the repaired 3 In general, one can impose the requirement that inserted atoms belong to E I and deleted atoms belong to E R, by introducing switching atoms only for the atoms in (E I \ D) (E R D). An atom of this set with a truth value true encodes either an insertion of an element in E I \ D or a deletion of an element in E R D. f_amai04.tex; 10/01/2005; 15:11; p.5 6 6 O. Arieli, M. Denecker, B. Van Nuffelen and M. Bruynooghe database with respect to IC in terms of the switching atoms. This condition is expressed by the theory obtained from IC by simultaneously substituting signed literals τ p for all atoms p occurring in IC. Formally, for every formula ψ of L, its signed formula with respect to D is defined as follows: ψ = ψ [ τ p1 /p 1,..., τ pm /p m ]. As we shall show below (Theorem 2.6), repairs of DB correspond to models of IC = {ψ ψ IC}. EXAMPLE 2.5. Consider again the database DB = ({p}, {p q}) of Example 2.4. In this case τ p = s p and τ q = s q, hence the signed formula of ψ = p q is ψ = s p s q, or, equivalently, s p s q. Intuitively, this formula indicates that in order to restore the consistency of DB, at least one of p or q should be switched, i.e., either p should be removed from the database or q should be inserted to it. Indeed, the three classical models of ψ are exactly the three valuations on {s p, s q } that are associated with the three repairs of DB (see Example 2.4). As Theorem 2.6 below shows, this is not a coincidence. Next we formulate the main correctness theorems of our approach. First we express the correspondences between updates and valuations of the switching atoms. Given an update R = (Insert, Retract) of a database DB, define a valuation ν R on switch(p) as follows: ν R (s p ) = t iff p Insert Retract. ν R is called the valuation that is associated with R. Conversely, a valuation ν of switch(p) induces a database update R ν = (Insert, Retract), where Insert = {p D ν(s p ) = t} and Retract = {p D ν(s p ) = t}. Obviously, these mappings are the inverse of each other. THEOREM 2.6. For a database DB = (D, IC), let IC = {ψ ψ IC}. a) if R is a repair of DB then ν R is a model of IC, b) if ν is a model of IC then R ν is a repair of DB. Proof. For (a), suppose that R is a repair of DB = (D, IC). Then, in particular, D R = IC, where D R = (D Insert)\Retract. Let ψ IC and let H DR be the (unique) model of D R and CWA(D R ). Then H DR (ψ) = t, and so it remains to show that ν R (ψ) = H DR (ψ). The proof of this is by induction on the structure of ψ, and we show only the base step (the rest is trivial), i.e., for every atom p Dom, ν R (p) = H DR (p). Note that ν R (p) = ν R (τ p ), hence: f_amai04.tex; 10/01/2005; 15:11; p.6 7 Computational methods for database repair by signed formulae 7 if p D \Retract, then p D R, and so ν R (p) = ν R ( s p ) = ν R (s p ) = f = t = H DR (p). if p Retract, then p D \ D R, thus ν R (p) = ν R ( s p ) = ν R (s p ) = t = f = H DR (p). if p Insert, then p D R \ D, hence ν R (p) = ν R (s p ) = t = H DR (p). if p D Insert, then p D R, and so ν R (p) = ν R (s p ) = f = H DR (p). For part (b), suppose that ν is a model of IC. Let R ν = (Insert, Retract) = ({p D ν(s p ) = t}, {p D ν(s p ) = t}). We shall show that R ν is a repair of DB. According to Definition 2.2, it is obviously an update of DB. It remains to show that every ψ IC follows from D R = (D Insert) \ Retract, i.e., that H DR (ψ) = t, where H DR is the model of D R and CWA(D R ). Since ν is a model of IC, ν(ψ) = t, and so it remains to show that H DR (ψ) = ν(ψ). Again, the proof is by induction on the structure of ψ, and we show here only the base step, that is: for every atom p Dom, H DR (p) = ν(p). Again, ν R (p) = ν R (τ p ), hence if p D \ Retract, then p D R and ν(s p ) = f, thus H DR (p) = t = ν(s p ) = ν( s p ) = ν(p). if p Retract, then p D \ D R and ν(s p ) = t, hence H DR (p) = f = ν(s p ) = ν( s p ) = ν(p). if p Insert, then p D R \ D and ν(s p ) = t, therefore H DR (p) = t = ν(s p ) = ν(p). if p D Insert, then p D R and ν(s p ) = f, and so H DR (p) = f = ν(s p ) = ν(p). The second part of the above theorem implies, in particular, that in order to compute repairs for a given database DB, it is sufficient to find the models of the signed formulae that are induced by the integrity constraints of DB; the pairs that are induced by these models are the repairs of DB. We have now established a correspondence between arbitrary repairs of a database and models of the signed theory IC. It remains to show how preferred repairs according to some preference relation correspond f_amai04.tex; 10/01/2005; 15:11; p.7 8 8 O. Arieli, M. Denecker, B. Van Nuffelen and M. Bruynooghe to a specific class of models of IC. We do this for the minimal cardinality preference relation c and the set inclusion preference relation i. For any two valuations ν 1, ν 2 of switch(p), denote ν 1 c ν 2 if the number of switching atoms that are assigned the value true by ν 1 is less than those that are assigned true by ν 2. Similarly, denote ν 1 i ν 2 if the set of the true switching atoms of ν 1 is a subset of the set of the true switching atoms of ν 2. Now, the following property is straightforward: LEMMA 2.7. Let R 1, R 2 be two updates of a database (D, IC) and let ν 1, ν 2 be two models of IC = {ψ ψ IC}. Then: a) if R 1 c R 2 then ν R 1 c ν R 2 and if R 1 i R 2 then ν R 1 i ν R 2. b) if ν 1 c ν 2 then R ν 1 c R ν 2 and if ν 1 i ν 2 then R ν 1 i R ν 2. This lemma leads to the following simple characterizations of c - preferred and i -preferred models in terms of the models of IC. THEOREM 2.8. For a database DB = (D, IC) let IC = {ψ ψ IC}. Then: a) if R is a c -preferred repair of DB, then ν R is a c -minimal model of IC. b) if ν is a c -minimal model of IC, then R ν is a c -preferred repair of DB. Proof. By Theorem 2.6, the repairs of a database correspond exactly to the models of the signed theory IC. By Lemma 2.7, c -preferred repairs of DB (i.e., those with minimal cardinality) correspond to c - minimal models of IC. It follows that c -preferred repairs of a database can be computed by searching for models of IC with minimal cardinality (called c - minimal models). We shall use this fact in Section 3, where we consider computations of preferred repairs. A similar theorem holds also for i -preferred repairs: THEOREM 2.9. For a database DB = (D, IC) let IC = {ψ ψ IC}. Then: a) if R is an i -preferred repair of DB, then ν R is an i -minimal model of IC. f_amai04.tex; 10/01/2005; 15:11; p.8 9 Computational methods for database repair by signed formulae 9 b) if ν is an i -minimal model of IC, then R ν is an i -preferred repair of DB. Proof. Similar to that of Theorem 2.8, replacing c by i First-order databases We now turn to the first-order case. As we show below, using the standard technique of grounding, our method of database repairs by signed formulae may be applied in this case as well. Let L be a language of first-order formulas based on a vocabulary consisting of the predicate symbols in a fixed database schema S and a finite set Dom of constants representing the elements of some domain of discourse. In a similar way to that considered in Section 2.1, it is possible to define a database instance D as a finite set of ground atoms in L. The meaning of D is given by the conjunction of the atoms in D augmented with following three assumptions: the Domain Closure Assumption (DCA(Dom)) states that all elements of the domain of discourse are named by constants in Dom, the Unique Name Assumption (UNA(Dom)) states that different constants represent different objects, and the Closed World Assumption (CWA(D)) states that each atom which is not explicitly mentioned in D is false. These three assumptions are hard-wired in the inference mechanisms of the database and therefore are not made explicit in the integrity constraints. The meaning of a database instance under these three assumptions is formalized in a model theoretical way by the least Herbrand model semantics. The unique model of a database instance D is the least Herbrand model H D, i.e., an interpretation in which the domain is Dom, each constant symbol c Dom is interpreted by itself, each predicate symbol p S is interpreted by the set {(x 1,...,x n ) p(x 1,...,x n ) D}, and the interpretation of the equality predicate is the identity relation on Dom. As Dom may change during the lifetime of the database, it is sometimes called the active domain of the database. Again, we say that a first-order sentence ψ follows from D if the least Herbrand model of D satisfies ψ. f_amai04.tex; 10/01/2005; 15:11; p.9 10 10 O. Arieli, M. Denecker, B. Van Nuffelen and M. Bruynooghe Now, a (first-order) database is a pair (D, IC), where D is a database instance, and the set IC of integrity constraints is a finite, consistent set of first-order sentences in L. Consistency of databases is defined just as before. As in the propositional case, an inconsistent first-order database (D, IC) can be repaired by inserting or deleting atoms about elements of Dom. However, there may be also other ways of repairing a database that do not have an equivalent in the propositional case: a database may be updated by adding new elements to Dom and inserting facts about them, or deleting elements from Dom and removing from the database instance all atoms in which they occur; a database may also be updated by equalizing different elements from Dom. The following example illustrates these methods: EXAMPLE a) Let DB = ({P(a)}, { x(p(x) Q(x))}). Clearly, this database is not consistent. When Dom = {a} the actual meaning of this database is given by ({P(a)}, {P(a) Q(a)}) and it is equivalent to the database considered in Examples 2.4 and 2.5 above. As noted in those examples, the repairs in this case, R 1 = ({}, {P(a)}), R 2 = ({Q(a)}, {}), and R 3 = ({Q(a)}, {P(a)}), correspond, respectively, to removing P(a) from the database, inserting Q(a) to the database, and performing both actions simultaneously. Suppose now that the database instance is {P(a), Q(b)} and the domain of discourse is Dom = {a, b}. Then the update ({a = b}, {}) would restore consistency by equalizing a and b. Notice that this solution violates the implicit constraint UNA(Dom). b) Let DB = ( {P(a)}, { x(p(x) y(y x Q(x, y)))} ), and Dom = {a}. Again, this database is not consistent. One of the repairs of this database is R = ({Q(a, b)}, {}). It adds an element b to the domain Dom and restores the consistency of the integrity constraint, but this repair violates the implicit constraint DCA(Dom). In the context of database updating, we need the ability to change the database domain and to merge and equalize two different objects of the database. However, this paper is about repairing database inconsistencies. In this context, it is much less clear whether database repairs that f_amai04.tex; 10/01/2005; 15:11; p.10 11 Computational methods for database repair by signed formulae 11 revise the database domain (and hence violate DCA(Dom)) or revise the identity of objects (and hence violate UNA(Dom)) can be viewed as acceptable repairs. In what follows we shall not consider such repairs as legitimate ones. From now on, we assume that a repair does not contain equality atoms and consists only of atoms in L, and hence, does not force a revision of Dom. This boils down to the fact that DCA(Dom) and UNA(Dom) are considered as axioms of IC which must be preserved in all repairs. Under this assumption, it turns out to be easy to apply the propositional methods described in Section 2 on first-order databases. To do this, we use the standard process of grounding. We denote by ground(ψ) the grounding of a sentence ψ with respect to a finite domain Dom. That is, ground(ψ) = ψ if ψ is a ground atom, ground( ψ) = ground(ψ), ground(ψ 1 ψ 2 ) = ground(ψ 1 ) ground(ψ 2 ), ground(ψ 1 ψ 2 ) = ground(ψ 1 ) ground(ψ 2 ), ground( x ψ(x)) = a Dom ψ[a/x], ground( x ψ(x)) = a Dom ψ[a/x]. (where ψ[a/x] denotes the substitution in ψ of x by a). Since Dom is finite, ground(ψ) is also finite. The resulting formula is further simplified as follows: substitution of true for equality s = s and substitution of false for equality s = t where s t, 4 elimination of truth values by the following rewriting rules: false ϕ false true ϕ true true false true ϕ ϕ false ϕ ϕ false true Clearly, a sentence ψ is satisfied in D if and only if ground(ψ) is satisfied in D. Now, the Herbrand expansion of a database DB = (D, IC) is the pair (D, ground(ic)), where ground(ic) = {ground(ψ) ψ IC}. As a Herbrand expansion of a given (first-order) database DB can be considered as a propositional database, we can apply Definition 2.2 on it for defining repairs of DB. PROPOSITION The database (D, IC {DCA(Dom), UNA(Dom)}) and the propositional database (D, ground(ic)) have the same repairs. 4 In general, when a set E I of insertable atoms and a set E R of retractable atoms are specified, we substitute false for every atom A P \ (D E I ), and true for every atom A D \ E R. f_amai04.tex; 10/01/2005; 15:11; p.11 12 12 O. Arieli, M. Denecker, B. Van Nuffelen and M. Bruynooghe 3. Computing preferred database repairs In this section we show that various constraint solvers for logic programs (Section 3.1) and quantified Boolean formulae (Section 3.2) can be utilized for computing database repairs based on the signed theories. The complexity of these computations is also considered (Section 3.3) Computing preferred repairs by model generation First we show how solvers for constraint logic programs (CLPs), answerset programming (ASP), and SAT solvers, can be used for computing c -preferred repairs (Section 3.1.1) and i -preferred repairs (Section 3.1.2). The experimental results are presented in Section Computing c -preferred repairs In what follows we discuss two techniques to compute c -minimal Herbrand models. The first approach is based on using finite domain CLP solvers. Encoding the computation of c -preferred repairs using a finite domain constraint solver is a straightforward process. The switching atoms s p are encoded as finite domain variables with domain {0, 1}. A typical encoding specifies the relevant constraints (i.e., the encoding of IC), assigns a special variable, Sum, for summing-up the values of the finite domain variables associated with the switching atoms (the sum corresponds to the number of true switching atoms), and searches for a solution with a minimal value for Sum. EXAMPLE 3.1. Below is a code for repairing the database of Example 2.5 with the Sicstus Prolog finite domain constraint solver CLP(FD) [23] 5. domain([sp,sq],0,1), %domain of the atoms Sp #\/ Sq, %the signed theory sum([sp,sq],#=,sum), %Sum: num of true atoms minimize(labeling([],[sp,sq]),sum). %resolve with min. sum The solutions computed here are [1, 0] and [0, 1], and the value of Sum is 1. This means that the cardinality of the c -preferred repairs of DB should be 1, and that these repairs are induced by the valuations ν 1 = {s p : t, s q : f} and ν 2 = {s p : f, s q : t}. 6 Thus, the two c -minimal 5 A Boolean constraint solver would also be appropriate here. As the Sicstus Prolog Boolean constraint solver has no minimization capabilities, we prefer to use here the finite domain constraint solver. 6 Here and in what follows we write ν = {x 1 : a 1,..., x n : a n} to denote that ν(x i) = a i for i = 1,..., n. f_amai04.tex; 10/01/2005; 15:11; p.12 13 Computational methods for database repair by signed formulae 13 repairs here are ({}, {p}) and ({q}, {}), which indeed insert or retract exactly one atomic formula. A second approach is based on using the disjunctive logic programming system DLV [31]. To compute c -minimal repairs using DLV, the signed theory IC is transformed into a propositional clausal form. A clausal theory is a special case of a disjunctive logic program without negation in the body of the clauses. The stable models of a disjunctive logic program without negation as failure in the body of rules coincide exactly with the i -minimal models of such a program. Hence, by transforming the signed theory IC to clausal form, DLV can be used to compute i -minimal Herbrand models. To eliminate models with nonminimal cardinality, weak constraints are used. A weak constraint is a formula for which a cost value is defined. With each model computed by DLV, a cost is defined as the sum of the cost values of all weak constraints satisfied in the model. The DLV system can be asked to generate models with minimal total cost. The set of weak constraints used to compute c -minimal repairs is exactly the set of all atoms s p ; each atom has cost 1. Clearly, i -minimal models of a theory with minimal total cost are exactly the models with least cardinality. EXAMPLE 3.2. Below is a code for repairing the database of Example 2.5 with DLV. Sp v Sq. %the clause :~ Sp. %the weak constraints :~ Sq. %(their cost is 1 by default) Clearly, the solutions here are {s p : t, s q : f} and {s p : f, s q : t}. These valuations induce the two c -minimal repairs of DB, R 1 = ({}, {p}) and R 2 = ({q}, {}) Computing i -preferred repairs The i -preferred repairs of a database (D, IC) correspond to the i - minimal Herbrand models of the signed theory IC. Below we use this fact for introducing some simple techniques to compute an i -preferred repair by model generators; in Section 3.2 we consider another method that is based on reasoning with quantified Boolean formulae. A. A naive algorithm First, we consider a straightforward iterative algorithm for computing all the i -preferred repairs of the input database. The idea behind the following algorithm is to compute, at each iteration, one i -minimal f_amai04.tex; 10/01/2005; 15:11; p.13 14 14 O. Arieli, M. Denecker, B. Van Nuffelen and M. Bruynooghe model of the union of the signed theory IC and the exclusion of all the repairs that have been constructed in previous iterations. By Theorem 2.9, then, this model induces an i -preferred repair of the input database. A pseudo-code of the algorithm is shown in Figure 1. input: a database DB = (D, IC). 1. T = IC; Exclude-Previous-Repairs = ; 2. do { 3. T = T Exclude-Previous-Repairs; 4. compute one i -minimal Herbrand model of T, denote it by M; 5. if {s p M(s p ) = t} = then 6. return (, ) and exit; % this is the only preferred repair 7. else { 8. return the update that is associated with M; 9. ψ M = {s p M(s p)=t} s p; 10. Exclude-Previous-Repairs = Exclude-Previous-Repairs {ψ M }; 11. } 12. } until there are no i -minimal models for T; % no more repairs Figure 1. i-preferred repairs computation by minimal models. EXAMPLE 3.3. Consider the database of Examples 2.4 and 2.5. At the first iteration, one of the two i -minimal Herbrand models of T = ψ = s p s q is computed. Suppose, without a loss of generality, that it is {s p : t, s q : f}. The algorithm thus constructs the corresponding ( i -preferred) repair, which is ({}, {p}). At the next iteration s p is added to T and the only i -minimal Herbrand model of the extended theory is {s p : f, s q : t}. This model is associated with another i - preferred repair of the input database, which is ({q}, {}), and this is the output of the second iteration. At the third iteration s q is added, and the resulting theory is not consistent anymore. Thus, this theory has no i -minimal models, and the algorithm terminates. In particular, therefore, the third repair of the database (which is not an i -preferred one) is not produced by the algorithm. In the last example the algorithm produces exactly the set of the i -preferred repairs of the input database. It is not difficult to see that f_amai04.tex; 10/01/2005; 15:11; p.14 15 Computational methods for database repair by signed formulae 15 this is the case for any input database. First, by Theorem 2.6, every database update that is produced by the algorithm (in line 8) is a repair, since it is associated with a valuation (M) that is a model of IC (as M is an i -minimal model of T ). Moreover, by the next proposition, the output of the algorithm is exactly the set of the i -preferred repairs of the input database. PROPOSITION 3.4. A database update is produced by the algorithm of Figure 1 for input DB iff it is an i -preferred repair of DB. Proof. One direction of the proposition immediately follows from the definition of the algorithm (see lines 4 and 8 in Figure 1). The converse follows from Theorem 2.9 and the fact that Exclude-Previous-Repairs blocks the possibility that the same repair will be computed more than once. Observe that Proposition 3.4 also implies the termination of the algorithm of Figure 1. B. Some more robust methods The algorithm described above implements a direct and simple method of computing all the i -preferred repairs, but it assumes the existence of an (external) procedure that computes one i -minimal Herbrand model of the underlying theory. In what follows we describe three techniques of using ASP/CLP/SAT-solvers for efficiently computing the desired repairs, without relying on any external process. I. One possible technique is based on SAT-solvers. These solvers, e.g. zchaff [50], do not directly compute minimal models, but can be easily extended to do so. The algorithm uses the SATsolver to generate models of the theory T, until it finds a minimal model. Minimality of a model M of T can be verified by checking the unsatisfiability of T, augmented with the axioms p M p and p M p. The model M is minimal exactly when these axioms are inconsistent with T. A pseudo-code of an algorithm that implements this approach is shown below. if T is not satisfiable then halt; while sat(t) { % as long as T is satisfiable } M := solve(t); % find a model of T { T := T p M p, } p M p ; return M % this is an i -minimal model of T f_amai04.tex; 10/01/2005; 15:11; p.15 16 16 O. Arieli, M. Denecker, B. Van Nuffelen and M. Bruynooghe We have tested this approach using the SAT solver zchaff [50]; the results are discussed in Section 4. II. Another possibility is to adapt CLP-techniques to compute i - minimal models of Boolean constraints. The idea is simply to make sure that whenever a Boolean variable (or a finite domain variable with domain {0, 1}) is selected for being assigned a value, one first assigns the value 0 before trying to assign the value 1. PROPOSITION 3.5. If the above strategy for value selection is used, then the first computed model is an i -minimal model. Proof. Consider the search tree of the CLP-problem. Each path in this tree represents a value assignment to a subset of the constraint variables. Internal nodes, correspond to partial solutions, are labeled with the variable selected by the labeling function of the solver and have two children: the left child assigns value 0 to the selected variable and the right child assigns value 1. We say that node n 2 is on the right of a node n 1 in this tree if n 2 appears in the right subtree, and n 1 appears in the left subtree of the deepest common ancestor node of n 1 and n 2. It is then easy to see that in such a tree, each node n 2 to the right of a node n 1 assigns the value 1 to the variable selected in this ancestor node, whereas n 1 assigns value 0 to this variable. Consequently, the left-most node in the search tree which is a model of the Boolean constraints, is i -minimal. In CLP-systems such as Sicstus Prolog, one can control the order in which values are assigned to variables. We have implemented the above strategy and discuss the results in Section 4. EXAMPLE 3.6. Below is a code for computing an i -preferred repair of the database of Example 2.5, using CLP(FD). domain([sp,sq],0,1), % domain of the atoms Sp #\/ Sq, % the signed theory labeling([up,leftmost],[sp,sq]). % find min. solution For computing all the i -minimal repairs, a call to a procedure, compute minimal([sp,sq]), should replace the last line of the code above. This procedure is defined as follows: f_amai04.tex; 10/01/2005; 15:11; p.16 17 Computational methods for database repair by signed formulae 17 compute_minimal(vars):- % find one minimal solution once(labeling([up,leftmost],vars)), bb_put(min_repair,vars). compute_minimal(vars):- % find another solution bb_get(min_repair,solution), exclude_repair(solution,vars), compute_minimal(vars). exclude_repair(sol,vars):- % exclude previous solutions exclude_repair(sol,vars,constraint), call(#\ Constraint). exclude_repair([],[],1). exclude_repair([1 Ss],[V Vs],V#=1 #/\ C):- exclude_repair(ss,vs,c). exclude_repair([0 Ss],[V Vs],C):- exclude_repair(ss,vs,c). Note that the code above is the exact encoding for the Sicstus Prolog solver of the algorithm in Figure 1. III. A third option, mentioned already in Section 3.1.1, is to transform IC to clausal form and use the DLV system. In this case the weak constraints are not needed Computing i -preferred repairs by QBF solvers Quantified Boolean formulae (QBFs) are propositional formulae extended with quantifiers, over propositional variables. It has been shown that this language is useful for expressing a variety of computational paradigms, such as default reasoning [20], circumscribing inconsistent theories [21], paraconsistent preferential reasoning [6], and computations of belief revision operators (see [29], as well as Section 5 below). In this section we show how QBF solvers can be used for computing the i -preferred repairs of a given database. In this case it is necessary to add to the signed formulae of IC an axiom (represented by a quantified Boolean formula) that expresses i -minimality, i.e., that an i -preferred repair is not included in any other database repair. Then, QBF solvers such as QUBOS [12], EVALUATE [22], QUIP [30], QSOLVE [32], QuBE [35], QKN [41], SEMPROP [43], and DECIDE [54], can be applied to the signed quantified Boolean theory that is obtained, in order to compute the i -preferred repairs of the database. Below we give a formal description of this process. f_amai04.tex; 10/01/2005; 15:11; p.17 18 18 O. Arieli, M. Denecker, B. Van Nuffelen and M. Bruynooghe Quantified Boolean formulae In what follows we shall denote propositional formulae by Greek lowercase letters (usually ψ, φ) and QBFs by Greek upper-case letters (e.g., Ψ, Φ). Intuitively, the meaning of a QBF of the form p q ψ is that there exists a truth assignment of p such that ψ is true for every truth assignment of q. Next we formalize this intuition. As usual, we say that an occurrence of an atomic formula p is free if it is not in the scope of a quantifier Qp, for Q {, }, and we denote by Ψ[φ 1 /p 1,...,φ m /p m ] the uniform substitution of each free occurrence of a variable p i in Ψ by a formula φ i, for i=1,...,m. The notion of a valuation is extended to QBFs as follows: Given a function ν at : Dom {t, f} {t, f} s.t. ν(t) = t and ν(f) = f, a valuation ν on QBFs is recursively defined as follows: ν(p) = ν at (p) for every atom p Dom {t, f}, ν( ψ) = ν(ψ), ν(ψ φ) = ν(ψ) ν(φ), where {,,, }, ν( p ψ) = ν(ψ[t/p]) ν(ψ[f/p]), ν( p ψ) = ν(ψ[t/p]) ν(ψ[f/p]). A valuation ν satisfies a QBF Ψ if ν(ψ) = t; ν is a model of a set Γ of QBFs if it satisfies every element of Γ. A QBF Ψ is entailed by a set Γ of QBFs (notation: Γ = Ψ) if every model of Γ is also a model of Ψ. In what follows we shall use the following notations: for two valuations ν 1 and ν 2 we denote by ν 1 ν 2 that for every atomic formula p, ν 1 (p) ν 2 (p) is true. We shall also write ν 1 < ν 2 to denote that ν 1 ν 2 and ν 2 ν Representing i -preferred repairs by signed QBFs It is well-known that quantified Boolean formulae can be used for representing circumscription [49], thus they properly express logical minimization [20, 21]. In our case we use this property for expressing minimization of repairs w.r.t. set inclusion. Given a database DB = (D, IC), denote by IC the conjunction of all the elements in IC (i.e., the conjunction of all the signed formulae that are obtained from the integrity constraints of DB). Consider the following QBF, denoted by Ψ DB : s p1,...,s p n ( IC [ s p 1 /s p1,...,s p n /s pn ] ( n i=1 (s p i s pi ) n i=1 (s pi s p i ) ) ). f_amai04.tex; 10/01/2005; 15:11; p.18 19 Computational methods for database repair by signed formulae 19 Consider a model ν of IC, i.e., a valuation for s p1,...,s pn that makes IC true. The QBF Ψ DB expresses that every interpretation µ (valuation for s p 1,...,s p n ) that is a model of IC, has the property that µ ν implies ν µ, i.e., there is no model µ of IC, s.t. the set {s p ν(s p ) = t} properly contains the set {s p µ(s p ) = t}. In terms of database repairs, this means that if R ν = (Insert, Retract) and R µ = (Insert, Retract ) are the database repairs that are associated, respectively, with ν and µ, then Insert Retract Insert Retract. It follows, therefore, that in this case R ν is an i -preferred repair of DB, and in general Ψ DB represents i -minimality. EXAMPLE 3.7. For the database DB of Examples 2.4 and 2.5, IC Ψ DB is the following theory Γ: { s p s q, s p s q }. ( (s p s q) ((s p s p ) (s q s q ) (s p s p) (s q s q)) The models of Γ are those that assign t either to s p or to s q, but not to both of them, i.e., ν 1 = (s p : t, s q : f) and ν 2 = (s p : f, s q : t). The database updates that are induced by these valuations are, respectively, R ν 1 = ({}, {p}) and R ν 2 = ({q}, {}). By Theorem 3.8 below, these are the only i -preferred repairs of DB. THEOREM 3.8. Let DB = (D, IC) be a database and IC = {ψ ψ IC}. Then: a) if R is an i -preferred repair of DB then ν R is a model of IC Ψ DB, b) if ν is a model of IC Ψ DB then R ν is an i -preferred repair of DB. Proof. Suppose that R = (Insert, Retract) is an i -preferred repair of DB. In particular, it is a repair of DB and so, by Theorem 2.6, ν R is a model of IC. Since Theorem 2.6 also assures that a database update that is induced by a model of IC is a repair of DB, in order to prove both parts of the theorem, it remains to show that the fact that ν R satisfies Ψ DB is a necessary and sufficient condition for assuring that R is i -minimal among the repairs of DB. Indeed, ν R satisfies Ψ DB iff for every valuation µ that satisfies IC and for which µ ν R, it is also true that ν R µ. Thus, ν R satisfies Ψ DB iff there is no model ) f_amai04.tex; 10/01/2005; 15:11; p.19 20 20 O. Arieli, M. Denecker, B. Van Nuffelen and M. Bruynooghe µ of IC s.t. µ < ν R, iff (by Theorem 2.6 again) there is no repair R of DB s.t. ν R < ν R, iff there is no repair R = (Insert, Retract ) s.t. Insert Retract Insert Retract, iff R is an i -minimal repairs of DB. DEFINITION 3.9. [4, 5] Q is a consistent query answer of a database DB = (D, IC) if it holds in (the databases that are obtained from) all the i -preferred repairs of DB. An immediate consequence of Theorem 3.8 is that consistent query answering [4, 5, 37] may be represented in our context in terms of a consequence relation as follows: COROLLARY Q is a consistent query answer of a database DB = (D, IC) iff IC Ψ DB = Q. The last corollary and Section provide, therefore, some additional methods for consistent query answering, all of them are based on signed theories Complexity We conclude this section by an analysis of the computational complexity of the underlying problem. As we show below, Theorem 3.8 allows us to draw upper complexity bounds for the following two main approaches to database integration. a) A skeptical (conservative) approach to query answering (considered, e.g., in [4, 5, 37]), in which an answer to a query Q and a database DB is evaluated with respect to (the databases that are obtained from) all the i -preferred repairs of DB (i.e., computations of consistent query answers; see Definition 3.9 above). a) A credulous approach to the same problem, according to which queries are evaluated with respect to some i -preferred repair of DB. COROLLARY Credulous query answering lies in Σ P 2, and skeptical query answering is in Π P 2. Proof. By Theorem 3.8, credulous query answering is equivalent to satisfiability checking for IC Ψ DB, and skeptical query answering is equivalent to entailment checking for the same theory (see also Corollary 3.10 above). Thus, these decision problems can be encoded by QBFs in prenex normal form with exactly one quantifier alternation. The corollary is obtained, now, by the following well-known result: f_amai04.tex; 10/01/2005; 15:11; p.20 21 Computational methods for database repair by signed formulae 21 PROPOSITION [60] Given a propositional formula ψ, whose atoms are partitioned into i 1 sets {p 1 1,...,p1 m 1 },...,{p i 1,...,pi m i }, deciding whether p 1 1,..., p 1 m 1, p 2 1,..., p 2 m 2,...,Qp i 1,...,Qp i m i ψ is true, is Σ P i -complete (where Q = if i is odd and Q = if i is even). Also, deciding if p 1 1,..., p 1 m 1, p 2 1,..., p 2 m 2,...,Qp i 1,...,Qp i m i ψ is true, is Π P i -complete (where Q = if i is odd and Q = if i is even). As shown, e.g., in [37], the complexity bounds specified in the last corollary are strict, i.e., these decision problems are hard for the respective complexity classes. 4. Experiments and comparative study The idea of using formulae that introduce new ( signed ) variables aimed at designating the truth assignments of other related variables is used, for different purposes, e.g. in [7, 8, 19, 20]. In the area of database integration, signed variables are used in [37], and have a similar intended meaning as in our case. In [37], however, only i - preferred repairs are considered, and a rewriting process for converting relational queries over a database with constraints to extended disjunctive queries (with two kinds of negations) over a database without constraints, must be employed. As a result, only solvers that are able to process disjunctive Datalog programs and compute their stable models (e.g., DLV), can be applied. In contrast, as we have already noted above, motivated by the need to find practical and effective methods for repairing inconsistent databases, signed formulae serve here as a representative platform that can be directly used by a variety of off-theshelf applications for computing (either i -preferred or c -preferred) repairs. In what follows we examine some of these applications and compare their appropriateness to the kind of problems that we are dealing with. We have randomly generated instances of a database, consisting of three relations: teacher of schema (teacher name), course of schema (course name), and teaches of schema (teacher name, course name). Also, the following two integrity constraints were specified: f_amai04.tex; 10/01/2005; 15:11; p.21 22 22 O. Arieli, M. Denecker, B. Van Nuffelen and M. Bruynooghe ic1: A course is given by one teacher: ( X Y Z (teacher(x) teacher(y ) course(z) teaches(x, Z) teaches(y, Z)) X = Y ) ic2: Each teacher gives at least one course: ( ) X teacher(x) Y (course(y ) teaches(x, Y )) The next four test cases (identified by the enumeration below) were considered: 1. Small database instances with ic1 as the only constraint. 2. Larger database instances with ic1 as the only constraint. 3. Databases with IC = {ic1,ic2}, where the number of courses is the same as the number of teachers. 4. Databases with IC = {ic1,ic2} and fewer courses than teachers. Note that in the first two test cases, only retractions of database facts are needed in order to restore consistency, in the third test case both insertion and retractions may be needed, and the last test case is unsolvable, as the theory is not satisfiable. For each benchmark we generated a sequence of instances with an increasing number of database facts, and tested them w.r.t. the following applications: ASP/CLP-solvers: DLV [31] (release ), CLP(FD) [23] (version ). QBF-solvers: SEMPROP [43] (release ), QuBE-BJ [35] (release number 1.3). SAT-solvers: A minimal-model generator based on zchaff [50]. The goal was to construct i -preferred repairs within a time limit of five minutes. The systems DLV and CLP(FD) were tested also for constructing c -preferred repairs. All the experiments were done on a Linux machine, 800MHz, with 512MB memory. Tables I IV show the results for providing the first answer. 7 7 Times are given in seconds, empty cells mean that timeout is reached without an answer, vars is the number of variables, IC is the number of grounded integrity constraints, and size is the size of the repairs. We focus on the computation of one minimal model. The reason is simply that in most sizable applications, the computation of all minimal models is not feasible (there are too many of them). f_amai04.tex; 10/01/2005; 15:11; p.22 23 Computational methods for database repair by signed formulae 23 Table I. Results for test case 1. Test info. i -repairs c -repairs No. vars IC size DLV CLP zchaff SEMPROP QuBE DLV CLP Table II. Results for test case 2. Test info. i -repairs No. vars IC size DLV CLP zchaff f_amai04.tex; 10/01/2005; 15:11; p.23 24 24 O. Arieli, M. Denecker, B. Van Nuffelen and M. Bruynooghe Table III. Results for test case 3. Test info. i -repairs c -repairs No. vars size DLV CLP zchaff DLV CLP Table IV. Results for test case 4. Test info. i -repairs c -repairs No. teachers courses DLV CLP zchaff DLV CLP The results of the first benchmark (Table I) already indicate that DLV, CLP, and zchaff perform much better than the QBF-solvers. In fact, among the QBF-solvers that were tested, only SEMPROP could repair within the time limit most of the database instances of benchmark 1, and none of them could successfully repair (within the time restriction) the larger database instances, tested in benchmark 2. Another observation from Tables I IV is that DLV, CLP, and the zchaff-based system, perform very good for minimal inclusion greedy algorithms. However, when using DLV and CLP for cardinality minimization, their performance is much worse. This is due to an exhaustive search for a c -minimal solution. While in benchmark 1 the time differences among DLV, CLP, and zchaff, for computing i -repairs are marginal, in the other benchmarks the differences become more evident. Thus, for instance, zchaff performs better than the other solvers w.r.t. bigger database instances with f_amai04.tex; 10/01/2005; 15:11; p.24 CHAPTER 7 GENERAL PROOF SYSTEMS CHAPTER 7 GENERAL PROOF SYSTEMS 1 Introduction Proof systems are built to prove statements. They can be thought as an inference machine with special statements, called provable statements, or sometimes Logic in Computer Science: Autumn 2006 Introduction to Logic in Computer Science: Autumn 2006 Ulle Endriss Institute for Logic, Language and Computation University of Amsterdam Ulle Endriss 1 Plan for Today Now that we have a basic understanding: CS510 Software Engineering CS510 Software Engineering Propositional Logic Asst. Prof. Mathias Payer Department of Computer Science Purdue University TA: Scott A. Carr Slides inspired by Xiangyu Zhang. Which Semantics for Neighbourhood Semantics? Which Semantics for Neighbourhood Semantics? Carlos Areces INRIA Nancy, Grand Est, France Diego Figueira INRIA, LSV, ENS Cachan, France Abstract In this article we discuss two alternative proposals Correspondence analysis for strong three-valued logic Correspondence analysis for strong three-valued logic A. Tamminga abstract. I apply Kooi and Tamminga s (2012) idea of correspondence analysis for many-valued logics to strong three-valued logic (K UPDATES OF LOGIC PROGRAMS Computing and Informatics, Vol. 20, 2001,????, V 2006-Nov-6 UPDATES OF LOGIC PROGRAMS Ján Šefránek Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics, Comenius University,: Efficient Fixpoint Methods for Approximate Query Answering in Locally Complete Databases Efficient Fixpoint Methods for Approximate Query Answering in Locally Complete Databases Álvaro Cortés-Calabuig 1, Marc Denecker 1, Ofer Arieli 2, Maurice Bruynooghe 1 1 Department of Computer Science, THE ROOMMATES PROBLEM DISCUSSED THE ROOMMATES PROBLEM DISCUSSED NATHAN SCHULZ Abstract. The stable roommates problem as originally posed by Gale and Shapley [1] in 1962 involves a single set of even cardinality 2n, each member of which Mathematical Induction Mathematical Induction Victor Adamchik Fall of 2005 Lecture 2 (out of three) Plan 1. Strong Induction 2. Faulty Inductions 3. Induction and the Least Element Principal Strong Induction Fibonacci Numbers Mathematical Induction Mathematical Induction In logic, we often want to prove that every member of an infinite set has some feature. E.g., we would like to show: N 1 : is a number 1 : has the feature Φ ( x)(n 1 x! 1 x) 2: Universality CS 710: Complexity Theory 1/21/2010 Lecture 2: Universality Instructor: Dieter van Melkebeek Scribe: Tyson Williams In this lecture, we introduce the notion of a universal machine, develop efficient universal Chapter 7. Sealed-bid Auctions Chapter 7 Sealed-bid Auctions An auction is a procedure used for selling and buying items by offering them up for bid. Auctions are often used to sell objects that have a variable price (for example oil) Scheduling Shop Scheduling. Tim Nieberg Scheduling Shop Scheduling Tim Nieberg Shop models: General Introduction Remark: Consider non preemptive problems with regular objectives Notation Shop Problems: m machines, n jobs 1,..., n operations XML with Incomplete Information XML with Incomplete Information Pablo Barceló Leonid Libkin Antonella Poggi Cristina Sirangelo Abstract We study models of incomplete information for XML, their computational properties, and query answering. Satisfiability Checking Satisfiability Checking SAT-Solving Prof. Dr. Erika Ábrahám Theory of Hybrid Systems Informatik 2 WS 10/11 Prof. Dr. Erika Ábrahám - Satisfiability Checking 1 / 40 A basic SAT algorithm Assume the CN Exponential time algorithms for graph coloring Exponential time algorithms for graph coloring Uriel Feige Lecture notes, March 14, 2011 1 Introduction Let [n] denote the set {1,..., k}. A k-labeling of vertices of a graph G(V, E) is a function V 3. Cartesian Products and Relations. 3.1 Cartesian Products Chapter 3 Cartesian Products and Relations The material in this chapter is the first real encounter with abstraction. Relations are very general thing they are a special type of subset. After introducing Lecture 7: NP-Complete Problems IAS/PCMI Summer Session 2000 Clay Mathematics Undergraduate Program Basic Course on Computational Complexity Lecture 7: NP-Complete Problems David Mix Barrington and Alexis Maciel July 25, 2000 1. Circuit The Foundations: Logic and Proofs. Chapter 1, Part III: Proofs The Foundations: Logic and Proofs Chapter 1, Part III: Proofs Rules of Inference Section 1.6 Section Summary Valid Arguments Inference Rules for Propositional Logic Using Rules of Inference to Build Arguments 4 Domain Relational Calculus 4 Domain Relational Calculus We now present two relational calculi that we will compare to RA. First, what is the difference between an algebra and a calculus? The usual story is that the algebra RA is 17 : Equivalence and Order Relations DRAFT CS/Math 240: Introduction to Discrete Mathematics 3/31/2011 Lecture 17 : Equivalence and Order Relations Instructor: Dieter van Melkebeek Scribe: Dalibor Zelený DRAFT Last lecture we introduced the notion Fixed-Point Logics and Computation 1 Fixed-Point Logics and Computation Symposium on the Unusual Effectiveness of Logic in Computer Science University of Cambridge 2 Mathematical Logic Mathematical logic seeks to formalise the process of Boolean Representations and Combinatorial Equivalence Chapter 2 Boolean Representations and Combinatorial Equivalence This chapter introduces different representations of Boolean functions. It then discuss the applications of these representations for proving Logical Foundations of Relational Data Exchange Logical Foundations of Relational Data Exchange Pablo Barceló Department of Computer Science, University of Chile pbarcelo@dcc.uchile.cl 1 Introduction Data exchange has been defined as the problem of, } Computability Theory CSC 438F/2404F Notes (S. Cook and T. Pitassi) Fall, 2014 Computability Theory This section is partly inspired by the material in A Course in Mathematical Logic by Bell and Machover, Chap 6, sections 1-10. Expressive powver of logical languages July 18, 2012 Expressive power distinguishability The expressive power of any language can be measured through its power of distinction or equivalently, by the situations it considers indistinguishable. Advanced Relational Database Design APPENDIX B Advanced Relational Database Design In this appendix we cover advanced topics in relational database design. We first present the theory of multivalued dependencies, including a set of sound GRAPH THEORY LECTURE 4: TREES GRAPH THEORY LECTURE 4: TREES Abstract. 3.1 presents some standard characterizations and properties of trees. 3.2 presents several different types of trees. 3.7 develops a counting method based on a bijection XML Data Integration XML Data Integration Lucja Kot Cornell University 11 November 2010 Lucja Kot (Cornell University) XML Data Integration 11 November 2010 1 / 42 Introduction Data Integration and Query Answering A data
http://docplayer.net/12185651-Computational-methods-for-database-repair-by-signed-formulae.html
CC-MAIN-2018-39
en
refinedweb
<< Rasmussen and Williams (2006) is still one of the most important references on Gaussian process models. It is available freely The challenge comes when a third data point is observed and it doesn't naturally fit on the straight line. point 3: \(\inputScalar = 2\), \(\dataScalar=2.5\) \[2.5 = 2m + c\] Now there are three candidate lines, each consistent with our data. This is known as an overdetermined system because there are more data than we need to determine our parameters. The problem arises because the model is a simplification of the real world, and the data we observe is therefore inconsistent with our model._1<<_2<<}\] Two Important Gaussian Properties \(\alpha_1\)^2)\exp(b^2) = \exp(a^2 + b^2), \] Consider the distribution of height (in meters) of an adult male human population. We will approximate the marginal density of heights as a Gaussian density with mean given by \(1.7\text{m}\) and a standard deviation of \(0.15\text{m}\), implying a variance of \(\dataStd^2=0.0225\), \[ p(h) \sim \gaussianSamp{1.7}{0.0225}. \] Similarly, we assume that weights of the population are distributed a Gaussian density with a mean of \(75 \text{kg}\) and a standard deviation of \(6 kg\) (implying a variance of 36), \[ p(w) \sim \gaussianSamp{75}{36}. \] Independent Gaussians \[). _gp/includes/gp-intro-very-short.md Bayesian Inference by Rejection Sampling mechanims mathematically, and obtain the posterior density analytically. This is the benefit of Gaussian processes. import numpy as np from mlai import compute_kernel from mlai import exponentiated_quadratic _gp/includes/gpdistfunc.md Sampling a Function. from mlai import Kernel from mlai import polynomial_cov from mlai import exponentiated_quadratic _gp/includes/gaussian-predict-index-one-and-two.md Uluru. _gp/includes/gaussian-predict-index-one-and-eight.md _kern/includes/computing-rbf-covariance.md Where Did This Covariance Matrix Come From? \[ k(\inputVector, \inputVector^\prime) = \alpha \exp\left(-\frac{\left\Vert \inputVector - \inputVector^\prime\right\Vert^2_2}{2\lengthScale^2}\right)\] Polynomial Covariance from mlai import polynomial_cov
http://inverseprobability.com/talks/notes/gpss-session-1.html
CC-MAIN-2018-39
en
refinedweb
Especifications: - Server: Weblogic 9.2 fixed by customer. - Webservices defined by wsdl and xsd files fixed by customer; not modifications allowed. Hi, In the project we need to develope a mail system. This must ... I am facing this problem for over than one month , so i would be realy pleased by your help , in fact i am asking about a way that can ... Am using an implementation of MessageBodyWriter to marshall all my objects to a file(XML). MessageBodyWriter @XmlRootElement(name="root") @XmlAccessorType( XmlAccessType.FIELD ) class Myclass implements MyInterface{ // some private fields } interface MyInterface{ //some methods } List<MyClass> This has been a thorn in my side for the last 2 days. We have a Ear and EJB project that uses xml/xsd to configure our beans, but for some reason we are getting errors when we try to unmarshall our xml. Here is the error: DefaultValidationEventHandler: [FATAL_ERROR]: unexpected element (uri:"", local:"appConfiguration"). Expected elements are <{}appConfiguration> Location: line 12 The log ... Iam using JAXB1.6 to convert the below xml to java object. After unmarshalling when I print the contents for ErrorMsg element, JAXB doesn't do any conversion for & and the character mentioned in ENTITY in the xml. It just prints as such what is in the xml. Where as i need the output as like " Inhalt des Feldes ung >ig ... Hi all, I'm trying to unmarshal an xml schema. I used the tool XJCFacade provided under JaxB package com.sun.tools.xjc. After running the tool the autogenerated classes wont havesetters methods to corresponding properties. My question is how am I supposed to set properties in respective instances of those autogenereated classes. Should i add my own setter method or is there any other ... If I got your probelm correctly , you have changed the package name of the classes generated by your wsdl-2-java tool and you are getting a binding error while running the service. Generated class's package name is mapped to the namespace in the wsdl schema by default. So if you change the package name, those mappings will won't work. I think ...
http://www.java2s.com/Questions_And_Answers/Java-Enterprise/jaxb/marshall.htm
CC-MAIN-2018-39
en
refinedweb
ConcurrentHashMap public class ConcurrentHashMap<K,V> extends AbstractMap<K,V> implements ConcurrentMap<K,V>, Serializable { ... } 1. Some important parameters 1.1 MAXIMUM_ Capability parameter /** * The largest possible table capacity. This value must be * exactly 1<<30 to stay within Java array allocation and indexing * bounds for power of two table sizes, and is further required * because the top two bits of 32bit hash fields are used for * control purposes. */ private static final int MAXIMUM_CAPACITY = 1 << 30; MAXIMUM_ The capability parameter indicates the maximum capacity of the map. The default value is 1 < < 30. 1.2 DEFAULT_ Capability parameter /** * The default initial table capacity. Must be a power of 2 * (i.e., at least 1) and at most MAXIMUM_CAPACITY. */ private static final int DEFAULT_CAPACITY = 16; DEFAULT_ The capability parameter indicates the default capacity of the map, which is 16. 1.3 MAX_ARRAY_SIZE parameter /** * The largest possible (non-power of two) array size. * Needed by toArray and related methods. */ static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8; MAX_ ARRAY_ The size parameter indicates the maximum length of the map array, which may be used in toArray() and its related methods. The size is Integer.MAX_VALUE - 8. 1.4 DEFAULT_CONCURRENCY_LEVEL parameter /** * The default concurrency level for this table. Unused but * defined for compatibility with previous versions of this class. */ private static final int DEFAULT_CONCURRENCY_LEVEL = 16; DEFAULT_ CONCURRENCY_ The level parameter indicates the default concurrency level. It has been deprecated in the current version JDK13, but this parameter is reserved for compatibility with previous versions. 1.5 LOAD_FACTOR parameter /** * The load factor for this table. Overrides of this value in * constructors affect only the initial table capacity. The * actual floating point value isn't normally used -- it is * simpler to use expressions such as {@code n - (n >>> 2)} for * the associated resizing threshold. */ private static final float LOAD_FACTOR = 0.75f; LOAD_ The factor parameter indicates the loading factor, which is 0.75 by default, the same as HashMap. 1.6 TREEIFY_THRESHOLD parameter /** * The bin count threshold for using a tree rather than list for a * bin. Bins are converted to trees when adding an element to a * bin with at least this many nodes. The value must be greater * than 2, and should be at least 8 to mesh with assumptions in * tree removal about conversion back to plain bins upon * shrinkage. */ static final int TREEIFY_THRESHOLD = 8; TREEIFY_ The threshold parameter represents the threshold value of converting the linked list in the array into a red black tree. It is used to compare with the length of a linked list. 1.7 UNTREEIFY_THRESHOLD parameter /** * The bin count threshold for untreeifying a (split) bin during a * resize operation. Should be less than TREEIFY_THRESHOLD, and at * most 6 to mesh with shrinkage detection under removal. */ static final int UNTREEIFY_THRESHOLD = 6; UNTREEIFY_ The threshold parameter represents the threshold value for the red black tree in the array to be transformed into a linked list. It is used to compare with the size of a red black tree. 1.8 MIN_ TREEIFY_ Capability parameter /** * The smallest table capacity for which bins may be treeified. * (Otherwise the table is resized if too many nodes in a bin.) * The value should be at least 4 * TREEIFY_THRESHOLD to avoid * conflicts between resizing and treeification thresholds. */ static final int MIN_TREEIFY_CAPACITY = 64; MIN_ TREEIFY_ The capability parameter indicates the minimum capacity of the hash table to treelize the linked list. Only when the capacity of the entire ConcurrentHashMap is greater than this value can the specific linked list be treelized. If it is not greater than this value, it will be expanded instead of treelized. (capacity expansion will also reduce the number of elements in a single linked list). 1.9 MIN_TRANSFER_STRIDE parameter /** * Minimum number of rebinnings per transfer step. Ranges are * subdivided to allow multiple resizer threads. This value * serves as a lower bound to avoid resizers encountering * excessive memory contention. The value should be at least * DEFAULT_CAPACITY.STR */ private static final int MIN_TRANSFER_STRIDE = 16; In the capacity expansion operation, the transfer step allows multiple threads to be performed concurrently, min_ TRANSFER_ The stride parameter indicates the minimum number of tasks of a worker thread in a transfer operation. That is, the minimum number of consecutive hash buckets to be processed. The default is 16, that is, at least 16 consecutive hash buckets should be transferred. See the analysis of the transfer() method below for details. 1.10 RESIZE_STAMP_BITS parameter (not understood) /** * The number of bits used for generation stamp in sizeCtl. * Must be at least 6 for 32bit arrays. */ private static final int RESIZE_STAMP_BITS = 16; RESIZE_ STAMP_ The bits parameter is used to generate a unique generation stamp in each capacity expansion. 1.11 MAX_RESIZERS parameter (not understood) /** * The maximum number of threads that can help resize. * Must fit in 32 - RESIZE_STAMP_BITS bits. */ private static final int MAX_RESIZERS = (1 << (32 - RESIZE_STAMP_BITS)) - 1; This parameter defines the maximum number of worker threads when resizing, but I don't understand the calculation method. MAX_ RESIZERS = (1 << (32 - resize_STAMP_BITS)) - 1; 1.12 RESIZE_STAMP_SHIFT parameter (not understood) /** * The bit shift for recording size stamp in sizeCtl. */ private static final int RESIZE_STAMP_SHIFT = 32 - RESIZE_STAMP_BITS; This parameter defines the bit shift of the record size mark in sizeCtl, but I don't understand the calculation method. MAX_RESIZERS = 32 - RESIZE_STAMP_BITS; 1.13 hash status parameters of special nodes /* * Encodings for Node hash fields. See above for explanation. */ static final int MOVED = -1; // hash for forwarding nodes static final int TREEBIN = -2; // hash for roots of trees static final int RESERVED = -3; // hash for transient reservations Normally, the hash value should be positive. If it is negative, it indicates that it is an abnormal and special node. - When the hash value is - 1, it means that the current node is a Forwarding Node. - ForwardingNode is a temporary node that only appears during capacity expansion, and it does not store actual data. - If all the nodes in a hash bucket of the old array are migrated to the new array, the old array will place a ForwardingNode in the hash bucket - When a ForwardingNode is encountered during a read operation or iterative read operation, the operation is forwarded to the new table array after capacity expansion for execution. When a write operation encounters it, it attempts to help with capacity expansion. - When the hash value is - 2, it means that the current node is a TreeBin. - TreeBin is a special node in ConcurrentHashMap for agent operation of TreeNode. It holds the root node of the red black tree that stores actual data. - Because the red black tree performs write operations, the structure of the whole tree may change greatly, which has a great impact on the read thread. Therefore, TreeBin also needs to maintain a simple read-write lock, which is an important reason for the new introduction of this special node compared with HashMap. - When the hash value is - 3, it means that the current node is a reserved node, that is, a placeholder. - Generally, it will not appear. 1.14 HASH_BITS parameters static final int HASH_BITS = 0x7fffffff; // usable bits of normal node hash HASH_BITS is also seen in HashTable. Through bit operation with bits, the hash value of negative numbers can be transformed into positive numbers. 1.15 NCPU parameters /** Number of CPUS, to place bounds on some sizings */ static final int NCPU = Runtime.getRuntime().availableProcessors(); The NCPU parameter can obtain the number of processor cores that can be used by the current JVM. 2. Some important attributes It is worth noting that the key attributes in ConcurrentHashMap are basically volatile variables. 2.1 table attribute /** * The array of bins. Lazily initialized upon first insertion. * Size is always a power of two. Accessed directly by iterators. */ transient volatile Node<K,V>[] table; The table attribute is used for storage nodes and is a collection of buckets. 2.2 nextTable attribute /** * The next table to use; non-null only while resizing. */ private transient volatile Node<K,V>[] nextTable; The nextTable property indicates the next array to be used. It is used to assist the resize operation. It is only non empty when resizing. 2.3 baseCount attribute /** * Base counter value, used mainly when there is no contention, * but also as a fallback during table initialization * races. Updated via CAS. */ private transient volatile long baseCount; The baseCount property is the basic counter value when there is no contention. It is also used in the contention of the initialization table. 2.4 sizeCtl attribute /** * Table initialization and resizing control. When negative, the * table is being initialized or resized: -1 for initialization, * else -(1 + the number of active resizing threads). Otherwise, * when table is null, holds the initial table size to use upon * creation, or 0 for default. After initialization, holds the * next element count value upon which to resize the table. */ private transient volatile int sizeCtl; The sizeCtl attribute plays a role in table initialization and resize operation control. - When sizeCtl is negative, it indicates that the table is initializing or resizing. - Table initialization is - 1. - When the table resize s, it is - (1 + number of capacity expansion threads). - When sizecl is positive. - Initial table size or 0 when the table is null. - When the table is not null, it is the next count value to resize. 2.5 transferIndex attribute /** * The next table index (plus one) to split while resizing. */ private transient volatile int transferIndex; The index of the next table to split in resize. 2.6 cellsBusy attribute /** * Spinlock (locked via CAS) used when resizing and/or creating CounterCells. */ private transient volatile int cellsBusy; Spin locks used during the resize process and / or the creation of counter cells. 2.7 counterCells array /** * Table of counter cells. When non-null, size is a power of 2. */ private transient volatile CounterCell[] counterCells; Obviously, this is the array of counter cells, that is, the array of counting units. 3. Internal class 3.1 Node internal class The Node inner class is an abstraction of ordinary nodes in the ConcurrentHashMap class. /** * Key-value entry. This class is never exported out as a * user-mutable Map.Entry (i.e., one supporting setValue; see * MapEntry below), but can be used for read-only traversals used * in bulk tasks. Subclasses of Node with a negative hash field * are special, and contain null keys and values (but are never * exported). Otherwise, keys and vals are never null. */ static class Node<K,V> implements Map.Entry<K,V> { final int hash; final K key; volatile V val; volatile Node<K,V> next; Node(int hash, K key, V val) { this.hash = hash; this.key = key; this.val = val; } Node(int hash, K key, V val, Node<K,V> next) { this(hash, key, val); this.next = next; } public final K getKey() { return key; } public final V getValue() { return val; } public final int hashCode() { return key.hashCode() ^ val.hashCode(); } public final String toString() { return Helpers.mapEntryToString(key, val); } public final V setValue(V value) { throw new UnsupportedOperationException(); } public final boolean equals(Object o) { Object k, v, u; Map.Entry<?,?> e; return ((o instanceof Map.Entry) && (k = (e = (Map.Entry<?,?>)o).getKey()) != null && (v = e.getValue()) != null && (k == key || k.equals(key)) && (v == (u = val) || v.equals(u))); } /** * Virtualized support for map.get(); overridden in subclasses. */ Node<K,V> find(int h, Object k) { Node<K,V> e = this; if (k != null) { do { K ek; if (e.hash == h && ((ek = e.key) == k || (ek != null && k.equals(ek)))) return e; } while ((e = e.next) != null); } return null; } } significance The Node internal class is the implementation of the ConcurrentHashMap Node. Implementation of hashCode() Note the implementation of hashCode(): Objects.hashCode(key) ^ Objects.hashCode(value); find() Here, the find() method of the Node internal class will not be called in general business methods such as get(), because it will be traversed directly in those places. This method will be called in the find() method of the ForwardingNode class. 4. Tools and methods 4.1 spread method /** * Spreads (XORs) higher bits of hash to lower and also forces top * bit to 0. spread(int h) { return (h ^ (h >>> 16)) & HASH_BITS; } The hash conflict is reduced by taking the high bit and then performing mask calculation (ensuring that the hash value is positive). This method is called perturbation method. 4.2 tableSizeFor method /** * Returns a power of two table size for the given desired capacity. * See Hackers Delight, sec 3.2 */ private static final int tableSizeFor(int c) { int n = -1 >>> Integer.numberOfLeadingZeros(c - 1); return (n < 0) ? 1 : (n >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : n + 1; } The tableSizeFor method is used to calculate the resize threshold corresponding to parameter c. It often appears as the following statement. 4.3 comparable class for method /** * Returns x's Class if it is of the form "class C implements * Comparable<C>", else null. */ static Class<?> comparableClassFor(Object x) { if (x instanceof Comparable) { Class<?> c; Type[] ts, as; ParameterizedType p; // If it is a String, it returns directly if ((c = x.getClass()) == String.class) return c; if ((ts = c.getGenericInterfaces()) != null) { for (Type t : ts) { if ((t instanceof ParameterizedType) && ((p = (ParameterizedType)t).getRawType() == Comparable.class) && (as = p.getActualTypeArguments()) != null && as.length == 1 && as[0] == c) // type arg is c return c; } } } return null; } If parameter x is an implementation class of a Comparable interface, its type is returned. 4.4 compareComparables method /** * Returns k.compareTo(x) if x matches kc (k's screened comparable * class), else 0. */ @SuppressWarnings({"rawtypes","unchecked"}) // for cast to Comparable static int compareComparables(Class<?> kc, Object k, Object x) { return (x == null || x.getClass() != kc ? 0 : ((Comparable)k).compareTo(x)); } If the object x matches the comparable class kc of K, k.compareTo(x) is returned; otherwise, 0 is returned. 4.5 list element access method 4.5.1 tabAt method static final <K,V> Node<K,V> tabAt(Node<K,V>[] tab, int i) { return (Node<K,V>)U.getReferenceAcquire(tab, ((long)i << ASHIFT) + ABASE); } The tabAt() method can obtain the Node at the i position. 4.5.2 casTabAt method static final <K,V> boolean casTabAt(Node<K,V>[] tab, int i, Node<K,V> c, Node<K,V> v) { return U.compareAndSetReference(tab, ((long)i << ASHIFT) + ABASE, c, v); } The casTabAt() method can update the Node at the i location in the form of CAS 4.5.3 setTabAt method static final <K,V> void setTabAt(Node<K,V>[] tab, int i, Node<K,V> v) { U.putReferenceRelease(tab, ((long)i << ASHIFT) + ABASE, v); } The setTabAt method can set the Node at the i position. Note: methods like Unsafe.getReferenceAcquire() and Unsafe.putReferenceRelease() are actually the release versions of volatile methods in Unsafe. For example, the latter is the release version of putReferenceVolatile(). 4.6 initTable method private final Node<K,V>[] initTable() { Node<K,V>[] tab; int sc; while ((tab = table) == null || tab.length == 0) { if ((sc = sizeCtl) < 0) // If the sizeCtl attribute is less than 0, it indicates that initialization or resize is in progress Thread.yield(); // lost initialization race; just spin else if (U.compareAndSetInt(this, SIZECTL, sc, -1)) {// If SIZECTL is still sc, it is set to - 1. It indicates that initialization is entered try { if ((tab = table) == null || tab.length == 0) { // Get the initial size (when sc is positive, it is the initial size) int n = (sc > 0) ? sc : DEFAULT_CAPACITY; // Create a node array @SuppressWarnings("unchecked") Node<K,V>[] nt = (Node<K,V>[])new Node<?,?>[n]; // Assign a value to the table property table = tab = nt; sc = n - (n >>> 2); } } finally { // Finally, remember to update sizeCtl sizeCtl = sc; } break; } } return tab; } The initTable() method initializes an empty table. 4.7 hashCode method public int hashCode() { int h = 0; Node<K,V>[] t; if ((t = table) != null) { Traverser<K,V> it = new Traverser<K,V>(t, t.length, 0, t.length); for (Node<K,V> p; (p = it.advance()) != null; ) h += p.key.hashCode() ^ p.val.hashCode(); } return h; } The hashCode() method is to traverse each key value pair, make their key and value hash codes different or, and then stack them all. 4.8 addCount method The addCount() method will be called when the number of ConcurrentHashMap elements changes. The first of the two parameters is the number change value, and the second is the parameter that controls whether expansion check is required. private final void addCount(long x, int check) { // Create counter cell CounterCell[] cs; long b, s; /** 1.If counterCells is null: Then, it indicates that there has been no concurrency conflict before. Then, U.compareAndSetLong(...,b+x) will be executed to directly update the count value baseCount. If the local method is executed successfully, it will return true, and if it is reversed, it will be false. Then, the whole if determines that the two conditions are false, and the contents in the if block are not executed. 2.If couterCells is not null: It indicates that concurrency conflicts have occurred before, and the following if block processing is required. Here, if the first condition is true, the update method of the second condition will not be executed. */ if ((cs = counterCells) != null || !U.compareAndSetLong(this, BASECOUNT, b = baseCount, s = b + x)) { // Enter the if block, indicating that there has been a concurrency conflict, then add the value to the CounterCell CounterCell c; long v; int m; boolean uncontended = true; if (cs == null // cs becomes null again in concurrency || (m = cs.length - 1) < 0 // cs length less than 1 || (c = cs[ThreadLocalRandom.getProbe() & m]) == null // The corresponding CouterCell is null || !(uncontended = U.compareAndSetLong(c, CELLVALUE, v = c.value, v + x))) {// Attempt to update the value of the found count cell c // If the update fails. Generally, the method in the last condition above returns false, and the reverse is true // Description there is a concurrency conflict in the CounterCells array, which may involve the expansion of the array. Call the fullAddCount method fullAddCount(x, uncontended); return; } if (check <= 1)// If there is no need to check, return directly return; // Count and save it in s. the following is used for inspection s = sumCount(); } // Check whether capacity expansion is required if (check >= 0) { Node<K,V>[] tab, nt; int n, sc; while (s >= (long)(sc = sizeCtl) // The number of elements is greater than the capacity expansion threshold: capacity expansion is required && (tab = table) != null // Table is not empty && (n = tab.length) < MAXIMUM_CAPACITY) {// Table length does not reach the upper limit int rs = resizeStamp(n) << RESIZE_STAMP_SHIFT; // If you are performing resize if (sc < 0) { // Give up some conditions to help expand capacity if (sc == rs + MAX_RESIZERS || sc == rs + 1 || (nt = nextTable) == null || transferIndex <= 0) break; // sc+1 indicates that a new thread is added to help expand the capacity if (U.compareAndSetInt(this, SIZECTL, sc, sc + 1)) transfer(tab, nt); } // Currently, resizing is not being executed. Try to become the first thread to enter the capacity expansion. Set sc to rs+2 else if (U.compareAndSetInt(this, SIZECTL, sc, rs + 2)) transfer(tab, null); // Recalculate the number of elements s = sumCount(); } } } See the code comments for detailed logic. Here are a few separate points. - The first if judgment condition is wonderful. Check whether the value should be added directly to baseCount or to the corresponding counter cell according to whether the counter cells array is null. - Note how to find the slot position in the counter cells array: C = CS [threadlocalrandom. Getprobe() & M]) = = null. - When the check parameter is less than or equal to 1, exit without checking. When it is greater than 1, check whether capacity expansion is required after the main logic of addCount is completed. When the put method calls addCount, the check parameter passed in is actually the number of nodes traversed during the put process, so the logic is connected: if there is only one node or it is empty, it is not necessary to consider whether to check the expansion again; Otherwise, check in addCoumt. 4.9 helpTransfer method The helpTransfer method can assist in data migration and return a new array when the node is resizing. This method is called in business methods such as put and remove. /** * Helps transfer if a resize is in progress. */ final Node<K,V>[] helpTransfer(Node<K,V>[] tab, Node<K,V> f) { Node<K,V>[] nextTab; int sc; // Three conditions need to be met simultaneously to enter the main logic of the method if (tab != null// Table is not empty && (f instanceof ForwardingNode)// f is a Forwarding Node && (nextTab = ((ForwardingNode<K,V>)f).nextTable) != null) // nextTable is not empty { // Calculate the mark "stamp" during this resize int rs = resizeStamp(tab.length) << RESIZE_STAMP_SHIFT; while (nextTab == nextTable // nextTab unchanged && table == tab // table unchanged && (sc = sizeCtl) < 0) // Sizecl remains less than 0 (resizing) { if (sc == rs + MAX_RESIZERS // The number of worker threads is full || sc == rs + 1 // In the addCount method, if there is the first capacity expansion thread, sc=rs+2. If it becomes rs+1, the expansion is over. || transferIndex <= 0) // If transferIndex is less than or equal to 0, it actually indicates that the expansion has been completed and the subscript adjustment has been entered. break; // Enable sc + + to enter capacity expansion if (U.compareAndSetInt(this, SIZECTL, sc, sc + 1)) { transfer(tab, nextTab); break; } } // Return to new table return nextTab; } // Return to original table return table; } 4.10 transfer method The function of the transfer method is to move and / or copy the nodes in each bin to a new table. There are calls in addCount() and helpTransfer(), which are the core implementation classes of capacity expansion. If there is a specific number in the following example, the length of the incoming tab shall be 16. private final void transfer(Node<K,V>[] tab, Node<K,V>[] nextTab) { // Define n as the table length. int n = tab.length, stride; /** stride Represents the number of tasks of a worker thread in a transfer, that is, the number of consecutive hash buckets to be processed. Initialize stripe: if the number of available CPU cores is greater than 1, initialize to (n > > > 3) / ncpu; otherwise, initialize to n. If the initialized stripe is less than MIN_TRANSFER_STRIDE, set it to this minimum. */ if ((stride = (NCPU > 1) ? (n >>> 3) / NCPU : n) < MIN_TRANSFER_STRIDE) stride = MIN_TRANSFER_STRIDE; // subdivide range if (nextTab == null) { // If nextTab is not initialized, initialize the array first try { @SuppressWarnings("unchecked")' // Create a nextTab array with the length of the original array * 2 Node<K,V>[] nt = (Node<K,V>[])new Node<?,?>[n << 1]; nextTab = nt; } catch (Throwable ex) { // Failed to create a new array. sizeCtl is set to the maximum value of int sizeCtl = Integer.MAX_VALUE; return; } // This array is assigned to nextTable nextTable = nextTab; // Update transfer subscript transferIndex = n; } int nextn = nextTab.length; // Create ForwardingNode fwd and pass in nextTab as the parameter ForwardingNode<K,V> fwd = new ForwardingNode<K,V>(nextTab); // The first advance is true. If it is equal to true, it indicates that a subscript (i --) needs to be pushed again. On the contrary, if it is false, the subscript cannot be pushed. The current subscript needs to be processed before proceeding boolean advance = true; // Mark whether the expansion has been completed boolean finishing = false; // to ensure sweep before committing nextTab /** It is also a for loop to process the linked list elements in each slot */ for (int i = 0, bound = 0;;) { Node<K,V> f; int fh; /** This while loop continuously tries to allocate tasks to the current thread through CAS until the allocation succeeds or the task queue has been fully allocated. If the thread has been allocated a bucket area, it will point to the next pending bucket through -- i and exit the loop. */ while (advance) { int nextIndex, nextBound; // --i indicates entering the next bucket to be processed. Greater than or equal to bound after subtraction indicates that the current thread has allocated buckets, and advance=false if (--i >= bound || finishing) advance = false; // All bucket s have been allocated. Assign value to nextIndex. else if ((nextIndex = transferIndex) <= 0) { i = -1; advance = false; } // CAS modifies TRANSFERINDEX to assign tasks to threads. // The processing node interval is (nextBound,nextINdex) else if (U.compareAndSetInt (this, TRANSFERINDEX, nextIndex, nextBound = (nextIndex > stride ? nextIndex - stride : 0))) { bound = nextBound; i = nextIndex - 1; advance = false; } } // Processing process // CASE1: the old array has been traversed, and the current thread has processed all responsible bucket s if (i < 0 || i >= n || i + n >= nextn) { int sc; // Capacity expansion completed if (finishing) { // Delete the member variable nextTable nextTable = null; // Update array table = nextTab; // Update capacity expansion threshold sizeCtl = (n << 1) - (n >>> 1); return; } // Use the CAS operation to subtract 1 from the lower 16 bits of sizeCtl, which means that you have completed your own task if (U.compareAndSetInt(this, SIZECTL, sc = sizeCtl, sc - 1)) { if ((sc - 2) != resizeStamp(n) << RESIZE_STAMP_SHIFT) return; // If the above if is not executed, i.e. (SC - 2) = = resizestamp (n) < < resize_ STAMP_ SHIFT // This indicates that there is no thread for capacity expansion, and the capacity expansion is over finishing = advance = true; i = n; // recheck before commit } } // CASE2: if node i is empty, put it into the ForwardingNode just initialized else if ((f = tabAt(tab, i)) == null) advance = casTabAt(tab, i, null, fwd); // CASE3: the current hash value of this location is MOVED, which is a ForwardingNode. It indicates that it has been processed by other threads, so it is required to continue else if ((fh = f.hash) == MOVED) advance = true; // already processed // CASE4: execute transfer else { // Lock the head node synchronized (f) { // Check again if (tabAt(tab, i) == f) { Node<K,V> ln, hn; // The head node in the slot is a chain head node if (fh >= 0) { // First calculate the current fh * n int runBit = fh & n; // Stores the lastRun that traverses the final position Node<K,V> lastRun = f; // Traversal linked list for (Node<K,V> p = f.next; p != null; p = p.next) { int b = p.hash & n; // If hash&n changes during traversal, runBit and lastRun need to be updated if (b != runBit) { runBit = b; lastRun = p; } } //If lastRun refers to a low-level linked list, make ln lastRun if (runBit == 0) { ln = lastRun; hn = null; } // If lastrun refers to a high-order linked list, make hn lastrun else { hn = lastRun; ln = null; } // Traverse the linked list, put the hash & n with 0 in the low-level linked list and those not with 0 in the high-level linked list // Loop out condition: current loop node= lastRun for (Node<K,V> p = f; p != lastRun; p = p.next) { int ph = p.hash; K pk = p.key; V pv = p.val; if ((ph & n) == 0) ln = new Node<K,V>(ph, pk, pv, ln); else hn = new Node<K,V>(ph, pk, pv, hn); } // The position of the low linked list remains unchanged setTabAt(nextTab, i, ln); // The position of the high-order linked list is: original position + n setTabAt(nextTab, i + n, hn); // Mark current bucket migrated setTabAt(tab, i, fwd); // If advance is true, return to the above for --i operation advance = true; } // The head node in the slot is a tree node; } // The head node in the slot is a reserved placeholder node else if (f instanceof ReservationNode) throw new IllegalStateException("Recursive update"); } } } } } The transfer() method is the core method for concurrent HashMap to perform capacity expansion. Its capacity expansion and transfer operation is actually similar to HashMap, which splits the original linked list into two linked lists. However, there are many differences in implementation details. See the source code Notes for details. 4.11 resizeStamp method /** * Returns the stamp bits for resizing a table of size n. * Must be negative when shifted left by RESIZE_STAMP_SHIFT. */ static final int resizeStamp(int n) { return Integer.numberOfLeadingZeros(n) | (1 << (RESIZE_STAMP_BITS - 1)); } The resizeStamp(int n) method can calculate stamp bits when a table of size n is expanded 5. Business methods 5.1 construction method // Default construction method public ConcurrentHashMap() { } // Construction method of providing only initial capacity public ConcurrentHashMap(int initialCapacity) { this(initialCapacity, LOAD_FACTOR, 1); } // Provides the construction method of map public ConcurrentHashMap(Map<? extends K, ? extends V> m) { this.sizeCtl = DEFAULT_CAPACITY; putAll(m); } // Provides the construction method of default capacity and load factor public ConcurrentHashMap(int initialCapacity, float loadFactor) { this(initialCapacity, loadFactor, 1); } // Provides the construction method of default capacity, load factor and number of Concurrent update threads. public ConcurrentHashMap(int initialCapacity, float loadFactor, int concurrencyLevel) { if (!(loadFactor > 0.0f) || initialCapacity < 0 || concurrencyLevel <= 0) throw new IllegalArgumentException(); // If the initial capacity is smaller than the number of Concurrent update threads, assign a new value to it if (initialCapacity < concurrencyLevel) // Use at least as many bins initialCapacity = concurrencyLevel; // as estimated threads long size = (long)(1.0 + (long)initialCapacity / loadFactor); // cap is assigned as the maximum capacity or expansion threshold int cap = (size >= (long)MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : tableSizeFor((int)size); this.sizeCtl = cap; } 5.2 methods // Count cell array private transient volatile CounterCell[] counterCells; public int size() { // Call sumCount() long n = sumCount(); return ((n < 0L) ? 0 : (n > (long)Integer.MAX_VALUE) ? Integer.MAX_VALUE : (int)n); } final long sumCount() { // Get count cell array CounterCell[] cs = counterCells; long sum = baseCount; if (cs != null) { // The values in all counting units are added up for (CounterCell c : cs) if (c != null) sum += c.value; } return sum; } // A very simple counting unit with only one volatile counter value @jdk.internal.vm.annotation.Contended // This annotation ensures that the object of the current class has exclusive cache lines static final class CounterCell { // Only constructors are provided, but get/set methods are not provided. That is, the value of value is determined during initialization and will not be changed later volatile long value; CounterCell(long x) { value = x; } } The implementation of the size() method is to first obtain baseCount, which is the counter value obtained when there is no contention. Then the count values in the counting unit array are accumulated above. He has the following measures to ensure thread safety: - Set the value variable in the counterCells array and the CounterCell class to volatile. - The get/set method is not set for the value variable in the CounterCell class. So how is the counter cells array created and initialized, and how is baseCount increased. Later, we will explain the source code of business methods that change size, such as put(). 5.3 isEmpty method public boolean isEmpty() { return sumCount() <= 0L; // ignore transient negative values } See 5.2 for sumCount() method 5.4 get method public V get(Object key) { Node<K,V>[] tab; Node<K,V> e, p; int n, eh; K ek; // DP Hash int h = spread(key.hashCode()); if ((tab = table) != null // Table is not empty && (n = tab.length) > 0 // Table length is not 0 && (e = tabAt(tab, (n - 1) & h)) != null) {// The specified location is not null // The first position is the key to be found if ((eh = e.hash) == h) { if ((ek = e.key) == key || (ek != null && key.equals(ek))) return e.val; } else if (eh < 0)// The hash value of the current linked list header is less than 0, indicating that it is a special node // Call the find method of the special node e return (p = e.find(h, key)) != null ? p.val : null; // A normal node, normal linked list, normal traversal while ((e = e.next) != null) { if (e.hash == h && ((ek = e.key) == key || (ek != null && key.equals(ek)))) return e.val; } } return null; } Note that first, we calculate the hash position of the key to be searched in the hash table. Then do different processing according to the hash value of the found node. - If the hash value is the value to be found, it is returned directly. - If the hash value is less than 0, it means that the current node is a special node. Refer to 1.13 hash status parameters of special nodes. In this way, the find() method of special nodes will be called, such as the find() method of ForwardingNode class and TreeNode class. - If the hash value is greater than or equal to 0, traverse the current linked list. 5.5 containsKey method public boolean containsKey(Object key) { return get(key) != null; } 5.6 containsValue method public boolean containsValue(Object value) { if (value == null) throw new NullPointerException(); Node<K,V>[] t; if ((t = table) != null) { Traverser<K,V> it = new Traverser<K,V>(t, t.length, 0, t.length); for (Node<K,V> p; (p = it.advance()) != null; ) { V v; if ((v = p.val) == value || (v != null && value.equals(v))) return true; } } return false; } The Traverser class encapsulates the traversal logic of the containsValue method. The code is complex. The following table is not included here for the time being. 5.7 test method public V put(K key, V value) { return putVal(key, value, false); } final V putVal(K key, V value, boolean onlyIfAbsent) { // Air judgment if (key == null || value == null) throw new NullPointerException(); // DP Hash int hash = spread(key.hashCode()); // Counter for current bucket int binCount = 0; // Spin insert node until successful for (Node<K,V>[] tab = table;;) { Node<K,V> f; int n, i, fh; K fk; V fv; // CASE1: if the table is empty, call the initialization method first if (tab == null || (n = tab.length) == 0) tab = initTable(); // CASE2: if the hash location node is empty, it is unlocked when inserting into the empty location else if ((f = tabAt(tab, i = (n - 1) & hash)) == null) { // Try to put the key value pair to put directly here if (casTabAt(tab, i, null, new Node<K,V>(hash, key, value))) break;// sign out } // CASE3: if the hash value of the hash location node is - 1, it is a Forwarding Node. Call helperTransfer() else if ((fh = f.hash) == MOVED) // Assist in transferring data and getting new arrays tab = helpTransfer(tab, f); // CASE4: if onlyIfAbsent is true and the header node is the required node, return it directly else if (onlyIfAbsent && fh == hash && ((fk = f.key) == key || (fk != null && key.equals(fk))) && (fv = f.val) != null) return fv; // CASE5: the specified location was found and is not empty (hash conflict occurred). else { V oldVal = null; synchronized (f) {// Lock the current node (chain header) if (tabAt(tab, i) == f) {// Then judge whether f is the head node to prevent it from being modified by other threads // if - is not a special node if (fh >= 0) { binCount = 1; for (Node<K,V> e = f;; ++binCount) {// Note that the counter is incremented during traversal K ek; // In the process of traversal, the value you want to insert is found. It will be returned according to the situation if (e.hash == hash && ((ek = e.key) == key || (ek != null && key.equals(ek)))) { oldVal = e.val; if (!onlyIfAbsent) e.val = value; break; } // If the tail is reached, a new node built by the current key value is inserted Node<K,V> pred = e; if ((e = e.next) == null) { pred.next = new Node<K,V>(hash, key, value); break; } } } // elseIf - is a tree node else if (f instanceof TreeBin) { Node<K,V> p; binCount = 2; if ((p = ((TreeBin<K,V>)f).putTreeVal(hash, key, value)) != null) { oldVal = p.val; if (!onlyIfAbsent) p.val = value; } } // else - if it is a reserved node else if (f instanceof ReservationNode) throw new IllegalStateException("Recursive update"); } } // After the insertion, check whether you need to treelize the current linked list if (binCount != 0) { if (binCount >= TREEIFY_THRESHOLD) treeifyBin(tab, i); if (oldVal != null) return oldVal; break; } } } // Counter plus one addCount(1L, binCount); // Return null return null; } See the notes for the specific logic, which are explained in detail. The putVal method keeps spinning with a for loop and keeps trying to insert the required key value pair. There are the following cases in the loop, which are embodied as five branches in the if else block. - The table is empty. Call the initialization method. - Hash position is empty. put directly without lock. - The hash location is a ForwardingNode. Call helpTransfer. - The hash position header is the current key, and onlyIfAbsent is true, which is returned directly. - The hash position is not empty, indicating a hash conflict. Pay attention to the update of binCount during traversal. Finally, add one to the object with addCount() and use binCount as the check parameter. 5.8 remove method public V remove(Object key) { return replaceNode(key, null, null); } final V replaceNode(Object key, V value, Object cv) { int hash = spread(key.hashCode()); // spin for (Node<K,V>[] tab = table;;) { Node<K,V> f; int n, i, fh; // CASE1: cases where you can exit directly: the array is empty or the hash result position is null. if (tab == null || (n = tab.length) == 0 || (f = tabAt(tab, i = (n - 1) & hash)) == null) break; // CASE2: the node is moving. Help to move else if ((fh = f.hash) == MOVED) tab = helpTransfer(tab, f); // CASE3: hash conflict occurs. Look it up in the linked list else { V oldVal = null; boolean validated = false; // Lock the head node synchronized (f) {// The internal specific logic will not be repeated, which is similar to the put method above if (tabAt(tab, i) == f) { if (fh >= 0) { validated = true; // e represents the current loop processing node, and pred represents the previous node of the current loop node for (Node<K,V> e = f, pred = null;;) { K ek; // find if (e.hash == hash && ((ek = e.key) == key || (ek != null && key.equals(ek)))) { V ev = e.val; if (cv == null || cv == ev || (ev != null && cv.equals(ev))) { oldVal = ev; if (value != null) e.val = value; else if (pred != null) pred.next = e.next; else setTabAt(tab, i, e.next); } break; } pred = e; if ((e = e.next) == null) break; } } else if (f instanceof TreeBin) { validated = true; TreeBin<K,V> t = (TreeBin<K,V>)f; TreeNode<K,V> r, p; if ((r = t.root) != null && (p = r.findTreeNode(hash, key, null)) != null) { V pv = p.val; if (cv == null || cv == pv || (pv != null && cv.equals(pv))) { oldVal = pv; if (value != null) p.val = value; else if (t.removeTreeNode(p)) setTabAt(tab, i, untreeify(t.first)); } } } else if (f instanceof ReservationNode) throw new IllegalStateException("Recursive update"); } } if (validated) { if (oldVal != null) { // If it is a deletion, the number of elements is reduced by one if (value == null) addCount(-1L, -1); return oldVal; } break; } } } return null; } The key is to lock the linked list header to achieve thread safety. Just look at the source code directly.
https://programmer.help/blogs/jdk-source-code-reading-concurrent-hashmap-class-reading-notes.html
CC-MAIN-2021-49
en
refinedweb
Tutorial Defining Twitter Cards in your Jekyll Template. Twitter cards are a great way to have your content highlighted when Twitted. There are a few formats available, with Summary /w Large Image being my favorite. Here’s how I defined it in Jekyll in my head.html include file: <meta name="twitter:card" content="summary_large_image"> <meta name="twitter:site" content="@alligatorio"> <meta name="twitter:title" content="{{ page.title }}"> {% if page.description %} <meta name="twitter:description" content="{{ page.meta_description }}"> {% else %} <meta name="twitter:description" content="{{ page.content | strip_html | xml_escape | truncate: 200 }}"> {% endif %} A few notes If there’s no meta description defined for the page, we pull the first 200 words of the post using some Jekyll template filters. Thanks to Paul Stamatiou for the trick. If there’s no thumbnail defined for the post, we pull a general cover image for the site. You’ll obviously want to change the twitter:site to reflect the Twitter handle for your site. If needed, you can also define a twitter:creator with the content set to the Twitter handle of the author of the specific post. Maybe for this you could see if an author is defined in the Jekyll Front Matter for the post. Validating your cards You can use this tool to validate your Twitter cards. For the Summary Card with Large Image type, twitter:card, twitter:site, twitter:title and twitter:description are required.
https://www.digitalocean.com/community/tutorials/jekyll-twitter-cards
CC-MAIN-2021-49
en
refinedweb
However, when I came into contact with smart doc, another interface documentation tool, I think it is more suitable for integration in the project than Swagger and is more suitable for old birds. Today, we will introduce the use of smart doc component as a supplement to the old bird series. swagger vs smart-doc First, let's take a look at the main problems of Swagger components: Swagger's code is very intrusive This is easy to understand. In order for Swagger to generate interface documents, corresponding annotations must be added to methods or fields. There is code intrusion. Native swagger does not support parameter grouping of interfaces For the interface with parameter grouping, the native Swagger does not support it. Although we can support parameter grouping by extending its components, it needs to be developed after all, and it does not support the latest Swagger3 version. That's for comparison, smart doc It is based on the interface source code analysis to generate the interface document, which completely achieves zero annotation intrusion. You only need to write the annotation according to the java standard, and smart doc can help you generate a simple and clear markdown or a static html document like GitBook style. Official address: Briefly list the advantages of smart doc: Zero annotation, zero learning cost, only need to write standard java annotations to generate documents. Automatic derivation based on source code interface definition and powerful derivation of return structure. Support Spring MVC,Spring Boot,Spring Boot Web Flux(controller writing mode). Support the derivation of callable, future, completable future and other asynchronous interface returns. Support JSR303 parameter verification specification on JavaBean and parameter grouping. Some common field definitions can generate valid analog values. ... Next, let's take a look at how to integrate smart doc in SpringBoot. SpringBoot integration smart doc Smart doc supports the generation of interface documents in many ways: maven plug-in, gradle plug-in and unit test (not recommended). Here I use the generation based on maven plug-in. The steps are as follows: Introduce dependency version, and select the latest version <!--introduce smart-doc--> <plugin> <groupId>com.github.shalousun</groupId> <artifactId>smart-doc-maven-plugin</artifactId> <version>2.2.7</version> <configuration> <configFile>./src/main/resources/smart-doc.json</configFile> <projectName>Smart-Doc First experience</projectName> </configuration> </plugin> Focus on specifying the smart doc configuration file smart doc.json in the configFile Create a new configuration file smart-doc.json { "outPath": "src/main/resources/static/doc" } Specify the document path generated by smart doc. For other configuration items, please refer to the official wiki. Generate the corresponding interface document by executing the maven command //Generate html mvn -Dfile.encoding=UTF-8 smart-doc:html Of course, it can also be generated through the maven plug-in in idea Provider documentation After generating the interface document, we pass The results are as follows: See the students here may laugh, that's it? Nothing! Does this want me to replace Swagger? Don't worry. I just experienced the basic functions of smart doc. Next, we will enhance the functions of smart doc by enriching its configuration file. Function enhancement 1. Start commissioning An excellent interface documentation tool must have debugging functions. Smart doc supports online debugging. Only the following configuration items need to be added: { "serverUrl": "", -- server address "allInOne": true, -- Whether to merge documents into one file is generally recommended true "outPath": "src/main/resources/static/doc", -- Specifies the output path of the document "createDebugPage": true, -- Open test "allInOneDocFileName":"index.html", -- Custom document name "projectName": "First acquaintance smart-doc" -- entry name } Use "createDebugPage": true to enable the debug function and put it directly under static/doc / when generating smart DOC documents, so that you can directly start the program to access the page Develop and debug. Some developers directly use [Open In Browser] in idea to open the debug page generated by smart doc. If they have to do this, cross domain occurs when the front-end js requests the background interface. Therefore, you need to configure cross domain on the back-end. Here, take springboot 2.3. X as an example to configure the backend cross domain: @Configuration public class WebMvcAutoConfig implements WebMvcConfigurer { @Bean public CorsFilter corsFilter() { final UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource(); final CorsConfiguration corsConfiguration = new CorsConfiguration(); /* Allow requests with authentication information */ corsConfiguration.setAllowCredentials(true); /* Allowed client domain name */ corsConfiguration.addAllowedOrigin("*"); /* Client request header to allow server access */ corsConfiguration.addAllowedHeader("*"); /* Allowed method name, GET POST, etc */ corsConfiguration.addAllowedMethod("*"); urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration); return new CorsFilter(urlBasedCorsConfigurationSource); } } After cross domain is enabled, we can debug directly in the static interface page. 2. General responder In“ How does SpringBoot unify the back-end return format? Old birds play like this! ”In this article, we wrap all the returned values by implementing ResponseBodyAdvice and return the unified data structure ResultData to the front end. We need to make it also have this function in the interface document and add the configuration content to the configuration file: { "responseBodyAdvice":{ -- Universal responder "className":"com.jianzh5.blog.base.ResultData" } } 3. Customize Header In the front end and back end separation project, we generally need to set a request header when requesting the interface, such as token, Authorization, etc... the back end determines whether it is a legal user of the system according to the request header. At present, smart doc also supports it. Continue to add the following configuration contents to the smart doc configuration file smart doc.json: "requestHeaders": [ //Set the request header. If there is no requirement, it can not be set { "name": "token",//Request header name "type": "string",//Request header type "desc": "Custom request header - token",//Request header description information "value":"123456",//Do not set default null "required": false,//Is it necessary "since": "-",//What version of change request header is added "pathPatterns": "/smart/say",//Only with / smart/say The first url will have this request header "excludePathPatterns":"/smart/add,/smart/edit" // url=/app/page / will not have the request header } ] The effects are as follows: 4. Parameter grouping Demonstrate smart Doc's support for parameter grouping When adding an operation, age and level are required, and sex is not required. When editing, id, appid, leven are required, and sex is not required. From the above results, we can see that smart doc fully supports parameter grouping. 5. idea configuration doc Custom tags are not automatically prompted by default and need to be set in idea. After setting, they can be used. The following is an example of setting smart doc custom mock tag s. The setting operations are as follows: 6. Complete configuration The complete configuration is attached. If you need other configurations, you can refer to the wiki to introduce them yourself. { "serverUrl": "", "allInOne": true, "outPath": "src/main/resources/static/doc", "createDebugPage": true, "allInOneDocFileName":"index.html", "projectName": "First acquaintance smart-doc", "packageFilters": "com.jianzh5.blog.smartdoc.*", "errorCodeDictionaries": [{ "title": "title", "enumClassName": "com.jianzh5.blog.base.ReturnCode", "codeField": "code", "descField": "message" }], "responseBodyAdvice":{ "className":"com.jianzh5.blog.base.ResultData" }, "requestHeaders": [{ "name": "token", "type": "string", "desc": "Custom request header - token", "value":"123456", "required": false, "since": "-", "pathPatterns": "/smart/say", "excludePathPatterns":"/smart/add,/smart/edit" }] } Summary In fact, there is nothing to summarize. Smart doc is very simple to use and the official documents are very detailed. As long as you can write standard java comments, you can generate detailed interface documents for you. (if you say you can't write comments, this article may not be suitable for you) Moreover, after introducing smart doc, developers can be forced to write comments for the interface to ensure that there will be no great difference in team code style.
https://programmer.help/blogs/springboot-integrates-smart-doc-to-generate-interface-documents.html
CC-MAIN-2021-49
en
refinedweb
Chapter 2 - Exploring Symfony's Code At first glance, the code behind a symfony-driven application can seem quite daunting. It consists of many directories and scripts, and the files are a mix of PHP classes, HTML, and even an intermingling of the two. You'll also see references to classes that are otherwise nowhere to be found within the application folder, and the directory depth stretches to six levels. But once you understand the reason behind all of this seeming complexity, you'll suddenly feel like it's so natural that you wouldn't trade the symfony application structure for any other. This chapter explains away that intimidated feeling. The MVC Pattern Symfony is based on the classic web design pattern known as the MVC architecture, which consists of three levels: - The model represents the information on which the application operates--its business logic. - The view renders the model into a web page suitable for interaction with the user. - The controller responds to user actions and invokes changes on the model or view as appropriate. Figure 2-1 illustrates the MVC pattern. The MVC architecture separates the business logic (model) and the presentation (view), resulting in greater maintainability. For instance, if your application should run on both standard web browsers and handheld devices, you just need a new view; you can keep the original controller and model. The controller helps to hide the detail of the protocol used for the request (HTTP, console mode, mail, and so on) from the model and the view. And the model abstracts the logic of the data, which makes the view and the action independent of, for instance, the type of database used by the application. Figure 2-1 - The MVC pattern MVC Layering To help you understand MVC's advantages, let's see how to convert a basic PHP application to an MVC-architectured application. A list of posts for a weblog application will be a perfect example. Flat Programming In a flat PHP file, displaying a list of database entries might look like the script presented in Listing 2-1. Listing 2-1 - A Flat Script <?php // Connecting, selecting database $link = mysql_connect('localhost', 'myuser', 'mypassword'); mysql_select_db('blog_db', $link); // Performing SQL query $result = mysql_query('SELECT date, title FROM post', $link); ?> <html> <head> <title>List of Posts</title> </head> <body> <h1>List of Posts</h1> <table> <tr><th>Date</th><th>Title</th></tr> <?php // Printing results in HTML while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "\t<tr>\n"; printf("\t\t<td> %s </td>\n", $row['date']); printf("\t\t<td> %s </td>\n", $row['title']); echo "\t</tr>\n"; } ?> </table> </body> </html> <?php // Closing connection mysql_close($link); ?> That's quick to write, fast to execute, and impossible to maintain. The following are the major problems with this code: - There is no error-checking (what if the connection to the database fails?). - HTML and PHP code are mixed, even interwoven together. - The code is tied to a MySQL database. Isolating the Presentation The echo and printf calls in Listing 2-1 make the code difficult to read. Modifying the HTML code to enhance the presentation is a hassle with the current syntax. So the code can be split into two parts. First, the pure PHP code with all the business logic goes in a controller script, as shown in Listing 2-2. Listing 2-2 - The Controller Part, in index.php <?php // Connecting, selecting database $link = mysql_connect('localhost', 'myuser', 'mypassword'); mysql_select_db('blog_db', $link); // Performing SQL query $result = mysql_query('SELECT date, title FROM post', $link); // Filling up the array for the view $posts = array(); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $posts[] = $row; } // Closing connection mysql_close($link); // Requiring the view require('view.php'); ?> The HTML code, containing template-like PHP syntax, is stored in a view script, as shown in Listing 2-3. Listing 2-3 - The View Part, in view.php <html> <head> <title>List of Posts</title> </head> <body> <h1>List of Posts</h1> <table> <tr><th>Date</th><th>Title</th></tr> <?php foreach ($posts as $post): ?> <tr> <td><?php echo $post['date'] ?></td> <td><?php echo $post['title'] ?></td> </tr> <?php endforeach; ?> </table> </body> </html> A good rule of thumb to determine whether the view is clean enough is that it should contain only a minimum amount of PHP code, in order to be understood by an HTML designer without PHP knowledge. The most common statements in views are echo, if/endif, foreach/endforeach, and that's about all. Also, there should not be PHP code echoing HTML tags. All the logic is moved to the controller script, and contains only pure PHP code, with no HTML inside. As a matter of fact, you should imagine that the same controller could be reused for a totally different presentation, perhaps in a PDF file or an XML structure. Isolating the Data Manipulation Most of the controller script code is dedicated to data manipulation. But what if you need the list of posts for another controller, say one that would output an RSS feed of the weblog posts? What if you want to keep all the database queries in one place, to avoid code duplication? What if you decide to change the data model so that the post table gets renamed weblog_post? What if you want to switch to PostgreSQL instead of MySQL? In order to make all that possible, you need to remove the data-manipulation code from the controller and put it in another script, called the model, as shown in Listing 2-4. Listing 2-4 - The Model Part, in model.php <?php function getAllPosts() { // Connecting, selecting database $link = mysql_connect('localhost', 'myuser', 'mypassword'); mysql_select_db('blog_db', $link); // Performing SQL query $result = mysql_query('SELECT date, title FROM post', $link); // Filling up the array $posts = array(); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $posts[] = $row; } // Closing connection mysql_close($link); return $posts; } ?> The revised controller is presented in Listing 2-5. Listing 2-5 - The Controller Part, Revised, in index.php <?php // Requiring the model require_once('model.php'); // Retrieving the list of posts $posts = getAllPosts(); // Requiring the view require('view.php'); ?> The controller becomes easier to read. Its sole task is to get the data from the model and pass it to the view. In more complex applications, the controller also deals with the request, the user session, the authentication, and so on. The use of explicit names for the functions of the model even makes code comments unnecessary in the controller. The model script is dedicated to data access and can be organized accordingly. All parameters that don't depend on the data layer (like request parameters) must be given by the controller and not accessed directly by the model. The model functions can be easily reused in another controller. Layer Separation Beyond MVC So the principle of the MVC architecture is to separate the code into three layers, according to its nature. Data logic code is placed within the model, presentation code within the view, and application logic within the controller. Other additional design patterns can make the coding experience even easier. The model, view, and controller layers can be further subdivided. Database Abstraction The model layer can be split into a data access layer and a database abstraction layer. That way, data access functions will not use database-dependent query statements, but call some other functions that will do the queries themselves. If you change your database system later, only the database abstraction layer will need updating. A sample database abstraction layer is presented in Listing 2-6, followed by an example of a MySQL-specific data access layer in Listing 2-7. Listing 2-6 - The Database Abstraction Part of the Model <?php function open_connection($host, $user, $password) { return mysql_connect($host, $user, $password); } function close_connection($link) { mysql_close($link); } function query_database($query, $database, $link) { mysql_select_db($database, $link); return mysql_query($query, $link); } function fetch_results($result) { return mysql_fetch_array($result, MYSQL_ASSOC); } Listing 2-7 - The Data Access Part of the Model function getAllPosts() { // Connecting to database $link = open_connection('localhost', 'myuser', 'mypassword'); // Performing SQL query $result = query_database('SELECT date, title FROM post', 'blog_db', $link); // Filling up the array $posts = array(); while ($row = fetch_results($result)) { $posts[] = $row; } // Closing connection close_connection($link); return $posts; } ?> You can check that no database-engine dependent functions can be found in the data access layer, making it database-independent. Additionally, the functions created in the database abstraction layer can be reused for many other model functions that need access to the database. note The examples in Listings 2-6 and 2-7 are still not very satisfactory, and there is some work left to do to have a full database abstraction (abstracting the SQL code through a database-independent query builder, moving all functions into a class, and so on). But the purpose of this book is not to show you how to write all that code by hand, and you will see in Chapter 8 that symfony natively does all the abstraction very well. View Elements The view layer can also benefit from some code separation. A web page often contains consistent elements throughout an application: the page headers, the graphical layout, the footer, and the global navigation. Only the inner part of the page changes. That's why the view is separated into a layout and a template. The layout is usually global to the application, or to a group of pages. The template only puts in shape the variables made available by the controller. Some logic is needed to make these components work together, and this view logic layer will keep the name view. According to these principles, the view part of Listing 2-3 can be separated into three parts, as shown in Listings 2-8, 2-9, and 2-10. Listing 2-8 - The Template Part of the View, in mytemplate.php <h1>List of Posts</h1> <table> <tr><th>Date</th><th>Title</th></tr> <?php foreach ($posts as $post): ?> <tr> <td><?php echo $post['date'] ?></td> <td><?php echo $post['title'] ?></td> </tr> <?php endforeach; ?> </table> Listing 2-9 - The View Logic Part of the View <?php $title = 'List of Posts'; $posts = getAllPosts(); Listing 2-10 - The Layout Part of the View <html> <head> <title><?php echo $title ?></title> </head> <body> <?php include('mytemplate.php'); ?> </body> </html> Action and Front Controller The controller doesn't do much in the previous example, but in real web applications, the controller has a lot of work. An important part of this work is common to all the controllers of the application. The common tasks include request handling, security handling, loading the application configuration, and similar chores. This is why the controller is often divided into a front controller, which is unique for the whole application, and actions, which contain only the controller code specific to one page. One of the great advantages of a front controller is that it offers a unique entry point to the whole application. If you ever decide to close the access to the application, you will just need to edit the front controller script. In an application without a front controller, each individual controller would need to be turned off. Object Orientation All the previous examples use procedural programming. The OOP capabilities of modern languages make the programming even easier, since objects can encapsulate logic, inherit from one another, and provide clean naming conventions. Implementing an MVC architecture in a language that is not object-oriented raises namespace and code-duplication issues, and the overall code is difficult to read. Object orientation allows developers to deal with such things as the view object, the controller object, and the model classes, and to transform all the functions in the previous examples into methods. It is a must for MVC architectures. tip If you want to learn more about design patterns for web applications in an object-oriented context, read Patterns of Enterprise Application Architecture by Martin Fowler (Addison-Wesley, ISBN: 0-32112-742-0). Code examples in Fowler's book are in Java or C#, but are still quite readable for a PHP developer. Symfony's MVC Implementation Hold on a minute. For a single page listing the posts in a weblog, how many components are required? As illustrated in Figure 2-2, we have the following parts: - Model layer - Database abstraction - Data access - View layer - View - Template - Layout - Controller layer - Front controller - Action Seven scripts--a whole lot of files to open and to modify each time you create a new page! However, symfony makes things easy. While taking the best of the MVC architecture, symfony implements it in a way that makes application development fast and painless. First of all, the front controller and the layout are common to all actions in an application. You can have multiple controllers and layouts, but you need only one of each. The front controller is pure MVC logic component, and you will never need to write a single one, because symfony will generate it for you. The other good news is that the classes of the model layer are also generated automatically, based on your data structure. This is the job of the Propel library, which provides class skeletons and code generation. If Propel finds foreign key constraints or date fields, it will provide special accessor and mutator methods that will make data manipulation a piece of cake. And the database abstraction is totally invisible to you, because it is dealt with by another component, called Creole. So if you decide to change your database engine at one moment, you have zero code to rewrite. You just need to change one configuration parameter. And the last thing is that the view logic can be easily translated as a simple configuration file, with no programming needed. Figure 2-2 - Symfony workflow That means that the list of posts described in our example would require only three files to work in symfony, as shown in Listings 2-11, 2-12, and 2-13. Listing 2-11 - list Action, in myproject/apps/myapp/modules/weblog/actions/actions.class.php <?php class weblogActions extends sfActions { public function executeList() { $this->posts = PostPeer::doSelect(new Criteria()); } } ?> Listing 2-12 - list Template, in myproject/apps/myapp/modules/weblog/templates/listSuccess.php <h1>List of Posts</h1> <table> <tr><th>Date</th><th>Title</th></tr> <?php foreach ($posts as $post): ?> <tr> <td><?php echo $post->getDate() ?></td> <td><?php echo $post->getTitle() ?></td> </tr> <?php endforeach; ?> </table> Listing 2-13 - list View, in myproject/apps/myapp/modules/weblog/config/view.yml listSuccess: metas: { title: List of Posts } In addition, you will still need to define a layout, as shown in Listing 2-14, but it will be reused many times. Listing 2-14 - Layout, in myproject/apps/myapp/templates/layout.php <html> <head> <?php echo include_title() ?> </head> <body> <?php echo $sf_data->getRaw('sf_content') ?> </body> </html> And that is really all you need. This is the exact code required to display the very same page as the flat script shown earlier in Listing 2-1. The rest (making all the components work together) is handled by symfony. If you count the lines, you will see that creating the list of posts in an MVC architecture with symfony doesn't require more time or coding than writing a flat file. Nevertheless, it gives you huge advantages, notably clear code organization, reusability, flexibility, and much more fun. And as a bonus, you have XHTML conformance, debug capabilities, easy configuration, database abstraction, smart URL routing, multiple environments, and many more development tools. Symfony Core Classes The MVC implementation in symfony uses several classes that you will meet quite often in this book: sfControlleris the controller class. It decodes the request and hands it to the action. sfRequeststores all the request elements (parameters, cookies, headers, and so on). sfResponsecontains the response headers and contents. This is the object that will eventually be converted to an HTML response and be sent to the user. - The context singleton (retrieved by sfContext::getInstance()) stores a reference to all the core objects and the current configuration; it is accessible from everywhere. You will learn more about these objects in Chapter 6. As you can see, all the symfony classes use the sf prefix, as do the symfony core variables in the templates. This should avoid name collisions with your own classes and variables, and make the core framework classes sociable and easy to recognize. note Among the coding standards used in symfony, UpperCamelCase is the standard for class and variable naming. Two exceptions exist: core symfony classes start with sf, which is lowercase, and variables found in templates use the underscore-separated syntax. Code Organization Now that you know the different components of a symfony application, you're probably wondering how they are organized. Symfony organizes code in a project structure and puts the project files into a standard tree structure. Project Structure: Applications, Modules, and Actions In symfony, a project is a set of services and operations available under a given domain name, sharing the same object model. Inside a project, the operations are grouped logically into applications. An application can normally run independently of the other applications of the same project. In most cases, a project will contain two applications: one for the front-office and one for the back-office, sharing the same database. But you can also have one project containing many mini-sites, with each site as a different application. Note that hyperlinks between applications must be in the absolute form. Each application is a set of one or more modules. A module usually represents a page or a group of pages with a similar purpose. For example, you might have the modules articles, shoppingCart, account, and so on. Modules hold actions, which represent the various actions that can be done in a module. For example, a shoppingCart module can have add, show, and update actions. Generally, actions can be described by a verb. Dealing with actions is almost like dealing with pages in a classic web application, although two actions can result in the same page (for instance, adding a comment to a post in a weblog will redisplay the post with the new comment). tip If this represents too many levels for a beginning project, it is very easy to group all actions into one single module, so that the file structure can be kept simple. When the application gets more complex, it will be time to organize actions into separate modules. As mentioned in Chapter 1, rewriting code to improve its structure or readability (but preserving its behavior) is called refactoring, and you will do this a lot when applying RAD principles. Figure 2-3 shows a sample code organization for a weblog project, in a project/ application/module/action structure. But be aware that the actual file tree structure of the project will differ from the setup shown in the figure. Figure 2-3 - Example of code organization File Tree Structure All web projects generally share the same types of contents, such as the following: - A database, such as MySQL or PostgreSQL - Static files (HTML, images, JavaScript files, style sheets, and so on) - Files uploaded by the site users and administrators - PHP classes and libraries - Foreign libraries (third-party scripts) - Batch files (scripts to be launched by a command line or via a cron table) - Log files (traces written by the application and/or the server) - Configuration files Symfony provides a standard file tree structure to organize all these contents in a logical way, consistent with the architecture choices (MVC pattern and project/application/module grouping). This is the tree structure that is automatically created when initializing every project, application, or module. Of course, you can customize it completely, to reorganize the files and directories at your convenience or to match your client's requirements. Root Tree Structure These are the directories found at the root of a symfony project: apps/ frontend/ backend/ batch/ cache/ config/ data/ sql/ doc/ lib/ model/ log/ plugins/ test/ unit/ functional/ web/ css/ images/ js/ uploads/ Table 2-1 describes the contents of these directories. Table 2-1 - Root Directories Application Tree Structure The tree structure of all application directories is the same: apps/ [application name]/ config/ i18n/ lib/ modules/ templates/ layout.php error.php error.txt Table 2-2 describes the application subdirectories. Table 2-2 - Application Subdirectories note The i18n/, lib/, and modules/ directories are empty for a new application. The classes of an application are not able to access methods or attributes in other applications of the same project. Also note that hyperlinks between two applications of the same project must be in absolute form. You need to keep this last constraint in mind during initialization, when you choose how to divide your project into applications. Module Tree Structure Each application contains one or more modules. Each module has its own subdirectory in the modules directory, and the name of this directory is chosen during the setup. This is the typical tree structure of a module: apps/ [application name]/ modules/ [module name]/ actions/ actions.class.php config/ lib/ templates/ indexSuccess.php validate/ Table 2-3 describes the module subdirectories. Table 2-3 - Module Subdirectories note The config/, lib/, and validate/ directories are empty for a new module. Web Tree Structure There are very few constraints for the web directory, which is the directory of publicly accessible files. Following a few basic naming conventions will provide default behaviors and useful shortcuts in the templates. Here is an example of a web directory structure: web/ css/ images/ js/ uploads/ Conventionally, the static files are distributed in the directories listed in Table 2-4. Table 2-4 - Typical Web Subdirectories note Even though it is highly recommended that you maintain the default tree structure, it is possible to modify it for specific needs, such as to allow a project to run in a server with different tree structure rules and coding conventions. Refer to Chapter 19 for more information about modifying the file tree structure. Common Instruments A few techniques are used repeatedly in symfony, and you will meet them quite often in this book and in your own projects. These include parameter holders, constants, and class autoloading. Parameter Holders Many of the symfony classes contain a parameter holder. It is a convenient way to encapsulate attributes with clean getter and setter methods. For instance, the sfResponse class holds a parameter holder that you can retrieve by calling the getParameterHolder() method. Each parameter holder stores data the same way, as illustrated in Listing 2-15. Listing 2-15 - Using the sfResponse Parameter Holder $response->getParameterHolder()->set('foo', 'bar'); echo $response->getParameterHolder()->get('foo'); => 'bar' Most of the classes using a parameter holder provide proxy methods to shorten the code needed for get/set operations. This is the case for the sfResponse object, so you can do the same as in Listing 2-15 with the code of Listing 2-16. Listing 2-16 - Using the sfResponse Parameter Holder Proxy Methods $response->setParameter('foo', 'bar'); echo $response->getParameter('foo'); => 'bar' The parameter holder getter accepts a default value as a second argument. This provides a useful fallback mechanism that is much more concise than possible with a conditional statement. See Listing 2-17 for an example. Listing 2-17 - Using the Attribute Holder Getter's Default Value // The 'foobar' parameter is not defined, so the getter returns an empty value echo $response->getParameter('foobar'); => null // A default value can be used by putting the getter in a condition if ($response->hasParameter('foobar')) { echo $response->getParameter('foobar'); } else { echo 'default'; } => default // But it is much faster to use the second getter argument for that echo $response->getParameter('foobar', 'default'); => default The parameter holders even support namespaces. If you specify a third argument to a setter or a getter, it is used as a namespace, and the parameter will be defined only within that namespace. Listing 2-18 shows an example. Listing 2-18 - Using the sfResponse Parameter Holder Namespace $response->setParameter('foo', 'bar1'); $response->setParameter('foo', 'bar2', 'my/name/space'); echo $response->getParameter('foo'); => 'bar1' echo $response->getParameter('foo', null, 'my/name/space'); => 'bar2' Of course, you can add a parameter holder to your own classes to take advantage of its syntax facilities. Listing 2-19 shows how to define a class with a parameter holder. Listing 2-19 - Adding a Parameter Holder to a Class class MyClass { protected $parameter_holder = null; public function initialize ($parameters = array()) { $this->parameter_holder = new sfParameterHolder(); $this->parameter_holder->add($parameters); } public function getParameterHolder() { return $this->parameter_holder; } } Constants You will not find any constants in symfony because by their very nature you can't change their value once they are defined. Symfony uses its own configuration object, called sfConfig, which replaces constants. It provides static methods to access parameters from everywhere. Listing 2-19 demonstrates the use of sfConfig class methods. Listing 2-20 - Using the sfConfig Class Methods Instead of Constants // Instead of PHP constants, define('SF_FOO', 'bar'); echo SF_FOO; // Symfony uses the sfConfig object sfConfig::set('sf_foo', 'bar'); echo sfConfig::get('sf_foo'); The sfConfig methods support default values, and you can call the sfConfig::set() method more than once on the same parameter to change its value. Chapter 5 discusses sfConfig methods in more detail. Class Autoloading Usually, when you use a class method or create an object in PHP, you need to include the class definition first: include 'classes/MyClass.php'; $myObject = new MyClass(); On large projects with many classes and a deep directory structure, keeping track of all the class files to include and their paths can be time consuming. By providing an spl_autoload_register() function, symfony makes include statements unnecessary, and you can write directly: $myObject = new MyClass(); Symfony will then look for a MyClass definition in all files ending with php in one of the project's lib/ directories. If the class definition is found, it will be included automatically. So if you store all your classes in lib/ directories, you don't need to include classes anymore. That's why the symfony projects usually do not contain any include or require statements. note For better performance, the symfony autoloading scans a list of directories (defined in an internal configuration file) during the first request. It then registers all the classes these directories contain and stores the class/file correspondence in a PHP file as an associative array. That way, future requests don't need to do the directory scan anymore. This is why you need to clear the cache every time you add or move a class file in your project by calling the symfony clear-cache command. You will learn more about the cache in Chapter 12, and about the autoloading configuration in Chapter 19. Summary Using an MVC framework forces you to divide and organize your code according to the framework conventions. Presentation code goes to the view, data manipulation code goes to the model, and the request manipulation logic goes to the controller. It makes the application of the MVC pattern both very helpful and quite restricting. Symfony is an MVC framework written in PHP 5. Its structure is designed to get the best of the MVC pattern, but with great ease of use. Thanks to its versatility and configurability, symfony is suitable for all web application projects. Now that you understand the underlying theory behind symfony, you are almost ready to develop your first application. But before that, you need a symfony installation up and running on your development server.
https://symfony.com/legacy/doc/book/1_0/pl/02-Exploring-Symfony-s-Code
CC-MAIN-2021-49
en
refinedweb
Welcome to the Parallax Discussion Forums, sign-up to participate. [nixdemo@ubuntut0:~] $ bash <(curl) Note: a multi-user installation is possible. See performing a single-user installation of Nix... directory /nix does not exist; creating it by running 'mkdir -m 0755 /nix && chown nixdemo /nix' using sudo [sudo] password for nixdemo: copying Nix to /nix/store................................. initialising Nix database... Nix: creating /home/nixdemo/.nix-profile installing 'nix-2.2.1' building '/nix/store/jkcbkr60gzcmz6bk9y4j4bhlx8qcqcyz-user-environment.drv'... created 6 symlinks in user environment unpacking channels... created 2 symlinks in user environment modifying /home/nixdemo/.profile... Installation finished! To ensure that the necessary environment variables are set, either log in again, or type . /home/nixdemo/.nix-profile/etc/profile.d/nix.sh in your shell. [nixdemo@ubuntut0:~] $ . /home/nixdemo/.nix-profile/etc/profile.d/nix.sh [nixdemo@ubuntut0:~] $ nix-env -iA cachix -f unpacking ''... installing 'cachix-0.1.3' these paths will be fetched (9.88 MiB download, 47.89 MiB unpacked): /nix/store/86kmx16flgixkzf22gaga8lxdds2wiw2-ncurses-6.1-20181027 /nix/store/frvzsnzrw8baq58vb2zhqjkrkm3x0pxc-gmp-6.1.2 /nix/store/idq4dzxj0ylmh16vm3hyv25s2dz1w6kc-zlib-1.2.11 /nix/store/im2lxq8pz0l6qb4wx25hiqnv0d1lbcsb-xz-5.2.4 /nix/store/mrfcv8ipiksfdrx3xq7dvcrzgg2jdfsw-glibc-2.27 /nix/store/x3jacyl2lp46wcd6n9qyn07rhafnsp1q-gcc-7.3.0-lib /nix/store/xdbc2dja9dn6yrbm9ln8245cxynm5qhb-cachix-0.1.3 copying path '/nix/store/mrfcv8ipiksfdrx3xq7dvcrzgg2jdfsw-glibc-2.27' from ''... copying path '/nix/store/x3jacyl2lp46wcd6n9qyn07rhafnsp1q-gcc-7.3.0-lib' from ''... copying path '/nix/store/86kmx16flgixkzf22gaga8lxdds2wiw2-ncurses-6.1-20181027' from ''... copying path '/nix/store/frvzsnzrw8baq58vb2zhqjkrkm3x0pxc-gmp-6.1.2' from ''... copying path '/nix/store/im2lxq8pz0l6qb4wx25hiqnv0d1lbcsb-xz-5.2.4' from ''... copying path '/nix/store/idq4dzxj0ylmh16vm3hyv25s2dz1w6kc-zlib-1.2.11' from ''... copying path '/nix/store/xdbc2dja9dn6yrbm9ln8245cxynm5qhb-cachix-0.1.3' from ''... building '/nix/store/vkpic61rfqphsxllp4m1wad12qa024s4-user-environment.drv'... created 22 symlinks in user environment [nixdemo@ubuntut0: ~] $ cachix use redvers Configured binary cache in /home/nixdemo/.config/nix/nix.conf [nixdemo@ubuntut0:~] $ mkdir -p .config/nixpkgs/overlays [nixdemo@ubuntut0:~] $ cd .config/nixpkgs/overlays/ [nixdemo@ubuntut0:~/.config/nixpkgs/overlays] $ git clone Cloning into 'parallax-tooling'... remote: Enumerating objects: 51, done. remote: Counting objects: 100% (51/51) remote: Counting objects: 100% (51/51), done. [nixdemo@ubuntut0:~/.config/nixpkgs/overlays] $ nix-env -i p2gcc installing 'p2gcc-2019-01-12r1' these paths will be fetched (0.08 MiB download, 0.37 MiB unpacked): /nix/store/slxljvzw1a8hgqnkap7yz5z34dq2d0q6-p2gcc-2019-01-12r1 copying path '/nix/store/slxljvzw1a8hgqnkap7yz5z34dq2d0q6-p2gcc-2019-01-12r1' from ''... building '/nix/store/hg585gay00f0rs7mwl94g0xrsczmpsj6-user-environment.drv'... created 327 symlinks in user environment nixdemo@ubuntut0: ~/.config/nixpkgs/overlays] $ p2gcc usage: p2gcc [options] file [file...] options are -c - Do not run the linker -v - Enable verbose mode -d - Enable debug mode -r - Run after linking -t - Run terminal emulator -T - Run terminal emulator in PST mode -k - Keep intermediate files -s - Run simulutor -o file - Set output file name -p port - Port used for loading [nixdemo@ubuntut0:~/.config/nixpkgs/overlays] $ nix-env -i propeller-gcc installing 'propeller-gcc-2018-04-14r1' these paths will be fetched (74.08 MiB download, 369.81 MiB unpacked): /nix/store/22lrlr8d1d0dymy29jfpgmksfx1p5kc6-glibc-2.27-bin /nix/store/5l7mynximjv4jl6wm22bwzclabggxswi-propeller-gcc-2018-04-14r1 /nix/store/6dywfq0s7crkl012wbkp6sjq9wgzklwy-expat-2.2.6-dev /nix/store/b2xkfmhfa4l4fznwqr4xz6vy97qzq250-flex-2.6.4 /nix/store/c90akqjk2lk9r18wvxnkvd07j2nnl3f1-linux-headers-4.18.3 /nix/store/g3laz2ssygn0nllgndqn64qi3phsijsh-gnum4-1.4.18 /nix/store/p7j7qg5cri229ihf8nllwjhzgbvgx5d0-gcc-7.3.0 /nix/store/psqblh5bsgkbkhn4r648pgjw5rq4npkv-glibc-2.27-dev copying path '/nix/store/c90akqjk2lk9r18wvxnkvd07j2nnl3f1-linux-headers-4.18.3' from ''... copying path '/nix/store/6dywfq0s7crkl012wbkp6sjq9wgzklwy-expat-2.2.6-dev' from ''... copying path '/nix/store/22lrlr8d1d0dymy29jfpgmksfx1p5kc6-glibc-2.27-bin' from ''... copying path '/nix/store/g3laz2ssygn0nllgndqn64qi3phsijsh-gnum4-1.4.18' from ''... copying path '/nix/store/psqblh5bsgkbkhn4r648pgjw5rq4npkv-glibc-2.27-dev' from ''... copying path '/nix/store/b2xkfmhfa4l4fznwqr4xz6vy97qzq250-flex-2.6.4' from ''... copying path '/nix/store/p7j7qg5cri229ihf8nllwjhzgbvgx5d0-gcc-7.3.0' from ''... copying path '/nix/store/5l7mynximjv4jl6wm22bwzclabggxswi-propeller-gcc-2018-04-14r1' from ''... building '/nix/store/p2cj0p96zjm53y28x0sjagzn2sv1h87m-user-environment.drv'... created 425 symlinks in user environment #include "stdio.h" int main() { sleep(10); printf("Hello World\n"); } [nixdemo@ubuntut0:~$] p2gcc -v -t -s foo.c -o foo propeller-elf-gcc -mcog -Os -m32bit-doubles -S foo.c s2pasm -p/nix/store/slxljvzw1a8hgqnkap7yz5z34dq2d0q6-p2gcc-2019-01-12r1/lib/prefix.spin2 foo p2asm -c -o foo.spin2 p2link /nix/store/slxljvzw1a8hgqnkap7yz5z34dq2d0q6-p2gcc-2019-01-12r1/lib/prefix.o -v foo.o -o foo /nix/store/slxljvzw1a8hgqnkap7yz5z34dq2d0q6-p2gcc-2019-01-12r1/lib/stdio.a /nix/store/slxljvzw1a8hgqnkap7yz5z34dq2d0q6-p2gcc-2019-01-12r1/lib/stdlib.a /nix/store/slxljvzw1a8hgqnkap7yz5z34dq2d0q6-p2gcc-2019-01-12r1/lib/string.a Found offset of 12 for symbol ___files of type 04 at location 5f4 spinsim -b -t foo Hello World [red@apophenia:~/projects/testing-propellergcc]$ loadp2 -p /dev/ttyUSB0 -t foo [ Entering terminal mode. Press ESC to exit. ] Hello World cd ~/.config/nixpkgs/overlays/parallax-tooling git pull nix-env -i propeller-gcc nix-env -i p2gcc nix-collect-garbage reveal a surprising finding that contradicts Danish physicist Niels Bohr's established view —the jumps are neither abrupt nor as random as previously thought." If you want it to always compile locally, just don't execute the cachix command as that's the command that enables the binary caching. I'm tracking them in the repo so as updates get pushed them them, those changes should update too. I'll document how this works when I see the next set of code updates hit. The very abridged version of a simple local version bump: Edit the file pkgs/packagename/default.nix. For example, for p2gcc: version = date of the last push and the r# is there in case of updates to dependencies. rev = last git commit. sha256 = checksum of the code download from github. When you make those edits, it will go ahead and compile all the things. Here's how the upgrade looks (maybe I should write some simple shellscripts to make this easier?) Query the version updates: Do the upgrade: Done. Is there any way to lean out the "/nix" directory? When I ran "nix-env -i p2gcc", it took a good time compiling (lots and lots of files) and that directory now takes up 2GB of space. It even compiled grep. Kind regards, Samuel Lourenço yes: This I'm really curious about because you should have been able to pull everything from cache. What hardware / OS are you running? Thanks, Red Agreed - it shouldn't be anywhere near that size. Sure, but like I said his machine shouldn't be compiling anything as all of the package definitions he's using should be in cache. Answering to your question, I'm using a VM with Kubuntu 18.04 LTS, 64bit. The VM manager is VirtualBox. However, since my virtual RAM was limited to 2GB, the "nix-env -i p2gcc" step failed. I had to extend the RAM to 4GB temporarily and try again. Kind regards, Samuel Lourenço I'm going to set up the same VM here and test this - I can't think of any reason why it would force a compilation. I'll let you know if I can replicate. Thanks, Red EDIT: It's installing now... (it's actually propeller-gcc which is a dependency of p2gcc that's causing the issue - I'll know why shortly). I shall return! Kind regards, Samuel Lourenço Okey-dokey, Nuke your /nix directory from orbit and: I'm not entirely sure why this build differs but I'm going to find out. This should get you moving in the meantime. Thanks, Red I just bumped it due to changes in p2gcc to include these changes: The terminal still asks for and accepts ESC, although now it seems to accept Ctrl+] as well. Kind regards, Samuel Lourenço I am currently re-factoring the propeller-gcc package to remove openspin, spinsim, and spin2cpp from it. The reason being that the propeller-gcc package has old versions tagged and, as a user you may want to run more recent versions. When the work is completed I'll add full docs above. Update the overlay: Update propeller-gcc: Update p2gcc: Update spin2cpp:
http://forums.parallax.com/discussion/comment/1464144/
CC-MAIN-2019-30
en
refinedweb
The software described in this documentation is either no longer supported or is in extended support. Oracle recommends that you upgrade to a current supported release. Docker version 1.9 and later require that you configure the system to use the Unbreakable Enterprise Kernel Release 4 (UEK R4) and boot the system with this kernel. To install and configure the Docker Engine on an Oracle Linux 6 system: If you want to install Docker, configure the system to use the Unbreakable Enterprise Kernel Release 4 (UEK R4) and boot the system with this kernel: If your system is registered with ULN, disable access to the ol6_x86_64_UEKR3_latestor ol6_x86_64_UEK_latestchannels and enable access to the ol6_x86_64_UEKR4channel. If you use the Oracle Linux yum server, disable the ol6_UEKR3_latestrepository and enable the ol6_UEKR4repository in the repository configuration files in /etc/yum.repos.d/uek-ol6.repo, for example: [ol6_UEKR4] name=Latest Unbreakable Enterprise Kernel Release 4 for Oracle Linux $releasever ($basearch) baseurl= gpgkey= gpgcheck=1 enabled=1 [ol6_UEKR3_latest] name=Latest Unbreakable Enterprise Kernel for Oracle Linux $releasever ($basearch) baseurl= gpgkey= gpgcheck=1 enabled=0 [ol6_UEK_latest] name=Latest Unbreakable Enterprise Kernel for Oracle Linux $releasever ($basearch) baseurl= gpgkey= gpgcheck=1 enabled=0 Run the following command to upgrade the system to UEK R4: # yum update To ensure that UEK R4 is the default boot kernel, edit /boot/grub/grub.confand change the value of the defaultdirective to index the entry for the UEK R4 kernel. For example, if the UEK R4 kernel is the first entry, set the value of defaultto 0. Reboot the system, selecting the UEK R4 kernel if this is not the default boot kernel. # reboot If your system is registered with ULN, enable the ol6_x86_64_addonschannel. If you use the Oracle Linux yum server, enable the ol6_addonsrepository in the repository configuration file at /etc/yum.repos.d/oracle-linux-ol6.repo, for example: [ol6_addons] name=Oracle Linux $releasever Add ons ($basearch) baseurl= gpgkey= gpgcheck=1 enabled=1 Install the docker-enginepackage. # yum install docker-engine By default, the Docker Engine uses the device mapper as a storage driver to manage Docker containers. As with LXC, there are benefits to using the snapshot features of btrfs instead.Note Oracle recommends using btrfs because of the stability and maturity of the technology. If a new device for btrfs is not available, you should use overlay2as the storage driver instead of devicemapperfor performance reasons. You can configure overlay2by adding the --storage-driver=overlay2option to other_argsin /etc/sysconfig/docker. The overlayfs file system is available with UEK R4. For more information, see. To configure the Docker Engine to use btrfs instead of the device mapper: Use yum to install the btrfs-progspackage. # yum install btrfs-progs Create a btrfs file system on a suitable device such as /dev/sdbin this example: # mkfs.btrfs /dev/sdbNote Any unused block device that is large enough to store several containers is suitable. The suggested minimum size is 1GB but you might require more space to implement complex Docker applications. If the system is a virtual machine, Oracle recommends that you create, partition, and format a new virtual disk. Alternatively, convert an existing ext3 or ext4 file system to btrfs. See in the Oracle Linux Administrator's Solutions Guide for Release 6. If an LVM volume group has available space, you can create a new logical volume and format it as a btrfs file system. Mount the file system on /var/lib/docker. On a fresh installation, you might need to create this directory first. # mkdir /var/lib/docker# mount /dev/sdb /var/lib/dockerImportant It is critical that you ensure that there is always available disk space in /var/lib/dockerfor all of the images and containers that you intend to run. If a running container fills /var/lib/docker, a restart of the Docker Engine fails with an error similar to the following: Error starting daemon: write /var/lib/docker/volumes/metadata.db: no space left on device Without the Docker Engine running it becomes difficult to clean up or remove existing or obsolete images. If this happens, you can try to gain some space by removing the contents of /var/lib/docker/tmp. However, the best solution is to avoid reaching this situation by implementing quotas that prevent a scenario where the Docker Engine runs out of the disk space required to run. Add an entry for /var/lib/dockerto the /etc/fstabfile. /dev/sdb /var/lib/docker btrfs defaults 0 0 Edit /etc/sysconfig/dockerto configure global networking options, for example: If your system needs to use a web proxy to access the Docker Hub, add the following lines: export HTTP_PROXY=" proxy_URL: port" export HTTPS_PROXY=" proxy_URL: port" Replace proxy_URLand portwith the appropriate URL and port number for your web proxy. To configure IPv6 support in version 1.5 and later of Docker, add the --ipv6option to OPTIONS, for example: OPTIONS="--ipv6" With IPv6 enabled, Docker assigns the link-local IPv6 address fe80::1to the bridge docker0. If you want Docker to assign global IPv6 addresses to containers, additionally specify the IPv6 subnet to the --fixed-cidr-v6option, for example: OPTIONS="--ipv6 -- fixed-cidr-v6='2001:db8:1::/64'" For more information about configuring Docker networking, see. In version 1.5 and later of Docker, the docker service unshares its mount namespace to resolve device busyissues with the device mapper storage driver. However, this configuration breaks autofsin the host system and prevents you from accessing subsequently mounted volumes in Docker containers. The workaround is to stop the Docker service from unsharing its mount namespace. Edit /etc/init.d/dockerand remove the $unshare -m --parameters from the line that starts the daemon. For example, change the line that reads similar to the following: "$unshare" -m -- $exec $other_args &>> $logfile & so that it reads: $exec $other_args &>> $logfile &Note You might need to reapply this workaround if you update the dockerpackage and the change to /etc/init.d/dockeris overwritten. Start the dockerservice and configure it to start at boot time: # service docker start# chkconfig docker on If you have installed the mlocate package, it is recommended that you modify the PRUNEPATHS entry in /etc/updatedb.conf to prevent updatedb from indexing directories below /var/lib/docker, for example: PRUNEPATHS="/media /tmp /var/lib/docker /var/spool /var/tmp" This entry prevents locate from reporting files that belong to Docker containers. To check that the docker service is running, use the following command: # service docker statusdocker (pid 1958) is running... You can also use the docker command to display information about the configuration and version of the Docker Engine, for example: # docker infoContainers: 0 Images: 6 Storage Driver: btrfs Execution Driver: native-0.2 Kernel Version: 3.8.13-35.3.1.el7uek.x86_64 Operating System: Oracle Linux Server 6.6 # docker versionClient version: 1.3.3 Client API version: 1.15 Go version (client): go1.3.3 Git commit (client): 4e9bbfa/1.3.3 OS/Arch (client): linux/amd64 Server version: 1.3.3 Server API version: 1.15 Go version (server): go1.3.3 Git commit (server): 4e9bbfa/1.3.3 For more information, see the docker(1) manual page.
https://docs.oracle.com/cd/E37670_01/E75728/html/section_kfy_f2z_fp.html
CC-MAIN-2019-30
en
refinedweb
: - Add files from PubNubUnity/Assetsfolder to the Assetsfolder of your project. PubNub- instantiate a PubNub instance. Subscribe()- subscribe to a specific channel. Publish()- send a message on a specific channel. Unsubscribe()- additively unsubscribe to a specific channel. Include the PubNub library Download the PubNub Unity package and import it to your Unity project by going to Assets -> Import Package -> Custom Package. Now that your PubNub Unity Package has been imported, you must enable it in the Test Runner. To enable the PubNub Unity Package, go to Window -> General -> Test Runner. Click on the mini drop down menu next to the window close button, and click Enable playmode tests for all assemblies. You will have to restart your Unity editor to finalize these changes. Congrats, you are now all setup to start using the PubNub Unity SDK! (OR if using the code from the source add files from PubNubUnity/Assets folder to the Assets folder of your project.) using PubNubAPI;.SubscribeKey = "my_subkey"; pnConfiguration.PublishKey = "my_pubkey"; pnConfiguration.Secure = true; pubnub = new PubNub(pnConfiguration);. When using the Subscribe()method, the messages will be received through the EventHandler: SubscribeCallbackas an instance of the MessageResultclass. pubnub.Subscribe() .Channels(new List<string>() { "my_channel" }) .Execute(); For Publish(), the message attribute contains the data you are sending. Unity PNConfiguration pnConfiguration = new PNConfiguration(); pnConfiguration.SubscribeKey = "my_subkey"; pnConfiguration.PublishKey = "my_pubkey"; pnConfiguration.SecretKey = "my_secretkey"; pnConfiguration.LogVerbosity = PNLogVerbosity.BODY; pnConfiguration.UUID = "PubNubUnityExample"; pubnub = new PubNub(pnConfiguration); pubnub.SubscribeCallback += (sender, e) => { SubscribeEventEventArgs mea = e as SubscribeEventEventArgs; if (mea.Status != null) { if (mea.Status.Category.Equals(PNStatusCategory.PNConnectedCategory)) {); } }); } } if (mea.MessageResult != null) { Debug.Log("In Example, SubscribeCallback in message" + mea.MessageResult.Channel + mea.MessageResult.Payload); } if (mea.PresenceEventResult != null) { Debug.Log("In Example, SubscribeCallback in presence" + mea.PresenceEventResult.Channel + mea.PresenceEventResult.Occupancy + mea.PresenceEventResult.Event); } }; pubnub.Subscribe() .Channels(new List<string>(){ "my_channel" }) .Execute();() .ChannelGroups(new List<string>(){ "my_channel_group" }) .Channels(new List<string>() { "my_channel" }) .Async((result, status) => { if (status.Error) { Debug.Log(string.Format("Unsubscribe Error: {0} {1} {2}", status.StatusCode, status.ErrorData, status.Category)); } else { Debug.Log(string.Format("DateTime {0}, In Unsubscribe, result: {1}", DateTime.UtcNow, result.Message)); } }); Like Subscribe(), Unsubscribe()can be called multiple times to successively remove different channels from the active subscription list. Additional Resources for Data Streams with Publish and Subscribe:
https://www.pubnub.com/docs/unity3d-c-sharp/data-streams-publish-and-subscribe
CC-MAIN-2019-30
en
refinedweb
What are words with double b? rubble rabble scrabble scribble hobble bubble ribbon babble bobble hebblewhite bobbin rabble rubble wobble wibble pebble pobble (with no toes) nobble nibble gobble dabble yabby cabby cubby tubby hubby bubby stubby nubbly rubber stubble Ebb chubby How do you play the double b flat on flute? A double b flat is also an A What s words have a double b in them? subbuteo sabbatical Sabbath sobbing Are there any words using double b? bubble In Italian - repubblica Can any note in an octave have an enharmonic - such as G-sharp and A-flat B and C-flat and A and B-double-flat etc? I am guessing so... I've seen something like a key signature having a B-flat, and somewhere in the piece there is a flat in front of a B, so it would be a B-double-flat. If double flats are allowed,then it would be C,B-sharp;C-sharp,D-flat;D, E-double-flat; D-sharp, E-flat; E, F-flat;F,G-double-flat;F-sharp,G-flat;G,A-double-flat;G-sharp,A-flat;A,B-double-flat;and B,C-double-flat. How can you write an algorithm to read two numbers then display the smallest? Algorithm smallest Is:- Input: two values, a and b Output: smallest value of a and b if a<b then return a else return b In C programming: long double smallest (long double a, long double b) { return a<b?a:b; } How do you Calculate the average of two numbers then return the average in c plus plus? double getAverage(const double a, const double b) { return (a + b)/2.0;} What is the enharmonic of A double sharp? A double sharp is the enharmonic of B nature What is the value of a Fox Model B double barrel with double triggers? i wood like to know the value of a Fox Model B How do you write a program to find the area of triangle? To find the area of a triangle you first need to know the base and height: double area_of_triangle (double base, double height) { return base * height / 2; } If we don't know the height, then we need to know the length of any two sides and the included angle. Using standard notation where the sides are labelled a, b and c and their opposing angles as A, B and C, given sides a… How do you find the general equation of cone using C language? If you mean the "general equation of a cone" to be the elliptical cone equation: z = √( (x/a)2 + (y/b)2 ) ... then the function in C to compute this given the proper variables is: double genEqCone(const double x, const double y, const double a, const double b) { const double X_A = (x/a); const double Y_B = (y/b); return sqrt((X_A * X_A) + (Y_B * Y_B)); } What does double d mean? Double d means twice b (2) d as in dodder. Can you compare NaN values? Yes using the equals method. Example: Double a = new Double(Double.NaN); Double b = new Double(Double.NaN); if( a.equals(b) ) System.out.println("True"); else System.out.println("False"); If you execute the above code snippet you will see "True" in the console. If you try the "==" operator to compare the 2 values a and b you will get only false What actors and actresses appeared in Double B-side - 2013? The cast of Double B-side - 2013 includes: Chelsea Schuchman as Frankie Simone How to calculate sum of two complex number in c plus plus? #include<iostream> #include<complex> int main() { std::complex<double> a(1,0); std::complex<double> b(3,1); std::complex<double> c = a + b; } If two fair dice are rolled what is the probability of rolling a double given that the sum was 11? Let A = rolling a double Let B = sum is 11 P(A)=6/36=1/6 P(B)=2/36=1/18 since (5,6) and (6,5) produce a sum of 11. We want to find P(A/B)= P(A & B) / P(B) = 0 / P(B)=0 P(A & B) represent the event getting a double and the sum being 11. Can i get a Java program for quadratic formula? import java.util.*; public class quadratic { public static void main(String[] args) { Scanner input = new Scanner(System.in); String equation = "( ax^2 + bx + c = 0 1 )"; System.out.println("The equation is " + equation); System.out.println("Please enter the values of coefficients a, b, c, separated by spaces"); System.out.println("a = "); double a = input.nextDouble(); System.out.println("b = "); double b = input.nextDouble(); System.out.println("c = "); double c = input.nextDouble(); System.out.println(); double discriminant = Math.pow(b,2)… What interval is c double sharp to b? diminished 7th Write a java program to demonstrate the method overloading for sum function? Below is an example of method overloading which returns the sum of two number types. Each method performs the calculation and returns a value in a different type. int sum(final int a, final int b) { return a + b; } long sum(final long a, final long b) { return a + b; } float sum(final float a, final float b) { return a + b; } double sum(final double a, final double b) {… What is an example of a double displacement reaction? The preparation of hydrogen peroxide is a double displacement reaction. ---- Ab+c->ac+b Program in c to find the roots of a quadratic equation using switch statement?"); scanf("%d", &option); printf("************* *************************\n"); /* Get a, b, and c from user */ printf("\na = "); scanf("%lf", &a); printf("b = "); scanf("%lf", &b); printf("c… What are All the enharmonics on the piano? Enharmonics is the name for a pitch that is "spelled" three different ways. # C=B sharp, D double flat # D flat= C sharp, B double sharp.... What has the author John B Geijsbeek written? John B. Geijsbeek has written: 'Ancient double-entry bookkeeping' What nicknames does Blair Barnette go by? Blair Barnette goes by B.B., Ave B. Blair, and Double B. What is the enharmonic equivalent of b flat? A-sharp, C-double-flat or in some northern European Countries, B. Is Hepatitis B RNA or DNA? Hepatitis B is an infectious condition of the liver. Hepatitis B has a double stranded DNA that belongs to the hepadnavirus family. 4 s on a d b? 4 Strings on a Double Bass. How to write a c plus plus program to calculate the square of number using a function? ... double squareOf_Number(double Number) { return (Number*Number); } ... int main() { ... double Number = 0; ... printf("Enter a number: "); cin >> Number; ... printf("Square of %f is %f\n", Number, squareOf_Number(Number)); ... } Or you can include #include <math.h> and use the function pow(double a, double b) which returns a^b. What two syllable words have double b in them? Some choices: cabbage, rubble, bubble, babble, wobble, clobber, pebble, stubble, gibbon, fibber Double coincidence of demand? For example; the supplier of good A wants good B and the supplier of good B wants good A. Program to find the roots of quadratic equation in c using switch case? Pls try the following program. "); /* Get option from user */ scanf("%d", &option); printf("************* *************************\n"); /* Get a, b, and c from user */… What are the Words to Doublemint Gum jingle? Double your pleasure Double your fun With Double mint Double good Double Mint Gum Two methods cannot have the same name in Java? Multiple methods with the same name is called method overloading. The way to do this is to have the different methods accept different parameters. Examples: Adding two values and returning the result. Let's use different methods for adding various numeric primitives. public static int add(int a, int b) { return a + b; } public static short add(short a, short b) { return a + b; } public static long add(long a, long b) {… Program to find the sum of harmonic series? Let's assume that you want the sum of the general harmonic series: sum(n=0,inf): 1/(an+b) Since we know that the harmonic series will converge to infinity, we'll also assume that you want the sum from 0 to n. double genHarmonic(const double n, const double a, const double b) { double sum = 0.0; // perform calculations int k; for(k = 0; k <= n; ++k) { sum += 1.0 / (a * k + b); }… What is 4 s 0 a d b? 4 Strings on a Double Bass How do you forge on epic pet wars? press a b x double que Why do we need type casting in programming? Becuase, sometimes data is in a form that is unrecognizable to the program. Example: int a = 2; int b = 3; double c = a / b; We cast c as a double. if it was not, then the data would not have a decimal value. Why is there no B sharp or C flat in music? B# and Cb are used in music, just not very much. Most keys do not use either notes, but some do, and they can be used as accidentals. In this way they are similar to double-sharps and double-flats. How do we tuple initialize a class or structure? Consider the following structure: struct X { int a; double b; // ... }; Here we could initialise with a std::tuple<int, double>. To achieve this we simply define a constructor that accepts the required tuple: #include<tuple> struct X { int a; double b; X::X (std::tuple<int, double>& t): a {std::get<0>(t)}, b {std::get<1>(t)} {} // ... }; Note that any constructor that has one argument is known as a conversion constructor, in this case converting from tuple… Write a c plus plus program that prints all reals olutions to the quadratic equation? #include <iostream> #include <math.h> using std::cin; using std::cout; int main() { cout << endl << "This program find real roots of a*x*x + b*x + c = 0"; double a = 0.0; cout << endl << "Enter a: "; cin >> a; double b = 0.0; cout << endl << "Enter b: "; cin >> b; double c = 0.0; cout << endl << "Enter c: "; cin >> c; double det = b*b… What is the lowest string on a double bass? The lowest string on a four string double bass is an E string. If you have a fairly rare five string double bass then the lowest fifth string is a B string. Did the song Daytripper have a B side? We Can Work It Out Technically, there is no 'B-side' this single by the Beatled was a 'Double A-side' (Ah those were the days) What type of chemical reactions are double replacement reactions? A double replacement reaction is a chemical reaction where two reactant ionic compounds exchange ions to form two new product compounds with the same ions. Double replacement reactions take the form: A+B- + C+D- → A+D- + C+B- Double h words? Withhold has a double h. What does it mean when a sharp and a flat are in front of the same note? Offhand, I would say that is a misprint. However, a natural and flat means to return to a normal flat note after a double-flat. For example, suppose you are in a key with B-flat in the key signature, but you have an E-flat diminished chord, which includes B-double-flat. After that you have a regular B-flat. The natural cancels the double-flat, and the single flat returns to the usual note. After a double-sharp, a natural and… What has the author Rodney B Taylor written? Rodney B. Taylor has written: 'Jamestown' -- subject(s): Biography, Buildings, structures, Historic buildings, History, Pictorial works 'Double taxation relief' -- subject(s): Double taxation What words start with double letters? Aardvark and eel are words. They begin with double letters. What Words that have bee in them? If you mean b double e then Been Beel (as in Louis Beel) Beem (acronym for Best Evidence in Emergency Medicine) Beehive Beegees and Bees What is the enharmonic of c flat? The enharmonic equivalent of C flat is B natural. N.B - B natural can also be called A double-sharp. What brass instrument play the lowest note in the orchestra? Double B-flat Tuba What would your weight b if earths mass were to be doubled? Your weight would be double what it is now.
https://www.answers.com/Q/What_are_words_with_double_b
CC-MAIN-2019-30
en
refinedweb
free - free allocated memory #include <stdlib.h> void free(void *ptr); The free() function causes the space pointed to by ptr to be deallocated; that is, made available for further allocation. If ptr is a null pointer, no action occurs. Otherwise, if the argument does not match a pointer earlier returned by the calloc(), malloc(), realloc() or valloc() function, or if the space is deallocated by a call to free() or realloc(), the behaviour is undefined. Any use of a pointer that refers to freed space causes undefined behaviour. The free() function returns no value. No errors are defined. None. There is now no requirement for the implementation to support the inclusion of <malloc.h>. None. calloc(), malloc(), realloc(), <stdlib.h>. Derived from Issue 1 of the SVID.
http://pubs.opengroup.org/onlinepubs/7908799/xsh/free.html
CC-MAIN-2019-30
en
refinedweb
- Passing multi value list from PRD to PDI (Spoon) - Logging database name is NULL when I try to run job using kitchen.bat - JOB Not Executing All the Transformations - Output Report that uses Data Integration as data source - Read XMl file from table - Update LOG_TABLE.ERRORS at the end of a JOB - Issue while migrating the data With Two Input files - Is this product able to keep data synced? - Use ETL script to Produce Report Output - Update step - NOT A VALID DATETIME VALUE - Error while reading Blob data from database - Performance issue while using update step - Kettle with on Browser - Problems with "Get value from sequence" step using an Informix db sequence - 95 percentile - Kettle through Browser - REST Client - Can we send zip file to Table output step? - How to trouble shoot "This is not a replay transformation" - Facebook Data through PDI - Multiple copies of a step in transactional mode - changing the format of a given date - Parameters, variables, kettle and kitchen. - Error: org.pentaho.di.core.exception.KettleException: - Better way to reformat XML stream to use Get Data from XML - Consultant Wanted for Kettle projects - location flexible - How to set up MapReduce Job account - HowTo Tutorial for simple maooing - Pentaho KETTLE performance - access database repository - KETTLE performance problem - get data from repository - KETTLE performance - database access ping time query - Set locale settings / number format kettle - java - Kettle 4.2 number format locale - Did handling of variables with null values change in 4.4? - Excel spaces in columns names - Pentaho/Kettle Contract Denver, CO - [Kettle] Spoon - LDAP input error during Get Fields - How to process a JSON file with multiple records? - need to validate values in a field against the db then not process any rows if not - Column spaces in Transform - parameter list - How to do Insert/update when the field are dynamic (parameterized ) - org.apache.commons.vfs.FileSystemException: Could not open Zip file - How to get Transformations Metrics in a Job through Java API? - MongoDB Input Step Query Expression does not work - LdapInput connexion problem ubuntu - How do I create multiple folders? - Transformation repetition on field value change - Unable to create webresult from XML when trying to execute remotely - Open multiple files with Stax Step - Put File over FTP and afterwards chmod - scenarios - Using GLobal Variables in Transformation/Job - Values of variables being dropped between transformations within the same job - PGP De/Encryption Step - DB join slowness issue, pls help. - Export and ${DATA_PATH_1} - Connection to API (HasOffers-Salesforce) - How to do a bulk Load ?? - input / output 10000 buffer size - Penntaho Performance Test - 5 Million Rows - Multiple DB Lookup - Pentaho performance - Exceute a DB stored Procedure - Text file stored on solaris - Where can I get Pentaho 4.5 BI Suite Enterprise Edition for Download? - poor performance with fact table load - poor pdi transformation design ? - Removing last special character from String in PDI - Wait for file - Add XML step, prefixes and undeclared namespace error - Switch/Case continues on both paths in parallel - How to combine two csv document using spoon - insert/update step comparison of timestamp columns - Value Mapper converting string 'A' to null. - Mapping (sub-transformation) parameter inherit issue - Write to several files as data is processed then email files, sends to many email - Loop through each field to remove leading characters - Split one column into multiple column - day - Movies webservice lookup example - pulling data from facebook pages and facebook apps - Rhino JavaScript debugging with Eclipse - PDI - kettle, Pig Srcipt Executor - Copy rows to result - readfiles - Execute SQL Script issue - No repository definder error from terminal window - Login error to a remote repository - [Carte] Remotely started transformations ignore custom parameters - Saparator field in Text file output - Matrix operations? - RSS Input Connection Time-Out - configuring Kettle for use with Java and Postgres - configuring Kettle for use with Java and Postgres - Error Saving Transformation To PostgreSQL Repositiory - Problem with "Get Value from Sequence" - Pentaho kettle performance or speed while transferring data from csv to text file - Pentaho kettle performance or speed while transferring data from csv to text file - can this be done in Kettle? XML Input Stream (StAX) or get data from XML? - Pentaho Kettle Performance / Speed - Pentaho Kettle Performance / Speed - Flush PDI-server Mondrian Cache? - Data load from Greenplum to sqlserver - Connection Timeout roperty in Kettle - Adding Pentaho to the existing infrastructure (mongo cluster + postgresql) - Adding Pentaho to the existing infrastructure (mongo cluster + postgresql) - wrong characters in row data on linux - Simple step by step flow help - ISO8583 file parse - Schedule a job - disabled ? - Export/Import of repo directory - invalid kettle file type - Trouble changing the value of variables - Calling external code from User Defined Java Step - Are there ways to get JobConfiguration's xml without using Java API? - Help me to get Solution - Fill out web form via transformation - how to get data from google analytic using http client step - Populating Parameters from SQL - SCD - deleted records at source ? - Pentaho character set issue - Spedd SQL to SQL - Formula nested too deeply? - Unique rows - Pentaho Reporting Output - dynamic output file name - Pentaho Kettle Step with multiple output steps having different metadata - MySql bulk load touble! - Receiver's Mailbox Full Issues - Target column mapping contain IF then ELSE Condition - Spoon : Open File option problem - RESTful Client to CSV Input -- FileNotFoundException - How to output multiple rows. - Job Mail step - deletes attached files after mailing - read - instead of load - binary data from database table - GROUP BY fails when casting BigDecimal to Double - What pre-requesitie should i do if i am goona connect the MongoDB in Spoon - Transformation vs. Job parallel vs sequential - how to covert a 2-D spreadsheet with multiple column and row header in to 1-D spreads - Getting error while establishing database connection - Facing problem reading japanese character for ms-access database odbc connection - Output steps metrics, How to use - Google translate API- web service transformation - File repo, database change, keeps on trying to use old db - GoogleApp + ReST config - params not getting sent with GET - what am I doing wrong? - How to specify classpath for JDBC driver in Spoon - Merging two datasources - CSV file dynamic splitting - Convert data from PDF to Excel.. - Convert data from PDF to Excel.. - Using output of two stored procedure to start new transformation. - Update shared DB connection in all jobs/transformations without re-opening all - Modified Java Value Script - getting missing ; error ?? - Mongo - recover & update by _id - Starting a job/transformation remotely - How to encode a URL in 4.2.0 GA - getLasrModifiedTime Javascript - Unable to Launch Spoon/PDI - PostgreSQL Bulk Load dynamic fields - salesforce upsert give error on Account parentId relation - Manejo de variables - Job Scheduling - How to Schedule Jobs Using Kitchen.bat - Job Scheduling - Spoon - "Invalid object name" when Visualizing Model - Job with Shell Command Step does not work with Windows Scheduler only - Problem with Table Input and parameters - Streaming mass data through a Webservice - I need help with SDK and MergeJoin - Cannot read negative numbers in text file input - Can't connect to database using JDBC driver - How do I connect the Embedded Hypersonic to Postgresql Data Transformation - How to connect to an Embedded HSQLDB - Problem with table input - Execution Time - Split some rows into one row - Problem using ETL Metadata Injection step - Problem using ETL Metadata Injection step - Problem using ETL Metadata Injection step - Problem using ETL Metadata Injection step - dashboard date range on analyzer report - Problem using ETL Metadata Injection step - Closed Connection issue - Kettle 4.3 - Unable to add a job to Carte using Carte's web service - XLSX file producing java.lang.OutOfMemory:Java heap space - How to insert a field in a flow to another flow. - Facing issue in order to install Kettle 4.4 - concat - Switch case - Error in Update/Insert object with Oracle concurrency - Text File Input - problems with decimal and group of numbers - How to configure master slave clusterring in Pentaho with community edition? - Kettle sources repository. Where is it?? - PDI issue with Calculator Step (Date A + B Days) - str2date format help - Unable to extract Zip file using unzip step in kettle - Unable to extract Zip file using unzip step in kettle - dateformat - How to load multiple csv files e.g different columns, into MySQL DB? - Unable to get the header row in output text file in Append mode - Reading Single File In Parallel - New Plugin works in Spoon, but not in kitchen. - partial logging on transformation does not work - Different files - Split text file - S3 File Output Does not work - can a change in kettle database repository trigger an http-call or smth. similar? - Problem using ETL Metadata Injection step - XPath statement returned no reuslt [/customer[@customer-no='2']] - Wildcards and regex on "Check if files exist" job step - How to get members of group from LDAP - Concat Fields adds a 'return' (new line) when outputting to CSV - Add Sequence + Empty space - Metada Input Step + Output Field Type - Trouble Installing pdi-ce-4.4.0-stable.zip - issue with calculator step - AMQP Consumer Uses too much CPU - SQL preview not working..? - Can database connections be un-shared under Enterprise Repository? - Inconsistance result from ldap input. - Inconsistance result from ldap input. - Inconsistance result from ldap input. - Data validator - How can I use the tested value with my custom message? - Is the UDJC substantially slower/faster than writing a plugin? - Error saving to repository - Content is not allowed in prolog. - I want to clone and lookup - I want to clone and lookup - PDI unable to get system time - Microsoft Excel Input Hyperlinked Cell - how can i make a stdout or console in my transition ??? - pentaho forum - Connect to SLQServer DB via VPN - .kettle folder access by Mutilple user - Generating multi-level XML with Kettle 4.4 - Config file based fiie parsing - Text file input error - Text file input error - Getting line length of a Fixed length file - Excel source files - multiple worksheets - Text Input - CRLF in field - Split one txt file which contains data from many table into txt files for every table - Table Input step - double number in output is truncated - read XML field - Split one txt file which contains data from many table into txt files for every table - Table Input step - double number in output is truncated - xml load, transform and insert in mongoDb - Facing problem related to status in kettle transformation logs table. - Java version for Kettle 4.3? - Using Infobright Bulk Loader on Windows - Email Message Input - Body text in zeroes and ones - Pentaho execution of job getting killed - Google Analytics Problem
https://forums.pentaho.com/archive/index.php/f-135-p-60.html?s=c405835d3da6ca4309254cffd6778a1d
CC-MAIN-2019-30
en
refinedweb
Just before the holidays I was working on a .NET Core project that needed data available from some web services. I’ve done this a bunch of times previously, and always seem to spend a couple of hours writing code using the HttpClient object before remembering there are libraries out there that have done the heavy lifting for me. So I thought I’d do a little write up of a couple of popular library options that I’ve used – RestSharp and Flurl. I find that learn quickest from reading example code, so I’ve written sample code showing how to use both of these libraries with a few different publically available APIs. I’ll look at three different services in this post: - api.postcodes.io – no authentication required, uses GET and POST verbs - api.nasa.gov – authentication via an API key passed in the query string - api.github.com – Basic Authentication required to access private repo information And as an architect, I’m sometimes asked how to get started (and sometimes ‘why did you chose library X instead of library Y?’), so I’ve wrapped up with a comparison and which library I like best right now. Reading data using RestSharp This is a very mature and well documented open source project (released under the Apache 2.0 licence), with the code available on Github. You can install the nuget package in your project using package manager with the command: Install-Package RestSharp First – using the GET verb with RestSharp. Using HTTP GET to return data from a web service Using Postcodes.io I’ve been working with mapping software recently – some of my data sources don’t have latitude and longitude for locations, and instead they only have a UK postcode. Fortunately I can use the free Postcodes.io RESTful web API to determine a latitude and longitude for each of the postcode values. I can either just send a postcode using a GET request to get the corresponding geocode (latitude and longitude) back, or I can use a POST request to send a list of postcodes and get a list of geocodes back, which speeds things up a bit with bulk processing. Let’ start with a simple example – using the GET verb for a single postcode. I can request a geocode corresponding to a postcode from the Postcodes.io service through a browser with a URL like the one below: 3JR This service doesn’t require any authentication, and the code below shows how to use RestSharp and C# to get data using a GET request. // instantiate the RestClient with the base API url var client = new RestClient(""); // specify the resource, e.g. 3JR var getRequest = new RestRequest("postcodes/{postcode}"); getRequest.AddUrlSegment("postcode", "IP1 3JR"); // send the GET request and return an object which contains the API's JSON response var singleGeocodeResponseContainer = client.Execute(getRequest); // get the API's JSON response var singleGeocodeResponse = singleGeocodeResponseContainer.Content; The example above returns raw JSON content, which I can deserialise into a custom POCO, such as the one below. public class GeocodeResponse { public string Status { get; set; } public Result Result { get; set; } } public class Result { public string Postcode { get; set; } public string Longitude { get; set; } public string Latitude { get; set; } } But I can do better than the code above – if I specify the GeocodeResponse type in the Execute method (as shown below), RestSharp uses the classes above and intelligently hydrates the POCO from the raw JSON content returned: // instantiate the RestClient with the base API url var client = new RestClient(""); // specify the resource, e.g. var getRequest = new RestRequest("postcodes/{postcode}"); getRequest.AddUrlSegment("postcode", "OX495NU"); // send the GET request and return an object which contains a strongly typed response var singleGeocodeResponseContainer = client.Execute<GeocodeResponse>(getRequest); // get the strongly typed response var singleGeocodeResponse = singleGeocodeResponseContainer.Data; Of course, not APIs all work in the same way, so here are another couple of examples of how to return data from different publically available APIs. NASA Astronomy Picture of the Day This NASA API is also freely available, but slightly different from the Postcodes.io API in that it requires an API subscription key. NASA requires that the key is passed as a query string parameter, and RestSharp facilitates this with the AddQueryParameter method (as shown below). This method of securing a service isn’t that unusual – goodreads.com/api also uses this method. // instantiate the RestClient with the base API url var client = new RestClient(""); // specify the resource, e.g. var getRequest = new RestRequest("planetary/apod"); // Add the authentication key which NASA expects to be passed as a parameter // This gives getRequest.AddQueryParameter("api_key", "DEMO_KEY"); // send the GET request and return an object which contains the API's JSON response var pictureOfTheDayResponseContainer = client.Execute(getRequest); // get the API's JSON response var pictureOfTheDayJson = pictureOfTheDayResponseContainer.Content; Again, I could create a custom POCO corresponding to the JSON structure and populate an instance of this by passing the type with the Execute method. Github’s API The Github API will return public data any authentication, but if I provide Basic Authentication data it will also return extra information relevant to me about my profile, such as information about my private repositories. RestSharp allows us to set an Authenticator property to specify the userid and password. // instantiate the RestClient with the base API url var client = new RestClient(""); // pass in user id and password client.Authenticator = new HttpBasicAuthenticator("jeremylindsayni", "[[my password]]"); // specify the resource that requires authentication // e.g. var getRequest = new RestRequest("users/jeremylindsayni"); // send the GET request and return an object which contains the API's JSON response var response = client.Execute(getRequest); Obviously you shouldn’t hard code your password into your code – these are just examples of how to return data, they’re not meant to be best practices. You might want to store your password in an environment variable, or you could do even better and use Azure Key Vault – I’ve written about how to do that here and here. Using the POST verb to obtain data from a web service The code in the previous example refers to GET requests – a POST request is slightly more complex. The api.postcodes.io service has a few different endpoints – the one I described earlier only finds geocode information for a single postcode – but I’m also able to post a JSON list of up to 100 postcodes, and get corresponding geocode information back as a JSON list. The JSON needs to be in the format below: { "postcodes" : ["IP1 3JR", "M32 0JG"] } Normally I prefer to manipulate data in C# structures, so I can add my list of postcodes to the object below. public class PostCodeCollection { public List<string> postcodes { get; set; } } I’m able to create a POCO object with the data I want to post to the body of the POST request, and RestSharp will automatically convert it to JSON when I pass the object into the AddJsonBody method. // instantiate the ResttClient with the base API url var client = new RestClient(""); // specify the resource, e.g. var postRequest = new RestRequest("postcodes", Method.POST, DataFormat.Json); // instantiate and hydrate a POCO object with the list postcodes we want geocode data for var postcodes = new PostCodeCollection { postcodes = new List<string> { "IP1 3JR", "M32 0JG" } }; // add this POCO object to the request body, RestSharp automatically serialises it to JSON postRequest.AddJsonBody(postcodes); // send the POST request and return an object which contains JSON var bulkGeocodeResponseContainer = client.Execute(postRequest); One gotcha – RestSharp Serialization and Deserialization One aspect of RestSharp that I don’t like is how the JSON serialisation and deserialisation works. RestSharp uses its own engine for processing JSON, but basically I prefer Json.NET for this. For example, if I use the default JSON processing engine in RestSharp, then my PostcodeCollection POCO needs to have property names which exactly match the JSON property names (including case sensitivity). I’m used to working with Json.NET and decorating properties with attributes describing how to serialise into JSON, but this won’t work with RestSharp by default. // THIS DOESN'T WORK WITH RESTSHARP UNLESS YOU ALSO USE **AND REGISTER** JSON.NET public class PostCodeCollection { [JsonProperty(PropertyName = "postcodes")] public List<string> Postcodes { get; set; } } Instead I need to override the default RestSharp serializer and instruct it to use Json.NET. The RestSharp maintainers have written about their reasons here and also here – and helped out by writing the code to show how to override the default RestSharp serializer. But personally I’d rather just use Json.NET the way I normally do, and not have to jump through an extra hoop to use it. Reading Data using Flurl Flurl is newer than RestSharp, but it’s still a reasonably mature and well documented open source project (released under the MIT licence). Again, the code is on Github. Flurl is different from RestSharp in that it allows you to consume the web service by building a fluent chain of instructions. You can install the nuget package in your project using package manager with the command: Install-Package Flurl.Http Using HTTP GET to return data from a web service Let’s look at how to use the GET verb to read data from the api.postcodes.io. api.nasa.gov. and api.github.com. First, using Flurl with api.postcodes.io The code below searches for geocode data from the specified postcode, and returns the raw JSON response. There’s no need to instantiate a client, and I’ve written much less code than I wrote with RestSharp. var singleGeocodeResponse = await "" .AppendPathSegment("postcodes") .AppendPathSegment("IP1 3JR") .GetJsonAsync(); I also find using the POST method with postcodes.io easier with Flurl. Even though Flurl doesn’t have a build in JSON serialiser, it’s easy for me to install the Json.NET package – this means I can now use a POCO like the one below… public class PostCodeCollection { [JsonProperty(PropertyName = "postcodes")] public List<string> Postcodes { get; set; } } … to fluently build up a post request like the one below. I can also createmy own custom POCO – GeocodeResponseCollection – which Flurl will automatically populate with the JSON fields. var postcodes = new PostCodeCollection { Postcodes = new List<string> { "OX49 5NU", "M32 0JG" } }; var url = await "" .AppendPathSegment("postcodes") .PostJsonAsync(postcodes) .ReceiveJson<GeocodeResponseCollection>(); Next, using Flurl with api.nasa.gov As mentioned previously, NASA’s astronomy picture of the day requires a demo key passed in the query string – I can do this with Flurl using the code below: var astronomyPictureOfTheDayJsonResponse = await "" .AppendPathSegments("planetary", "apod") .SetQueryParam("api_key", "DEMO_KEY") .GetJsonAsync(); Again, it’s a very concise way of retrieving data from a web service. Finally using Flurl with api.github.com Lastly for this post, the code below show how to use Flurl with Basic Authentication and the Github API. var singleGeocodeResponse = await "" .AppendPathSegments("users", "jeremylindsayni") .WithBasicAuth("jeremylindsayni", "[[my password]]") .WithHeader("user-agent", "csharp-console-app") .GetJsonAsync(); One interesting difference in this example between RestSharp and Flurl is that I had to send user-agent information to the Github API with Flurl – I didn’t need to do this with RestSharp. Wrapping up Both RestSharp and Flurl are great options for consuming Restful web services – they’re both stable, source for both is on Github, and there’s great documentation. They let me write less code and do the thing I want to do quickly, rather than spending ages writing my own code and tests. Right now, I prefer working with Flurl, though the choice comes down to personal preference. Things I like are: - Flurl’s MIT licence - I can achieve the same results with less code, and - I can integrate Json.NET with Flurl out of the box, with no extra classes needed. About me: I regularly post about Microsoft technologies and .NET – if you’re interested, please follow me on Twitter, or have a look at my previous posts here. Thanks! 7 thoughts on “Comparing RestSharp and Flurl.Http while consuming a web service in .NET Core” Hey! I’m a big fan of Polly, and it looks like the net core team are too. They seem to have done a really good job with the httpclientfactory: Hello! Thank you for this, that’s a good link – practical ways of improving overall system quality is something I want to understand more deeply, Polly and Flurl might be a pretty awesome combination (I think that Flurl tries to address the socket issue the article describes), I’ll have to look into it to see what’s happening under the hood. You should check out It’s a light wrapper around HttpClient that provides the same fluent / convenience helpers in a more standard way since it’s not replacing the standard way of doing HTTP requests in .NET. Nice – thank you, I’ll check it out! Hi Jeremy, Nice article, Thank you for that. Have you already checked Refit for this purpose? Might make your life a bit easier. I hadn’t heard of Refit () – it looks good too, thank you for sharing. I’ve already planned my next post on Polly and Flurl but I definitely want to explore Refit and FluentRest as alternative tools for the job!
https://jeremylindsayni.wordpress.com/2018/12/27/comparing-restsharp-and-flurl-http-while-consuming-a-web-service-in-net-core/
CC-MAIN-2019-30
en
refinedweb
Last time I scratched the surface of creating databases and collections in Azure Cosmos using the emulator and some C# code written using .NET Core. This time I’m going to dig a bit deeper into how to query these databases and collections with C#, and show a few code snippets that I’m using to help remove cruft from my classes. I’m also going write a little about Indexing Policies and how to use them to do useful string comparison queries. Initializing Databases and Collections I use the DocumentClient object to create databases and collections, and previously I used the CreateDatabaseAsync and CreateDocumentCollectionAsync methods to create databases and document collections. But after running my test project a few times it got a bit annoying to keep having to delete the database from my local Cosmos instance before running my code, or have the code throw an exception. Fortunately I’ve discovered the Cosmos SDK has a nice solution for this – a couple of methods which are named CreateDatabaseIfNotExistsAsync and CreateDocumentCollectionIfNotExistsAsync. string DatabaseId = "LocalLandmarks"; string NaturalSitesCollection = "NaturalSites"; var databaseUrl = UriFactory.CreateDatabaseUri(DatabaseId); var collectionUri = UriFactory.CreateDocumentCollectionUri(DatabaseId, NaturalSitesCollection); client.CreateDatabaseIfNotExistsAsync(new Database { Id = DatabaseId }).Wait(); client.CreateDocumentCollectionIfNotExistsAsync(databaseUrl, new DocumentCollection { Id = NaturalSitesCollection }).Wait(); Now I can initialize my code repeatedly without having to tear down my database or handle exceptions. What about querying by something more useful than the document resource ID? Last time I wrote some code that took a POCO and inserted it as a document into the Cosmos emulator. // Let's instantiate a POCO with a local landmark var giantsCauseway = new NaturalSite { Name = "Giant's Causeway" }; // Add this POCO as a document in Cosmos to our natural site collection var collectionUri = UriFactory.CreateDocumentCollectionUri(DatabaseId, NaturalSitesCollection); var itemResult = client.CreateDocumentAsync(collectionUri, giantsCauseway).Result; Then I was able to query the database for that document using the document resource ID. // Use the ID to retrieve the object we just created var document = client .ReadDocumentAsync( UriFactory.CreateDocumentUri(DatabaseId, NaturalSitesCollection, itemResult.Resource.Id)) .Result; But that’s not really useful to me – I’d rather query by a property of the POCO. For example, I’d like to query by the Name property, perhaps with an object instantiation and method signature like the suggestion below: // Instantiate with the DocumentClient and database identifier var cosmosQueryFacade = new CosmosQueryFacade<NaturalSite> { DocumentClient = client, DatabaseId = DatabaseId, CollectionId = NaturalSitesCollection }; // Querying one collection var sites = cosmosQueryFacade.GetItemsAsync(m => m.Name == "Giant's Causeway").Result; There’s a really useful sample project available with the Cosmos emulator which provided some code that I’ve adapted – you can access it from the Quickstart screen in the Data Explorer (available at after you start the emulator). The image below shows how I’ve accessed the sample, which is available by clicking on the “Download” button after selecting the .NET Core tab. The code below shows a query facade class that I have created – I can instantiate the object with parameters like the Cosmos DocumentClient, and the database identifier. I’m going to be enhancing this Facade over the next few posts in this series, including how to use the new version 3.0 of the Cosmos SDK which has recently entered public preview. public class CosmosQueryFacade<T> where T : class { public string CollectionId { get; set; } public string DatabaseId { get; set; } public DocumentClient DocumentClient { get; set; } public async Task<IEnumerable<T>> GetItemsAsync(Expression<Func<T, bool>> predicate) { var documentCollectionUrl = UriFactory.CreateDocumentCollectionUri(DatabaseId, CollectionId); var query = DocumentClient.CreateDocumentQuery<T>(documentCollectionUrl) .Where(predicate) .AsDocumentQuery(); var results = new List<T>(); while (query.HasMoreResults) { results.AddRange(await query.ExecuteNextAsync<T>()); } return results; } } This class lets me query when I know the full name of the site. But what happens if I want to do a different kind of query – instead of exact comparison, what about something like “StartsWith”? // Querying using LINQ StartsWith var sites = cosmosQueryFacade.GetItemsAsync(m => m.Name.StartsWith("Giant")).Result; If I run this, I get an error: An invalid query has been specified with filters against path(s) that are not range-indexed. Consider adding allow scan header in the request. What’s gone wrong? The clue is in the error message – I don’t have the right indexes applied to my collection. Indexing Policies in Cosmos From Wikipedia, an index is a data structure that improves the speed of data retrieval from a database. But as we’ve seen from the error above, in Cosmos it’s even more than this. Certain types of index won’t permit certain types of comparison operation, and when I tried to carry out that operation, by default I got an error (rather than just a slow response). One of the really well publicised benefits of Cosmos is that documents added to collections in a Azure Cosmos database are automatically indexed. And whereas that’s extremely powerful and useful, it’s not magic – Cosmos can’t know what indexes match my specific business logic, and won’t add them. There are three types of indexes in Cosmos: - Hash, used for: - Equality queries e.g. m => m.Name == “Giant’s Causeway” - Range, used for: - Equality queries, - Comparison within a range, e.g. m => m.Age > 5, or m => m.StartsWith(“Giant”) - Ordering e.g. OrderBy(m => m.Name) - Spatial – used for geo-spatial data – more on this in future posts. So I’ve created a collection called “NaturalSites” in my Cosmos emulator, and added some data to it – but how can I find out what the present indexing policy is. That’s pretty straightforward – it’s all in the Data Explorer again. Go to the Explorer tab, expand the database to see its collections, and then click on the “Scale & settings” menu item – this will show you the indexing policy for the collection. When I created the database and collection from C#, the indexing policy created by default is shown below: { "indexingMode": "consistent", "automatic": true, "includedPaths": [ { "path": "/*", "indexes": [ { "kind": "Range", "dataType": "Number", "precision": -1 }, { "kind": "Hash", "dataType": "String", "precision": 3 } ] } ], "excludedPaths": [] } I can see that in the list of indexes for my collection, the dataType of String has an index of Hash (I’ve highlighted this in red above). We know this index is good for equality comparisons, but as the error message from before suggests, we need this to be a Ranged index to be able to do more complex comparisons than just equality between two strings. I can modify the index policy for the collection in C#, as shown below: // Set up Uris to create database and collection var databaseUri = UriFactory.CreateDatabaseUri(DatabaseId); var constructedSiteCollectionUri = UriFactory.CreateDocumentCollectionUri(DatabaseId, ConstructedSitesCollection); // Create the database client.CreateDatabaseIfNotExistsAsync(new Database { Id = DatabaseId }).Wait(); // Create a document collection var naturalSitesCollection = new DocumentCollection { Id = NaturalSitesCollection }; // Now create the policy to make strings a Ranged index var indexingPolicy = new IndexingPolicy(); indexingPolicy.IncludedPaths.Add(new IncludedPath { Path = "/*", Indexes = new Collection<Microsoft.Azure.Documents.Index>() { new RangeIndex(DataType.String) { Precision = -1 } } }); // Now assign the policy to the document collection naturalSitesCollection.IndexingPolicy = indexingPolicy; // And finally create the document collection client.CreateDocumentCollectionIfNotExistsAsync(databaseUri, naturalSitesCollection).Wait(); And now if I inspect the Data Explorer for this collection, the index policy created is shown below. As you can see from the section highlighted in red, the kind of index now used for comparing the dataType String is now a Range. { "indexingMode": "consistent", "automatic": true, "includedPaths": [ { "path": "/*", "indexes": [ { "kind": "Range", "dataType": "String", "precision": -1 }, { "kind": "Range", "dataType": "Number", "precision": -1 } ] } ], "excludedPaths": [] } So when I run the code below to look for sites that start with “Giant”, the code now works and returns objects rather than throwing an exception. var sites = cosmosQueryFacade.GetItemsAsync(m => m.Name.StartsWith("Giant")).Result; There are many more indexing examples here if you’re interested. Wrapping up I’ve taken a small step beyond the previous part of this tutorial, and I’m now able to query for strings that exactly and partially match values in my Cosmos database. As usual I’ve uploaded my code to GitHub and you can pull the code from here. Next time I’m going to try to convert my code to the new version of the SDK, which is now in public preview. 2 thoughts on “Getting started with Azure Cosmos DB and .NET Core: Part #2 – string querying and ranged indexes”
https://jeremylindsayni.wordpress.com/2019/03/03/getting-started-with-azure-cosmos-db-and-net-core-part-2-string-querying-and-ranged-indexes/
CC-MAIN-2019-30
en
refinedweb
Applications, packages and modules¶ Simba has three software components; the application, the package and the module. Application¶ An application is an executable consisting of zero or more packages. An application file tree can either be created manually or by using the tool simba. myapp ├── main.c └── Makefile Package¶ A package is a container of modules. A package file tree can either be created manually or by using the tool simba. A package file tree must be organized as seen below. This is required by the build framework and Simba tools. See the inline comments for details about the files and folders contents. mypkg ├── mypkg │ ├── doc # package documentation │ ├── __init__.py │ ├── src # package source code │ │ ├── mypkg │ │ │ ├── module1.c │ │ │ └── module1.h │ │ ├── mypkg.h # package header file │ │ └── mypkg.mk # package makefile │ └── tst # package test code │ └── module1 │ ├── main.c │ └── Makefile └── setup.py Development workflow¶ The package development workflow is fairly straight forward. Suppose we want to add a new module to the file tree above. Create src/mypkg/module2.h and src/mypkg/module2.c, then include mypkg/module2.h in src/mypkg.h and add mypkg/module2.c to the list of source files in src/mypkg.mk. Create a test suite for the module. It consists of the two files tst/module2/main.c and tst/module2/Makefile. It’s often conveniant to use an existing modules’ files as skeleton for the new module. After adding the module module2 the file tree looks like this. mypkg ├── mypkg │ ├── doc │ ├── __init__.py │ ├── src │ │ ├── mypkg │ │ │ ├── module1.c │ │ │ ├── module1.h │ │ │ ├── module2.c │ │ │ └── module2.h │ │ ├── mypkg.h │ │ └── mypkg.mk │ └── tst │ ├── module1 │ │ ├── main.c │ │ └── Makefile │ └── module2 │ ├── main.c │ └── Makefile └── setup.py Now, build and run the test suite to make sure the empty module implementation compiles and can be executed. $ cd tst/module2 $ make -s run Often the module development is started by implementing the module header file and at the same time write test cases. Test cases are not only useful to make sure the implementation works, but also to see how the module is intended to be used. The module interface becomes cleaner and easier to use it you actually start to use it yourself by writing test cases! All users of your module will benefit from this! So, now we have an interface and a test suite. It’s time to start the implementation of the module. Usually you write some code, then run the test suite, then fix the code, then run the tests again, then you realize the interface is bad, change it, change the implementation, change the test, change, change... and so it goes on until you are satisfied with the module. Try to update the comments and documentation during the development process so you don’t have to do it all in the end. It’s actually quite useful for yourself to have comments. You know, you forget how to use your module too! The documentation generation framework uses doxygen, breathe and sphinx. That means, all comments in the source code should be written for doxygen. Breathe takes the doxygen output as input and creates input for sphinx. Sphinx then generates the html documentation. Just run make in the doc folder to generate the html documentation. $ cd doc $ make $ firefox _build/html/index.html # open the docs in firefox Namespaces¶ All exported symbols in a package must have the prefix <package>_<module>_. This is needed to avoid namespace clashes between modules with the same name in different packages. There cannot be two packages with the same name, for the namespace reason. All packages must have unique names! There is one exception though, the three Simba packages; kernel, drivers and slib. Those packages does not have the package name as prefix on exported symbols. int mypackage_module1_foo(void); int mypackage_module2_bar(void);
https://simba-os.readthedocs.io/en/11.0.0/user-guide/applications-packages-and-modules.html
CC-MAIN-2019-30
en
refinedweb
I? I did anything wrong here? I am pretty sure that my thinger.io setting is correct, as I am able to run the same code on my linkitone and work perfectly. thankyou all here. Ivan code: #include <BridgeSSLClient.h> #include <ThingerYun.h> #define USERNAME "myusername" #define DEVICE_ID "mydeviceid" #define DEVICE_CREDENTIAL "mydevice_credential" ThingerYun thing(myusername, mydeviceid, mydevice_credential); void setup() { pinMode(LED_BUILTIN, OUTPUT); // initialize bridge Bridge.begin(); // pin control example (i.e. turning on/off a light, a relay, etc) thing["led"] << digitalPin(LED_BUILTIN); // resource output example (i.e. reading a sensor value, a variable, etc) // more details at } void loop() { thing.handle(); } Seeeduino Cloud works with Thinger.io? Arduino, Seeeduino Serials and mutants. Share your problems and experence on arduino compatible board such as seeeduino/stalker, etc. Moderators: violet, jessie Post Reply 1 post • Page 1 of 1 Post Reply 1 post • Page 1 of 1
https://forum.seeedstudio.com/viewtopic.php?p=25872
CC-MAIN-2018-39
en
refinedweb
. Introduction In this tutorial we will check how to setup a simple Flask server on the Raspberry Pi and send HTTP POST requests to it from the ESP32. Then, we will access the body of the request on the Raspberry Pi. If you are looking for a similar tutorial but to send HTTP GET requests from the ESP32 instead, please check here. For a detailed tutorial on how to send HTTP POST requests from the ESP32, please consult this previous post.. The Python code The Python code for this tutorial is very similar to what we have been covering before. As usual, we start by importing the Flask class from the flask module, to setup the whole HTTP server. Additionally, we will need to import the request object from the flask module, so we can later access the body of the request sent by the client. After the imports, we need to create an instance of the Flask class. from flask import Flask, request app = Flask(__name__) Now that we have our app object, we can proceed with the configuration of the routes of the server. We will have a single route called “/post”, since we are going to test it against POST requests. Naturally, you can call it what you want, as long as you use the endpoint you defined in the client code. Additionally, we will also limit the actual HTTP methods that this route accepts. You can check a more detailed guide on how to do it on this previous post. This will ensure that the route handling function will only be executed when the client makes a POST request. @app.route('/post', methods = ["POST"]) def post(): The route handling function will be very simple. We will just access the body of the request to print it and then return an empty answer to the client. Note that it is common that the answer of a POST request does not contain any content, since a success HTTP response code is, in many cases, enough for the client to know the operation was executed. So, to get the actual request body, we simple need to access the data member of the request object. We will simply print the result so we can later confirm it matches the content sent by the client. After that, as already mentioned, we return the response to the client, with an empty body. print(request.data) return '' To finalize and to start listening to incoming requests, we need to call the run method on our app object. As first input we pass the ‘0.0.0.0’ IP, to indicate the server should be listening in all the available IPs of the Raspberry Pi, and as second input we pass the port where the server will be listening. The full Python code for the Raspberry Pi is shown below. from flask import Flask, request app = Flask(__name__) @app.route('/post', methods = ["POST"]) def post(): print(request.data) return '' app.run(host='0.0.0.0', port= 8090) The Arduino code We start with the includes of the libraries we will need to both connect the ESP32 to a wireless network and also to make the HTTP POST requests. These are the Wifi.h and the HTTPClient.h libraries, respectively. We will also need to declare the credentials to connect to the WiFi network, more precisely the network name and the password. Then, in the Arduino setup function, we take care of connecting the ESP32 to the WiFi network. "); } The HTTP POST requests will be performed on the Arduino main loop function. To be able to perform the requests, we will need an object of class HTTPClient. HTTPClient http; Now, we need to call the begin method on our HTTPClient object, to initialize the request. As input of the method, we need to pass the endpoint to which we want to send the request. The destination endpoint will be composed by the IP of the server, the port where it is listening and the route we want to reach. The port was specified in the Python code and it is 8090. The route is “/post“, which was also specified in the Python code. To get the local IP address of the Raspberry Pi, the simplest way is opening a command line and sending the ifconfig command, as explained in greater detail here. Also, take in consideration that both the ESP32 and the Raspberry Pi need to be connected to the same WiFi network for the code shown in this tutorial to work. http.begin(""); Since we are sending a POST request, we need to specify the content-type of the body, so the server knows how to interpret it. In this introductory example, we will send just a “Hello World” string, which means we can define the content-type as plain text. The content-type is sent in the request as a header, which we can specify by calling the addHeader method of the HTTPClient object. This method receives as first input the name of the header and as second input its value. http.addHeader("Content-Type", "text/plain"); To send the actual request, we need to call the POST method on the HTTPClient object, passing as input the body of the request, as a string. Note that this method returns as output the HTTP response code in case the request is successfully sent. Otherwise, if an internal error occurs, it returns a number lesser than zero that can be used for error checking. int httpResponseCode = http.POST("POSTING from ESP32"); In case of success, we simply print the returned HTTP code, just to confirm that the request was correctly received by the Flask server. Serial.println(httpResponseCode); To finalize, we call the end method on the HTTPClient, to free the resources. http.end(); //Free resources You can check the final code below. Note that it includes some additional checks to ensure we are sending the request only if the ESP32 is still connected to the WiFi network, and also to confirm the HTTP Post request was sent with success and no internal error has occurred. ){ //Check WiFi connection status HTTPClient http; http.begin(""); http.addHeader("Content-Type", "text/plain"); int httpResponseCode = http.POST("POSTING from ESP32"); //Send the actual POST request if(httpResponseCode>0){ Serial.println(httpResponseCode); }else{ Serial.println("Error on sending POST"); } http.end(); //Free resources }else{ Serial.println("Error in WiFi connection"); } delay(10000); //Send a request every 10 seconds } Testing the code To test the code, first run the Python code to start the server. After that, compile and upload the Arduino code to the ESP32, using the Arduino IDE. Once the procedure finishes, open the Arduino IDE serial monitor. After the ESP32 is connected to the WiFi network, it should start sending the requests to the Flask server and printing the result status code, as shown below at figure 1. Figure 1 – HTTP status code returned by the server to the ESP32. If you go back to the Python prompt where the Flask server is running, you should get a result similar to figure 2, where it shows the messages sent by the ESP32 getting printed. Figure 2 – ESP32 messages printed on the Flask server, running on the Raspberry Pi. Related posts - Raspberry Pi Flask: Receiving HTTP GET Request from ESP32 - Raspberry Pi 3 Raspbian: Exposing a Flask server to the local network - Raspberry Pi 3: Getting the local IP address - Raspberry Pi 3 Raspbian: Running a Flask server - ESP32: HTTP GET Requests - ESP32 Arduino: HTTPS GET Request - ESP32 Arduino: HTTP POST Requests to Bottle application - ESP32: HTTP POST Requests 2 Replies to “Raspberry Pi 3 Flask: Receiving HTTP POST Request from ESP32” Hello thank you so much for this, really helping out my home project. I have one question. I’m trying to take the “POSTING from ESP32” and putting it into a text file. I can open a text file and write my own string to it, but cant get the “POSTING from ESP32” to go into the text file. What do I need to put into the f.write() to make this happen? Thank you LikeLiked by 1 person Hi, You’re welcome 🙂 That’s weird, writing to a file should be very simple in Python. Are you opening the file in write mode, when calling the open function? Also, are you closing the file at the end? I think this should be enough: f = open(“yourFile”, “w”) f.write(request.data) f.close() What happens to the file you try to write? Does it stay empty? Best regards, Nuno Santos
https://techtutorialsx.com/2018/06/21/raspberry-pi-3-flask-receiving-http-post-request-from-esp32/
CC-MAIN-2018-39
en
refinedweb
Write a program that prompts the user to input a decimal integer and display its binary equivalent. #include <stdio.h> int main() { int number, n, remainder, binary = 0, place = 1; printf("Enter a number :"); scanf("%d", &number); n = number; while (n > 0) { remainder = n % 2; binary += remainder * place; place *= 10; n /= 2; } printf("Binary equivalent of %d is %d", number, binary); return 0; } Enter a number :12 Binary equivalent of 12 is 1100
http://cprogrammingnotes.com/question/decimal-to-binary.html
CC-MAIN-2018-39
en
refinedweb
Two numbers are entered through the keyboard. Write a program to find the value of one number raised to the power of another. #include <stdio.h> int main() { int i, base, power, result = 1; printf("Enter a number :"); scanf("%d", &base); printf("Enter the power it raised to :"); scanf("%d", &power); for (i = 1; i <= power; i++) { result *= base; } printf("The result is %d", result); return 0; } Enter a number :6 Enter the power it raised to :4 The result is 1296
http://cprogrammingnotes.com/question/power.html
CC-MAIN-2018-39
en
refinedweb
Summary Geometry objects define a spatial location and an associated geometric shape. Geometry (geometry, When you set the output parameter of a geoprocessing tool to an empty Geometry object, the tool will return a list of Geometry objects. import arcpy # Run the Copy Features tool, setting the output to the geometry object. # geometries is returned as a list of geometry objects. geometries = arcpy.CopyFeatures_management("c:/data/streets.shp", arcpy.Geometry()) # Walk through each geometry, totaling the length length = 0 for geometry in geometries: length += geometry.length print("Total length: {0}".format(length))
http://pro.arcgis.com/en/pro-app/arcpy/classes/geometry.htm
CC-MAIN-2018-39
en
refinedweb
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7) Gecko/20040707 Firefox/0.9.2 Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7) Gecko/20040707 Firefox/0.9.2 The first bug is that firefox stores the cache data in a known location. This location depends partially on the OS, but in windows 2000 the path look as following: C:\Documents and Settings\Administrator\Application Data\Mozilla\Firefox\Profiles\default.nop\Cache. There are 3 files in this directory that have known names, _CACHE_001_, _CACHE_002_, and _CACHE_003_. The second bug is the famous NULL bug. By submiting the following URI ":\Documents and Settings\Administrator\Application Data\Mozilla\Firefox\Profiles\default.nop\Cache\_CACHE_001_" we cause firefox to pop up a download window, but since we want to cause firefox to execute the javascript code inside one of the CACHE files we can just do the following: ":\Documents and Settings\Administrator\Application Data\Mozilla\Firefox\Profiles\default.nop\Cache\_CACHE_001_%00.txt" or ":\Documents and Settings\Administrator\Application Data\Mozilla\Firefox\Profiles\default.nop\Cache\_CACHE_001_%00.html" Firefox thinks that we are calling a html/text file, yet it still only open the cache file without the .html. The combination of these 2 bugs could lead to the following situations: If someone finds a way to redirect a user in Internet Zone to a file:// location, it is possible to execute code on a victim in Local Zone and thus compromising the victims computer. If the attacker can make a user visit his website (to store the malicious code in one of the cache files) and then make him go to one of the 2 urls shown above, the attacker can take over the victims computer. I hope you take this seriously, it's not as bad as the Internet Explorer vulnerabilities, but it's close. - Mindwarper - mindwarper@mlsecurity.com - Reproducible: Always Steps to Reproduce: Clearly explained in Details Section. Actual Results: I was able to execute javascript in local zone. Expected Results: Software should create an unkown path to the cache directory, and ignore %00 when reading local files. openning bug since it was disclosed by the reporter deleting useless URL (it's not required, please only fill in if it's useful as a testcase or similar). The profile directory name contains three random characters. Guessing them would not be as trivial as you suggest. Web content is not allowed to open urls "local" files don't have any special powers that web content doesn't have, except the ability to open other urls The fixed-name cache files contain random bits of different files, it would be extremely hard to get your specific attack file to come up first against a random victim. The null-in-filename bug definitely needs to be fixed, but I don't see how it's exploitable on its own. It's also not firefox-specific: reassigning This vulnerability also appears in other protocols that are not http. For example, you can easily tell the difference between the following two results: and Also while testing this I found out that when requesting user:pass@domain through firefox, firefox does not hash or hide the pass field, instead it leaves it in plain text allowing anyone with access to the computer to view other users's ftp user/pass. Created attachment 153078 [details] [diff] [review] Patch for suspicious file URLs This patch makes unix versions of Mozilla refuse file URLs generating suspicious filenames: - including a null character (from %00) - including /../ or trailing /.. (from /..%2f, /.%2e etc--URL parsing does not grok these encoded sequences) - not starting with a slash (including empty filenames) Cases #2 and #3 are not known to have any dangerous consequences (and #3 should never happen) but we all know the rule: better safe than sorry. I do not dare to write a similar piece of code for Windows because their interpretation of filenames is too magical for me (see canonical_filename() in Apache). Other platforms may need other specific checks. I've just observed a really odd side-effect of %00 in a file URL: I've got a text file called /blah/blah (no extension). is displayed as text/plain but (still no extension) is displayed as text/html! That patch isn't enough. And I'd argue it's the wrong approach. We should fix the problem at/before the call to NS_UnescapeURL not after it's munged the string. Windows goes through net_GetFileFromURLSpec (nsurlhelperwin.cpp) for people playing along at home: > necko.dll!net_GetFileFromURLSpec(const nsACString & aURL={...}, nsIFile * * result=0x00ed24cc) Line 133 C++ necko.dll!nsStandardURL::GetFile(nsIFile * * result=0x0012fe40) Line 2223 C++ necko.dll!nsFileChannel::GetClonedFile(nsIFile * * result=0x0012fe5c) Line 84 C++ necko.dll!nsFileChannel::EnsureStream() Line 99 C++ necko.dll!nsFileChannel::AsyncOpen(nsIStreamListener * listener=0x00eb7870, nsISupports * ctx=0x00ed2930) Line 455 C++ TestProtocols.exe!StartLoadingURL(const char * aUrlString=0x00364928) Line 685 + 0xf C++ TestProtocols.exe!main(int argc=0x00000003, char * * argv=0x003648d8) Line 835 + 0x7 C++ TestProtocols.exe!mainCRTStartup() Line 400 + 0xe C kernel32.dll!GetCurrentDirectoryW() + 0x44 TestProtocols.exe -verbose "" Created attachment 153100 [details] [diff] [review] Prevent loading of ftp:// URI's with %00 in the path There's also code that checks for \n and \r when creating FTP URL objects (in nsFtpProtocolHandler::NewURI), but it does that w/o unescaping them. Should we unescape there too, and check for embedded nulls there as well? + // test for bad stuff: missing leading /, nulls, /../ Why does / or /../ matter in a file url? > We should fix the problem at/before the call > to NS_UnescapeURL not after it's munged the string. Checking after NS_UnescapeURL (or any transformation in general) is good because it no bad things can reappear during the transformation. (Look at the infamous IIS "Unicode bug": they checked URI before the last transformation from UTF-8 to ASCII and that transformation (due to sloppy coding accepting illegal UTF-8 sequences, indeed) was able to introduce bad things that should have already been dealt with (/../)). It might make some sense to do these checks at the end of NS_UnescapeURL. Unfortunately, there are two problems: - there are different policies for different protocols/platforms (POSIX filesystem API cannot handle \0, Win32 filesystem API should be protected from \0 as well as magical device names (*) or god knows what else, FTP cannot handle \r and \n and \0), - the interface of (most variants of) NS_UnescapeURL cannot report any errors to the caller, (*) Try this on a Windows machine: <img src="con.png"> BTW: A comment in nsEscape.h reads "Expands URL escape sequences... beware embedded null bytes!" Very funny... > Prevent loading of ftp:// URI's with %00 in the path... The code in netwerk/protocol/ftp is quite messy IMHO. The check in nsFtpProtocolHandler::NewURI is (almost) pointless as it checks the URI before it is unescaped (see above). Moreover, usernames and passwords and should be checked for nulls too (to make things worse, they are checked for \r and \n in UCS-2 form before they are converted to ASCII with AppendWithConversion()...it appears untranslateable chars are converted to a rather bening '.' but it is still ugly). > Why does / or /../ matter in a file url? It is "a *missing* leading / or ..." Anyway, such things should never appear in the resulting filename. This is a proactive measure. E.g. one day, someone might decide to divide file:-URL namespace into multiple mutually untrusting domains or something similar and such a check will stop attempts to fool Mozilla with things like /.%2e/. (Hmm...I guess it might make sense to forbid /./ as? (In reply to comment ? Darin, I guess the question is do we want to skip control characters, or flag URIs with such characters as invalid and refuse to do anything with them? I'd vote for the latter. Yeah, you make a good point. Rejecting these URLs is probably best. Any update on this bug? It would be nice if we could get a fix in soonish here... Created attachment 154673 [details] [diff] [review] Prevent creation of ftp: URI's with nulls in them Comment on attachment 154673 [details] [diff] [review] Prevent creation of ftp: URI's with nulls in them >Index: netwerk/protocol/ftp/src/nsFtpProtocolHandler.cpp > nsFtpProtocolHandler::NewURI(const nsACString &aSpec, ... >+ char* fwdPtr = spec.BeginWriting(); nit: |char *fwdPtr| sr=darin Aren't we unescaping twice now? Also, why just ftp? Isn't this a problem in general? For the record, IE cuts an FTP URL at the %00 mark, and we'll refuse to recognize it as a valid URL (i.e. a link with a bad FTP URL in it won't show up as a link, and won't be clickable). *I* doubt that would affect any real usage. Comment on attachment 154673 [details] [diff] [review] Prevent creation of ftp: URI's with nulls in them r=bzbarsky (For the curious, the answers are: 1) Yes, but we unescape on a copy the first time and don't use it thereafter. 2) For other protocols (eg HTTP), %00 is valid in a URI.) I do think that file: has the same problem (that's why I put it into the summary :) ) > Win32 filesystem API should be protected from > \0 as well as magical device names (*) > > (*) Try this on a Windows machine: <img src="con.png"> If anyone wants to do the magical device name protection, there is some code for it at: At bug 103468 comment #36 I did some testing for control characters in filenames and found that Windows seems to protect itself from them. ftp: fix checked in on the trunk. Created attachment 154726 [details] [diff] [review] FTP patch for 1.4 branch Comment on attachment 154673 [details] [diff] [review] Prevent creation of ftp: URI's with nulls in them a=asa for the 1.7.2 mini-branch and the aviary branch. Comment on attachment 154726 [details] [diff] [review] FTP patch for 1.4 branch a=blizzard for 1.4 ftp: fix landed on all sorts of branches (aviary, 1.7, 1.7.2) Can someone supply a testcase with details of expected behavior. I just ran this: ":\Documents and Settings\Administrator\Application Data\Mozilla\Firefox\Profiles\default.nop\Cache\_CACHE_001_%00.html" It launched a testcase from another security bug that I had just verified. Should that have happened? Note: The Common Vulnerabilities and Exposures project (cve.mitre.org) has assigned the name CAN-2004-0760 to this issue. (In reply to comment #26) > It launched a testcase from another security bug that I had just verified. > Should that have happened? It should have. Sort of. This is the "expected" wrong behaviour: it interprets the cache file as HTML and runs whatever JS it finds there. A simpler and more deterministic test is as follows: 1. create evil.txt containing the following text <html><body onload="alert('Gotcha!')"></body></html> 2. open it will display the text, ok 3. open if a "Gotcha!" alert pops up then you have a problem (In reply to comment #28) > 3. open > if a "Gotcha!" alert pops up then you have a problem No alert, only display of. But that is the error. If comment 18 states that a file URL with %00 in it is valid, I EXPECT that I get a file not found error for because that file doesn't exist (or are not allowed due to file system restrictions) and I don't want Mozilla to fix up that url internally to and display the content without changing the (valid) URL in the address bar. (In reply to comment #28) > It should have. Sort of. This is the "expected" wrong behaviour: it interprets > the cache file as HTML and runs whatever JS it finds there. note that the patch here does not fix file: > 3. open > if a "Gotcha!" alert pops up then you have a problem for some definition of "problem", since the only issue is that the url shown in the urlbar does not quite match the content. (In reply to comment #29) > I don't want Mozilla to > fix up that url internally to and display the content > without changing the (valid) URL in the address bar. that "fixup" is not done intentionally, it's a side-effect of how this code stores strings and does unescaping, I'm sure. from the following: A simpler and more deterministic test is as follows: 1. create evil.txt containing the following text <html><body onload="alert('Gotcha!')"></body></html> 2. open it will display the text, ok ---yes, opens the text file as is--- 3. open if a "Gotcha!" alert pops up then you have a problem ---a file not found error message. no file type conversion--- On Linux, I am seeing this on Firefox 0.9+ from today(0804) and the latest Firefox 0.9.3 bits. Mac and Windows 0.9+ builds looked good. just tested with the ftp test in comment #3 and this passed on linux ff 0.9.3 (In reply to comment #32) Note: your test is for file URIs (how did this bug morph?). Anyway, the word from jst is (transcribed from #developers on IRC): Jul 29 22:14:20 <caillon> jst, yt? Jul 29 22:17:18 <jst> caillon: y Jul 29 22:18:19 <caillon> jst, is 250906 ready for landing? Jul 29 22:18:41 <caillon> jst, (comment 19 and 20 seem to say no...) Jul 29 22:21:06 <jst> caillon: Yeah, the ftp: part of that bug is ready... we kinda don't care about file: for now, since you can't link to that from web content anyways Jul 29 22:21:21 <jst> caillon: that part should of course be fixed too, at some point Jul 29 22:21:38 <caillon> jst, ok that's what i thought. Jul 29 22:21:46 <caillon> jst, i just wanted to make sure before i started backporting it The NULL bug is still present in Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0 This is a security bug, so why has it been fixed, you guys? I think %00 should be omitted in every URL, unless there's a legitemate use for it. Just my 2 euro cents mass reassigning to nobody. Mavericks, are you interested in taking a crack at this bug? It's not clear to me what part was fixed and what's left. Tested as per comment #28 on FF 18.0.2 on Win Vista Basic(x86) file://<path>.txt shows text file as is file://<path>.txt%00.html does nothing Created attachment 725268 [details] [diff] [review] Patch that prevents null(%00) and addresses windows specific issues in file url Builds on top of Pavel's patch 153078 Compiles and pending testing. Some testcases are at and few more mentioned in comment #20 Comment on attachment 725268 [details] [diff] [review] Patch that prevents null(%00) and addresses windows specific issues in file url Review of attachment 725268 [details] [diff] [review]: ----------------------------------------------------------------- Mostly seems good, though it seems we're only fixing checking for "." and ".." here, not %00? I'm also not the right reviewer for the forbidden name stuff. Given that this bug already has patches that landed in 2004 in Firefox 0.9 :) we should definitely move this new patch into a new bug (please CC me on it). You also need a test--an xpcshell test shouldn't be too hard to write, and it looks like netwerk/test/unit/test_bug396389.js has the basic infrastructure. ::: netwerk/base/src/nsURLHelperUnix.cpp @@ +82,5 @@ > + // test for bad stuff: missing leading /, /../, /./ > + nsACString::const_iterator iter, end; > + path.BeginReading(iter), path.EndReading(end); > + int slashdotdot = 0; > + if (iter == end || *iter != '/') return NS_ERROR_MALFORMED_URI; put return statements on a new line. @@ +85,5 @@ > + int slashdotdot = 0; > + if (iter == end || *iter != '/') return NS_ERROR_MALFORMED_URI; > + for (; iter != end; ++iter) { > + if (*iter == '/') { > + if (slashdotdot == 3 || slashdotdot == 2) return NS_ERROR_MALFORMED_URI; Why do we allow slashdotdot == 1 here, too--is it important to allow "//"? @@ +89,5 @@ > + if (slashdotdot == 3 || slashdotdot == 2) return NS_ERROR_MALFORMED_URI; > + slashdotdot = 1; > + } > + else if (*iter == '.') { > + if (slashdotdot > 0 && slashdotdot <= 3) ++slashdotdot; I assume that clamping slashdotdot to 4 here and checking only for 2 or 3 above is so that you only fail for "." and "..", but allow "..." and "....", etc to be valid filenames? If true leave a comment saying that. @@ +93,5 @@ > + if (slashdotdot > 0 && slashdotdot <= 3) ++slashdotdot; > + } > + else slashdotdot = 0; > + } > + //check for /. , /.., etc as filenames comprising of periods only are not allowed Your code appear to allow names of 3 periods or more, so comment wrong? ::: netwerk/base/src/nsURLHelperWin.cpp @@ +94,5 @@ > } > > NS_UnescapeURL(path); > + > + // check for %00 Does this patch in fact check for %00? It seems to be checking mostly for "." and "..", the forbiddenChars checks are only on windows, and even there I don't see '\00' listed as a forbidden char. @@ +114,5 @@ > + else if (*iter == '.') { > + if (slashdotdot > 0 && slashdotdot <= 3) ++slashdotdot; > + } > + else { > + if ( forbiddenChars.FindChar(*iter) != -1 ) return NS_ERROR_MALFORMED_URI; So the 20 lines or so of code here are common across unix/windows except for this check of forbiddenChars. It seems like you could just always check forbiddenChars (the list evaluates to empty on Unix, but it ought to work fine?) and stick this code in some common central location. @@ +126,5 @@ > + // check for \con or \con.xyz > + // CLOCK$ as filename or CLOCK$.txt's allowed on Win Vista > + // XXX move it to proper location for reuse > + static const char* forbiddenNames[] = { > + "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8","COM9", "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7","LPT8", "LPT9", "CON", "PRN", "AUX", "NUL" }; //"CLOCK$" I'm not the right person to know if this magic list is correct. Not sure who the right reviewer is, either--sorry. Ask bsmedberg?
https://bugzilla.mozilla.org/show_bug.cgi?id=250906
CC-MAIN-2017-30
en
refinedweb
Opened 3 years ago Closed 3 years ago #16349 closed defect (fixed) Make UniqueFactory unpickling more flexible Description Currently UniqueFactory's unpickling protocol is to call generic_factory_unpickle(), whose first argument must be an instance of UniqueFactory. However we might want to change the object in the global namespace, let's say to a function, and then we will not be able to unpickle any thing beforehand ( register_unpickle_override can not help here because the pickle info is (UniqueFactory, generic_factory_unpickle)). Came up in #15289. Change History (9) comment:1 Changed 3 years ago by - Branch set to u/SimonKing/ticket/16349 - Created changed from 05/13/14 15:42:28 to 05/13/14 15:42:28 - Modified changed from 05/13/14 15:42:28 to 05/13/14 15:42:28 comment:2 Changed 3 years ago by - Commit set to 321a9e407ef260269f4d66159a787316440082e3 - Status changed from new to needs_review comment:3 Changed 3 years ago by - Commit changed from 321a9e407ef260269f4d66159a787316440082e3 to 187d1aa8d95cf2b64ab2c45224844a709412127b Branch pushed to git repo; I updated commit sha1. New commits: comment:4 Changed 3 years ago by I had to fix one detail (I made a wrong assumption on the format of _factory_data. comment:5 Changed 3 years ago by Hey Simon, I didn't have a chance to finish it yesterday. I will finish up what I was working on today as an alternative proposal. comment:6 Changed 3 years ago by - Branch changed from u/SimonKing/ticket/16349 to public/pickling/unique_factories-16349 - Commit changed from 187d1aa8d95cf2b64ab2c45224844a709412127b to c7646c1a28493f94a5362212cf8bd089ffce3279 - Reviewers set to Travis Scrimshaw, Simon King Okay I've just put in both versions. I've implemented something similar to register_unpickle_override() (which I've called register_factory_unpickle()). This way we can handle when the factory is removed from the global namespace (such as for name change). If you could check that and agree, then we can set this to positive review. Thanks. New commits: comment:7 Changed 3 years ago by - Status changed from needs_review to positive_review With the current branch, we provide two ways to deal with old pickles of UniqueFactory: If we replace the old factory by something new that has the same name, is in the same module and can process the same input as the UniqueFactory, then nothing more needs to be done (that's my contribution). Moreover, it is possible to override unpickling so that a new callable is used for unpickling even if the old factory is still there (that's your contribution). I think both possibilities make sense. Hence, I complete the positive review. comment:8 Changed 3 years ago by Thank you Simon. comment:9 Changed 3 years ago by - Branch changed from public/pickling/unique_factories-16349 to c7646c1a28493f94a5362212cf8bd089ffce3279 - Resolution set to fixed - Status changed from positive_review to closed Travis, you have been inserted as "Author", but I think you did not provide code. So, I took the liberty to replace your name by mine, and attach a branch. The new doctest demonstrates how to replace a unique factory by unique representation and correctly unpickle. New commits:
https://trac.sagemath.org/ticket/16349
CC-MAIN-2017-30
en
refinedweb
MPI_Accumulate - Accumulates data into a window #include <mpi.h> int MPI_Accumulate(void *orgaddr, int orgcnt, MPI_Datatype orgtype, int rank, MPI_Aint targdisp, int targcnt, MPI_Datatype targtype, MPI_Op op, MPI_Win win) orgaddr - initial address of buffer (choice) orgcnt - number of entries in buffer (nonnegative integer) orgtype - datatype of each buffer entry (handle) rank - rank of target (nonnegative integer) targdisp - displacement from start of window to beginning of target buffer (nonnegative integer) targtype - datatype of each entry in target buffer (handle) op - reduce operation (handle) win - window object (handle) MPI_PUT is a special case of MPI_ACCUMULATE, with the operation MPI_REPLACE. Note, however, that MPI_PUT and MPI_ACCUMULATE have different constraints on concurrent updates. ( End of advice to users.)_WIN - Invalid window. A common error is to use a null window in a call. MPI_ERR_TYPE - Invalid datatype argument. May be an uncommitted MPI_Datatype (see MPI_Type_commit ). combination of datatypes and operations are defined, see MPI-1, section 4.9.2) or one-sided operations where the actions on specific datatpyes have not been implemented yet. MPI_Put(3), MPI_Get(3), MPI_Win_create(3), MPI_Win_start(3), MPI_Win_complete(3), MPI_Win_fence(3), MPI_Win_free(3), MPI_Win_get_group(3), MPI_Win_get_group(3), MPI_Win_wait(3) For more information, please see the official MPI Forum web site, which contains the text of both the MPI-1 and MPI-2 standards. These documents contain detailed information about each MPI function (most of which is not duplicated in these man pages). accumulate.c
http://huge-man-linux.net/man3/MPI_Accumulate.html
CC-MAIN-2017-30
en
refinedweb
Thanks.Vote Up0Vote Down Reply3 years 9 months agoGuestNomanHow can i use JDBC with MYSQL in a JSP page ?? But you need to understand them -- along with object-oriented concepts, they cannot be underestimated as to their importance to understanding how to program.Vote Up0Vote Down Reply21 days 13 hours agoGuestEricYes How does the axiom of regularity make sense? asked 3 years, 7 months ago viewed 27370 times active 10 months ago Blog Exploring the State of Mobile Development with Stack Overflow Trends Stack Overflow Official App launches on both have a peek here Check this in ur code:- Class.forName("com.mysql.jdbc.Driver"); con=DriverManager.getConnection("jdbc:mysql://localhost:3306/karthicraj","mysql","mysql"); then u run it will give result Same code: ---------- /*import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.sql.*; import java.sql.Connection.*; public class EmpDetail extends Need two // !Vote Up0Vote Down Reply3 years 6 months agoGuestKumail HaiderHello. Java JDBC connection exampleCode snippets to use a JDBC driver to connect a MySQL database. Links and Literature Appendix A: Copyright and License MySQL and Java JDBC. Java JDBC Create a Java project and a package called de.vogella.mysql.first. Create the following class to connect to the MySQL database and perform queries, inserts and deletes. can u make same tutorial for android ? This example shows how you can obtain a Connection instance from the DriverManager. It's better let server manage it. I am really stuck on this matter. How To Connect Mysql Database In Java Using Eclipse Introduction to MySQL 3. If it is not present, you can properly output a message for the user "I am sorry, you want me to connect to this f… DB, but I don't even have finish now you may add jar file... But i was looking for any tutorial that does JDBC connection without using ANY IDE.Actually i have a case where i don't have any IDE, all i have is JDK and Note : If you are using Java 7 then there is no need to even add the Class.forName("com.mysql.jdbc.Driver") statement.Automatic Resource Management (ARM) is added in JDBC 4.1 which comes by default In this example, we are going to use root as the password. Jdbc:mysql://localhost Contact Sales USA/Canada: +1-866-221-0634 (More Countries ») © 2017, Oracle Corporation and/or its affiliates Products Oracle MySQL Cloud Service MySQL Enterprise Edition MySQL Standard Edition MySQL Classic Edition MySQL MySQL JDBC driver To connect to MySQL from Java, you have to use the JDBC driver from MySQL. Check output consolecom.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failureThe last packet sent successfully to the server was 0 milliseconds ago. Execute a query: Requires using an object of type Statement for building and submitting an SQL statement to the database. Mysql Jdbc Url S. Mysql Jdbc Driver Download First config the context.xml (if you are using tomcat) like this: Not the answer you're looking for? It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party. S. more stack exchange communities company blog Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and Mysql Jdbc Driver Maven The MySQL JDBC driver is called MySQL Connector/J. PREV HOME UP NEXT Related Documentation MySQL Connector/J 5.1 Release Notes Download this Manual PDF (US Ltr) - 479.0Kb PDF (A4) - 478.9Kb HTML Download (TGZ) - 119.5Kb Specify to the DriverManager which JDBC drivers to try to make Connections with. Check This Out Creating statement... create database sonoo; use sonoo; create table emp(id int(10),name varchar(40),age int(3)); Example to Connect Java Application with mysql database In this example, sonoo is the database name, root is the username Jdbc Connection Java Code Add that jar into the buildpath. Tags : jdbc mysqlShare this article onTwitterFacebookGoogle+ About the Author mkyong Founder of Mkyong.com, love Java and open source stuff. Most often, using import java.sql.* will suffice. It is built on WordPress, hosted by Liquid Web, and the caches are served by CloudFlare CDN. Mkyong.com is created, written by, and maintained by Yong Mook Kim, aka Mkyong. No Suitable Driver Found For Jdbc:mysql i have correct that error myself.. How is temperature defined, and measured? Star crossed lovers XP PCs in company network Fan and heatsink - suck or blow? About this website Support free content Questions and discussion Tutorial & code license Get source code 7. this contact form Open a connection: Requires using the DriverManager.getConnection() method to create a Connection object, which represents a physical connection with the database. This will show you how to open a database connection, execute a SQL query, and display the results. vogella GmbH training and consulting support TRAINING SERVICE & SUPPORT The vogella company provides comprehensive training and education services from experts in the areas of Eclipse RCP, Android, Git, Java, Privacy Policy) Sample Code This sample example can serve as a template when you need to create your own JDBC application in the future. import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; Connection conn = null; ... You can simply use JNDI. Content reproduced on this site is the property of the respective copyright holders. I had to search a lot to find how to "install" or where to put this JDBC driver Jar file. If testing this code, first read the installation section at Chapter 3, Connector/J Installation, to make sure you have connector installed correctly and the CLASSPATH set up. Can a dual citizen disregard border controls? Links: front page me on twitter search privacy java java applets java faqs misc content java source code test projects lejos Perl perl faqs programs perl recipes perl tutorials Unix After searching the internet for 6 Hours it stranded upon this. Clean up the environment: Requires explicitly closing all database resources versus relying on the JVM's garbage collection. Make sure to download a correct MySQL jar and place it in your Tomcat's lib/ directory (or alternatively your WAR's WEB-INF/lib). Links and Literature MySQL homepage Download link for MySQL 7.1. Golf a Custom Fibonacci Sequence Boolean switch with a third state Use color in verbatim environment How long is my number? finish now you may add jar file...
http://themotechnetwork.com/mysql-jdbc/com-jdbc-mysql-driver-class.html
CC-MAIN-2017-30
en
refinedweb
Delorean 0.2.1 library for manipulating datetimes with ease and clarity Delorean: Time Travel Made Easy Delorean is a library for clearing up the inconvenient truths that arise dealing with datetimes in Python. Understanding that timing is a delicate enough of a problem delorean hopes to provide a cleaner less troublesome solution to shifting, manipulating, and philsophy. Pretty much make you a badass time traveller. Getting Started Here is the world without a flux capacitor at your side: from datetime import datetime from pytz import timezone EST = "US/Eastern" UTC = "UTC" d = datetime.utcnow() utc = timezone(UTC) est = timezone(EST) d = utc.localize(d) d = est.normalize(EST) return d Now lets warm up the delorean: from delorean import Delorean EST = "US/Eastern" d = Delorean(timezone=EST) return d Look at you looking all fly. This was just a test drive: check out out what else delorean can help with below. - Author: Mahdi Yusuf - License: MIT license - Package Index Owner: myusuf3 - DOAP record: Delorean-0.2.1.xml
https://pypi.python.org/pypi/Delorean/0.2.1
CC-MAIN-2017-30
en
refinedweb
Ecuador - Results of the new law Positive Over 3,600 “outsourcing” companies have closed. About 200,000 public and private workers changed from outsourced to permanent jobs (although in many cases, only for one year). Thousands of workers /Global Unions.” Among the many principles: “Agency workers must be specifically guaranteed the right to join a union with a collective bargaining relationship with the user enterprise and be part of a bargaining unit comprising direct employees of the user enterprise and/ to Companies that demand ISO 9000 Companies whose competitors are seeking this certification. Companies with geographical and global operations Companies whose parental companies need this certification. WHOM ISO DOES NOT HELP: Companies that see/SOCIALISM: The private enterprise does not contribute to the economy and is entirely controlled by the government!!! No scope for Entrepreneurship !!! MIXED ECONOMY- Private & Public Sector Ex India. Public Sector Units take care of manufacture and sale of / and improving the quality of vocational education and training system. It proposed to launch a major “National Skills Development Mission” to improve the public sector skill development infrastructure and promote private-public partnership in the field. The programme was to support private/requirements. Problems of Public Sector Enterprises : Price policy of public enterprise As regards the pricing policy of public sector enterprise, we can find 2 different approaches The public utility approach / ) External reserve ($ billion) 1998 crisis GKO, government GKO holders (banks) 2010 2008 crisis Loans, global crisis and banks and enterprises Debtors (banks, enterprises) 500800 Comparison of crisis in 1998 and 2008 88 Financial deficitsFinal debtors 1998 crisis Large deficitsgovernment 2008 crisis Stable surplus, austerity economic policy, sterilization policy Enterprises and banks (private but semi- government, government) Comparison of three crises 199219982008/2009 Political crisisYes No Decline of/ E1) Production globalization. - (E2) Market fluctuations for resources and rates of exchange. - (Eco4) Water basins and other environment /enterprises and foreign research centers - Part of activities financed by public-private partnership - Number of commercialized and patented developments (including experimental- industrial samples) for key products (services) directions. - Quantity of projects realized jointly with enterprises and foreign research centers - Part of activities financed by public-private/ as production costs driven down HIGHLOWHIGHLOW 113 iv. Opportunity Areas for urban slum sanitation Total global slum population without improved sanitation estimated to be some 800 million people: Conventional sewered networks/. Greater flexibility in management models (associations of service providers, mixed private- public enterprises, franchising to the private sector etc.). Group connections. Learning projects and alliances. Multiple use approaches. Minimize water consumption. Municipal water companies / Public/Private/Hybrid) ▪ Software as a Service (SaaS). ▪ IBM Signature Selling Method (SSM™) Professional, (B2B), Statement of Work (SoW) Development, IBM International Customer Agreement (IICA) ▪ Sold enterprise solutions (CRM/ ERP/ASP) and professional services including change management, re-engineering strategy and / the Cloud?” Cloudbook Journal, Vol 3 Issue 1, 2012 “The CIO’s Role in Going Global.” Enterprise Efficiency, June 2012 "I have known Preston for over thirty years during which time I have / -foundation-complete-certification-kit-fourth-edition-study-guide-ebook-and-online-course.html IaaS - Cloud management challenges 1 Capacity management is a challenge for both public and private cloud environments because end users have the ability to/ebook-and-online-course.html FUJITSU Cloud IaaS Trusted Public S5 1 FUJITSU Cloud IaaS Trusted Public S5 is a Fujitsu cloud computing platform that aims to deliver standardized enterprise- class Cloud computing#Public cloud|public cloud services globally. https/ . As Most medium and large-scale enterprises (SMEs) have extensive education and training facilities and centres for research and innovation. So, that the potential partnership between Public and private sectors, will hold opportunities to develop training courses to Public sector employees.As Most medium and large-scale enterprises (SMEs) have extensive education and training facilities and centres for research and innovation. So, that the potential partnership between Public and private sectors, will hold/ a number of products Adverse changes in climatic conditions, both short-term and long-term (global warming and associated increase in arid and semi-arid land, growing water scarcity, instability, weather conditions, etc.) / to biotic and abiotic factors and product quality 1 Conducting researchreportNIO, universities, international centers, private companies 2014-2030RB, international grants. funds of enterprises 2 Attracting leading foreign scientists to implement R & D The report, publication in the / Economic Impact Internal to the firm, industry or sector Broader economic impacts Social impacts Enhancing efficiency and effectiveness of state enterprises Reducing the public sector borrowing requirement Ensuring wider participation in the South African economy Accessing globally competitive technology Attracting foreign direct investment and portfolio inflows Mitigating possible negative social impacts arising from restructuring Creating effective market structures in the sectors currently dominated by/ ENTREPRENEURSHIP34 Brokerage Models SKOLL CENTRE FOR SOCIAL ENTREPRENEURSHIP35 Policy and Social Enterprise The formation of a Social Enterprise Unit within DTI (2002), now incorporated within the/and programs Bring together private and public social investors with social entrepreneurs and social purpose organizations Created in tandem with ACCESS (Keystone) Ratings agency designed to give SEs recognition under a common, global profiling system SKOLL CENTRE FOR SOCIAL ENTREPRENEURSHIP51 Quality assurance and/ public sector debt burden, raise efficiency of public sector fixed investment Improve service delivery (higher efficiency at lower cost) Modernise SA port system to be globally competitive in terms of planning operations,systems and structures Leads to private sector participation in operations via concessions that retain public ownership and harness private investment and/that flows from private sector participation and extend beyond the gains from commercialisation of state owned enterprises. To drive / million/ 1.138 5 = $5,172 million (The cost of capital for Global Crossing is 13.80%) –The probability that Global Crossing will not make it as a going concern is 77%. –Expected Enterprise value today = 0.23 (5172) = $1,190 million 76 Relative valuation /– 0.11 (0)= 12.88% $0.521 (1-.1288) = $0.454 million 124 II. Private company sold to publicly traded company The key difference between this scenario and the previous scenario is that the seller of the business is not diversified but the buyer is (or at / and Tenant Consolidation Simple Management, Global Dedupe Full Automation & Orchestration Suite APIs to provision, monitor and bill Your Files. Your Cloud. enabling the enterprise cloud IT and user services transformation an innovative two-tier, global and unified file services architecture a private SaaS platform you deploy and/ preview of 50+ document formats CTERA Agent Browse Online Share this file Copy public link Version History An Intuitive & Easy- to-Use Interface 47NDA CONFIDENTIAL An Intuitive/ the European supranational organizations including EU, EIB and EBRD Global capital markets should be tapped in an /public and private sectors supporting development of “new” member countries Recently, MF market in Europe shows the tendency to,,,,, In European countries, MF activities are focused on,,, An important element of EC-wide SME policy: Competitiveness and Innovation Framework Program, Joint European Resources for Micro to Medium Enterprises (JEREMIE) Economic/financial development Active public/ Public sector Private economy Social and solidarity economy (SSE) Based on Westall, A (2001) Value-Led, Market-Driven: social enterprise solutions to public policy, London: IPPR Grants / no owners shares / private owners Relationship to private capital Trustor + public benefit Member + public benefit Member + investor benefit Member Benefit Mutual benefit Private (corporate) investor benefit State / public/ (grown from 23.8% to 27.3% of the global market). Evidence of a paradigm shift 915 million people get / environment and safety on the job. 4. PRIVATIZATION. Selling of state-owned enterprises, goods and services to private investors. This includes banks, key industries, railroads, highways, electricity, schools, hospitals and even /public goods by defining traditional state and local governance mechanisms as non-tariff barriers to trade. Contradictions between private profit and public interest appear at the sub-national level but their resolution is engaged at the global level between private investors and/ Remittances from Vietnamese Overseas Other foreign capital (foreign private investment) Proper Capital of population and enterprises Capital from the State Budget: The total budget/ in total loans: + Non-public sectors account for 47% of the total credit + State-run businesses occupies 39% + Enterprises with foreign investment occupies 14%. /firmly maintain the stability of global and regional economy so as to minimize possible financial crises’ impacts on financial market and growth of poor countries. / :/ and quality of healthcare and affordable housing Ensuring public safety and security Enhancing the development and promotion of Malaysian culture, arts and heritage NATIONAL MISSION, 2006-2020 Investment Incentives . . . Pioneer status or Investment tax allowance for manufacturing companies Incentives for small- & medium-scale enterprise Training and R&D Grant Incentives for high technology companies Incentives for strategic projects Incentives for R&D SUPPORTING PRIVATE/global market linkages PUBLIC-PRIVATE/ Platform… and we sell it to very large Global Enterprises like UBS, Pfizer, Visa, and others The Agility Platform is a Cloud Management Platform… and its used to deploy and manage enterprise-grade platforms and applications portfolios/: Agility Platform is the only enterprise grade cloud management platform that: Automates the deployment and management of enterprise applications across private, public and hybrid cloud environments Enforces governance, compliance and security across the full lifecycle of/ & export consortia Industrial Upgrading and Modernization Policy Creation and Development of Enterprises through special programs EDIP, ICT services Upgrading & Restructuring pilot projects and building national consulting capabilities Tools and Services Investment planning, technological upgrading and innovation Fostering Inter-Firm Partnerships and Cooperation Public Private and Business Partnerships link local industries to global value chains Clusters, Business Linkages and Export Consortia Creation/ global customer Pre-sales, subcontracts, supply Financing and insurance Commercial transactions: ordering, delivery, payment Product service and maintenance Co-operative product development Distributed co-operative working Use of public and private services Business-to-administrations (e.g. customs, etc) Transport and logistics Public/ that has been transformed from raw data to reflect the real dimensionality of the enterprise as understood by the user. The term OLAP (On-Line Analytical Processing) was/ public & private debt- management; tax increases; & political multilateralism (policy consulting with key financial benefactors). “The global currency and banking crises of the 1990s and the investment banking scandal of 2008-2009 demonstrated that the largest and/is the ideology of most Western nations (especially the USA). Its bedrock principles include the importance of private enterprise, free (borderless) trade, minimum government encroachment on the “invisible hand” (impersonal marketplace) of / : Our economy is not binary (public and private); it is plural private – public – collective A plural economy:. allows for choices between private, public or collective control of production and distribution. avoids creating a hierarchy of forms. recognises the specificity of each form of enterprise. an economy with a market vs a market economy. The social economy: where? The social/solidarity economy is emerging as a global movement National, regional, continental/ GCC Steffen Hertog London School of Economics Conventional wisdom on state-owned enterprises (SOEs) Post Washington Consensus: state is allowed to play a role in development, but state ownership of productive assets is still seen as negative global trend of SOE privatization Rentier states perceived as having particularly weak administrative structures and public sectors Algerian, Indonesian, Iranian, Venezuelan, Mexican etc. precedents of bad SOE management/ and remote interfaces, this only works for simple data models – more later Enterprise Java v131013EJB: Session Beans38 Example Session Bean: Bean Class package ejava.examples.ejbsessionbank.ejb; import javax.annotation.*; import javax.ejb.*; import javax.persistence.*;... @Stateless public class TellerEJB implements TellerLocal, TellerRemote { private/tests run by failsafe plugin Enterprise Java Remoting JNDI Tree (Internally Accessible) java:global/ejbsessionBankEAR/ejbsessionBankEJB/TellerEJB!ejava./ of the financial sector to deliver wide access to services like credit and loans, is an important aspect of the joint international efforts to support African women entrepreneurs and those operating in the micro, small and medium enterprises. Finally I will like see more Regional Economic Communities as well private sector and civil society and all stakeholders, have to work together as a team to develop a/ logging common Timber increasingly produced on private and community lands Increased role/voice of civil society, demand for independent verification Increased social demand for tourism, ecosystem services Reduced cost of information: generation and dissemination, expectation of transparence Growing importance of global trade – challenge of keeping rural industry competitive Changing Context for Public Forest Agencies Key Trend (1) Reforming State-Owned Enterprises: Context An issue in E/ public sector. The existing enterprises of private sector are partially or fully sold to private sector. Following measure are adopted through privatization : a) Reducing nos. of industries reserved for public sector from 17 to 8. b) Public sector share are sold to foreign investor, mutual funds etc. c) Sick industries cases are forward to Board of industrial & financial reconstruction. Globalization/ cars, cigarettes, hazardous, chemicals, pharmaceuticals and some luxury items Business houses intending to/ private investment to maintain a 1.68% growth rate. New and added investment cases under the MOEAs oversight will amount to more than NT$1.007 trillion. Foreign trade Maintaining a stable situation: Although the global/Foreign Nationals, Negative List for Investment by Overseas Chinese and Foreign Nationsals Prohibitions: Prohibited investments Enterprises having a negative impact on national security, public order, good morals, or public health. Enterprises in which investment is prohibited by law. / (USD 1.5 trillion) in public and private investment including financial incentives and subsidies. The government has since refuted such claims. Detailed policies with specific targets and guidance across sectors will be released overtime/PUBLIC Theme B: Overseas development and “Going out” ObjectivesGovernment planOutlook 1. Encourage and support PRC companies in “Going out” The government remains committed to helping PRC companies to “Go out” and “Go global” by: -Supporting major PRC enterprises and/ creating a level playing field and providing a long-term business advantage. Apply to bribery of public officials and to private-to-private transactions. Countering Bribery Business principles/’ s family, friends, associates or acquaintances. 2.Political contributions The enterprise, its employees or agents should not make direct or indirect contributions to/effective ’ in its anti-corruption work. One in six surveyed globally thinks that their government actually encourages corruption rather than fighting it/ provide for businesses, include: Linking chamber of commerce, trade associations and enterprises to both national and global trade; Reduced commercial transaction costs; Online trade related information and import/export opportunities; Development and marketing of new products through electronic networks. 1.2.5. ICT for Good Governance ICT is a powerful tool that can be used to facilitate macroeconomic and public sector management. Efforts to stabilize the macroeconomic environment/ owned by members of the public and institutional investors, such as large banks or insurance companies. The directors are paid a salary to run the company and may, or may not, own shares. Selling shares to the public means that this type of company can raise large amounts of money to expand or develop the enterprise. ScenarioCriteriaTasks 13456789 1011121314151617181920 2 Private Co-Operative - Two variations on/ or no connection to any other internal systems The Internet is the public, global network of networks which is based on the Internet Protocol (IP) and related standards Designed to provide a standard means of interconnecting networks (/ systems A private application of the same internetworking technology, software, and applications within a private network, for use within an enterprise Internet, Intranet, Extranet May be entirely disconnected from the public Internet –usually linked to it and protected from / Cloud Services Future Enterprise Architectures demands Cloud Service & Delivery Model Trade-offs 4 IaaS PaaS SaaS Private Public Hybrid User Responsible for Security Vendor Responsible for Security Adaptation to Future Architectures Reliability Interoperability security Reliability Interoperability Adaptation to Future Architectures Open Standard Specifications Proprietary Specifications better concernsbetter PaaS (IaaS high cost) With balanced options, Security is still an issue for global operations Basis/ system Governance Regime Taxation and regulation of enterprise Enterprise access to finance Size of manufacturing base Organization of the university sector Levels and orientation of government-funded Research; and the Role and weight of different public institutions. Industrial and technological specializations N. Boukhatem UMP Common characteristics of successful national systems, An ability to generate long-term and risky investment at scale for new ideas, both public and private. These new ideas are/ , Start Small, Scale Fast, Deliver Value Emphasize simplicity and completeness Centralize and manage complexity-- on network Integrate public and private spatial services Provide distributed access to integrated location based services Share everything--data, content, infrastructure Create meaningful public-private partnerships around standards Critical Success Factors The Challenge Can You Support the Vision for the Spatially Enabled, e-Everything Global Enterprise Can the GSDI Initiatives Support the New/ 6 © De Pardieu Brocas Maffei A.A.R.P.I. Pre-crisis European support policies n Historical lending activity: Borrowers: public bodies and private enterprises. Sectors: sectors of the economy provided the project satisfies at least one of the six lending objectives mentioned above: Type / months ago). never reached n The initial caps that the Government had in mind initially for this program, i.e. a global amount of EUR 360 bn / 47,178 bn JPY was in fact never reached (360 = EUR 265 of refinancing by / national budget Direct reporting to ministry level Vertical integration –Exploration and production to refining and marketing Large employment base Non-energy responsibilities * NOC = national (sovereign owned) oil company © 2005 by Institute for Energy, Law & Enterprise, University of Houston Law Center. All rights reserved. 63 Typical, IOC** Structure Many shareholders -- concept of “publicly-held” private companies No link to national budgets No direct reporting to ministry/ ment research institutes Strategic program for tech. Business (R&BD, TBI, NTB) Globalization of technology Pursuit newly launched technology business and investment Innovative Capability of Private secret Innovative Capability of Private secret 2010s Green Technology Promotion Strategic increase of R&D invest- ment in GT /.0) 81,699 (42.2) 72,208 (39.1) 113,676 (30.6) Large Enterprises 94,053 (57.9) 112,015 (57.7) 112,460 (60.8) 257,813 (69.4) Other (Public sector) 110 (0.1) 103 (0.1) 216 (0.1) (0.0) (Unit/ database public class Employee { private Long id; private Long version; private String firstName; private String lastName; private Money salary; private Address address; // Setters and getters // left out } Cadec 2007 - Java Persistence API v1.0, Slide 8 Copyright 2007, Callista Enterprise AB/model –Support for transactions Both JPA resource local and JTA/EJB CMT global transactions Cadec 2007 - Java Persistence API v1.0, Slide 15 Copyright 2007, Callista Enterprise AB JPA 1.0 - Declarative Object Relational/ into global economy Low productivity of state enterprises and of state itself Weak investment climate, onerous regulation Education and Skills High illiteracy, low average educational attainment Low secondary and tertiary attainment, gender imbalance Underdeveloped system of life long learning Brain drain with limited brain gain Innovation System Limited use of foreign direct investment, technology transfer Low R&D levels and productivity, low private R&D Poor public, private, university/ stronger reliance on a wider network KEY IMPLICATIONS FOR PRIVATE WEALTH ADVISORS For broker/dealer use only. Not for use with the public. Source: World Wealth Report 2011. Higher value placed on expertise and skills Wealthy will place high value on investment expertise, trustworthiness, financial expertise, communication and attention to detail Effective leveraging of “Enterprise Value” can significantly drive client satisfaction Highest priority should be/ associated with urbanization, emergence of new organizational forms, and regional and global trade—all these trends, in turn, are closely linked to agglomeration of people and ideas” 5 Stages of Economic Development 6 Factor-driven/ farmers Innovating new sustainable enterprise models Knowledge networking for critical capabilities Building on indigenous social capital for enterprise development Optimum mix of overseas development assistance, private, and public investment in various forms of capital/ global leader in the development and use of Information and Communication Technologies for socio-economic development ICT ENTERPRISE DEVELOPMENT 21 Purpose: To oversee and manage the Government’s shareholding interest in public entities and to facilitate growth and development of small, medium, and micro enterprises/in the digital broadcasting sector. The dialogue sought to explore areas where public private partnership could be formed to reach the under-serviced communities. The dialogue also sought / state has been made possible by government regulation that created a balance of power between governments, large corporations, and the financial sector. Post WW11 globalization Neoliberal market globalism. This is based upon a deregulation of the corporate sector, the privatization of public enterprises and institutions, tax reductions for businesses and individuals, the setting of limits on the powers of labor unions, reducing the role of government in the/ No control over underlying cloud infrastructure Control over ability to deploy and run software – operating systems and applications E.g. Amazon Web Services (AWS) Used for: /Private Cloud used for core data & services – Core Data Customer / HR / Finance & Accounting – Core Services Essential Business Processes core to the enterprise 42 Global adoption of cloud in the enterprise In order that Public Cloud is adopted more widely in enterprises either – Enterprises must learn to trust large scale public/
http://slideplayer.com/theme/ppt-on-private-public-and-global-enterprises-404.html
CC-MAIN-2017-30
en
refinedweb
Python brctl wrapper Pybrctl is a pure Python library for managing bridges. It is a lightwight wrapper for the linux brctl command, included in the bridge-utils package. It requires Python, Linux, and the bridge-utils package. It was written by Ido Nahshon at Jan 2015, and it was released under the GPL license. This example shows how to set up a new bridge and remove it: from pybrctl import BridgeController brctl = BridgeController() b = brctl.addbr("br0") b.addif("eth0") b.addif("eth1") b.setmaxageing(0) brctl.delbr("br0") Latest version on github: Feel free to contribute. ;) Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
https://pypi.org/project/pybrctl/
CC-MAIN-2017-30
en
refinedweb
If you want to check if the integer value is a multiple of a number in Java , you can use the modulus (%) operator . If you get the result as zero , then it is considered as multiple of a number. How to Check if Integer is a multiple of a number in Java? Below is a sample code snippet demonstrating the usage of the modulus operator to find out if the given number is a multiple of a number. public class Main { public static void main(String[] args) { int input = 5; int result = input % 5; System.out.println(result); } }
http://abundantcode.com/how-to-check-if-integer-is-a-multiple-of-a-number-in-java/
CC-MAIN-2017-30
en
refinedweb