text stringlengths 454 608k | url stringlengths 17 896 | dump stringclasses 91 values | source stringclasses 1 value | word_count int64 101 114k | flesch_reading_ease float64 50 104 |
|---|---|---|---|---|---|
I try to "Add Existing Item" to a project, and when I add a .h or .cpp file, it doesn't show up in my "Resource View". I wish I knew where these files I'm adding are going, if they are even being added in the first place!
I figured I have to add header files to my project in order to reference them in my code. I try:
#include <iostream.h> --and-- #include "iostream.h"
and neither of these work. I get an error saying unexpected end of header file.
I appreciate all help! Thanks for your time everyone! | http://cboard.cprogramming.com/cplusplus-programming/47177-simple-question-about-vcplusplus-net-2003-a-printable-thread.html | CC-MAIN-2015-18 | refinedweb | 101 | 87.01 |
Apache, JBI, Mina, SCA, CXF it also works well with external components and dataformats. To get a feel of versatility of Camel you can browse the list of Components and URIs it supports in the link below.
Camel is easy to use
Camel allows us to use same set of APIs to create routes and mediate messages between various components. This makes it extremely easy to use
Unit Testing camel is a breeze
Unit testing is essential to writing any quality code. Camel makes this facade of software development extremely easy. It provides bunch of ready make components like CamelContextSupport, camel-guice, camel-test-blueprint for easily testing the code. More of this in a future post.
The Camel Terminologies/Classes/Interfaces
Endpoint
Endpoints are places where the exchange of messages takes place. It may refer to an address, a POJO, email address, webservice uri, queue uri, file etc. In camel an endpoint is implemented by implemented Endpoint interface. The endpoints are wrapped by something called routes.
CamelContext
CamelContext is at heart of all camel application and it represents Camel run time system.
- Create camelcontext.
- Add endpoints or components.
- Add Routes to connect the endpoints.
- Invoke camelcontext.start() – This starts all the camel-internal threads which are responsible for receiving, sending and processing messages in the endpoints.
- Lastly invoking camelcontext.stop() when all the messages are exchanged and processed. This will gracefully stop all the camel-internal threads and endpoints.
CamelTemplate
This is a thin wrapper around the CamelContext object and it is responsible to sending exchange or messages to an endpoint.
Component
Component is really an endpoint factory. As camel supports lots of different kind of resources, each of these resources have different kind of endpoints. In practical cases application don’t create endpoints directly using Components. Instead CamelContext decideds which component to instantiate and then uses that component instance to create endpoints. So in app we will have. CamelContext.getEndpoint(“pop3://john.smith@mailserv.example.com?password=myPassword”); Now pop3 in this case is name of the component. CamelContext maps all the component name with the component classes and using the name it instantiates the instance. Once it has handle to the component it instantiates the endpoint by calling. Component.createInstance() method.
Mesaage represents a single concrete message ie request, reply or exception. All concrete message class impements a message interface for example JmsMessage class.
Exchange
Exchange is a container of message. It is created when a message is received by a consumer during routing process.
Processor
Processor interface represents a class that processes a message. It contains a single method public void process(Exchange exchange) throws exception Application developers can implement this interface to preform business logic on the message when message is received by the consumer.
Routes and RouteBuilder
Route is the step by step movement of message from a source, through arbitrary types of decision by filters or routers to a destination. They are configured by help of DSL (Domain Specific language). Java DSL is created by implementing routebuilder interface. It has single method called configure() which defines the entire route of message. Routes can also be configured via xml file using spring.
A Small Example of Camel code.
Lets follow this with a small example to get a taste of what Camel can do. In this example we will move group of files present in a folder to a different folder. In this process we will do following
- Create a simple RouterBuilder.
- Registering CamelContext in a spring file.
- Injecting the routerbuilder in a the CamelContext Bean
- Executing the class by starting the Camelcontext and finally stopping it once the execution is done.
1. Dependencies – Add following dependencies in your pom.xml
. Create RouterBuilder – RouterBuilder can be created by extending org.apache.camel.builder.RouterBuilder class and overriding configure() method. Here is an example
import org.apache.camel.builder.RouteBuilder; /** * Created by IntelliJ IDEA. * User: Niraj Singh * Date: 7/28/13 * Time: 10:29 AM * To change this template use File | Settings | File Templates. */ public class MyFirstRouterBuilder extends RouteBuilder { @Override public void configure() throws Exception { try{ from( "file:d:/vids").to("file:d:/temp"); }catch(Exception e){ } } }
- From() is the source endpoint and contains uri of file or directory which camel will be polling.
- to() represents the target endpoint and contains name of target file or directory.
- The file component uri is of form ““.
3. Registering CamelContext in spring and injecting RouterBuilder in spring.
<beans xmlns="" xmlns: <camelContext id="sqsContext" xmlns=""> <routeBuilder ref="myFirstRouter" /> </camelContext> <bean id="myFirstRouter" class="com.aranin.aws.sqs.MyFirstRouterBuilder"/> </beans>
4. Starting the camel context and executing the code and stopping the camel context.
import org.apache.camel.CamelContext; import org.springframework.context.ApplicationContext; import org.springframework.context.support.FileSystemXmlApplicationContext; /** * Created by IntelliJ IDEA. * User: Niraj Singh * Date: 4/16/13 * Time: 11:21 AM * To change this template use File | Settings | File Templates. */ public class CamelHello { public static void main(String args[]) throws Exception { try { ApplicationContext springcontext = new FileSystemXmlApplicationContext("D:/samayik/awsdemo/src/main/resources/hellocamel.xml"); CamelContext context = springcontext.getBean("firstCamelContext", CamelContext.class); context.start(); Thread.sleep(10000); context.stop(); } catch ( Exception e ) { System.out.println(e); } } }
If you run this class then first we load the camelcontext from the spring config file. Inject the router builder in it. After the context starts then all the file from source directory is copied to the target directory. Once all the file are copied then try copying a new file to the source directory, it will be copied to target as well until the context is running 10000 ms in this case.
I have few more advanced tutorials on camel. Perhaps you will find them useful. There links are listed in the reference sections.
References
-
-
-
-
-
That is all folks. Though no one will write comments, but I like to persevere, and still request folks to drop in a line or two if you like this tutorial.
Warm Regards
Niraj
wonderful
very nice tutorial about Apache Camel
Thanks Guys,
I am glad you like it.
Regards
Niraj
Hi Niraj,
Thanks for sharing this very good introduction about Camel.
The example was fantastic for beginners.
Cheers,
Raghav
Great introduction.Thanks man
It was nice , To the point Tutorial , Liked it !
Very Appreciative…. Good Intro tutorial about Apache Camel!
Thanks Guys,
I am very happy that you found the article useful :-).
Warm Regards
Niraj
Thanks for sharing!
A great tutorial for beginners.
Good work Niraj
Keep it up
Thanks for sharing. Good intro about camel | https://www.javacodegeeks.com/2013/08/introduction-to-apache-camel.html | CC-MAIN-2018-34 | refinedweb | 1,082 | 51.04 |
Spring Boot and Zipkin for Distributed Tracing
In this post, We will learn how to use Zipkin with Spring Boot for distributed tracing.
Spring Boot is currently the first choice of Developers to create microservices. With multiple services in place, Traceability of a single request can be cumbersome. Here is Zipkin to the rescue.
Zipkin Architecture
Zipkin is a distributed tracing tool that has two components. One is part of the application service itself that collects data and a tracer(instrumentation) library that reports to the said server. This tracer library is supposed to sit along with the application while running. Here is a simple architecture illustration from Zipkin’s official site.
As you see in the architecture diagram, All applications that have a Reporter contacts Zipkin collector and provides information. This information usually in the form of a specification called B3 propagation.
B3 Propagation and tracing specification
B3 specification is a set of HTTP headers for passing Trace information from one application to another. Let’s say you have service A which calls Service B and Service B calls Service C. Zipkin uses this format to forward trace information between Spring Boot and Zipkin Server
In this scenario,
- The whole journey is called a transaction.
- Each API call is a span. Technically a single unit of operation is span. But for this example, each API call is an operation.
- Along with these two facts, there is also a correlation between parent and child spans. In this example, the API call done on A triggers an API of B. So A is the parent of B. Similarly operation at B is the parent of the API call to C.
all the above information is what we call as Trace information or
Trace Context. This context is supposed to be passed from parent to child so that the instrumenting agents on each application can get this information and forward it to Zipkin central server.
Here are the B3 headers comes in place. As the applications communicate using HTTP, all this information can be encoded as HTTP headers and passed down.
Here is the List of B3 headers.
Zipkin TraceId
For every transaction, Zipkin starter generates a unique TraceId encoded in hex. The header key for this is
X-B3-TraceId. This value won’t change throughout the journey of the transaction.
SpanId
A SpanId is a 64-bit hex value that indicates the current operation/API call. The header key for this is
X-B3-SpanId.
ParentSpanId
Every API call may or may not have subsequent calls to other services. If they do have subsequent calls, then we can form a tree of all these API calls. This situation is where the
X-B3-ParentSpanId header comes in picture. The Parent Span Id is the span id of the parent API call or operation. When Zipkin server gets all the trace context from all the servers, it can arrange the trace tree structure using the
ParentSpanIds.
Sampling State
The header
X-B3-Sampled takes a 1 or 0 on whether to trace the subsequent spans or not. This decision is made on a 0.1 probability(10%) by default. What this means is that at the root span, the Trace reporter may or may not create a context based on a random probability. We can force the reporter to sample using three ways. * Call the Root Span with X-B3-Sampled as 1 * Set the default tracing probability to 1 (100%). We will get to this later. * Call using Debug flag
Debug Flag
X-B3-Flags: 1 is the representation for DEBUG flag. Any other value of absence of this header would mean that the trace is not in debug mode. Also, In debug mode, the trace decision probability is 1 (Always trace.). This header is helpful in production where you want to make sure that the Zipkin will trace that transaction.
So A typical set of headers for an intermediate span would look like below.
Code language: HTTP (http)Code language: HTTP (http)
X-B3-TraceId: 98dcb578d3c0dec17f57a9950b28bcd0 X-B3-ParentSpanId: cf6cf79caba2eb97 X-B3-SpanId: ee802197f3d49d5f X-B3-Sampled: 1
Enough with the technical stuff. Let’s try a simple Zipkin setup.
Setting up a Zipkin Server
The server setup is straight forward. Zipkin Server is an executable Jar that can directly be downloaded from Maven repository. If you are using Linux, you can run the following command to download and start the Zipkin server.
Code language: JavaScript (javascript)Code language: JavaScript (javascript)
$ curl -sSL | bash -s $ java -jar zipkin.jar
There is also a docker image available for quick startup.
docker run -d -p 9411:9411 openzipkin/zipkin
Once you start the jar or docker image, the application UI will be available at.
Spring Boot Zipkin dependencies
Zipkin has a Spring Boot starter which is part of the Spring Cloud ecosystem. And all of their dependencies are managed within
spring-cloud-dependencies pom. To add Zipkin to your project, You need to bring in
spring-cloud-dependencies as a managed dependency.
So first add the following
dependencyManagement snippet. If you already have a dependency management setup, add just the
dependency tag in an appropriate place.
Code language: HTML, XML (xml)Code language: HTML, XML (xml)
<dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Hoxton.SR8</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
Next, you need to bring in the spring boot starter for Zipkin. This step is as easy as adding any other starter. Just include the following artifact to the dependencies list.
Code language: HTML, XML (xml)Code language: HTML, XML (xml)
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-zipkin</artifactId> </dependency>
Above all, You can generate the same settings from start.spring.io by selecting
Zipkinas a dependency.
Zipkin And Spring Boot in Action
Meanwhile, We created a
/hello Rest API endpoint that calls a URL configured in the properties file.
Code language: JavaScript (javascript)Code language: JavaScript (javascript)
@RestController @SpringBootApplication public class ZipkinDemoApplication { @Autowired private RestTemplate restTemplate; @Bean public RestTemplate restTemplate() { return new RestTemplate(); } @Value("${spring.application.name}") private String appName; @Value("${target.service.url}") private String target; @GetMapping("/hello") public String sayHello() { return appName + " to > " + restTemplate.getForObject(target, String.class); } public static void main(String[] args) { SpringApplication.run(ZipkinDemoApplication.class, args); } }
The idea here is that just by changing the
server.port and
target.service.url, I can simulate one service calling another service.
Point Spring Boot to Zipkin Server
The first thing to do here is to point our Spring Boot application to Zipkin server. Along with this, we will have to specify how the collectors are supposed to communicate to the central Zipkin server. (Current options are ActiveMQ, RABBIT, KAFKA and WEB). We will use the WEB sender type. To make sure that the Zipkin Reporter samples all requests, I’m setting up the sampler probability to 1.
Never set probability as 1 in production for two reasons. Make sure you consider these points into account.
- Your application will become slow.
- Zipkin central server will get a huge load.
I have specified these settings in the application properties.
Code language: JavaScript (javascript)Code language: JavaScript (javascript)
spring.zipkin.base-url= spring.zipkin.sender.type=web spring.sleuth.sampler.probability=1.0
Along with these, we will be passing server port, target URL and the application name as spring boot command-line parameters. This approach gives the flexibility to start as many services as we want under different ports.
The following set of commands builds the project and starts three instances of the demo application with different port and endpoint URLs.
Code language: JavaScript (javascript)Code language: JavaScript (javascript)
mvn clean install java -jar -Dspring.application.name=APP-1 -Dserver.port=8001 \ -Dtarget.service.url= \ zipkin-demo-0.0.1-SNAPSHOT.jar java -jar -Dspring.application.name=APP-2 -Dserver.port=8002 \ -Dtarget.service.url= \ zipkin-demo-0.0.1-SNAPSHOT.jar java -jar -Dspring.application.name=APP-3 -Dserver.port=8003 \ -Dtarget.service.url= \ zipkin-demo-0.0.1-SNAPSHOT.jar
If we set it up correctly, We would have three applications in such a way that, APP-1 calling APP-2 and APP-2 calling APP3 and APP-3 calling mock service.
Let’s call the API for APP-1.
Code language: PHP (php)Code language: PHP (php)
$curl -iv GET HTTP/1.1 200 Content-Type: text/plain;charset=UTF-8 Content-Length: 54 Date: Wed, 04 Nov 2020 15:36:04 GMT Keep-Alive: timeout=60 Connection: keep-alive APP-1 to > APP-2 to > APP-3 to > { "status" : "OK" }
The output tells us the flow from
APP-2 to
APP-2 to
APP-3 and so on. This output proves that our setup worked. Let’s check the Zipkin server UI.
Navigating through Zipkin UI
Select RunQuery -> Expand All and you see that there is one new trace. As you see, this trace was created for a transaction that happened between app-1,app-2 and app-3. By clicking show on that entry, We can see How the calls happened and how much time each subsequent spans took. And by selecting each of the spans, We can even see the spanId and parent ID.
All of these may seem magic. But under the hood, the Zipkin starter is intercepting all requests on each application and adding these span id and transaction ids. Meanwhile, the reporter will send this information to the central Zipkin server.
Let’s take a look at the logs. If you have seen the properties file I have mentioned before, I have marked the logging level as
debug. This setup will show us the HTTP headers for each request.
The highlighted segment shows which headers the APP-1 is sending to APP-2. Feel free to experiment these headers yourself.
The best part about the Zipkin starter is that no additional code change needed and there is no side effect. The span in the UI gives a list of tags that would carry the information about the controller method, method type etc.
Conclusion
To summarize, We learned how to add zipkin distributed tracing for a Spring Boot applications to trace between multiple microservices. | https://springhow.com/spring-boot-zipkin-distributed-tracing/ | CC-MAIN-2021-31 | refinedweb | 1,709 | 57.87 |
When browsing eBay and looking for the NRF24L01+ one is swamped by a multitude of sellers selling these dongles for really low prices. The current rate is approx. $1.60 to $1.70 and you get a lot for that amount of money, a transceiver capable of:
Sending and Receiving data at a max rate of 2Mbps using 2.4GHz. 5 additional "pipes" to communicate with other NRF24L01+ transceivers (which makes a total of 6). Auto acknowledgment and CRC coding for reliable transmission. Low power modes and maskable interrupts for reception and transmission of data. Lots of information on the web regarding these dongles.
I found my dongles at eBay and have the best experience with the green ones containing a "loop". I also have the PA+LNA version, but that doesn't seem to add much to the range.
(Figure: Three varieties of the NRF24L01+ dongle. The green version is the one currently used)
Launchpads and wireless
The first part has been getting the wireless link up and running on the launchpad. Although many libraries exist for the Arduino, getting it to work on the launchpads (both MSP430 and Stellaris) requires some tweaking. I finally chose to use RF24 by Maniacbug as it exposes a lot of low level functionality as well. I did the following tweaks (file will be up in my repository soon):
- MSP430 - Add an external C function at the beginning of your sketch for "putchar(x)" for printf to work:
extern "C"{ int putchar(int c) { Serial.write((uint8_t)c); return c; } }
- MSP430 and Stellaris - Remove references to flash memory from the RF24.cpp file. These are the pgm_read and pgm_write functions and the PROGMEM directives. Note: this is probably not necessary as there are several #if and #endif statements declaring alternatives for these commands and directives.
- MSP430 and Stellaris - Remove the #include "printf.h" directive.
- Stellaris - Comment the _write(x) function in the startup_gcc.cpp function and add this function to your sketch.
- Stellaris - You need to select the SPI module to get a working connection.
SPI.setModule(0) or SPI.setModule(1)
This will yield a working version. I somehow messed up the printf statements. These are only needed to execute the radio.printDetails() function, so if you remove this function you can skip many of the steps.
Beyond pinging hence and forth
When the changes have been made in the code it is possible to try out the examples. I've been trying the "pingpair" examples and finally made it work between two launchpads. These could either be the Stellaris or one of the MSP430 launchpads.
OK, that's nice and it's a nice way to check the potential range. You will get the best results when you use 250Kbps, a small payload size and auto acknowledge enabled. I am able to get a range of 6-15 meters indoor, depending on the medium (we have a concrete house which blocks many signals).
Now, it's time to do some sending and receiving of other data. I've created a sendval(char* x) function that sends a string with a maximum length of the configured payload size. I will be sending strings constructed from sensor data and finally I will write a small parser to parse commands to the greenhouse.
Note: Using strings is very costly for memory. Although small examples work with the MSP430G2553 controller, larger examples will yield strange results as the memory overflows. I am currently using the Fraunchpad which provides just enough storage. The F5529 launchpad is nice but cannot be powered by other means than the USB port (which is annoying the least).
Using simple libraries for my RTC (snippets from a DS1307 program), DHT22 (from the DHT22 lib found on Energia.nu), BMP180 (from the BMP085t lib from Energia.nu), I've been able to construct environmental data.
A Raspberry Pi gateway
The Raspberry Pi can also handle the NRF24L01+. I specifically wanted to program it using Python. I found the Pynrf24 library on the net which maintains the same class members as the RF24 library used for the launchpads. The Pynrf24 library relies on the spidev library for python. It can be installed using the following statement:
sudo easy_install spidev
The Pynrf24 library is hosted in a github repository.
Getting the library to work has proven to be a little challenge, as the pynrf24 library is written for the BeagleBone Black and can be ported easily to the Raspberry PI, by making the following changes to nrf24.py:
- Change the import ... as GPIO by:
import RPi.GPIO as GPIO
- Add a statement to set the pin numbers to Broadcom in __init__(self) :
GPIO.setmode(GPIO.BCM)
- Add a statement to maximize the SPI speed (more on this later) in the begin() method:
self.spidev.max_speed_hz=(4000000) # limit to 4MHz
Due to the kernel implementation of the Raspberry Pi, the SPI clock scales with the CPU clock. Overclocking will yield a higher SPI clock and without the former statement it will not work.
I have made a simple program to receive data from the wireless node and print it out. It is a great way to work with both Energia to program the microcontroller platform and using PuTTY and Xming to edit the python programs on the Raspberry Pi.
Next steps
The next step is introducing bidirectional communication and making a command parser that is small enough to fit into the microcontroller. Commands should include:
Measure now Set time Set Servo angle Turn on/off LED's and pumps Reboot
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In. | https://hackaday.io/project/504-smart-greenhouse-using-a-raspberry-pi-launchpad/log/860-wireless-adventures-using-the-nrf24l01 | CC-MAIN-2022-33 | refinedweb | 944 | 64.91 |
We value your feedback.
Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!
Become a Premium Member and unlock a new, free course in leading technologies each month.
using System; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; namespace Coderbuddy { public class ExtractEmails { private string s; public ExtractEmails(string Text2Scrape) { this.s = Text2Scrape; } public string[] Extract_Emails() { string[] Email_List = new string[0]; Regex r = new Regex(@"[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}", RegexOptions.IgnoreCase); Match m; //Searching for the text that matches the above regular expression(which only matches email addresses) for (m = r.Match(s); m.Success; m = m.NextMatch()) { //This section here demonstartes Dynamic arrays if (m.Value.Length > 0) { //Resize the array Email_List by incrementing it by 1, to save the next result Array.Resize(ref Email_List, Email_List.Length + 1); Email_List[Email_List.Length - 1] = m.Value; } } return Email_List; } } }
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
If you are experiencing a similar issue, please ask a related question
Join the community of 500,000 technology professionals and ask your questions. | https://www.experts-exchange.com/questions/26821708/c-Cannot-convert-method-group.html | CC-MAIN-2017-34 | refinedweb | 203 | 52.97 |
Alexa.RemoteVideoPlayer Interface: SearchAndPlay (VSK Fire TV)
When users ask Alexa to play specific video content, such as "Watch Bosch" or "Watch the Warriors game," the
Alexa.RemoteVideoPlayer interface sends
SearchAndPlay directives to your app or Lambda.
- Overview
- Utterances for SearchAndPlay Directives
- SearchAndPlay Directive Example
- Payload Definitions
- Handling SearchAndPlay Directives
- Response Example
- Declaring Capability Support for this Interface
Overview
The
SearchAndPlay directive signals that the customer has asked Alexa to "watch" an item.
SearchAndPlay results in playback of the specifically requested title, or a title that best matches the requested entity. If there are no matched titles, search results are returned instead.
Here are some example utterances:
- Alexa, watch title
- Alexa, play title
- Alexa, stream title
- Alexa, start title
Utterances for SearchAndPlay Directives
Alexa sends a
SearchAndPlay directive to your app (for app-only integrations) or to your Lambda (for cloudside integrations) when users say the following utterances.
SearchAndPlay Directive Example
The following is an example
SearchAndPlay directive. This is a directive that Alexa might send in response to a user's request to watch "Manchester by the Sea."
EXTRA_DIRECTIVE_NAMESPACE: Alexa.RemoteVideoPlayer EXTRA_DIRECTIVE_NAME: SearchAndPlay": "e7f9c31f-cb90-4003-9795-c6fb9f487945", "name": "SearchAndPlay", "namespace": "Alexa.RemoteVideoPlayer", "payloadVersion": "3" }, " } } } }
Payload Definitions)
Handling SearchAndPlay Directives
SearchAndPlay directives contain instructions to watch or play media. The directive contains the desired media object and URI obtained described as an entity. The directive contains an array of entities that specifies what to search and play.
(The
SearchAndPlay directive is similar to
GetPlayableItems in the video skills for multimodal implementations.)
The following sections provide guidance for handling
SearchAndPlay directives with different requests.
Watch by Title
When users say "Alexa, watch Interstellar" or any other title to your Alexa-enabled device, you will receive a
SearchAndPlay directive in your app or Lambda.
As part of the
SearchAndPlay directive, you will see an
externalIds section in the directive. Within this section, you should look for a field corresponding with your own catalog. This field will contain the same
ID values you used in your catalog integration, allowing you to know precisely which show a user desires to watch. You can then use that to fulfill the user's request by playing the media.
If within the same catalog you still see multiple
ID values in the directive, this may be because Alexa identified multiple shows within your catalog that match the title the user asked for. You should select the best one to play for the user. Leverage any algorithms that help match the content to the user.
If you do not see your own catalog
ID values in the
externalIds field, and you've made sure that you're asking Alexa to watch content that is in your app, contact your Amazon representative for assistance.
Watch by Title, Episode, and Season
When users say "Alexa, watch Interstellar Season 2 Episode 2," you will receive a similar directive as when users say "Alexa, watch Interstellar." However, the key difference is that this directive will also have the following JSON inside of it:
{ "type": "Episode", "value": "2" }, { "type": "Season", "value": "2" }
This JSON indicates the season and episode number that the user requested. You must play the season/episode the customer requests. The catalog
ID you receive will contain only the top-level show's catalog
ID, not the season/episode ID. However, you should be able to use the season/episode number alongside the show's catalog
ID to play the correct content.
You should also account for the fact that a user might choose to specify a season but not an episode, or an episode but not the season — you must still fulfill their request. Follow this guidance for identifying the right content:
- If the user asks to watch a title by season, (e.g., "Alexa, watch Bosch, Season 3"), and it is unclear which episode of a TV series a user wants, show the last watched episode. If the last watched episode is completed, show the next unwatched episode after that. Alternatively, show an episode list for the season.
- If the user asks to watch a title by episode, (e.g., "Alexa, watch Bosch, episode 5") that could belong to multiple seasons, identify the correct season by checking the user's last-watched episode. If the last-watched episode was within Season 2, then play episode 5 in Season 2. Alternatively, show an episode list for the season.
Watch by Franchise
For certain utterances, it's not actually clear which content the user wants. For example, a user might say "Alexa, watch Jurassic Park." In such a scenario, we don't know if the user meant Jurassic Park 1, Jurassic Park 2, or Jurassic Park 3. Media that has multiple variants like this is called a "franchise." Franchise scenarios, which don't fit neatly into the season/episode model, are handled by "Watch by Franchise."
When a user conducts a watch-by-franchise request, you will receive the franchise that the user requested (in this case, Jurassic Park) in the directive, but the directive will not contain a catalog ID. For these directives, the expectation is that you will conduct a search within your catalog for this content and then play the top result from your search. If that is not possible, you must at least take the user to search results within your app so that the user can use their remote to see the content they would like. You shouldn't simply ignore the directive.
A list of franchises is available in Franchise List.
Watch by Genre, Sport, Team, League, and Other Ambiguous Watch Directives
Alexa also supports phrases such as "Alexa, watch a comedy" or "Alexa, watch basketball." For generic scenarios like these, you have the option of either taking the user to search results, or taking the user to the detail page of that particular genre or appropriate entity.
For example, many apps have special pages dedicated to comedies, action movies, sitcoms, etc., which are different from simple search results. These genre pages curate media related to that topic. If desired, you can choose to take the user to these genre pages when the relevant ambiguous request is received by the user. The expectation is that, even in the worst case scenario, your app should at least take the user to search results. You shouldn't simply ignore the directive.
A list of genres that might be received in directives is available in Genre List.
Handling Ambiguous Requests
Similar to
SearchAndDisplayResults,
SearchAndPlay supports multiple entity types, including a content title, franchise name, actor, director, sports team, media type and more. This means one of these directives might contain an ambiguous entity request.
For example, a customer could request, "Alexa, watch a popular comedy," or "Alexa, watch a Billy Bob Thornton movie." Despite the ambiguity, you can decide how to act on a request. For example, you can do the following:
- Begin playing a popular comedy or Bob Thornton movie
- Generate a list of the top ten comedies or Billy Bob Thornton movies and randomly select one for the customer to avoid repetition
- Go straight to search results for that ambiguous entity
You can choose how to respond; however, it's recommended that you accommodate a customer's request if at all possible.
Viewing the Actual Customer's Request
Recall that an Alexa service in the cloud does the work of interpreting the customer's request, determining the intent, and then packaging it into a directive. What if you want to see the actual user's request (rather than Alexa's interpretation of it)? fortunately, a version of the user's actual request is available.
In the directive
payload, the
searchText object represents the customer search request. In the
searchText object, the
transcribed value is a string that represents the customer intent. This
transcribed value is a stripped-down version of what the customer said. For example, here's how the
transcribed value might look like for the request, "Alexa, watch popular comedy tv shows in HD":
{ "searchText": { "transcribed": "h.d. popular comedy tv shows" } }
As you can see, the
transcribed property is a summarized/redacted version of the request that selects the main words of the request. The
searchText object has the following limitations:
- There is no word order guarantee. For the same utterance,
searchTextmight return the
transcribedvalues with different order, such as:
- "h. d. korean war documentary movies"
- "korean war documentary h. d. movies"
- The content of
searchTextmight change over time or by directive. For the same utterance,
searchTextmight return different
transcribedvalues at different points in time, such as:
- "top ten comedies"
- "top 10 comedies"
- Action verbs are omitted. The
transcribedvalue will not show the action verbs used in the user's request.
Note that
searchText can include content provider names (if they were part of the customer's request). Here are some examples:
- The request, "Alexa, find content provider movies" will return the
transcribedvalue "content provider movies"
- The request, "Alexa, find comedies on content provider" will return the
transcribedvalue "content provider comedies"
searchTextonly as a fallback for other values in the search payload. The
searchTextfield is optional and might not appear in the directive you receive. Your implementation must return a response even if the directive contains no
searchTextvalue.
Use
searchText if you want to focus on key word searches (for example, a full text search). Note that
entities rely on resolved catalog values. Use these entities if you have specialized catalogs pertaining to specific values, such as Movie catalog, Genre catalog, and so on, or if you have some form of data model that facilitates structured queries.Receiver. Also see the
AlexaDirectiveReceiver class in the sample app for a more specific code example.
When a
SearchAndPlayResults directives to your app from the
RemoteVideoPlayer interface, you must indicate support for this interface when you declare your capabilities. See the following for more information on declaring capabilities with app-only integrations:
To indicate that your video skill supports
SearchAndPlay directives from the
Alexa.RemoteVideoPlayer interface, you must indicate support for it in your response to the
Discover directive sent through the
Alexa.Discovery interface. More details are provided in
Alexa.Discovery.
Last updated: Nov 12, 2020 | https://developer.amazon.com/es/docs/video-skills-fire-tv-apps/searchandplay.html | CC-MAIN-2021-17 | refinedweb | 1,693 | 52.49 |
Henry S. Thompson writes: > If you want _another_ factor of 10, go to PyLTXML. The report below > is from Python 2.2.1 on RedHat Linux 7.2 using PyXML 0.8.1 and > PyLTXML-1.3-2. Wow! That's fast! > I used Fred's driver, added two new functions to text bit-level and > tree-level access via PyLTXML. > > parser performance test > 100 parses took 3.88 seconds, or 0.04 seconds/parse > 100 parses took 0.25 seconds, or 0.00 seconds/parse > 100 parses took 0.02 seconds, or 0.00 seconds/parse > 100 parses took 0.03 seconds, or 0.00 seconds/parse > > The first measurement is the original 4DOM DOM builder, the second is > the expatbuilder, the third is PyLTXML returning the whole tree, the > fourth is PyLTXML returning every bit (start tag, end tag, text). I > guess the tree is faster because it's slightly lazy wrt Python > structures, i.e. only the root is in Python form as returned, the rest > gets converted from the native C structs as you walk the Python tree. So is the resulting object compliant (or at least close) to the Python DOM, as defined in the Python Library Reference? (Lazy building of structures is fine, of course, since that's implementation.) If it doesn't support the DOM API, does it support something with an equivalent model and functionality? > Here are the additions I made to Fred's version of the script: ... > def allBits(s): > f=PyLTXML.OpenString(s1,PyLTXML.NSL_read|PyLTXML.NSL_read_namespaces) > b=PyLTXML.GetNextBit(f) > while b: > b=PyLTXML.GetNextBit(f) > PyLTXML.Close(f) > > def itemParse(s): > f=PyLTXML.OpenString(s1,PyLTXML.NSL_read|PyLTXML.NSL_read_namespaces) > b=PyLTXML.GetNextBit(f) > while b.type!='start': > b=PyLTXML.GetNextBit(f) > d=PyLTXML.ItemParse(f,b.item) > PyLTXML.Close(f) > return d Ouch! Very inscrutible code... at least to me. I must confess that I've not had time to dig into the LTXML API (C or Python), though I've stashed a copy of the documentation on my desk somewhere, meaning to get to it. -Fred -- Fred L. Drake, Jr. <fdrake at acm.org> PythonLabs at Zope Corporation | https://mail.python.org/pipermail/xml-sig/2002-November/008725.html | CC-MAIN-2018-51 | refinedweb | 361 | 79.16 |
I am trying to integrate Layer alongwith Atlas into my project. I am working on Swift 2.2. I have made a swift class which should conform to ATLParticipant protocol but Xcode is throwing an error,
Type 'ConversationParticipant' does not conform to protocol 'ATLParticipant'
I don't understand what I am doing wrong. The code is:
import Atlas
import Foundation
class ConversationParticipant: NSObject, ATLParticipant {
var firstName: String
var lastName: String
var fullName: String?
var participantIdentifier: String?
var avatarImageURL: NSURL?
var avatarImage: UIImage?
var avatarInitials: String?
override init() {
super.init()
}
}
You are missing the
displayName and
userID Strings. You need to provide them because the protocol requires it. | https://codedump.io/share/1X6eoQPOhElB/1/atlas-type-does-not-conform-to-protocol-atlparticipant | CC-MAIN-2017-04 | refinedweb | 107 | 53.37 |
Created attachment 97947 [details]
IOContainer.patch
Please review.
The existing InputOutput.select() and IOContainer.select(), which IO.select()
delegates to, do "too much". They will open the containing TopComponent
and call requestVsible() on it in addition to bringing the IO's
tab to the front.
I need functionality to only bring the IO tab to the front and leave
the container alone.
I propose the addition of
void IOContainer.selectLite(JComponent);
and
interface IOContainer.SelectProvider {
void selectLite(JComponent);
}
No default implementation in org.openide.windows will be provided
only one in 'terminal' module which will be committed simultaneously.
Diff is attached.
Use case is as follows.
There exists a Term-based implementation of IOProvider and
IOContainer.Provider in module 'terminal'. One enhancement is
non-tabbed containers.I intend to use this implementation to
replace SunStudio dbxgui's own debugger console and process i/o windows.
One requirement is that when we switch debugging sessions, via
the sessions view, that the debugger console and process i/o "tabs"
become visible, but we don't want the TC's to neccessarily become
visible. selectLite() will just switch the tabs.
Note that I'm only proposing an enhancement to IOContainer and
not InputOutput. The reason is that I can enhance IO using
teleinterface in 'terminal' module but there's no way getting
around IOCOntainer being final which precludes casting it to
a Lookup.Provider. InputOutput implementations strictly use
IOCOntainer and are unaware of underlying implementations.
I have a slightly more complex reason to not enhance InputOuput
in org.openide.windows. Will provide it on request.
IS00: Is it OK that SelectProvider is inner to IOContainer? (That way
it's "next" to IOContainer.Provider).
VV1: IOContainer (and IOContainer.Provider) has 3 distinct methods: open(), select(comp), requestActive()
=> Why do we need to have selectLite(JComponent)? Looks like if IOContainer.Provider.select(comp) is implemented correctly (without opening and activating parent container) - it is exactly what you ask for in selectLite() and it match javadoc of select(comp)..
In principle one could implement InputOutput.select()
by having it's implementations call IOContainer.open, requestVisible
followed by a redefined lite select(). But I could do
that only in my implementation of IO putting interoperability at risk.
Also, doing that would make InputOutput's select() heavy and IOContainers
select() lite which would lead to confusion because of similarity of names.
(In reply to comment #2)
>.
bug against output2 impl?
>
> In principle one could implement InputOutput.select()
> by having it's implementations call IOContainer.open, requestVisible
> followed by a redefined lite select().
This is how I understand it should be.
> But I could do
> that only in my implementation of IO putting interoperability at risk.
Tim can do the same in output2
> Also, doing that would make InputOutput's select() heavy and IOContainers
> select() lite which would lead to confusion because of similarity of names.
Ok. I see.
InputOutput.select javadoc is clear:
/**
* Ensure this pane is visible.
*/
public void select ();
javadoc of IOContainer and IOContainer.Provider is not (nothing about visibility):
/**
* Selects component in parent container
* @param comp component that should be selected
*/
public void select(JComponent comp) {
Y01 I'd like to warn you a bit: changing semantics of InputOutput method is usually disastrous. There is too many callers and they rely on current behavior, that even slight shift in behavior will for sure hurt somebody.
Y02 I can see that you are considering shift in IOController.Provider semantics. I think it is relatively low risk, that can be done (if Y01 remains - e.g. no changes to semantics of InputOutput). Inconsistency between those two select methods shall not be important, users of InputOutput don't call the IOController.Provider methods at all.
Y03 Improve the javadoc of IOController.Provider to more exactly specify the expected contract.
Y04 Side thinking: If you want to be backward compatible (rather than changing the semantics as approved by Y02), then create new factory method IOContainer.create(Provider p, boolean supportsLiteSelectPolicy) rather than new interface. I'd also suggest to not introduce new "selectLite" method, but add new method with boolean parameter: IOContaier.select(JComponent c, boolean openWhenHidden). Of course under the assumptiong that this all will still be needed.
Y05 Missing @since, apichanges.xml shall be added for next version of the patch
Y06 I don't understand the actual usecase. Who's going to call the new interface/method (I don't know who is calling the old select, obviously)? Maybe a bit of test code showing the interactions between IOContainer and its Provider would be beneficial.
re Y01, 02: This IZ doesn't propose to change the semantics
of IO.select() for the reasons you state. That was VV's suggestion.
re Y04: A single openWhenHidden might not be enough. I'm trying to
follow the examples of the variety of methods on TC's (open, requestVisible,
requestActive) which control independent stuff and can be combined as needed.
re Y05: Will add as we approach closure.
re Y06: IOContainer isn't really meant as an end-user API. It's more a
support API for implementing IO's, so it' main (only?) callers are
InputOutput implementations.
Specifically IOContainer.select() is called as a result of
InputOutput.select() and any change in semantics of IOCOntainer.select
will impact those of IO.select().
So why isn't there a corresponding proposal for adding selectLite()
to InputOutput? Because for the time being I can add it in 'terminal'
and leave enhancements to 'output2' for later. The nature of
IOContainer is such that I cannot enhance it using teleinterface
in 'terminal' hence this IZ.
There's an analogy betwen IO's inside an IOContainer and TC's
inside Modes. The lifecycles and visibility semantics are similar.
This is why (I think) IOCOntainer mimics some of TC's methods.
In addition an IOCOntainer can be inside a TC (tabs within tabs).
The original IO.select() operates all the way up to the TC, which
sets a precedent for two sets of methods on IO ... ones that operate
on IO vs it's container, and ones that "pass thru" to the containing
TC and it's containing mode.
For example, IOContainer.requestVisible() is a pass-thru to the TC
while selectLite() is a "requestVisible" directly on the tab.
I like selectLite() because it does one simple primitive operation
on one pair of container/contained objects.
(In reply to comment #5)
> re Y01, 02: This IZ doesn't propose to change the semantics
> of IO.select() for the reasons you state. That was VV's suggestion.
Probably misunderstanding:
I propose to change semantics of IOContainer.Provider.select in output2 (not IO.select) and forget about new method.
Of course code in IO.select should be updated to call open, requestVisible, select to implement current semantics (clearly mentioned in javadoc for IO.select)
I'm starting to tend towards a variation on Yardas suggestion.
Roughly introduce a selet with an EnumSet parameter. Something
roughly like:
enum IOContainer.SelectExt {
AND_OPEN_TC,
AND_REQUEST_VISIBLE_TC
}
IOContainer.select(EnumSet<IOContainer.SelectExt>);
With a null set it would be like selectLite().
With all elements of the set it would be like select().
I'll have to work a bit on exactly what should be in the enum.
Do not use the IDE's built-in diff tool for anything. Use 'hg diff' from the command line, passing --git if this is not on by default. See also:
Diffs should also include the complete patch, including to implementation. Certainly for any API change to openide.io we would want to see a matching impl in core.output2 unless such an impl would clearly be inappropriate.
(In reply to comment #6)
> I propose to change semantics of IOContainer.Provider.select in output2 (not
> IO.select) and forget about new method.
> Of course code in IO.select should be updated to call open, requestVisible,
> select to implement current semantics
That seems a better idea to me too. In output2, Controller.performCommand(...,CMD_SELECT,...) should do some of what IOWindowImpl.selectTab does now. The Javadoc for IOContainer.select clearly says "selects component in parent container", nothing about displaying that container (which is explicitly left to other methods).
At some point, having a call on InputOutput to front the tab without activating the window would be useful. This would follow the usual API/SPI pattern in the package, such as for IOTab (not IOContainer which is unrelated!). For example, when the "Always Show Output" option is unchecked, the Ant module does not call IO.select when starting a process, which is irritating if the Output Window is visible but another tab is fronted; better would perhaps be to front the tab without forcing the whole window to pop up. But Ivan does not seem to be proposing such an API here.
JG: But Ivan does not seem to be proposing such an API
JG: [ InputOutput.selectLite() ] here.
Well, I am, but not in classic InputOutput. I was trying to
touch the minimum amount of code I don't own by adding that API
in 'terminal'. But considering how this is creating confusion perhaps
I should add it to output2 as well. (Uh-oh ... with Tomas Holy gone
am I getting dragged into maintaining output2 :-)
JG: That seems a better idea to me too.
I'm surprised that a semantic change is favored.
The justification here, I suppose, is that we're dealing with a
"closed universe". I.e. IOContainer has only two clients: output2
and terminal. In the past i've seen arguments based on "closed universe"
getting rejected in favor of "practicing compatibility even when we know
there's a closed univese".
It's really IO.select() that matters.
It's control path looks like this:
IO.select()
Controller ... CMD_SELECT
create
IOC.requestActive
IOC.select ...
IOController.select()
IOController.Provider.select()
output2...selectTab()
TC.open()
TC.requestVisible().
selectLite()
_if_ we agree to work with the "closed universe" assumption then the above
can, per Vladimir and Jesses opinions, be tansformed to ...
IO.select()
Controller ... CMD_SELECT
create
IOC.requestActive
IOC.open()
IOC.requestVisible().
IOC.select() ...
IOController.select()
IOController.Provider.select()
output2...selectTab()
selectLite()
However ... it seems that we _do_ want an IO.selectLite(). I definitely
need one and Jesse makes a case for it too. But the above transformation
doesn't really give us that! Sooo ...
What I think, _conceptually_, would be ideal is something like this:
io.select(AND_REQUEST_ACTIVE|AND_OPEN|AND_REQUEST_VISIBLE);
Which would be equivalent to the current IO.select(), or
io.select(0);
which would be equivalent to "selectLite".
This can be achieved in two ways:
1) Enhance IOContainer API:
I.e. IOContainer also implements a select(EnumSet<SelectOpts>)
2) Change IOContainer.select() semantics:
I.e. CMD_SELECT checks the EnumSet and calls IOC.requestActive,open,
requestVisible and a _semantically modfied_ select.
Either would suit me. The tradeoffs, as I see them, are that ...
- (1) Molests IOContainer API.
Maintains similarity btw IO and IOC.
- (2) Forces us to allow a 'closed universe" mindset.
(In reply to comment #10)
> JG: But Ivan does not seem to be proposing such an API
> JG: [ InputOutput.selectLite() ] here.
>
> Well, I am, but not in classic InputOutput.
That would be the form in which random modules just using IOProvider to get an InputOutput (of unknown implementation and default display location) could actually use it.
> I'm surprised that a semantic change is favored.
> The justification here, I suppose, is that we're dealing with a
> "closed universe". I.e. IOContainer has only two clients: output2
> and terminal.
More relevant is that the impl in core.output2 appears to be directly contradicting the specification; i.e. VV1 is a bug fix, not an API change.
> _if_ we agree to work with the "closed universe" assumption then the above
> can, per Vladimir and Jesses opinions, be transformed to ...
Looks right, though I'm not an expert in this code. (Tim do you still know core.output2 well?)
> This can be achieved in two ways:
Again I don't think changing IOContainer is right; it already has very specific methods for doing particular things to the tab and to the container, so the API does not need to be touched. The problem is that a normal user of an InputOutput cannot access this functionality; while you can guess that IOContainer.getDefault is the container you are using, you definitely do not know what JComponent corresponds to your InputOutput.
Additions to the functionality of InputOutput are done using the following pattern:
import org.openide.windows.IOSomething;
import org.openide.windows.IOSomething.Action.*;
InputOutput io = ...;
if (IOSomething.isSupported(io)) {
IOSomething.select(io, EnumSet.of(REQUEST_VISIBLE, SELECT_TAB));
} else {
...fallback...
}
where IOSomething has
private static IOSomething find(InputOutput io) {
if (io instanceof Lookup.Provider) {
Lookup.Provider p = (Lookup.Provider) io;
return p.getLookup().lookup(IOSomething.class);
}
return null;
}
I'm not sure what exactly the "Something" should be; "Tab" is taken, perhaps "Selection". Then TerminalInputOutput and/or NbIO would add an IOSomething impl to their lookups, which would call individual IOContainer methods according to the enum set. In the case of core.output2, Controller.performCommand would receive a Set<Action> as data, and would call methods on ioContainer.
Created attachment 98159 [details]
openide.io.patch
Attached is a patch to openide.io.
I introduced IOSelect to allow an IO to select with finer grain using
the usual extension method. It uses enum SelectExtraOps.
IOContainer is also extended in a similar manner, but I've
swayed towards changing the semantics of IOCOntainer.select()
mainly because the SelectExtraOps applied to IOCOntainer are redundant
in the face of IOCOntainer having open etc.
I've implemented this in 'terminal' and will proceed to implement it
in 'output2' with altered select() semantics and post an additional
patch for that.
It might be tricky to _exactly_ reproduce the semantics because
the container implementation tests before applying operations:
public void selectTab(JComponent comp) {
if (!isOpened()) {
open();
}
if (!isShowing()) {
requestVisible();
}
if (singleTab == null) {
pane.setSelectedComponent(comp);
}
checkTabSelChange();
}
These tests are not available in the IOContainer API.
I could move the tests to IOCOntainer.open nd reuestVisible.
At this point testing all of this becomes tricky. There are
unit tests in output2 but they don't measure visible effect.
I have a small user-driven "play" framework that I can use.
Y11 Rename SelectExtraOps; don't use abbreviations. My personal suggestion is IOSelect.Type or IOSelectType.
Y12 Should not select(JComponent comp, EnumSet<SelectExtraOps> extraOps) have a fallback if the SelectProvider is not provided?
re Y11: SelectType is inappropriate since there is a basic function
that select() will perform hence the word Extra.
Moving it inside IOSelect is OK now that IOCOntainer will not need it.
IOSelect.AdditionalActions
re Y12: Yes it should.
Created an actual bug# 185209 to document the eventual change and us in CS.
re Y05 Missing @since, apichanges.xml shall be added for next version of the patch
Does that mean I need to rev up the SpecificationVersion?
Created attachment 98237 [details]
patch for: openide.io core.io.ui core.output2
Allright this should do it. It's a complete patch covering
openide.io
core.io.ui
core.output2
Summary:
- Leave form of IOContainer unmolested.
- Simplify semantics of IOContainer.select()
- Retain semantics of InputOutput.select()
- Compensate for simplification by enhancing implementation of
InputOutput.select()
- Ensure that _other_ callers of IOCOntainer.select() are not
surprised by simplification.
- Introduce IOSelect (analog of IOTab) with method
select(InputOutput, EnumSet<IOSelect.AdditionalOperation>)
Implement it in Controller using IOEvent.CMD_FINE_SELECT.
- Minimal unit test in core.output2.
The only uncrossed t's and undotted i's are "since" comments
and API changes.
VV2: please, change subject of this IZ, because "Add selectLite() method to IOContainer" was in fact rejected and looks like you have agreed on that.
Now you are focused on IOSelect capability instead, right => then I agree with adding such capability.
VV3: Do not use EnumSet in API methods, EnumSet is impl (like ArrayList), use Set instead (Clients will use EnumSet)
re VV2: Does it really matter? API proposals evolve based on feedback.
Will you sleep poorly if I don't change the subject?
re VV3: I'm not sure I agree. I recall seeing API reviews recommending
EnumSets, and not Sets, over ints OR'ed together.
(In reply to comment #20)
> re VV2: Does it really matter? API proposals evolve based on feedback.
> Will you sleep poorly if I don't change the subject?
Ok. It's just confusing + changing subject may attract other reviewers :-)
>
> re VV3: I'm not sure I agree. I recall seeing API reviews recommending
> EnumSets, and not Sets, over ints OR'ed together.
I mean not over ints, just replace in API only:
select(InputOutput, Set<IOSelect.AdditionalOperation>)
internally of course EnumSets are passed as parameter
VV4: IOSelect can be used only by clients who knows about them => I propose to prohibit use of "null" as the second parameter in IOSelect.select. client should use empty EnumSet.nonOf if no extra action wanted (easier to read code then as well)
I think support VV3. Some designers believe that API should be written against interfaces not implementations. java.util.Set is the interface, EnumSet is implementation. As far as I can tell the methods both classes offer are same (plus EnumSet is publicly cloneable, but you don't want to use clone() anyway). The only practical reason for using EnumSet is prevent accidental use of HashSet (which would not be effective use of the API). I believe that a sample code in the javadoc of the method showing use of EnumSet would be enough. Use Set.
Re. Y05: Yes, you need to increase specification version of modules with new classes/methods and also increase dependencies of modules using these classes/methods (core.output2, terminal) to link properly.
Y13: When writing apichanges.xml create (an additional) entry to admit that there is a semantically incompatible change in IOController: "After fixing bug#185209 IOContainer.select() no longer performs these operations for us so we have to do them. ioContainer.open(); ioContainer.requestVisible();"
re VV4
I accept null simply because typing
EnumSet.noneOf(IOSelect.AdditionalOperation.class)
is a PIB.
I have also considered a plain IOSelect.select(InputOutput).
with a default empty set. Would that make things more convenient?
re VV3: EnumSet accepts only enums as it's members.
If I don't statically protect against that by using EnumSet
I will have to dynamically protect against non-enums in a
plain Set.
Don't you prefer static type-checking?
re VV3: Never mind. I guess the Set<T> T parameter will do enough
static type checking. I'll adjust after my "sleep period".
Re. Y05: Upping the dependency version of modules that directly use
the new classes/methods makes?
Let me second VV3 and VV4 - the param should be @NonNull Set<AdditionalOperation>. A no-op select is quite easy using either EnumSet.noneOf or Collections.emptySet.
(In reply to comment ?
Wrong; someone could update openide.io and core.output2 but not core.io.ui, without complaint from the module system. Be on the safe side and increment the specification versions of all three, as well as the relevant dependency versions.
By the way, improved behavior for the Ant module seems to work well with the proposed patch:
diff --git a/o.apache.tools.ant.module/src/org/apache/tools/ant/module/run/TargetExecutor.java b/o.apache.tools.ant.module/src/org/apache/tools/ant/module/run/TargetExecutor.java
[...imports...]
@@ -431,6 +433,8 @@
if (outputStream == null) {
if (displayed.get()) {
io.select();
+ } else if (IOSelect.isSupported(io)) {
+ IOSelect.select(io, EnumSet.noneOf(IOSelect.AdditionalOperation.class));
}
}
Ok, will make the additionalOps param non-null and rev up all versions.
Re VV4: @NonNull is for findbugs and doesn't really affect javac behaviour
right? Shall I throw an IA exception if a null is passed then?
(In reply to comment #30)
> @NonNull is for findbugs and doesn't really affect javac behaviour right?
Right.
> Shall I throw an IA exception if a null is passed then?
You can do so if you think violations would otherwise be hard to track down, say because the NPE would come much deeper in the stack trace or in another stack altogether. (Parameters.notNull is the easiest way.)
Note that in NB APIs, everything is assumed to be @NonNull unless explicitly stated otherwise.
I really don't get the philosophy of non-null here.
We cannot statically enforce it so we enforce it dynamically?
Why not just do "something reasonable" with null instead of
throwing exceptions?
JG: Note that in NB APIs, everything is assumed to be @NonNull unless explicitly
stated otherwise.
Does that mean I _don't_ have to put a @NonNull in my code?
(In reply to comment #33)
>> everything is assumed to be @NonNull unless explicitly stated otherwise
>
> Does that mean I _don't_ have to put a @NonNull in my code?
Sorry for not being clear. You are not required to use @NonNull, call Parameters.notNull, or to even mention in the Javadoc that null is not allowed - it is just assumed by default to be forbidden in every API parameter and return value. Sometimes people do one or more of these for particular reasons:
1. Use @NonNull (or @CheckForNull, etc.) so that FindBugs will produce helpful diagnostics, if you are running FB routinely on this or related modules.
2. Call Parameters.notNull where this would improve diagnostics. For example, if your method constructs an object and initializes fields, one of which accidentally is left null, then later some other method is called on the object and throws NPE, it might not be obvious where the null came from (since the code which passed in the null is nowhere to be seen in the NPE's stack trace). Calling notNull early pins down the culprit in the stack trace. More often a null value would throw NPE further down the same call stack so notNull doesn't help so much.
3. Sometimes Javadoc can be clarified by saying, as in this instance, "the set may be empty but not null".
Vladimir, can you lease clarify what you mean by "prohibiting null" in
comment #22? We'll be done after that. (I'll put out a final patch).
(In reply to comment #35)
> Vladimir, can you lease clarify what you mean by "prohibiting null" in
> comment #22? We'll be done after that. (I'll put out a final patch).
Call Parameters.notNull
Created attachment 98466 [details]
patch for: openide.io core.io.ui core.output2
Last call for patch to
openide.io
core.io.ui
core.output2
Summary:
- @since inserted for class IOSelect
- apichanges updated, including Y13.
- Use Enum instead of EnumSet.
- Applying Paramters.notNull() to extraOps.
Negative testcase in unit test.
- Per JG#28
All affected modules' spec #'s incremented.
dependency spec #'s adjusted.
I believe I have addressed all comments.
.
(In reply to comment #38)
> .
All corrected.
I'll proceed to check in after one last build and test.
Thanks for everyones input.
Integrated into 'main-golden', will be available in build *201005100200* on (upload may still be in progress)
Changeset:
User:
Log:
Any reason to keep this P2 open after the integration? | https://netbeans.org/bugzilla/show_bug.cgi?id=184894 | CC-MAIN-2018-09 | refinedweb | 3,856 | 51.75 |
At some point in the last month, I needed to create an .ICO file on the fly with a couple of images inside; preferably I was looking at code in C#. The .NET Framework 2.0 only supports HICON that basically is one Icon with just a single image in it. When I was searching out there, to my frustration, I did not find any Icon Editor with the source code. The only thing I found was closed commercial products charging from $19 to $39 for them and not exposing APIs at all. So the only solution was to create my own library capable of creating and parsing ICO files.
I believe in open-source code and I thought that I could help the developer community by sharing this knowledge. In addition, open-source pushes companies and commercial products to go farther.
After the work was done, I read about ICL files (Icon Libraries). These can contain many Icons inside a file and I decided to support that too. The same happened with EXE/DLLs and last but not the least I decided to support Windows Vista Icons. All this was really hard work and a lot of headache because there is not much information exposed. I ended up spending a lot of time reverse-engineering and researching over the net. I hope it will be useful for you as it is for me.
As in every new project, many things can happen. Not every case can be tested and many things cannot be seen even after they are tested. Since it is a very fresh project, if there is something that doesn't work, or you think should work differently than it does, before you give your vote, write a post and give me the chance to fix it. That way, we both get the benefit of getting more stable code and creating a more complete library, and at the same time you get my thanks if that helps.
I have also included two libraries as samples. I borrowed some icons from Windows Vista, for the 256x256 versions and I put a watermark because the icons has copyright ownership. Hopefully I won't have trouble with that.
The objective of the library is to create an abstraction layer from the different file formats and to provide an interface to allow icon modification without the hassle of knowing internal file formats.
Iconlib exposes three different objects.
Iconlib
MultiIcon
MultiIcon
SingleIcon
IconImage
IconImage
XOR
AND
HICON
As you can see there is a hierarchical structure, basically a MultiIcon contains Icons and an Icon contains Images.
Icons
Icon
Images
The library contains many classes and structs but only exposes the three important classes. become visible and probably will not be used properly.
IconLib
I cannot give support for the library when it is not used the way it was designed. I'm providing the source code as a nice gesture because I believe in open-source code, and I hope you will make good use of it without ripping of the source from where it belongs.
Before I started IconLib, I had no clue how icons work. However, I was not too long in the net before I found the excellent article Icons in Win32
IconLib
Although this article is outdated with the arrival of Windows Vista icons, it is very precise in explaining how Icons format files are.
Something to take care; in my first version, I followed the icon format details but the library could not load some of the icons I was testing. When I went deep into the bytes, I could notice that much of the information was missing from the directory entry.
I tested those Icons with another product and I could see that, for example one popular product had no problem opening this kind of icon, and that is because every icon directory entry points to a ICONIMAGE struct, this ICONIMAGE struct has a BITMAPINFOHEADER struct that contains more information than the icon directory entry itself. So basically, using the information from the BITMAPINFOHEADER, I could reconstruct the information in the directory entry.
ICONIMAGE
BITMAPINFOHEADER
BITMAPINFOHEADER
The same rule cannot be applied to Windows Vista Icons, because those images don't contain a BITMAPINFOHEADER struct anymore. Hence, if some information is missing from the directory entry, the icon image becomes invalid.
Anyway, reconstructing the icon directory entry is a plus and discarding icon image not properly constructed is acceptable, no company should provide icons with missing information in the headers.
NE Format is the popular format to store icon libraries; this format was originally used for Executables on 16-bit version of Windows.
You can get more information for NE format from the Microsoft web site at Executable-File Header Format
This was the most challenging part of the project. When I started researching about ICL, I had no clue that these were 16-bit DLLs. I couldn't find any data about this extension and couple of days later, I almost dropped the project. But I read in some place that ICLs are 16-bit with resources inside so my quest started on how to recover resources from a 16-bit DLL. So far my only next objective was trying to load in memory a 16-bit DLL. Of course, at first I tried to load the library with standard Win32API LoadLibrary, LoadLibraryEx but this failed with:
LoadLibrary
LoadLibraryEx
193 - ERROR_BAD_EXE_FORMAT (Is not a valid application.)
I'm not an expert in Kernel memory allocation but I guess this is because in Win32, the memory is protected between applications and in 16-bit is not so when trying to allocate memory for 16-bit the OS rejects the operation.
The next step was trying to load the ICL (16-bit DLL) in memory using just 16 bits APIs. If you read the MSDN WIN32 API, the only API left for 16-bit is Loadmodule
Loadmodule
When I tried, it loaded the library but immediately Windows started giving strange message boxes, as "Not enough memory to run 16-bit applications" or things like that.
I wrote in Microsoft forums and other forums, but found nothing really helpful on how I could get those resources. At that time, it was very clear that I could not load 16-bit DLL in memory and that I needed to create my own NE parser/"linker".
Microsoft article about NE Format (New Executable) is an excellent source and describes in detail every field in the file.
A NE format file start with an IMAGE_DOS_HEADER, this header is there to keep compatibility with MS-DOS OS. This header also contains some specific fields to indicate the existence of a new segmented file format. IMAGE_DOS_HEADER usually contains a valid executable program to run on MS-DOS. This program is called a stub program and usually it just prints the message on the screen 'This program cannot run on MS-DOS'.
IMAGE_DOS_HEADER
After we read the IMAGE_DOS_HEADER, the first thing to do is to know if this is a valid header. Usually every file contains what is called a magic number. It is called a magic number because the data stored in that field is not relevant to the program, but it contains a signature to describe the type of the file.
You can find Magic Number almost everywhere. The magic number for the IMAGE_DOS_HEADER is 0x5A4D, this represents the chars 'MZ', and it stands by "Mark Zbikowski" who is a Microsoft Architect and started working with Microsoft a few years after its inception. Probably he could never have thought that his signature was going to be used thousands of times in almost every personal computer in the world.
0x5A4D
If the magic number is 'MZ' then the only extra field we care about is the e_lfanew, this header is the offset to the new exe header, NE Header.
e_lfanew
We search in the file for this offset, and then at this point we read a new header. This header is IMAGE_OS2_HEADER and it contains all information about the program to be loaded in memory.
IMAGE_OS2_HEADER
The first thing to do is to load the magic number again, but this time the magic number must be 0x454E and it means 'NE'. If the signatures match, then we can continue analyzing the rest of the headers. At this point the more important field is ne_rsrctab as this field contains the offset of the resource table. From this offset, we get the number of bytes we have to jump from the beginning of this header to be in position to read the resource table.
0x454E
ne_rsrctab
If everything went well, we are ready to read the resource table.
The first field of the Resource Table is the align shift, usually you find the explanation as "The alignment shift count for resource data. When the shift count is used as an exponent of 2, the esulting value specifies the factor, in bytes, for computing the location of a resource in the executable file."
In my own words, the working of this field was tricky to understand. It was created for compatibility with MS-DOS, and it will contain the multiply factor necessary to reach the resource.
As you will see, the resource offset is a variable of type ushort, which means that it can only address 64Kb (65536). Actually almost every file is bigger than that, and here is where the 'alignment shift' field comes to play.
ushort
Alignment shift is a ushort and "usually" it is in the range of 2 to 10. This number is the number of times we have to shift the number 1 to the left. For example:
ushort
Now with the virtual offset address from the resource table we multiply for the result shift value and we get the real offset address in the file.
The resource located at the virtual address 0x2000 and the alignment shift is 5 then we get:
Realoffset = (1 << 5) * 0x2000
Realoffset = 32 * 0x2000
Realoffset = 0x40000
The real offset of this resource is at 262144 (0x40000).
Wow, this is cool right? Because we just use an ushort and we can locate a resource at any position. Now you will wonder where the trick lies?
The trick is for example if you use a shift alignment of 5 that means the minimum addressable space is 32 bytes (1 << 5), which means if you want to allocate 10 bytes with this method 32 bytes will be allocated and just the first 10 will be used, another 22 bytes will be wasted.
Now you might wonder, ok then let’s take the shift alignment as 0, then tells what the maximum file sizes are that uses a shift factor of 9 because I thought that 32MB was more than enough for an Icon library. But great was my surprise when I extracted Windows Vista DLLs and IconLib got out of range for some files. I then incremented the shift factor to 10 which enabled me to dump the content of the Windows Vista DLL in an ICL file, but it took 63MB.
A factor of ten allows to us to create an ICL library up to 64MB but every resource will address at minimum 1024 bytes. If you think that's not bad because all resources will be bigger than 1024, it is not so easy. A factor of ten means it can address in multiples of 1024, then if the resource is 1025 then it will allocate 2048 bytes in the file system.
In conclusion, with a factor of 10, IconLib is wasting an average of (1024 / 2) 512 bytes by resource allocated, but at the same time it lets us create an Icon Library with 64MB.
My next release will predict the max file size and will adjust the shift factor dynamically; it is not an easy task if you want to predict the number without scanning memory to know the max space to be addressed, especially for PNG images where this value is dynamic too.
Hopefully shift alignment field is clear now and we come back to the resource table.
The next field is an array of TYPEINFO
TYPEINFO
TYPEINFO is a struct that gives us information about the resource; there are many types of resources that can be allocated, but IconLib is just interested in two types RT_GROUP_ICON and RT_ICON.
RT_GROUP_ICON
RT_ICON
When IconLib reads the TYPEINFO array, it discards all structs where rtTypeID is not RT_GROUP_ICON or RT_ICON
rtTypeID
RT_GROUP_ICON
RT_ICON
RT_GROUP_ICON type gives us information about a icon.
RT_ICON type gives us information about a single image inside the icon
rtResourceCount is the number of resources of this type in the executable.
rtResourceCount
rtNameInfo is an array of TNAMEINFO containing the information about every resource of this type. The length of this array is equal to rtResourceCount.
rtNameInfo
TNAMEINFO
Here is where we have the information about the resource itself; the rnOffset is the virtual address where the physical resource is located. To know the real address, see how alignment shift works above.
rnOffset
The rnLength is the length of the resource on a virtual address space. This means if for example the resource has a length of 1500 bytes and the alignment shift is 10, then the value on this field will be 2.
rnLength
The way to calculate the length is:
rnLenght = Ceiling(ral""OLE_LINK6"">RT_GROUP_ICON
then we read the array of TNAMEINFO which gives us information about every icon in the resource.
TYPEINFO
""OLE_LINK6"">RT_GROUP_ICON
TNAMEINFO
The offset in every TNAMEINFO will contain a pointer to a GRPICONDIR struct, this struct will give information about a single icon, like how many images it contains and one array of GRPICONDIRENTRY, whenever GRPICONDIRENTRY contains information about the image, like width, height, colorcount, etc.
GRPICONDIR
GRPICONDIRENTRY
GRPICONDIRENTRY
Now if the TYPEINFO struct type is RT_ICON then we read the array of TNAMEINFO which gives us information about every single image inside the resource.
Going back to the Resource Table we have another three fields, rscEndTypes, rscResourcesNames and rscEndNames.
rscEndTypes
rscResourcesNames
rscEndNames
rscEndTypes is a ushort value that tell us when to stop reading for TYPEINFO structs. The resource table struct doesn't tell how many TYPEINFO structs it contains, so the only way to know it is with a stopper flag. This flag is rscEndTypes. If when we read TYPEINFO the first two bytes are zero, then it means that we reached the end of the TYPEINFO array.
rscResourceNames is an array of bytes with the names of every resource in TYPEINFO struct. The names (if any) are associated with the resources in this table. Each name is stored as consecutive bytes; the first byte specifies the number of characters in the name.
rscResourceNames
For example if the array is [5, 73, 67, 79, 78, 48, 5, 73, 67, 79, 78, 49]
[
,
]
This is translated like an array of two strings "Icon1", "Icon2".
Icon1
Icon2
[5, 73, 67, 79, 78, 48, 5, 73, 67, 79, 78, 49]
[73, 67, 79, 78, 48] = "Icon1"
[73, 67, 79, 78, 49] = "Icon2"
If you wonder when you have to stop reading for bytes in the array, there exists another stopper flag rscEndNames
with a value of zero. When the bytes are being read, if a null ('\x0') character is detected, then the process must stop reading the names, and they are ready to be translated as ANSI strings.
At this point we already have all the information and binary data for the Icons and the images inside the Icon.
Icon
IconLib
loads all the Icons and Icon images in memory to obtain a good performance while working with them. In addition, it does not need to lock the file on the file system.
Creating an ICL file is not so complex after all. Because IconLib creates an ICL from scratch, it doesn't have to care about the other segments in the NE Format, so the process is relatively simple. We write an IMAGE_DOS_HEADER, write the MSDOS stub program, write an IMAGE_OS2_HEADER, where we choose the right alignment factor and we write the resource table at the location specified by the field ne_rsrctab
in the os2_header.
MSDOS
IMAGE_OS2_HEADER
ne_rsrctab
os2_header
When the resource table is written it has to apply the same rules when loading. This means write a partial resource table struct, the two TYPEINFO
structs (RT_GROUP_ICON
and RT_ICON
and inside the TYPEINFO</ode>, write theTNAMEINFO
information)
</ode>
TNAMEINFO
The following table shows a NE format that stores 2 Icons, the first icon contains one image, the second icon contains 2 images.
That is something that I would like to mention. As I mentioned before, I redesigned the core 3 times, the first time I followed every known specification on how the Icon file has to be read and written from Icons and DLLs. When I exported icons from DLLs, I kept all information about the icon, as the Icon names, group ID and icon ID. When I saved them on the file system, I saved them in the same way I read them, so basically I could export the icons from a DLL, export it to a ICL file, then load the ICL and export to a DLL, and I would keep the same IDs for the groups and Icons.
So far I tested two popular commercial products and they could open them without problems, but for example I started to have problems when I exported some DLLs or EXEs to ICL files. For example if you open explorer.exe from Windows folder in Visual Studio, the first thing you will notice is that the icons IDs are not consecutive, they start with ID 100, 101, 102, 103, 104 and jump to 107, and continue.
IconLib
exported explorer.exe to an ICL file, and import it on Visual Studio and there was no problem at all. But to my surprise, when I tried to open it with a popular Icon Editor, the icon library showed images with icons mismatched and mixed between the icons. I spent many days trying to figure why it was happening.
Basically after many tests of different applications, I could notice that those applications write the ICL files and discard the Icons and Group IDs and they expect consecutive IDs.
For ICL files there is a header to be written TNAMEINFO, this header contains a field which is the ID. This ID can be a GRPICONDIRENTRY (Icon itself) or an ICONDIRENTRY ID (single image ID inside the icon). When those applications write ICL files, they do it in a consecutive way, basically they discard the IDs when they imported from the DLL and write groups id as 1, 2, 3, 4, same for the icons id, they do 1,2,3,4. etc.
ICONDIRENTRY
So basically I noticed that some applications are not prepared to handle ICL files properly for all cases. Another not so popular application passed it and basically it could read ICL files where the IDs were not consecutive, but still when it saved the ICL file it discarded the source ID and put its own.
So I had a big dilemma. Should I keep all the information and write that information as it is coming from the EXE/DLLs in the ICL files; that would make my ICL files properly constructed but incompatible with some applications out there. Or should I discard the original IDs in the importation and create consecutive IDs which means discard part of the original information and put my own (I was not keen on this solution), but small fishes can swim in a pool with big fishes unless they behave like one.
So I didn't have another choice than to redesign my core to produce those results using consecutive IDs. After I redesigned I reduced the source code because now I didn't need to keep all the information that was generated on the fly, but when icons are exported from the DLLs the original Icons IDs are lost. Anyway, a regular developer will rarely use those IDs.
I still wonder if it is a mis-implementation of those products to fully support ICLs, or if there is a rule in the NE Format files that says you can't store a resource with a "random" ID. So far, all my research concludes that you can use any ID for the ICONIMAGES
inside NE Format.
ICONIMAGES
PE Format means Portable Executable; this format was created by Microsoft to supports 32-bit and 64-bit version of Windows in NE Format replacement used for 16-bit version of Windows.
Basically files format like EXE, DLL, OCX, CPL, SCR don't differ too much amongst them. For example, think of an EXE like a DLL with an entry point. When working with resources, all those files are identical. This means if the library supports PE Format then it supports all the above extensions.
Because Win32 API already supports resources handling for PE format, then it was not necessary to support this file format natively, instead IconLib makes use of Win32 APIs to gain access to the icons resources.
The only native functionality was to read the first set of headers from the PE file to detect whether the file to be loaded is a PE format or not.
If we want to access just the resources then the best way to do it is to load the library as a DATAFILE. This means no code at all will be executed from the library, instead Win32 API will access just the resources data.
DATAFILE
hLib = Win32.LoadLibraryEx(fileName, IntPtr.Zero, LoadLibraryFlags.LOAD_LIBRARY_AS_DATAFILE);
IconLib
core just supports reading and writing from and to a stream. MultiIcon
overloads some functions as Load/Save and creates a FileStream from a file in the file system before calling the Load(stream). Win32 API LoadLibrary
can only load libraries from the file system; therefore the stream will be saved in a temporary file before Win32 API LoadLibraryEX
is called.
Load
Save
FileStream
Load(stream)
LoadLibraryEX
Access to the resources is an easy task when the resources are accessed in the proper order.
The first thing that IconLib
does is call Win32.EnumResourceNames
sending as parameter GROUP_ICONS, which gives us back the ID of every icon. This ID can be a number or a pointer to a string. If the value returned is less than 65535 then it is a number, if the value if bigger than 65535 then it is a pointer to one string.
Win32.EnumResourceNames
GROUP_ICONS
Once we have all the IDs for the icons, we call the function Win32.FindResource. For every ID found, this gives us a handle to the resource and then we can proceed to load and lock the resource to access the resources entries. Those entries contain the IDs of every image inside the icon just loaded/locked. Now we repeat the steps that we did before, but instead of using the constant code>GROUP_ICONS we use RT_ICON. This tells the Win32 API that we want to access the image inside the icons.
Win32.FindResource
Here is the critical step that needs to be done. Under Windows XP or previous OS, after we lock the resource for the icon image we will have a pointer to an ICONIMAGE. This icon image will contain the BITMAPINFOHEADER, Palette, XOR
Image, and the AND
Image (mask), but in Windows Vista instead, it returns a pointer to a PNG image, basically this is the main reason why current Icon Editors including the more popular ones will crash. They will allocate huge amount of memory or just drop the image because they will be parsing a PNG image like a BMP image.
ICONIMAGE
Palette
XOR
Image
AND
PNG
BMP
IconLib
resolves that issue by reading the first bytes of the Image and detecting the signature of the image creating the proper encoder instance before reading and parsing the image.
When IconLib
has to create a DLL, the best way so far was to use an empty DLL as a template, and add the resources to it.
DLL
Win32 API offers three APIs that will do the job for us.
BeginUpdateResources
UpdateResources
EndUpdateResources
MSDN tells us that you can call BeginUpdateResources, and then call UpdateResources
as many times as you want, the file won't be written yet. At last you call EndUpdateResources
and the changes are committed to the DLL.
That methodology worked pretty good for small DLL files. When IconLib
was creating libraries with more than 80 images, everything was OK but the call to EndUpdateResources
always failed. After a lot of unsuccessful tries, the only thing I could think of was that the API to update resources has an internal buffer. When that buffer is full, calls to EndUpdateResoruces
fail to commit the changes into the DLL.
EndUpdateResoruces
The workaround that I found was to commit every time on an average of 70 updates, this worked pretty well but enormously increased the time to update the DLL. For that reason, unless I can find why Win32 is doing that, I'll try to come up with my own PE Format implementation, and not use the Win32 at all. That will speed up the process a lot.
You can get more information for PE format from Microsoft web site at Microsoft Portable Executable and Common Object File Format Specification
I wanted to create a library to work with icons without having any limitations, so support for Windows Vista was a must.
In Windows XP, they introduced icons with an alpha channel and 48x48 pixels. In Windows Vista, Microsoft introduced icons images with a size of 256x256 pixels. This image inside the icon can take 256Kbytes for the image and another 8Kbytes for the mask in uncompress format. That increases the size of icons library substantially and basically resolves this issue of storing the image in a compressed format.
The compression used was PNG (Portable Network Graphic) because it is free of patents, supports transparency (Alpha Channel) and employs lossless data compression.
The factor is on an average between 3 to 5 times smaller than uncompress bitmaps.
If you think there is not much difference, then load the file imageres.dll from Windows\System32 in Windows Vista (11MB), do a for loop for all images and set the encoder to be BMP instead PNG, then save it to a DLL or a ICL file. You will notice that the DLL is about 45MB and the ICL about 54MB. This is where you can see that PNG really makes the difference.
To store the compress image, they could come up with a way to keep some backward compatibility and this was setting the field biCompression
in BITMAPINFOHEADER
to BI_PNG instead of BI_RGB. This header is already supported from Windows 3.1 and the filed BI_PNG
from Windows 95, but instead they broke compatibility and they store the image alone. (see 'Ohh Microsoft policy about compatibility is changing?' below)
biCompression
BI_PNG
BI_RGB
The sample only contains two images but there can be up to 65535.
Although in all my research, I saw only 256x256 images in PNG format, that doesn't mean it could not store all images as PNG. This was only a decision to have compatibility with previous version of Windows.
Personally I think Icons editors should support PNG at any size and bits depth. Icons not only are used by Windows OS, it is the same why Windows icons allow introducing non-standard images like 128x96x24 when Windows will never make use of it.
If you are creating an icon that Windows Vista will make use of, only store PNG compression for 256x256 images.
The more difficult stuff was how to come up with a clean code and APIs capable of understanding different icons formats and icons libraries and also different image compressions without creating a chaos of switch/if/else.
In my journey of creating the library, I redesigned the core from scratch 3 times, and still there is a TODO changes to avoid IconImages
objects from knowing about different compression methods. Basically an IconImage
should not be responsible for knowing the format of the image to be read/written. Instead it should depend on the different encoders to know this information.
IconImages
Right now IconImage
has a reference to an ImageEncoder
object (base class), but still IconImage
object is responsible for discovering the signature of the image to know if it has to create a BMPEncoder
or a PNGEncoder
instance.
ImageEncoder
BMPEncoder
PNGEncoder
Also there are a couple of changes to manage the memory allocations more efficiently, but that won't change the core design.
Coming back to what I called Smart Class/Structs: Basically an Icon is a hierarchical structure and Icon libraries are the same but contain one more level of information.
The objective of this smart classes/structs was to avoid interchange data between the different objects; instead every class/struct should be capable of reading and writing itself. If a class of struct contains more classes or structs inside, then it should ask the child to read/write that portion of information and so on.
If you open the source code, immediately you will notice that the parameter 'Stream stream' is everywhere. This allows the object that receives this parameter to read/write itself in the stream at the current position.
Stream stream
For example, when a Icon file has to be created, the MultiIcon
object will open a FileStream and will call ImageFormat.Save(stream), sending as a parameter the stream just opened.
ImageFormat.Save(stream)
ImageFormat object will contain only the logic to write itself and rely on the different classes/struct to write the rest of the information.
ImageFormat
ImageFormat.Save(stream)
{
ICONDIR.write(stream)
{
Write iconDir header
}
Loop for each IconImage
{
ImageEntry.Write(stream)
{
Write iconEntry header
}
Image.Write(stream)
{
BitmapInfoHeader.Write(stream)
{
Write bitmap info header
}
Write Color Palette
Write XOR image
Write AND image
}
}
}
This is a simple case, but more complex cases like reading ICL (Icon Libraries) follow the same behavior.
So, following this model writing and reading different formats was really easy. It also produced a super, cleaner code.
I wanted to provide a library easy to understand and flexible enough to adapt to any kind of image format. The ideal case was to create a class with basic functionality but to leave the specific format implementation to other classes.
ImageEncoder
object keeps all the information about one icon image and it contains information like image properties, palette, icon image, and icon mask.
This class is an abstract class that cannot be instantiated.
BMPEncoder class has the logic to read and write Icon entries when biCompression is BI_RGB (BMP)
PNGEncoder class has the logic to read and write Icon entries when image is PNG format.
I followed the information I could get from different sources to create Icons with PNG compression. So far the implementation doesn't have problems and Icons Images in PNG format can be opened with all Icons editors that support Windows Vista.
Icon libraries are a different subject. So far I did not find a single open source or commercial icon editor, including the more popular ones that allow opening or writing icon libraries like ICL or DLL with PNG compression, In some commercial products you will notice that the PNG icons are not loaded and also if you create PNG icons they are uncompressed before getting saved on a DLL or ICL. I think that is because Microsoft still didn't release any information about it and companies are waiting for the final Windows Vista to come out.
I based my work for creating compressed icon libraries (ICL, DLL) on reverse engineering in Windows Vista RC2 and following the same logic that the Microsoft boys used for icon files.
IconLib is capable of loading all icons from Windows Vista DLLs/EXEs and CPL files (PNG format inclusive). It also allows writing ICL/DLL icon libraries with PNG compressions.
The bad news is that only you can load them with IconLib
for now. If you try to load an ICL or DLL with PNG images generated with IconLib
and try to open it with third party icon editor, you will see that the PNG icons are gone, and also the icons contain images from other icons. So far, all my research concludes that there is a mis-implementation of PNG format for ICL libraries in those products and has nothing to do with IconLib.
Now if you wonder how I can be sure that IconLib
generates ICL or DLL properly?.. Of course that image doesn't exist and you can't edit it, but that's how Visual Studio sees it.
Now if you load a DLL with 256x256 PNG files, generated with IconLib
and save the icon that contains the PNG image to the file system and open the icon image with Visual Studio, you will notice the same behavior as the DLLs from Windows Vista.
Anyway, the entire work is based on suppositions, and I can't be really sure yet as long as any Windows Vista Libraries Icons Editors hit the market or Microsoft releases more information about it.
Usually there are programs that allow creating icons from a bitmap and they produce an Icon with alpha channel (transparency) compatible with Windows XP, those icons lacks of the support of low resolution images, Iconlib allows to add a low resolution image and also incorporate a whole namespace to produce a low resolution image from a high resolution image.
The techniques used by IconLib are:
A palette is an array of RGB colors, most of the times the length of the palette is the amount of colors supported, a palette can contains any length but in most of the cases the palettes are 256 or 16 indexes.
An optimized palette is created on base to the bitmap to be processed; it will analyze the input image and will create a new palette with the most used colors from the input image, many ways might be used to create an optimized palette.
Why use a palette on a Bitmap?
Every index in the palette is a RGB color, 3 bytes are necessary to create the color (1 byte for Red, 1 byte for Green, 1 byte for Blue), this allow to create a combination of 16 million colors because each channel can produce a 256 color gradient, then 256R * 256G * 256B = 16777216 color combinations.
If on the bitmap data we store the RGB information then at least we require 3 bytes to store every pixel color.
Instead, indexed bitmaps will store just one index to an array of colors; this means that the bitmap data does not contain color information but an index to an array (palette).
This can save a lot of space but the image quality may suffer considerably because very similar colors on non-indexed image will be converted to the same color (index) on an indexed image.
There are many more data store in a Bitmap but just for example let’s compare the size of 3 bitmaps.
100x100 pixels 24 bpp image
1 pixel = 3 bytes
100x100x3 = 30000 bytes to store the color information.
100x100 pixels 8bpp indexed image
1 pixel = 1 byte
1 palette = 256 indexes of RGB color = 256x3 = 768
100x100x1 + 768 = 10768 bytes to store the color information.
100x100 pixels 4bpp indexed image
1 pixel = 1/2 byte
1 palette = 16 indexes of RGB color = 16x3 = 48
100x100x1/2 + 48 = 5048 bytes to store the color information.
The key to have a low resolution indexed image and still good looking is to choose the right color for the palette, there are different palettes that can be used.
System palette: this is the default Windows palette and it contains 256 colors, it has a variety of colors in a wide spectrum, IconLib make no use of this palette because if for example the icon to be color reduced has many gradients when those gradient are converted to an index pixel version many of them will have the same index and the quality of the image will be greatly degraded.
Exact: If the image contains less than 256 colors, those are mapped directly to the palette.
Web: Is the intersection between Windows and Mac OS palette, it contains 216 colors that are safe to be used on Windows or Mac OS systems.
Adaptive: This palette reduces the colors in the bitmap based on their frequency; for example, if your image contains mostly skin tones, the adaptive color palette will be mostly skin tones.
Perceptual: This palette is weighted toward reducing the colors in the bitmap to those to which we are the most sensitive.
Selective: The Selective palette will choose the colors from the bitmap to the web-safe colors.
Custom: A custom palette might be provided.
IconLib creates an optimized palette using the Adaptive algorithm with an Octtree structure.
The idea behind color reduction is take an 32bits (ARGB) or 24bits (RGB) image where the data of every pixel contains the RGB color information and convert this image to a indexed image, they are called indexed because every pixel data does not contain the RGB color information instead it contains a index to a palette (Array of colors), this palette store n numbers of colors, 32bits and 24bits images can produce 16 million colors and every pixel is stored as 3 bytes (4th byte for alpha channel). Because indexed just store an index to the palette the store needed depends of the image resolution.
Non-Indexed 32 bits (16M colors plus transparency) = 4 bytes per pixel
Non-Indexed 24 bits (16M colors) = 3 bytes per pixel
Indexed 8 bits (256 colors) = 1 byte per pixel
Indexed 4 bits (16 colors) = 1/2 byte per pixel or 2 pixel per byte
Indexed 1 bit (Black&White) = 1/8 byte per pixel or 8 pixel per byte
In IconLib color reduction algorithm works pretty close with the palette optimization algorithm.
Before a pixel can be converted to an indexed pixel a palette must be available to choose the right color index.
Different palettes can be used in the process of color reduction.
See Palette Optimization above.
The algorithm I have use in the color selection was the Euclidian distance, basically it finds the nearest neighbor color in the palette, it maps the current color in the image with a color in the palette finding the shortest distance between the current color and the neighbor color in a 3D space.
Even when an optimized palette is used in the process of color reduction the resulting image may looks not good especially when the input bitmap contains high number of gradient, to improve the looking of image dithering is used.
Dithering is the process of juxtaposing pixels of two colors to create the illusion that a third color is present, basically noise is added in the process, this noise is proportional to the different color gaps between pixels.
There are many algorithm to implement dithering, and the output image vary between them, personally I like Floyd-Steinberg algorithm because the noise generated is spread uniformly creating a nice looking image.
No dithering: no noise is added to the output bitmap.
There are three kinds of dithering:
Noise dither: It is not really acceptable as a production method, but it is very simple to describe and implement. For each value in the image, simply generate a random number 1..256; if it is greater than the image value at that point, plot the point white, otherwise plot it black.
Ordered dither: Ordered dithering adds a noise pattern with specific amplitudes, for every pixel in the image the value of the pattern at the corresponding location is used as a threshold. Different patterns can generate completely different dithering effects.
Error diffusion: diffuses the quantization error to neighboring pixels.
Floyd-Steinberg dither: it is an error diffusion dither algorithm and is which is used in IconLib, it is based on error dispersion. For each point in the image, first find the closest color available. Calculate the difference between the value in the image and the color you have. Now divide up these error values and distribute them over the neighboring pixels which you have not visited yet. When you get to these later pixels, just add the errors distributed from the earlier ones, clip the values to the allowed range if needed, then continue as above.
In the following sample it reduces the image to 8, 4 and 1bpp from a 24bpp source image.
IColorQuantizer colorReduction = new EuclideanQuantizer(new OctreeQuantizer(), new FloydSteinbergDithering());
Bitmap bmp = (Bitmap) Bitmap.FromFile("c:\\Pampero.png");
Bitmap newBmp = colorReduction.Convert(bmp, PixelFormat.Format8bppIndexed);
newBmp.Save("c:\\Pampero 8.png", ImageFormat.Png);
newBmp = colorReduction.Convert(bmp, PixelFormat.Format4bppIndexed);
newBmp.Save("c:\\Pampero 4.png", ImageFormat.Png);
newBmp = colorReduction.Convert(bmp, PixelFormat.Format1bppIndexed);
newBmp.Save("c:\\Pampero 1.png", ImageFormat.Png);
24bits RGB 16M Colors
8bits 256 colors
Floyd-Steinberg dither
4bits 16 colors
1bit Black and White
For most of the application that use IconLib the ColorProcessing namespace contains all the tools necessary to create a quality icon, but because there are so many algorithm for color reduction then it is implemented with interfaces, this means that the library can be expanded to use different algorithms if it is necessary.
For color reduction there is an interface IColorQuantizer and it is implemented for the default class EuclideanQuantizer
IColorQuantizer
EuclideanQuantizer
For palette optimization there is an interface IPaletteQuantizer and it is implemented for the default class OctreeQuantizer
IPaletteQuantizer
OctreeQuantizer
For dithering there is an interface IDithering and it is implemented for the default class FloydSteinbergDithering
IDithering
FloydSteinbergDithering
Any of those interfaces can be implemented and the default can be replaced.
For example, if the developer implemented the noise or random dither algorithm then the color reduction initialization could be something like:
IColorQuantizer colorReduction = new EuclideanQuantizer(new OctreeQuantizer(), new NoiseDithering());
Even when with a few lines of code IconLib can create an icon with multiple images from a single one, anyway IconLib provideds a special API that will create a full Icon from a single input image.
MultiIcon mIcon = new MultiIcon();
SingleIcon sIcon = mIcon.Add("Icon1");
sIcon.CreateFrom("c:\\Clock.png", IconOutputFormat.FromWin95);
CreateFrom is a method exposed on SingleIcon class, this method will take a input image that must be 256x256 pixels and it must be a 32bpp (alpha channel must be included), the perfect candidate for this method are PNG24 images created for PhotoShop or any Image editing software.
CreateFrom
The second parameter in the API is a flag enumeration that target the OS which we want to create the icon, in the previous example it will take the input image and it will create the following IconImage formats.
256x256x32bpp (PNG compression)48x48x32bpp 48x48x8bpp48x48x4bpp32x32x32bpp32x32x8bpp16x16x32bpp16x16x8bpp
There are 14 possible enumerations defined, but they can be combined to get whatever format the developer is looking for.
This method make use of the whole library to provide the best IconImage for each format.
Something I have to comment about because I think it is a breakthrough on how Microsoft usually does things from my point of view.
I have been developing on Windows platform for the last decade from the Windows 3.1 to date, and something that I saw in Microsoft APIs is the amazing compatibility between versions. Personally I think many Win32 APIs are so intrinsic and complicated because they had to keep backward compatibility, and I had so many headaches in the last years because of it.
For example the huge show stopper for Windows future generation was the GDI that imposed a set of rules that could not be broken in any way, GDI+ helped but still ran under the GDI rules, and that is the reason why there are things that Windows could never do until now.
This happened when I decided to implement Windows Vista icons support.
I read that Windows Vista icons are 256x256 and they use PNG compression for them.
At first I was 100% convinced they were going to keep backward compatibility, so I started to think how they did it. The first thing that came to my mind was that Microsoft boys were going to use the field biCompression in the header BITMAPINFOHEADER
and instead set to BI_RGB (BMP). They were going to use BI_PNG
(PNG) that is already supported in the header, the palette was going to be empty and the XOR and AND Image would contain the PNG data.
biCompression
I was surprised when that didn't happen. Instead they completely dropped the concept of having a BITMAPINFOHEADER, the image (XOR) and the mask (AND). Instead, the icon directory pointed to a 100% PNG structure.
At first I thought, 'oh my God what have they done!'
This was going to break all Icons Editors out there, also Visual Studio and Resource Editors won't be able to open ICO files anymore, but when I sat and thought about it, it occurred to me that it was the right way to go.
Developers have always complained about how complicated some Win32 APIs are, and this time Microsoft heard that and did things right.
If they could have kept compatibility, it would mean that now ICO and ICON libraries could have 3 places with redundant information about each image.
Like ICONDIRENTRY, BITMAPINFOHEADER, and PNGHEADER usually find those bizarre things in Win32 API.
ICONDIRENTRY
PNGHEADER
Instead now they have the Icon directory entry that points to the image itself. That way, they open the way for future implementation for different images or compressions. Still ICO files are limited by a maximum of 256x256 pixels because the Icon directory stores width and height in two byte type fields bWidth
and bHeight. Probably that can be resolved using more than one Plane. But anyway still we are far from use ICONS with more than 256x256 pixels.
bWidth
bHeight
So this time I congratulate the boys at Microsoft for thinking "what is the best way to do it" over anything else.
If you wonder if this means VS2005 or any VS won't be able to open properly ICO or DLLs from Windows Vista, then you are right, it WON'T. I also tested ORCAS (VS2006) and it doesn't support it. But that can be easily resolved with a VS patch that hopefully will come out soon, else you will have a product like this library that will support Windows Vista Icons.
IconLib is a powerful library to allow icons or icon libraries creation and modifications. I plan to support updates for DLLs and EXE in the next version, allowing to replace/add/delete icons inside them.
IconLib alone is only useful from a programming language. So, I also plan to create an advance Icon Editor application to make full use of IconLib. That will probably be my next article in the next few months.
If I can get file formats like .icc (Icons collection), Icns, RSC, bin (mac), I'll support them. If you know of some file format and you have the internal file structure, let me know and I'll try it to implement it.
If someone is interested in creating an open-source Icon Extractor & Editor, then he or she is welcome to use IconLib as the file formats engine and I can provide support for IconLib.
IconLib 0.73 (01/31/2008)
IconLib 0.72 (11/02/2006)
IconLib 0.71 (Initial Release)
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.
This article, along with any associated source code and files, is licensed under The Creative Commons Attribution-ShareAlike 2.5 License
switch (mEncoder.IconImageFormat)
{
case IconImageFormat.BMP:
iconDirEntry.bHeight = (byte)(mEncoder.Header.biHeight / 2);
break;
default:
iconDirEntry.bHeight = (byte)mEncoder.Header.biHeight;
break;
}
iconDirEntry.bHeight = (byte)mEncoder.Header.biHeight;
public unsafe MultiIcon Load(Stream stream)
{
....
if (Win32.IS_INTRESOURCE(id))
hRsrc = Win32.FindResource(hLib, int.Parse(id), (IntPtr) ResourceType.RT_GROUP_ICON);
else
hRsrc = Win32.FindResource(hLib, id, (IntPtr) ResourceType.RT_GROUP_ICON);
if (hRsrc == IntPtr.Zero)
throw new InvalidFileException();
...
public unsafe MultiIcon Load(Stream stream)
{
....
hRsrc = Win32.FindResource(hLib, id, (IntPtr) ResourceType.RT_GROUP_ICON);
if (hRsrc == IntPtr.Zero)
{
if (Win32.IS_INTRESOURCE(id))
hRsrc = Win32.FindResource(hLib, int.Parse(id), (IntPtr) ResourceType.RT_GROUP_ICON);
}
if (hRsrc == IntPtr.Zero)
throw new InvalidFileException();
...
--- System/Drawing/IconLib/IconImage.cs (revision 1697)
+++ System/Drawing/IconLib/IconImage.cs (working copy)
@@ -208,8 +208,10 @@
{
ICONDIRENTRY iconDirEntry;
iconDirEntry.bColorCount = (byte) mEncoder.Header.biClrUsed;
- iconDirEntry.bHeight = (byte) mEncoder.Header.biHeight;
- iconDirEntry.bReserved = 0;
+ // iconDirEntry.bHeight = (byte) mEncoder.Header.biHeight;
+ // armin: biHeight is always *2
+ iconDirEntry.bHeight = (byte) (mEncoder.Header.biHeight/2);
+ iconDirEntry.bReserved = 0;
iconDirEntry.bWidth = (byte) mEncoder.Header.biWidth;
iconDirEntry.dwBytesInRes = (uint) (sizeof(BITMAPINFOHEADER) +
sizeof(RGBQUAD) * ColorsInPalette +
filename.dll
en-US\filename.resources.dll
en-US\filename.dll.mui
System.Globalization.CultureInfo.CurrentUICulture.Name
MultiIcon mico = new MultiIcon();
SingleIcon sico = mico.Add("Default");
sico.Add(Win.Icon);
sico.Save(sd.FileName);
XORImage = Bitmap.FromHbitmap(iconInfo.hbmColor);
Private mmultiicon As New IconLib.MultiIcon()
Public Function loadicons(ByVal path As String) As Image
If path.Contains(",") Then
path = path.Split(",")(0)
End If
Try
mmultiicon.Load(path)
mmultiicon.SelectedIndex = 0
Dim workimage As IconLib.IconImage = Nothing
For Each iconImage As IconLib.IconImage In mmultiicon(0)
If iconImage.Size.Width >= 48 AndAlso iconImage.Size.Height >= 48 AndAlso iconImage.PixelFormat = Imaging.PixelFormat.Format32bppArgb Then
If iconImage.Size.Width = 256 Then
workimage = iconImage
Exit For
ElseIf workimage Is Nothing Then
workimage = iconImage
ElseIf iconImage.Size.Width > workimage.Size.Width Then
workimage = iconImage
End If
End If
If Not workimage Is Nothing Then
Return resizeicon(workimage.Icon.ToBitmap)
Exit Function
Else
Return nothing 'here you can just return anyother image you want;
End If
Catch ex As Exception
Return resizeicon(Icon.ExtractAssociatedIcon(path).ToBitmap)
End Try
End Function
General News Suggestion Question Bug Answer Joke Praise Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages. | http://www.codeproject.com/Articles/16178/IconLib-Icons-Unfolded-MultiIcon-and-Windows-Vista?msg=4036505 | CC-MAIN-2016-44 | refinedweb | 8,344 | 59.03 |
Functions
On this page we'll learn how to write functions, which are named blocks of code that are designed to do one specific job. When you want to perform a particular task that you've defined in a function, you call the function responsible for it. If you need to perform that task multiple times throughout your program, you don't need to type all the code for the same task again and again; you just call the function dedicated to handling that task, and the call tells Python to run the code inside the function. You'll find that using functions makes your programs easier to write, read, test, and fix.
We will also learn ways to pass information to functions. We will learn how to write certain functions whose primary job is to display information and other functions desinged to process data and return a value or a set of values. Finally, we will cover how to store functions in separate files called modules to help organize our main program files.
Defining a Function
Here is a simple function named
greet_user() that prints a greeting:
defto inform Python that you're defining a function. This is the function definition, which tells Python the name of the function and, if applicable, what kind of information the function needs to do its job. The parentheses hold that information. In this case, the name of the function is
greet_user(), and it needs no information to do its job, so its parentheses are empty. (Even so, the parentheses are required.) Finally, the definition ends in a colon.
An indented lines that follow
def greet_user(): make up the body of the function. The text on line 2 is a comment called a docstring, which describes what the function does. Docstrings are enclosed in triple quotes, which Python looks for when it generates documentaion for the functions in your programs.
The line
print("Hello!") on line 3 is the only line of actual code in the body of this function, so
greet_user() has just one job:
print("Hello!").
When you want to use this function, you call it. A function call tells Python to execute the code in the function. To call a function, you write the name of the function, followed by any necessary information in parentheses, as shown on line 4. Because no information is needed here, calling our function is as simple as entering
greet_user(). As expected, it prints
Hello!.
Passing Information to a Function
Modified slightly, the function
greet_user() can not only tell the user
Hello! but also greet them by name. For the function to do this, you enter
username in the parentheses of the function's definition at
def greet_user(). By adding
username here you allow the function to accept any value of
username you specify. The function now expects you to provide a value for
username each time you call it. When you call
greet_user(), you can pass it a name, such as
'jesse', inside the parentheses:
greet_user('jesse')calls
greet_user()and give the function the information it needs to execute the
print()call. The function acceptsthe name you passed it and displays the greeting for that name:
Hello, Jesse!
Arguments and Parameters
In the preceding
greet_user() function, we defined
greet_user() to require a value for the variable
username. Once we called the function and gave it the information (a person's name), it printed the right greeting.
The variable
username in the definition of
greet_user() is an example of a parameter, a piece of information the function needs to do its job. The value
'jesse' is
reet_user('jesse') is an example of an argument. An argument is a piece of information that's passed from a function call to a function. When we call the function, we place the value we want the function to work with in the parenthese. In this case the argument
'jesse' was passed to the function
greet_user(), and the value was assigned to the parameter
username.
Passing Arguments
Because a function definition can have multiple parameters, a function call may need multiple arguments. You can pass arguments to your functions in a number of ways. You can use positional arguments, which need to be in the same order as the parameters were written; keyword arguements, where each argument consists of a variable name and a value; and lists and dictionaries of values.
Positional Arguments
When you call a function, Python must match each argument in the function call with a parameter in the function definition. The simplest way to do this is baased on the order of the arguments provided. Values matched up this way are called positional arguments.
To see how this works, consider a function that displays information about pets. The function tells us what kind of animal each pet is and the pet's name, as shown here:
describe_pet(), we need to provide an animal type and a name, in that order. For example, in the function call, the argument
'hamster'is assigned to the parameter
animal_typeand the argument
'harry'is assigned to the parameter
pet_name(line 6). In the function body, these two parameters are used to display information about the pet being described.
The output describes a hamster named Harry:
I have a hamster. My hamster's name is Harry.
Multiple Function Calls
You can call a function as many times as needed. Describing a second, different pet requires just one more call to
describe_pet():
describe_pet()the arguments
'dog'and
'willie'. As with the previous set of arguments we used, Python matches
'dog'with the parameter
animal_typeand
'willie'with the parameter
pet_name. As before, the function does its job, but this time it also prints the values for a Dog named Willie:
I have a hamster. My hamster's name is Harry. I have a dog. My dog's name is Willie.
You can use as many positional arguments as you need in your functions. Python works through the arguments you provide when calling the function and matches each one with the corresponding parameter in the function's definition.
Order Matters in Positional Arguments
You can get unexpected results if you mix up the order of the arguments in a function call when using positional arguments:In the above function, we list the name first and the type of animal second. Because the argument
'harry'is listed first this time, that value is assigned to the parameter
animal_type. Likewise,
'hamster'is assigned to
pet_name. Now we have a "harry" named "Hamster":
I have a harry. My harry's name is Hamster.
Keyword Arguments
A keyword argument is a name-value pair that you pass to a function. You directly associate the name of the value within the argument, so when you pass the argument to the function, there's no confusion (you won't end up with a harry named Hamster). Keyword arguments free you from having to worry about correctly ordering your arguments in the function call, and they clarify the role of each value in the function call.
Let's rewrite the program from above using keyword arguments to call
describe_pet():
describe_pet()hasn't changed, but when we call the function, we explicitly tell Python which parameter each argument should be matched with. When Python reads the function call, it knows to assign the argument
'hamster'to the parameter
animal_typeand the argument
'harry'to
pet_name. The output correctly shows that we have a hamster named Harry.
The order of keyword arguments doesn't matter because Python knows where each value should go. The following two function calls are equivalent:
Default Values
When writing a function, you can define a default value for each parameter. If an argument for a parameter is proivided in the function call, Python uses the argument value. If not, it uses the parameter's default value. So when you define a default value for a parameter, you can exclude the corresponding argument you'd usually write in the function call. Using default values can simplify your function calls and clarify the ways in which your functions are typically used.
For example, if you notice that most of the calls to
describe_pet() are being used to describe dogs, you can set the default value of
animal_type to
'dog'. Now anyone calling
describe_pet() for a dog can omit that information:
describe_pet()to include a default value,
'dog', for
animal_type. Now when the function is called with no
animal_typespecified, Python knows to use the value
'dog'for this parameter:
I have a dog. My dog's name is Willie.
pet_name.
The simplest way to use this function now is to provide just a dog's name in the function call:
describe_pet('willie')
'willie', so it is matched up with the first parameter in the definition,
pet_name. Because no argument is provided for
animal_type, Python uses the default value
'dog'.
To describe an animal other than a dog, you could use a function call like this:
describe_pet(pet_name='harry', animal_type='hamster')
animal_typeis provoided, Python will ignore the parameter's default value.
Note on default values
When you use default values, any parameter with a default value needs to be listed after all the parameters that don't have default values. This allows Python to continue interpreting positional arguments correctly.
Equivalent Function Calls
Because positional arguments, keyword arguments, and default values can all be used together, often you'll have several equivalent ways to call a function. Consider the following definition for
describe_pet() with one default value provided:
def describe_pet(pet_name, animal_type='dog'):
pet_name, and this value can be provided using the positional or keyword format. If the animal being described is not a dog, an argument for
animal_typemist be included in the call, and this argument can also be specified using the positional or keyword format.
All the follwoing calls would work for this function:
Avoiding Argument Errors
When you start to use functions, don't be surprides if you encounter errors about unmatched arguments. Unmatched arguments occur when you provide fewer or more arguments than a function needs to do its wor. For example, here's what happens if we try to call
describe_pet() with no arguments:
TypeError Traceback (most recent call last) File <"pets.py">, line 6, in <module> 4 print(f"My {animal_type}'s name is {pet_name.title()}.") 5 ----> 6 describe_pet() TypeError: describe_pet() missing 2 required positional arguments: 'animal_type' and 'pet_name'
Python is helpful in that it reads the function's code for us and tells us the names of the argument we need to provide. This is another motivation for giving your variables and functions descriptive names. If you do, Pythons error messages will be more useful to you and anyone else who might use your code.
If you provide too many arguments, you should get a similar traceback that cal help you correctly match your function call to the function definition.
Return Values
A function doesn't always have to display its output directly. Instead, it can process some data and then reutn a value or set of values. The value the function returns is called a return value. The return statement takes a value from inside a function and sends it back to the line that called the function. Return values allow you to move much of your program's grunt work into functions, which can simplify the body of your program.
Returning a Simple Value
Let's look at a function that takes a first and last name, and returns a neatly formatted name:The defintion of
get_formatted_name()takes as parameters a first and last name (line 1). The function combines these two names, adds a space between them, and assigns the result to
full_name(line 3). The value of
full_nameis converted to title case, and then returned to the calling line at line 4.
When you call a function that returns a value, you need to provide a variable that the return value can be assigned to. In this case, the returned value is assigned to the variable
musician on line 6. The output shows a neatly formatted name made up of the parts of a person's name:
Jimi Hendrix
print("Jimi Hendrix")
get_formatted_name()become very useful. You store first and last names separately and then call this function whenever you want to display a full name.
Making an Argument Optional
Sometimes it makes sense to make an argument optional so that people using the function can choose to provide extra information only if they want to. You can use default values to make an argument optional.
For example, say we want to exapand
get_formatted_name() to handle middle names as well. A first attempt to include middle names might look like this:
John Lee Hooker
middle_nameargument an empty default valuye and ignore the argument unless a user provides a value. To make
get_formatted_name()work without a middle name, we set the default value of
middle_nameto an empty string and move it to the end of list of parameters:
In this example, the name is built from three possible parts. Because there's always a first and last name, these parameters are listed first in the function's definition. The middle name is optional, so it's listed last in the definition, and its default value is an empty string (line 1).
In the body of the function, we check to see if a middle name has been provided. Python interprets non-empty strings as
True, so
if middle_name evaluates to
True if a middle name argument is in the function call (line 3). If a middle name is provided, the first, middle, and last names are combined to form a full name. This name is then changed to title case and returned to the function call line where it's assigned to the variable
musician and printed. If no middle name is provided, the empty string fails the
if test and the
else block runs (line 5). The full name is made with just a dirst and last name, and the formatted name is returned to the calling line where it's assigned to
musician and printed.
Calling this function with a first and last name is straightforward. If we're using a middle name, however, we have to make sure the middle name is the last argument passed so Python will match up the positional arguments correctly (line 12).
This modified version of our function works for people with just a first and last name, and it works for people who have a middle name as well:
Jimi Hendrix John Lee Hooker
Returning a Dictionary
A function can return any kind of value you need it to, including more complicated data structures like lists and dictionaries. For example, the following function takes in parts of a name and returns a dictionary representing a person:
build_person()takes in a first and last name, and puts these values into a dictionary (line 3). The value of
first_nameis stored with the key
'first', and the value of
last_nameis stored with the key
'last'. The entire dictionary representing the person is returned at line 4. The return value is printed on the final line with the original two pieces of textual information now stored in a dictionary:
{'first': 'jimi', 'last': 'hendrix'}
'jimi'and
'hendrix'are now labeled as a first name and last name. You can easily extend this function to accept optional values like a middle name, an age, an occupation, or any other information you want to store about a person. For example, the following change allows you to store a person's age as well:
We add a new optional parameter
ageto the function definition and assign the parameter the special value
None, which is used when a variable has no specific value assigned to it. You can think of
Noneas a placeholder value. In conditional tests,
Noneevaluates to
False. If the function call includes a value fo
age, that value is stored in the dictionary. This function always stores a person's name, but it can also be modified to store any other information you want about a person.
Using a Function with a
while Loop
You can use functions with all the Python structures you've learned about so far. For example, let's use the
get_formatted_name() function with a
while loop to greet users more formally. Here's a first attempt at greeting people using their first and last names:
get_formatted_name()that doesn't involve middle names. The
whileloop asks the user to enter their name, and we prompt for their first and last name separately (line 8).
But there's one problem with this
while loop: We haven't defined a quit condition. Where do you put a quit condition when you ask for a series of input? We want the user to be able to quit as easily as possible, so each prompt should offer a way to quit. The
break statement offers a straightforward way to exit the loop at either prompt:
'q'for either name:
Please tell me your name: (enter 'q' at any time to quit) First name: Nick Last name: Platt Hello, Nick Platt! Please tell me your name: (enter 'q' at any time to quit) First name: q
Passing a List
You'll often find it useful to pass a list to a function, whether it's a list of names, numbers, or more complex objects, such as dictionaries. When you pass a list to a function, the function gets direct access to the contents of the list. Let's use functions to make working with lists more efficient.
Say we have a list of users and want to print a greeting to each. The following example sends a list of names to a function called
greet_users(), which greets each person in the list individually:
greet_users()so it expects a list of names, which it assigns to the parameter
names. The function loops through the list it receives and prints a greeting to each user. On line 7, we define a list of users and then pass the list
usernamesto
greet_users()in our function call:
Hello, Hannah! Hello, Ty! Hello, Margot!
Modifying a List in a Function
When you pass a list to a function, the function can modify the list. Any changes made to the list inside the function's body are permanent, allowing you to work efficiently even when you're dealing with large amounts of data.
Consider a company that creates 3D printed models of designs that users submit. Designs that need to be printed are stored in a list, and after being printed they're moved to a separate list. The following code does this without using functions:
completed_modelsthat each design will be moved to after it has been printed. As long as designs remain
unprinted_designs, the
whileloop simulates printing each design by removing a design from the end of the list, storing it in
current_design, and displaying a message that current design is being printed. It then adds the design to the list of completed models. When the loop is finished running, a list of designs that have been printed is displayed:
Printing model: dodecahedron Printing model: robot pendant Printing model: phone case The following models have been printed: dodecahedron robot pendant phone case
print_models()with two parameters: a list of designs that need to be printed and a list of completed models. Given these two lists, the function simulates printing each design by emptying the list of unprinted designs and filling up the list of completed models. On line 10 we define the function
show_completed_models()with one parameter: the list of completed models. Given this list,
show_completed_models()displays the name of each model that was printed.
This program has the same output as the version without functions, but the code is much more organized. The code that does most of the work has been moved to two separate functions, which makes the main part of the program easier to understand. Look at the body of the program to see how much easier it is to understand what this program is doing:We set up a list of unprinted designs and an empty list that will hold the completed models. Then, because we've already defined our two functions, all we have to do is call them and pass them the right arguments. We call
print_models()and pass it the two lists it needs; as expected,
print_models()simulates printing the designs. Then we call
show_completed_models()and pass it the list of completed models so it can report the models that have been printed. The descriptive function names allow others to read this code and understand it, even without comments.
This program is easier to extend and maintain than the version without functions. If we need to print more designs later on, we can simply call
print_models() again. If we realize the printing code needs to be modified, we can change the code once, and our changes will take place everywhere the function is called. This technique is more efficient than having to update code separately in several places in the program.
This example also demonstrates the idea that every function should have one specific job. The first function prints each design, and the second displays the completed models. This is more beneficial than using one function to do both jobs. If you're writing a function and notice the function is doing too many different tasks, try to split the code into two functions. Remember that you can always call a function from another function, which can be helpful when splitting a complex task into a series of steps.
Preventing a Function from Modifying a List
Sometimes you'll want to prevent a function from modifying a list. For example, say that you start with a list of unprinted designs and write a function to move them to a list of completed models, as in the previous example. You may decide that even though you've printed all the designs, you want to keep the original list of unprinted designs for your records. But because you moved all the desing names out of
unprinted_designs, the list is now empty, and the empty list is the only version you have; the original is gone. In this case, you can address this issue by passing the function a copy of the list, not the original. Any changes the function makes to the list will affect only the copy, leaving the original list intact.
You can send a copy of a list to a function like this:
function_name(list_name[:])
printing_models.py, we could call
print_models()like this:
print_models(unprinted_designs[:], completed_models)
print_models()can do its work because it still receives the names of all unprinted designs. But this time it uses a copy of the original unprinted desings list, not the actual
unprinted_designslist. The list
completed_modelswill fill up with the names of printed models like it did before, but original list of unprinted designs will be unaffected by the function.
Even though you can preserve the contents of a list by passing a copy of it to your functions, you should pass the original list to functions unless you have a specific reason to pass a copy. It's more efficient for a function to work with an existing list to avoid using the time and memory needed to make a separate copy, especially when you're working with large lists.
Passing an Arbitrary Number of Arguments
Sometimes you won't know ahead of time how many arguments a function needs to accept. Fortunately, Python allows a function to collect an arbitrary number of arguments from the calling statement.
For example, consider a function that builds a pizza. It needs to accept a number of toppings, but you can't know ahead of time how many toppings a person will want. The function in the following example has one parameter,
*toppings, but this parameter collects as many arguments as the calling line provides:
*) in the parameter name
*toppingstells Python to make an empty tuple called
toppingsand pack whatever values it receives into this tuple. The
print()call in the function body produces output showing that Python can handle a function call with one value and a call with three values. It treats the different calls similarly. Note that Python packs the arguments into a tuple, even if the function receives only one value:
('pepperoni',) ('mushrooms', 'green peppers', 'extra cheese')
print()call with a loop that runs through the list of toppings and describes the pizza being ordered: The function responds appropriately, whether it receives one value or three values:
Making a pizza with the following toppings: - pepperoni Making a pizza with the following toppings: - mushrooms - green peppers - extra cheese
Mixing Positional and Arbitrary Arguments
If you want a function to accept several different kinds of arguments, the parameter that accepts an arbitrary number of arguments must be placed last in the function definition. Python matches positional and keyword arguments first and then collects any remaining arguments in the final parameter.
For example, if the function needs to take in a size for the pizza, that parameter must come before the parameter
*toppings:
size. All other values that come after are stored in the tuple
toppings. The function calls include an argument for the size first, followed by as many toppings as needed.
Now each pizza has a size and a number of toppings, and each piece of information is printed in the proper place, showing size first and toppings after:
Making a 16-inch pizza with the following toppings: - pepperoni Making a 12-inch pizza with the following toppings: - mushrooms - green peppers - extra cheese
Using Arbitrary Keyword Arguments
Sometimes you'll want to accept an arbitrary number of arguments, but you won't know ahead of time what kind of information will be passed to the function. In this case, you can write functions that accept as many key-value pairs as the calling statement provides. One example involves building user profiles: you know you'll get information about a user, but you're not sure what kind of information you will receive. The function
build_profile() in the following example always takes in a first and last name, but it accepts an arbitrary number of keyword arguments as well:
build_profile()expects a first and last name, and then it allows the user to pass in as many name-value pairs as they want. The double asterisks (
**) before the parameter
**user_infocause Python to create an empty dictionary called
user_infoand pack whatever name-value pairs it receives into this dictionary. Within the function, you can access the key-value pairs in
user_infojust as you would for any dictionary.
In the body of
build_profile(), we add the first and last names to the
user_info dictionary because we'll always receive these two pieces of information from the user (line ¾), and they haven't been placed into the dictionary yet. Then we return the
user_info dictionary to the function call line.
We call
build_profile(), passing it the first name
'albert', the last name
'einstein', and the two key-value pairs
location='princeton' and
field='physics'. We assign the returned
profile to
user_profile and print
user_profile:
{'location': 'princeton', 'field': 'physics', 'first_name': 'albert', 'last_name': 'einstein'}
You can mix positional, keyword, and arbitrary values in many different ways when writing your own functions. It's useful to know that all these argument types exist because you'll see them often when you start reading other people's code. It takes practice to learn to use the different types correctly and to know when to use each type.
Storing Your Functions in Modules
One advantage of functions is the way they separate blocks of code from your main program. By using descriptive names for your functions, your program will be much easier to follow. You can go a step further by storing your function in a separate file called a module and then importing that module into your main program. An
import statement tells Python to make the code in a module available in the currently running program file.
Storing your functions in a separate file allows you to hide the details of your program's code and focus on its higher-level logic. It also allows you to reuse functions in many different programs. When you store your functions in separate files, you can share those files with other programmers without having to share your entire program. Knowing how to import functions also allows you to use libraries of functions that other programmers have written.
There are several ways to import a module:
Importing an Entire Module
To start importing functions, we first need to create a module. A module is a file ending in .py that contains the code you want to import into your program. Let's make a module that contains the function
make_pizza(). To make this module, we'll remove everything from the file
pizza.py except the function
make_pizza().
Now we'll make a separate file called
pizza.py:
making_pizzas.pyin the same directory as
pizza.py. This file imports the module we just created and then makes two calls to
make_pizza().
When Python reads this file, the line
making_pizzas.py:
import pizzatells Python to open the file
pizza.pyand copy all the functions from it into this program. You don't actually see code being copied between files because Python copies the code behind the scenes just before the program runs. All you need to know is that any function defined in
pizza.pywill now be available in
making_pizzas.py.
To call a function from an imported module, enter the name of the module you imported,
pizza, followed by the name of the function,
make_pizza(), separated by a dot (line 3). This code produces the same output as the original program that didn't import a module:
Making a 16-inch pizza with the following toppings: - pepperoni Making a 12-inch pizza with the following toppings: - mushrooms - green peppers - extra cheese
importfollowed by the name of the module, makes every function from the module available in your program. If you use this kind of
importstatement to import an entire module named
module_name.py, each function in the module is available through the following syntax:
module_name.function_name()
Importing Specific Functions
You can also import a specific function from a module. Here's the general syntax for this approach:
from module_name import function_name
from module_name import function_0, function_1, function_2
making_pizzas.pyexample would look like this if we want to import just the function we're going to use: With this syntax, you don't need to use the dot notation when you call a function. Because we've explicitly imported the function
make_pizza()in the
importstatement, we can call it by name when we use the function.
Using
as to Give a Function an Alias
If the name of a function you're importing might conflict with an existing name in your program or if the function name is long, you can use a short, unique alias - an alternate name similar to a nickname for a function. You'll give the function this special nickname when you import the function.
Here we give the function
make_pizza() an alias,
mp() by importing
make_pizza as
mp. The
as keyword renames a function using the alias you provide:
importstatement shown here renames the function
make_pizza()to
mp()in this program. Any time we want to call
make_pizza()we can simply write
mp()instead, and Python will run the code in
make_pizza()while avoiding any confusion with another
make_pizza()function you might have written in this program file.
The general syntax for providing an alias is:
from module_name import function_name as fn
Importing All Functions in a Module
You can tell Python to import every function in a module by using the asterisk (
*) operator:
importstatement tells Python to copy every function from the module
pizza(
pizza.py) into this program file. Because every function is imported, you can call each function by name without using the dot notation. However, it is best not to use this approach when you're working with larger modules that you didn't write: if the module has a function name that matches an existing name in your project, you can get some unexpected results. Python may see several functions or variables with the same name, and instead of importing all the functions separately, it will overwrite the functions.
The best approach is to import the function or functions you want, or import the entire module and use the dot notation. This leads to clear code that's easy to read and understand. I include this section so you'll recognize
import statements like the following when you see them in other people's code:
from module_name import *
Styling Functions
You need to keep a few details in mind when you're styling functions. Functions should have descriptive names, and these names should use lowecase letters and underscores. Descriptive names help you and other understand what your code is trying to do. Module names should use these conventions as well.
Every function should have a comment that explains concisely what the function does. This comment should appear immediately after the function definition and use the docstring format. In a well-documented function, other programmers can use the function by reading only the description in the docstring. They should be able to trust that the code works as described, and as long as they the name of the function, the arguments it needs, and the kind of value it returns, they should be able to use it in their programs.
If you specify a default value for a parameter, no spaces should be used on either side of the equal sign:
def function_name(parameter_0, parameter_1='default value')
function_name(value_0, parameter_1='value')
ENTERafter opening parenthesis on the definition line. On the next line, press
TABtwice to separate the list of arguments from the body of the function, which will only be indented by one level.
Most editors automatically line up any additional lines of parameters to match the indentation you have established on the first line:If your program or module has more than one function, you can separate each by two blank lines to make it easier to see where one function ends and the next one begins.
All
import statements should be written at the beginning of a file. The only exception is if you use comments at the beginning of your file to describe the overall program. | https://docs.nicklyss.com/py-functions/ | CC-MAIN-2022-40 | refinedweb | 5,764 | 58.72 |
IMPLEMENTING A MULTI-STEP TRANSACTION IN WEBLOGIC WORKSHOP TUTORIAL INTRODUCTION In a multi-step transaction, user enters data using a sequence of forms. At the end of the sequence, the application does something with the input data. Desktop applications use wizards to simplify operations. Wizards are good examples of multi-step transaction. In an e-commerce site, the checkout flow can be seen as a multi-step transaction. In this tutorial, you will be a skeletal checkout flow. Starting from the shopping cart page, the user will go through the shipping, billing, confirmation and finally a thank you page. IMPLEMENTATION TECHNIQUE A good way to implement a multi-step transaction is to save the name of the current stage as a session attribute. Based on the current stage, the controller can forward the user to the next page in sequence. In WebLogic Workshop, the Page Flow object is stored in session. We can use a member variable in the Page FLow class to store the stage name. You can also use HttpSession to store the same data. In general, using a member variable in a Page Flow requires less coding and we will use that technique in this tutorial. CREATE THE APPLICATION Launch WebLogic Workshop. Create a new application called BasicApp, unless it is already created from a previous tutorial. The new application will have a web project called BasicAppWeb. CREATE THE PAGE FLOW Right click on BasicAppWeb and select New->Page Flow. Create a basic Page Flow called CheckoutFlow. Switch to the Source View of the Page Flow editor. Add a member variable as shown in boldface below. public class CheckoutFlowController extends PageFlowController { StringCheckout</netui:anchor></p> </body> Save and close the file. Similarly, set the content of the <body> tag of the shipping.jsp page to: <body> <h2>Shipping Page</h2> <p><netui:anchorNext</netui:anchor></p> </body> Contents of the <body> tag of the billing.jsp page should be: <body> <h2>Billing Page</h2> <p><netui:anchorNext</netui:anchor></p> </body> Contents of the <body> tag of the confirm.jsp page should be: <body> <h2>Confirmation Page</h2> <p><netui:anchorNext</netui:anchor></p> </body> Contents of the <body> tag of the thankyou.jsp page should be: <body> <h2>Than you</h2> <p>Your order number is: <netui:label.</p> </body> Save changes (Control+S). TEST Start the server if it is not already running. From a browser enter the URL: Make sure that you can proceed with the checkout process. WLSKB-006 IMPLEMENTING A MULTI-STEP TRANSACTION IN WEBLOGIC WORKSHOP TUTORIAL was last modified: October 30th, 2018 by admin | https://www.webagesolutions.com/knowledgebase/wlskb/wlskb006 | CC-MAIN-2021-04 | refinedweb | 433 | 58.28 |
Hi there, I have a Spawn class that spawns a character in my 3D game, and transforms it to a certain point in the game, like this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Spawn : MonoBehaviour {
public Object ObjectToSpawn;
public float speed = 5;
void Start () {
}
public void SpawnCharacterMethod() {
// spawns and moves character to a point
Instantiate(ObjectToSpawn, transform.position, transform.rotation);
}
public void SpawnCharacter() {
// calls method
SpawnCharacterMethod();
Debug.Log("NPC Spawned!");
}
}
I then have a Detect class, and when the collision detection goes off in the 'Detect.cs', I need to call the SpawnCharacterMethod() again that is in the 'Spawn.cs'. Here's how I've tried to call the SpawnCharacterMethod() function in the Detect.cs:
SpawnCharacterMethod()
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Detect : MonoBehaviour {
Animator anim;
int jumpHash = Animator.StringToHash("Bored");
public Spawn spawnNewCharacter;
public Object ObjectToSpawn;
Spawn Name = new Spawn();
void Start() {
anim = GetComponent<Animator>();
}
void Update(){
}
void OnCollisionEnter(Collision col) {
if (col.gameObject.name == "Target1") {
anim.SetTrigger(jumpHash);
Debug.Log("Play touched plane!");
}
if (col.gameObject.name == "Target1")
{
Debug.Log("Spawn?"); // this displays in the console!!
Name.SpawnCharacterMethod(); // but this doesn't call
}
}
}
As you can see in the second if statement in the Detect.cs, I've placed a debug that checks whether the if statement has been entered, it gets entered, the debug.log displays on console, but the function doesn't get called?
if statement
I've even tried this method for calling functions in different classes:
And nothing seems to work. Appreciate any help given please!!
Answer by Larry-Dietz
·
Dec 29, 2017 at 11:40 PM
Are you dragging an object into the inspector for spawnNewCharacter? And if so, is this the spawn object you are wanting to call the SpawnCharacterMethod function?
If so, then in that 2nd if statement, change Name to spawnNewCharacter and I think you will be good to go.
Creating a new Spawn object like you are with Name will create an instance of the script NOT attached to a gameobject, and would result in a null reference error when trying to call the method.
I hope this helps,
-Larry
Hi Larry, I think this will work, but just one small issue.
In the inspector, I can't seem to drag the object that I want to spawn in the spawnNewCharacter slot for Detect.cs:
I've tried dragging it into ObjectToSpawn but that doesn't work, I'm assuming it has something to do with spawnNewCharacter having the type 'Spawn'?
Anyway I get get around this?
For this to work, you need to have an object with the Spawn script attached, maybe an empty game object, and call it SpawnController or something. You would drag that object into the Spawn New Character field in the inspector.
Then you would drag the actual GameObject/prefab that you want to spawn into the Object To Spawn field in the inspector.
Doing this, SHOULD get you going.
There are few bugs that I should be able to fix within the hour, but that
500 People are following this question.
How can I change a function from another script?
1
Answer
Call function of a MonoBehaviour class in another class
0
Answers
How to access a variable from another C# script in Unity
1
Answer
Function not running everytime
0
Answers
Difference between C# Invoke and Unity Invoke
0
Answers | https://answers.unity.com/questions/1448098/calling-function-from-another-script-not-working.html?sort=oldest | CC-MAIN-2019-43 | refinedweb | 568 | 56.35 |
this question is about blender, python scripting
I'm completely new in this, so please excuse me for any stupid/newbie question/comment.
I made it simple (3 lines code) to make it easy addressing the problem.
what I need is a code that adds a new uv map for each object within loop function.
But this code instead is adding multiple new UV maps to only one object.
import bpy
for x in bpy.context.selected_objects:
bpy.ops.mesh.uv_texture_add()
The
uv_texture_add operator is one that only works on the current active object. You can change the active object by setting
scene.objects.active
import bpy for x in bpy.context.selected_objects: bpy.context.scene.objects.active = x bpy.ops.mesh.uv_texture_add() | https://codedump.io/share/E5csokoCOpUF/1/loop-doesn39t-work-3-lines-python-code | CC-MAIN-2017-39 | refinedweb | 123 | 51.24 |
It has been a long time since I wrote my last post but as I promised this is the continuation. Last time I was talking about ReentrantLock class in the package java.util.concurrent.locks.
This package gives us an interface called 'Lock' which is implemented by the ReentrantLock class. This kind of object works very similar to synchronized code blocks, as we can have just one 'Lock' at the same time. Its main advantage is that it allows us to schedule alternative executions if the 'Lock' object has been obtained by another thread. The most important method of this object is the method tryLock, which will try to get the 'lock' of the object and if it is not possible it will return false.
This will give us the possibility to write code in order to take other actions. That's its main advantage with regard the synchronized code blocks, in which an infinite loop is started until it can get the 'lock'. Now we are going to use this kind of object in order to solve the deadlock problems in the previous example. We are going to have one Cashier class and one OperateCash class, we are going to create 2 objects from the Cashier class whose methods will be invoke in the OperateCashier class. This is the code example:
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; public class Deadlock { static class Cashier { private double balance; private final String name; public final Lock lock = new ReentrantLock(); public Cashier(double balanceIni, String name) { this.balance = balanceIni; this.name = name; } public void debit(double value) { balance += value; } public void credit(double value) { balance -= value; } public double getBalance() { return balance; } public String getName() { return name; } } static class OperateCashier { public boolean transfer(Cashier cashierFrom, Cashier cashierTo, double value, String h){ Boolean lock1 = false; Boolean lock2 = false; System.out.println("Thread " + h + ": transfer cash from " + cashierFrom.getName() + " to " + cashierTo.getName()); try { System.out.println("Thread " + h + ": get lock " + cashierFrom.getName()); lock1 = cashierFrom.lock.tryLock(); System.out.println("Thread " + h + ": get lock " + cashierTo.getName()); lock2 = cashierTo.lock.tryLock(); } finally { if (!(lock1 && lock2)) { if (lock1) { cashierFrom.lock.unlock(); } if (lock2) { cashierTo.lock.unlock(); } } } if (lock1 && lock2) { try { if (cashierFrom.getBalance() >= value) { cashierFrom.debit(value); cashierTo.credit(value); System.out.println("Thread " + h + ": transfer finished..."); } } finally { cashierFrom.lock.unlock(); cashierTo.lock.unlock(); } } else { System.out.println("Thread " + h + ":It was not able to get the lock from both objects"); } return (lock1 && lock2); } } public static void main(String[] args) { final Cashier cashier1 = new Cashier(60000, "CJ1"); final Cashier cashier2 = new Cashier(80000, "CJ2"); final OperateCashier opc = new OperateCashier(); new Thread(new Runnable() { String nameThread = "H1"; boolean go = false; long time = 100; public void run() { while (!go) { go=opc.transfer(cashier1,cashier2,20000,nameThread); if (!go) { try { System.out.println("Thread "+ nameThread + ": Wating " + time); Thread.sleep(time); } catch (InterruptedException e) {} } } } }).start(); new Thread(new Runnable() { String nameThread = "H2"; boolean go = false; long time = 100; public void run() { while (!go) { go=opc.transfer(cashier2, cashier1, 10000, nameThread); if (!go) { try { System.out.println("Thread "+nameThread + ": Wating " + time); Thread.sleep(time); } catch (InterruptedException e) {} } } } }).start(); } }
In the Cashier class in line number 10 a 'Lock' object has been created which is the object that will be used in order to lock the object thus preventing the other thread to use it. So when a Thread needs to use a Cashier object, it will invoke the method tryLock of the object Lock, this method will check if other thread have already locked the object, if so then it will return false, if not, it will lock the object and will return true.
The OperateCashier class have a method named 'transfer', this method makes money transfers from one cashier to another cashier, the two objects which represent those cashiers are given as parameters and so also the value to transfer and a String value that will tell us which Thread is running at the moment. In order for the transfer operation be sucessfull, it is needed that none other thread already be making the transfer. So it will be necessary lock both cashiers. Thus any other thread will have to wait until the current transaction is complete.
In line number 49 we try to get the 'lock' of the cashier which is going to make the transfer, while in line number 53 we try to do the same with the cashier that will receive the transfer. The checking whether both cashier has been locked or not is done inside of the finally block, because in case it's not possible to lock both cashiers, it may be that at least one of them has been already locked so it should be released, we do not want an object locked for ever. In line number 65 again we check whether or not we managed lock both objects. If so then we go ahead and make the money transfer. Then we must unlock both objects. Finally a boolean value is returned pointing out if the transfer was sucessfull.
Now let's see what is happening in the method main. The two Threads that will invoke the method transfer are created in there. Each one of these threads will try to make a money transfer. The first, from cashier1 to cashier2 and the second from cashier2 to cashier1. It's for sure that in some point during execution, one thread will find that other thread have already locked one or both cashiers, but it won't be a problem because in that case the method will return false and then we can decide what to do. In this case we will have a while loop trying to complete the transaction every 100 ms. eventually it will have its chance but in the real life you could decide to make other things.
if we execute this program many times. We can see that always both transaction are completed successfully, in whatever order, preventing a deadlock. So this is one of the ways to reduce deadlocks in programs. | http://guido-granobles.blogspot.com/ | CC-MAIN-2014-15 | refinedweb | 1,006 | 64.3 |
DEBSOURCES
Skip Quicknav
sources / centrifuge / 1.0.3-2 / diff_sample.c
/*
*
* This file is part of Bowtie 2.
*
* Bowtie 2 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.
*
* Bowtie Bowtie 2. If not, see <>.
*/
#include "diff_sample.h"
struct sampleEntry clDCs[16];
bool clDCs_calced = false; /// have clDCs been calculated?
/**
* Entries 4-57 are transcribed from page 6 of Luk and Wong's paper
* "Two New Quorum Based Algorithms for Distributed Mutual Exclusion",
* which is also used and cited in the Burkhardt and Karkkainen's
* papers on difference covers for sorting. These samples are optimal
* according to Luk and Wong.
*
* All other entries are generated via the exhaustive algorithm in
* calcExhaustiveDC().
*
* The 0 is stored at the end of the sample as an end-of-list marker,
* but 0 is also an element of each.
*
* Note that every difference cover has a 0 and a 1. Intuitively,
* any optimal difference cover sample can be oriented (i.e. rotated)
* such that it includes 0 and 1 as elements.
*
* All samples in this list have been verified to be complete covers.
*
* A value of 0xffffffff in the first column indicates that there is no
* sample for that value of v. We do not keep samples for values of v
* less than 3, since they are trivial (and the caller probably didn't
* mean to ask for it).
*/
uint32_t dc0to64[65][10] = {
{0xffffffff}, // 0
{0xffffffff}, // 1
{0xffffffff}, // 2
{1, 0}, // 3
{1, 2, 0}, // 4
{1, 2, 0}, // 5
{1, 3, 0}, // 6
{1, 3, 0}, // 7
{1, 2, 4, 0}, // 8
{1, 2, 4, 0}, // 9
{1, 2, 5, 0}, // 10
{1, 2, 5, 0}, // 11
{1, 3, 7, 0}, // 12
{1, 3, 9, 0}, // 13
{1, 2, 3, 7, 0}, // 14
{1, 2, 3, 7, 0}, // 15
{1, 2, 5, 8, 0}, // 16
{1, 2, 4, 12, 0}, // 17
{1, 2, 5, 11, 0}, // 18
{1, 2, 6, 9, 0}, // 19
{1, 2, 3, 6, 10, 0}, // 20
{1, 4, 14, 16, 0}, // 21
{1, 2, 3, 7, 11, 0}, // 22
{1, 2, 3, 7, 11, 0}, // 23
{1, 2, 3, 7, 15, 0}, // 24
{1, 2, 3, 8, 12, 0}, // 25
{1, 2, 5, 9, 15, 0}, // 26
{1, 2, 5, 13, 22, 0}, // 27
{1, 4, 15, 20, 22, 0}, // 28
{1, 2, 3, 4, 9, 14, 0}, // 29
{1, 2, 3, 4, 9, 19, 0}, // 30
{1, 3, 8, 12, 18, 0}, // 31
{1, 2, 3, 7, 11, 19, 0}, // 32
{1, 2, 3, 6, 16, 27, 0}, // 33
{1, 2, 3, 7, 12, 20, 0}, // 34
{1, 2, 3, 8, 12, 21, 0}, // 35
{1, 2, 5, 12, 14, 20, 0}, // 36
{1, 2, 4, 10, 15, 22, 0}, // 37
{1, 2, 3, 4, 8, 14, 23, 0}, // 38
{1, 2, 4, 13, 18, 33, 0}, // 39
{1, 2, 3, 4, 9, 14, 24, 0}, // 40
{1, 2, 3, 4, 9, 15, 25, 0}, // 41
{1, 2, 3, 4, 9, 15, 25, 0}, // 42
{1, 2, 3, 4, 10, 15, 26, 0}, // 43
{1, 2, 3, 6, 16, 27, 38, 0}, // 44
{1, 2, 3, 5, 12, 18, 26, 0}, // 45
{1, 2, 3, 6, 18, 25, 38, 0}, // 46
{1, 2, 3, 5, 16, 22, 40, 0}, // 47
{1, 2, 5, 9, 20, 26, 36, 0}, // 48
{1, 2, 5, 24, 33, 36, 44, 0}, // 49
{1, 3, 8, 17, 28, 32, 38, 0}, // 50
{1, 2, 5, 11, 18, 30, 38, 0}, // 51
{1, 2, 3, 4, 6, 14, 21, 30, 0}, // 52
{1, 2, 3, 4, 7, 21, 29, 44, 0}, // 53
{1, 2, 3, 4, 9, 15, 21, 31, 0}, // 54
{1, 2, 3, 4, 6, 19, 26, 47, 0}, // 55
{1, 2, 3, 4, 11, 16, 33, 39, 0}, // 56
{1, 3, 13, 32, 36, 43, 52, 0}, // 57
// Generated by calcExhaustiveDC()
{1, 2, 3, 7, 21, 33, 37, 50, 0}, // 58
{1, 2, 3, 6, 13, 21, 35, 44, 0}, // 59
{1, 2, 4, 9, 15, 25, 30, 42, 0}, // 60
{1, 2, 3, 7, 15, 25, 36, 45, 0}, // 61
{1, 2, 4, 10, 32, 39, 46, 51, 0}, // 62
{1, 2, 6, 8, 20, 38, 41, 54, 0}, // 63
{1, 2, 5, 14, 16, 34, 42, 59, 0} // 64
}; | https://sources.debian.org/src/centrifuge/1.0.3-2/diff_sample.cpp/ | CC-MAIN-2019-30 | refinedweb | 740 | 62.08 |
why its jumping out of program?
I just start learning C++.
When I execute my code it's jumping out of the program without any error. Why?
#include "stdafx.h" #include <iostream> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { char s1[20],s2[10]; cout<<" enter a number : "; cin.get(s1,19); cout<<" enter a number : "; cin.get(s2,9); cout<<s1<<"/n"<<s2; getch(); }
Answers
The method get() reads upto the '\n' character but does not extract it.
So if you type: 122345<enter> This line:
cin.get(s1,19);
Will read 12345, but the '\n' (created by hitting <enter>) is left on the input stream. Thus the next line to read:
cin.get(s2,9);
Will read nothing as it sees the '\n' and stops. But it does not extract the '\n' either. So the input stream still has the '\n' there. So this line:
getch();
Just reads the '\n' character from the input stream. Which then allows it to finish processing and exit the program normally.
OK. That is what is happening. But there is more to this. You should not be using get() to read formatted input. Use the operator >> to read formatted data into the correct type.
int main() { int x; std::cin >> x; // Reads a number into x // error if the input stream does not contain a number. }
Because the std::cin is a buffered stream the data is not sent to the program until you push <enter> and the stream is flushed. Thus it is often useful to read the text (from user input) a line at a time then parse that line independently. This allows you to check the last user input for errors (on a line by line bases and reject it if there are errors).
int main() { bool inputGood = false; do { std::string line; std::getline(std::cin, line); // Read a user line (throws away the '\n') std::stringstream data(line); int x; data >> x; // Reads an integer from your line. // If the input is not a number then data is set // into error mode (note the std::cin as in example // one above). inputGood = data.good(); } while(!inputGood); // Force user to do input again if there was an error. }
If you want to get advanced then you can also look at the boost libs. They provide some nice code in general and as a C++ program you should know the contents of boost. But we can re-write the above as:
int main() { bool inputGood = false; do { try { std::string line; std::getline(std::cin, line); // Read a user line (throws away the '\n') int x = boost::lexical_cast<int>(line); inputGood = true; // If we get here then lexical_cast worked. } catch(...) { /* Throw away the lexical_cast exception. Thus forcing a loop */ } } while(!inputGood); // Force user to do input again if there was an error. }
Need Your Help
How do I unpack various form of integers in a byte buffer in golang?
C# Random codes - Is most of it simply wrong?
c# windows-phone-7 randomI had a lot of issues with randomizing lists. I am talking about a list of 200 elements, where I want to shuffle the list. Don't get me wrong, I read a lot of examples, and on first glance there are
NSInvocation for Dummies?
objective-c cocoa undo-redoHow exactly does NSInvocation work? Is there a good introduction? | http://unixresources.net/faq/4346852.shtml | CC-MAIN-2018-43 | refinedweb | 564 | 74.59 |
kubectl-pod-node-matrix
WORK IN PROGRESS!!
This plugin shows pod x node matrix with suitable colors to mitigate troubleshooting effort.
Details
Troubleshooting in Kubernetes takes some time and sorting out the real cause sometimes overwhelming.
Take an example of a couple of pods are not in running state, but the actual cause is node has insufficient
disk space. To reduce the amount of time being spent to this troubleshooting,
pod-node-matrix might provide a
place for “first look at”.
pod-node-matrix returns pods x node matrix. This plugin can clearly indicate that if there is a general node problem,
or can strongly suggest that node has no problem and instead deployment, service, etc. of this pod have problem.
Thanks to that, at least assuring that one part is working or not will definitely narrow down the places should be
checked.
Installation
Use krew plugin manager to install,
kubectl krew install pod-node-matrix kubectl pod-node-matrix --help
Or manually,
kubectl-pod-node-matrix can be installed via:
go get github.com/ardaguclu/kubectl-pod-node-matrix/cmd/kubectl-pod-node-matrix
Usage
# Just shows the pods in default namespace kubectl-pod-node-matrix # Shows the pods in given namespace kubectl-pod-node-matrix -n ${NAMESPACE} # Shows all pods in all namespaces kubectl-pod-node-matrix -A | https://golangexample.com/kubectl-plugin-shows-pod-x-node-matrix-with-suitable-colors-to-mitigate-troubleshooting-effort/ | CC-MAIN-2022-21 | refinedweb | 220 | 54.32 |
_lwp_cond_reltimedwait(2)
- schedule an alarm signal
#include <unistd.h> unsigned int alarm(unsigned int seconds);
The alarm() function causes the system to generate a SIGALRM signal for the process after the number of real-time seconds specified by seconds have elapsed (see signal.h(3HEAD)). Processor scheduling delays may prevent the process from handling the signal as soon as it is generated.
If seconds is 0, a pending alarm request, if any, is cancelled. If seconds is greater than LONG_MAX/hz, seconds is rounded down to LONG_MAX/hz. The value of hz is normally 100.
Alarm requests are not stacked; only one SIGALRM generation can be scheduled in this manner; if the SIGALRM signal has not yet been generated, the call will result in rescheduling the time at which the SIGALRM signal will be generated.
The fork(2) function clears pending alarms in the child process. A new process image created by one of the exec(2) functions inherits the time left to an alarm signal in the old process's image.
If there is a previous alarm request with time remaining, alarm() returns a non-zero value that is the number of seconds until the previous request would have generated a SIGALRM signal. Otherwise, alarm() returns 0.
The alarm() function is always successful; no return value is reserved to indicate an error.
See attributes(5) for descriptions of the following attributes:
exec(2), fork(2), signal.h(3HEAD), attributes(5), standards(5) | http://docs.oracle.com/cd/E26505_01/html/816-5167/alarm-2.html | CC-MAIN-2014-35 | refinedweb | 243 | 55.24 |
Using Standard C Headers · C Library Conventions · Program Startup and Termination
All Standard C library entities are declared or defined in one or more
standard headers.
To make use of a library entity in a program, write an
include directive
that names the relevant
standard header.
The full set of Standard C headers constitutes a
hosted implementation:
<assert.h>,
<ctype.h>,
<errno.h>,
<float.h>,
<iso646.h>,
<limits.h>,
<locale.h>,
<math.h>,
<setjmp.h>,
<signal.h>,
<stdarg.h>,
<stddef.h>,
<stdio.h>,
<stdlib.h>,
<string.h>,
<time.h>,
<wchar.h>, and
<wctype.h>.
The headers
<iso646.h>,
<wchar.h>, and
<wctype.h> are added with
Amendment 1, an addition
to the C Standard published in 1995.
Still more headers (not described here), and changes to existing headers, are added with C99, a revision to the C Standard published in 1999.
A freestanding
implementation
of Standard C provides only a subset of these standard headers:
<float.h>,
<iso646.h>,
<limits.h>,
<stdarg.h>, and
<stddef.h>.
Each freestanding implementation defines:
You include the contents of a standard header by naming it in an include directive, as in:
#include <stdio.h> /* include I/O facilities */
You can include the standard headers in any order, a standard header more than once, or two or more standard headers that define the same macro or the same type. Do not include a standard header within a declaration. Do not define macros that have the same names as keywords before you include a standard header.
A standard header never includes another standard header. A standard header declares or defines only the entities described for it in this document.
Every function in the library is declared in a standard header. The standard header can also provide a masking macro, with the same name as the function, that masks the function declaration and achieves the same effect. The macro typically expands to an expression that executes faster than a call to the function of the same name. The macro can, however, cause confusion when you are tracing or debugging the program. So you can use a standard header in two ways to declare or define a library function. To take advantage of any macro version, include the standard header so that each apparent call to the function can be replaced by a macro expansion.
For example:
#include <ctype.h> char *skip_space(char *p) { while (isspace(*p)) can be a macro ++p; return (p); }
To ensure that the program calls the actual library function, include the standard header and remove any macro definition with an undef directive.
For example:
#include <ctype.h> #undef isspace remove any macro definition int f(char *p) { while (isspace(*p)) must be a function ++p;
You can use many functions in the library without including a standard header (although this practice is no longer permitted in C99 and is generally not recommended). If you do not need defined macros or types to declare and call the function, you can simply declare the function as it appears in this chapter. Again, you have two choices. You can declare the function explicitly.
For example:
double sin(double x); declared in <math.h> y = rho * sin(theta);
Or you can declare the function implicitly if it is a function returning int with a fixed number of arguments, as in:
n = atoi(str); declared in <stdlib.h>
If the function has a
varying number
of arguments, such as
printf,
you must declare it explicitly: Either include the standard header
that declares it or write an explicit declaration.
Note also that you cannot define a macro or type definition without including its standard header because each of these typically varies among implementations.
A library macro that
masks
a function declaration expands to
an expression that evaluates each of its arguments once (and only
once). Arguments that have
side effects
evaluate the same way whether the expression executes
the macro expansion or calls the function.
Macros for the functions
getc and
putc
are explicit exceptions to this rule. Their
stream
arguments can be evaluated more than once. Avoid argument expressions
that have side effects with these macros.
A library function that alters a value stored in memory assumes
that the function accesses no other objects that overlap the
object whose stored value it alters. You cannot depend on consistent
behavior from a library function that accesses and alters the same
storage via different arguments. The function
memmove
is an explicit exception to this rule. Its arguments
can point at objects that overlap.
An implementation has a set of
reserved names that it
can use for its own purposes. All the library names described in this
document are, of course, reserved for the library. Don't define
macros with the same names. Don't try to supply your own definition
of a library function, unless this document explicitly says you can
(only in C++). An unauthorized replacement may be successful on some
implementations and not on others. Names that begin with
two underscores (or contain two successive underscores, in C++),
such as
__STDIO, and names that
begin with an underscore followed by an upper case letter, such as
_Entry, can be used as macro names, whether or not
a translation unit explicitly includes any standard headers.
Names that begin with an underscore can be defined with external
linkage. Avoid writing such names in a program
that you wish to keep maximally portable.
Some library functions operate on C strings, or pointers to null-terminated strings. You designate a C string that can be altered by an argument expression that has type pointer to char (or type array of char, which converts to pointer to char in an argument expression). You designate a C string that cannot be altered by an argument expression that has type pointer to const char (or type const array of char). In any case, the value of the expression is the address of the first byte in an array object. The first successive element of the array that has a null character stored in it marks the end of the C string.
wchar_t), followed by a null wide character.
If an argument to a library function has a pointer type, then the value of the argument expression must be a valid address for an object of its type. This is true even if the library function has no need to access an object by using the pointer argument. An explicit exception is when the description of the library function spells out what happens when you use a null pointer.
Some examples are:
strcpy(s1, 0) is INVALID memcpy(s1, 0, 0) is UNSAFE realloc(0, 50) is the same as malloc(50)
The target environment controls the execution of the program
(in contrast to the translator part of the implementation, which prepares
the parts of the program for execution). The target environment passes
control to the program at
program startup
by calling the function
main
that you define as part of the program.
Program arguments are
C strings
that the target environment provides, such as text from the
command line
that you type to invoke the program. If the program
does not need to access program arguments, you can define
main
as:
extern int main(void) { <body of main> }
If the program uses program arguments, you define
main
as:
extern int main(int argc, char **argv) { <body of main> }
You can omit either or both of
extern int, since
these are the default storage class and type for a function
definition. For program arguments:
argcis a value (always greater than zero) that specifies the number of program arguments.
argv[0]designates the first element of an array of C strings.
argv[argc]designates the last element of the array, whose stored value is a null pointer.
For example, if you invoke a program by typing:
echo hello
a target environment can call
main with:
argc.
"echo"stored in
argv[0].
"hello"stored in
argv[1].
argv[2].
argv[0] is the name used to invoke the program. The target
environment can replace this name with a
null string (
"").
The program can alter the values stored in
argc,
in
argv, and in the array objects
whose addresses are stored in
argv.
Before the target environment calls
main, it stores the
initial values you specify in all objects that have static duration.
It also opens three
standard streams,
controlled by the text-stream objects designated
by the macros:
stdin-- for standard input
stdout-- for standard output
stderr-- for standard error output
If
main returns to its caller, the target environment calls
exit
with the value returned from
main as the status argument to
exit. If the
return statement that
the program executes has no expression, the status argument is undefined.
This is the case if the program executes the implied
return statement
at the end of the function definition.
You can also call
exit
directly from any expression within the program. In both cases,
exit
calls all functions registered with
atexit
in reverse order of registry and then begins
program termination.
At program termination, the target environment closes
all open files, removes any temporary files that you created by calling
tmpfile,
and then returns control to the invoker, using the
status argument value to determine the termination status to report
for the program.
The program can terminate abnormally by calling
abort,
for example. Each implementation defines whether it closes files,
whether it removes temporary files, and what termination status it
reports when a program terminates abnormally.
See also the Table of Contents and the Index.
Copyright © 1989-2002 by P.J. Plauger and Jim Brodie. All rights reserved. | http://www.qnx.com/developers/docs/6.5.0/topic/com.qnx.doc.dinkum_en_cpp/lib_over.html | CC-MAIN-2022-05 | refinedweb | 1,610 | 61.46 |
- Type:
Bug
- Status: Closed
- Priority:
Major
- Resolution: Duplicate
- Affects Version/s: 2.19
- Fix Version/s: None
- Component/s: None
- Labels:None
Since 2.19 I can't run a single test by full name anymore:
package my.tests; import org.junit.Test; public class MyTest { @Test public void shouldRun() throws Exception { } }
And then command
Unable to find source-code formatter for language: bash.
mvn clean test -Dtest=my.tests.MyTest
Doesn't run any tests.
BTW -Dtest=MyTest works fine and -Dtest=my/tests/MyTest works fine.
- duplicates
SUREFIRE-1191 Run Single Test with Package Name Doesn't work
- Closed | https://issues.apache.org/jira/browse/SUREFIRE-1200 | CC-MAIN-2021-17 | refinedweb | 101 | 70.9 |
[
]
Rick Hillegas commented on DERBY-5901:
--------------------------------------
Emptying the statement cache when a shadowing function is created sounds like a cheap, adequate
fix for this rare edge-case. Thanks.
> You can declare user-defined functions which shadow builtin functions by the same name.
> ---------------------------------------------------------------------------------------
>
> Key: DERBY-5901
> URL:
> Project: Derby
> Issue Type: Bug
> Components: SQL
> Affects Versions: 10.10.1.1
> Reporter: Rick Hillegas
> Labels: derby_triage10_10
>
> You can override a Derby builtin function by creating a function with the same name.
This can give rise to wrong results.
> Consider the following user code:
> public class FakeSin
> {
> public static Double sin( Double input ) { return new Double( 3.0 ); }
> }
> Now run the following script:
> connect 'jdbc:derby:memory:db;create=true';
> values sin( 0.5 );
> create function sin( a double ) returns double language java parameter style java no
sql external name 'FakeSin.sin';
> values sin( 0.5 );
> values sin( 0.5 );
> Note the following:
> 1) The first invocation of sin() returns the expected result.
> 2) You are allowed to create a user-defined function named "sin" which can shadow the
builtin function.
> 3) The second invocation of sin() returns the result of running the builtin function.
This is because the second invocation is character-for-character identical to the first, so
Derby just uses the previously prepared statement.
> 4) But the third invocation of sin() returns the result of running the user-defined function.
Note that the third invocation has an extra space in it, which causes Derby to compile it
from scratch, picking up the user-defined function instead of the builtin one.
--
This message was sent by Atlassian JIRA
(v6.1#6144) | http://mail-archives.apache.org/mod_mbox/db-derby-dev/201312.mbox/%3CJIRA.12603246.1344868395458.53825.1385991517623@arcas%3E | CC-MAIN-2018-26 | refinedweb | 270 | 56.76 |
Alan,
On 04/04/2013 18:21 +0400, Alan Mackenzie wrote:
>> Here's the patch with nested "<>" constructs with max depth=6.
>
> 6? Do the test files come anywhere near that nesting level?
That's just a number that is hopefully greater than any sane
parameterized type nesting level. It could be 5 as well (not sure about
4).
> I tried out imenu on your original problematic snippet, this one:
>
> public class A {
> public static void main(String[] args) {
> //a a a (abcdef abcdef abcdef abcdefabcdefabcdef abcdef abcdef abcdef
> //abcdef
> }
> }
>
> , and it seemed to go very slowly (~6 seconds to scan). I think I've got
> the patch properly installed, but I haven't managed to track down the
> problem.
I've tested on that before mailing the patch, and had no problem (also
re-checked when writing this just to be sure).
Filipp
View entire thread | http://sourceforge.net/p/cc-mode/mailman/message/30683983/ | CC-MAIN-2014-23 | refinedweb | 147 | 79.6 |
I have a model like this
class Net(nn.Module): def __init__(self): super(Net, self).__init__() self.layer_a = nn.Linear(1,1, bias=False) self.layer_b = nn.Linear(1,1, bias=False) def forward(self, x): x_a = self.layer_a(x) x_b = self.layer_b(x) return (x_a, x_b)
There are two phases of training
Phase 1:
self.layer_a and
self.layer_b share the same weight.
Phase 2:
self.layer_a is frozen, only
self.layer_b keeps updating.
To achieve Phase 1, I do something like
model = Net() model.layer_b.weight = model.layer_a.weight
Then both of them share the same weight.
But the problem is how to freeze
model.layer_a.weight without affect
model.layer_b.weight in phase 2?
Or it there a better way to a | https://discuss.pytorch.org/t/how-to-share-weights-in-a-model-and-then-unshare-them-later/77374 | CC-MAIN-2022-21 | refinedweb | 126 | 65.89 |
Details
- Type:
Bug
- Status: Closed
- Priority:
Major
- Resolution: Fixed
- Affects Version/s: 0.5
-
- Component/s: Compiler (General)
- Labels:None
- Patch Info:Patch Available
Description
The patch from
THRIFT-857, applied as r987565, didn't work for smalltalk. (sorry, I tested it with python, and didn't look too hard at the smalltalk)
However, there's a bigger problem that the smalltalk generator is calling back into program_ to lookup namespaces using "smalltalk.<foo>" while it's registered as a generator for "st" so the root namespace check only allows "st.foo" namespaces. I really hate this, but if there are people expecting "namespace smalltalk" to work, maybe the best fix would be to hard-code the converstion to "st":
(note: I ran the smalltalk generator this time to make sure the "category" line was there, but would in no way claim to have tested the smalltalk.)
Activity
- All
- Work Log
- History
- Activity
- Transitions
I just committed this. I added a warning message to our special case indicating that it was deprecated.
Thanks for the patch, Bruce! | https://issues.apache.org/jira/browse/THRIFT-877?focusedCommentId=12904254&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel | CC-MAIN-2015-32 | refinedweb | 177 | 59.13 |
(Crazy busy day today, so simple article to meet my quota. Sorry)
I mentioned before about Kotlin being significantly streamlined as compared to Java. And one of the most obvious places it achieves this, that you are likely to see very early on, is in Data Classes.
Data classes are just classes. There's nothing special about them from that point. The actual "data" keyword was originally nothing more than an annotation that the compiler saw and reacted to. (I'm honestly not sure if this is still the case I'm afraid). As such, they can do (almost) anything that a normal class can do.
The point of Data Classes is that - believe it or not - they are meant to represent data, and not functionality. This is the definition of a Java Bean from Java-land. And that is exactly what they are. Only significantly more streamlines. When you add the "data" keyword (or annotation, or whatever it is) in front of the class definition, what you are telling the compiler to do is:
- Generate a class
- With this set of fields
- With getters (and optionally setters) for every field
- With an
equalsand
hashCodemethod that is correct
- With a
toStringmethod that is correct
- With a
copymethod
- With a set of
componentNmethods
The first three of those are just part of how Kotlin defines classes anyway. That's nothing special. It's the other 4 that are where data classes really come into it.
Writing
equals,
hashCode and
toString methods isn't hard. Writing them correctly can be though. But even then, most of the time people either have their IDE generate them automatically or else they use something like Commons-Lang Equals/HashCode/ToStringBuilder classes. And that's fine, but not without cost. The generated ones from the IDE will get stale as soon as the class changes, unless you remember to keep them updated. The Builder classes will either suffer the same problems, or else will use reflection with the performance cost that incurs.
The final set of methods are simply some helper methods. The
copy method lets you take one object, and create a new one with the same values. Or with some of the same values. You can selectively pick and choose which values you want to replace with new ones. For example:
val user = User(username = "graham", email = "my.email@example.com", banned = false) val copiedUser = user.copy(email = "my.real.email@example.com)
In this case, copiedUser has:
- username = "graham"
- banned = false
And you only had to specify one of those values.
The
componentN methods are used by Destructuring, which is a topic in itself. Simply put though, it lets you take a class and decompose it into individual fields. This is very useful in a few places - such as pattern matching - when you don't care about the class itself but just the individual fields.
In short though, data classes aren't anything special. They don't really do anything. They just allow you to not write a lot of boilerplate for what are essentially generated methods. You can write a Java Bean with a number of fields, and get all of the correct JavaBean methods for everything you need, and a few more on top, in a single line of code. To steal an example from Reddit, it's turning this:
public class User { private String name; private int age; public User(String name, int age) { this.name = name; this.age = age; } public String getName() { return name; } public int getAge() { return age; } public String component1() { return name; } public int component2() { return age; } public User copy() { return new User(name, age); } public User copy(String newName) { return new User(newName, age); } public User copy(String newName, int newAge) { return new User(newName, newAge); } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; User user = (User) o; if (age != user.age) return false; return name != null ? name.equals(user.name) : user.name == null; } @Override public int hashCode() { int result = name != null ? name.hashCode() : 0; result = 31 * result + age; return result; } @Override public String toString() { return "User{" + "name='" + name + '\'' + ", age=" + age + '}'; } }
into this:
data class User(val name: String, val age: Int)
Discussion (2)
Most of my articles will be way way simpler than this, for meeting my 100 days quota 😊
Yeah - turns out I don't know how to write short articles... ;) My emails at work are similar. I'm well known there for how long they can get! | https://practicaldev-herokuapp-com.global.ssl.fastly.net/grahamcox82/data-classes-in-kotlin | CC-MAIN-2021-25 | refinedweb | 755 | 63.49 |
Clark C . Evans [09/04/02 12:05 -0400]:
>. ;)
+1.
>. ;)
-1. A change is a change. #HARD turns out to be very easy :)
Later,
Neil. ;)
Clark
On 08/04/02 23:20 -0700, Neil Watkiss wrote:
>?
FWIW, I am working on a proprietary large scale XML/YAML project. My
team has developed two YAML Schema languages so far. The second is
actually not that far from your attempt, Neil.
We also have developed tools to go from XSD to YSD and from XML to YAML
and back. We've leveraged this to do some amazing YAML to HTML
transforms based on XML schemas.
I hope that some of this code eventually becomes OSS. At least I know
the issues :)
Cheers, Brian
On 09/04/02 03:01 -0400, Oren Ben-Kiki wrote:
>.
+10
Cheers, Brian
Andrew Kurn [mailto:kurn@...] wrote:
> > >.
I agree - if there was such a thing as an older (released) version.
> Every new version should have a new version number -- and no kidding!
Fine. I hereby declare all pre-release versions to be named
#YAML:0.yyyymmdd. I think this should solve the problem - it makes it clear
which version of the draft was intended. Actually it only works for versions
with a '#' directive... But I don't suppose anyone is working with *that*
old a spec draft.
> Really, there's no conceivable reason to break the faith of the
> user community just in order to put pretty numbers on the releases --
> or, for that matter, to release on pretty dates.
I wish to make something clear. There's *no released version of the spec* as
of this moment and *there has never been any*. I strongly agree about
"keeping the faith of users" which is why we haven't *ever* declared *any*
of the drafts as a "release candidate". Each version so far has included an
explicit warning that it is "work in progress" and "subject to change".
That said... I realize that now that implementations are coming out we can't
go on changing things without consideration of implications to existing
users. What I don't want to happen is to have a maze of twisty little
implementations, "almost" compatible because each used a different draft.
*That* would shake user's faith in YAML. We need *one* YAML version.
> First things first. . . . puh-lease.
Right. First thing: change the status of the spec to "release candidate".
Until then we reserve the right to make any change. Such changes would be
driven from the feedback by early implementers. I share their pain
(implementing a non-frozen spec) - hey, I'm working on an implementation
myself! This phase of early implementation is vital for the success of YAML;
it is our "last line of defense" against warts making it to the final spec.
When we do announce a release candidate, we'll formally assign it the
version number "1.0", and change the status section to something more
binding. Something like "no changes are intended, but wording may be changed
for clarification and resolution of ambiguous cases, if any are found". Then
after a few more months we'll declare it as "frozen" and defer any changes
to 1.1, if 1.1 is indeed necessary (I hope it isn't).
Our tentative schedule is to do this in May, that is in about a month from
now (which happens to be exactly one year since we've started work on YAML).
I think this is a reasonable schedule...
Have fun,
Oren Ben-Kiki.
Have fun,
Oren Ben-Kiki
Clark C . Evans [09/04/02 01:14 -0400]:
>.
+1
I think YAML-Schema is what you really want, Andrew, although you might not
know it yet. And, of course, it doesn't exist yet, so you're probably out of
luck for the moment. Even so, consider the following example:
I have a data structure here that I need to serialize in YAML. Because it's a
"mydoc" structure, I'll serialize it like so:
# We'll have to pick a nice abbreviation for yamlschema :)
--- #YAML:1.0 !ttul.org/~nwatkiss/mydoc.yamlschema
title: "My Hairy Arse"
date: 2002-03-04 10:11:12.527Z
content:
chapters:
# Three very short chapters:
- ~
- ~
- ~
authors:
- Neil Watkiss (That's me!)
- Someone Else
There you have it! Now the document itself is stored in the "content" area,
but there's a bunch of metadata required by the "mydoc" schema. I haven't
defined the "mydoc" schema, but for the purposes of argument:
--- #YAML:1.0 !yamlschema
name: "";
definition:
title:
type: leaf
required: yes
format: any
date:
type: leaf
format:
required: yes
content:
type: keyed
format: any
required: yes
children:
chapters:
type: series
format: any
required: yes
children:
type: leaf
format: any
required: yes
authors:
type: keyed
format: any
required: yes
That's a pretty simplistic attempt at YAML-Schema, but you get the idea.?
Later,
Neil
Clark C . Evans [08/04/02 17:21 -0400]:
> (apologies for re-hashing this, it probably won't go anywhere)
Personally, I hope we don't accept this, but I can see the motivation for
your solution. It _is_ nice to have a forgiving parser, especially if a big
use case is hand-edited configuration files.
> Ok. This was motivated by a private email conversation with Johan,
> the fella who discounted YAML (in Brian's email). After I explained
> that we only allow tabs when they are explicit, he said that this may
> cause problems with "newbies". So I was just trying to think if we
> could be slightly less restrictive so that some use of tabs would be
> "ok" as long as it didn't cause any conflicts. As I remember, we have
> two problematic use cases (are there more?):
>
> (a) Where the tabs are of different sizes, and tabs and spaces
> are mixed for indentation. In this case, "\t" may or may
> not be equivalent to " \t" or "\t " depending on the
> editor and placement.
Right.
> (b) The case where the content within a block is indented, and
> thus a tab spans the indenting column.
These are actually the same problem. Only (a) needs to be mentioned, since
(b) is simply a special case of (a).
Here, we have an ambiguity because we don't know how to compare a TAB to four
spaces:
--- #YAML:1.0 ]
--->First line, indented by a TAB
....Second line, indented by four spaces.
Here we have the same ambiguity:
--- #YAML:1.0
--->- first value
....- second value
In either case, if you know how to treat TABs (i.e. what column does the TAB
take you to?), you know whether you have a parse error or not.
> We've solved these two use cases by banning tabs unless there
> is a #TAB directive (did this really solve case b, btw?).
Yes. Here's an example where half of the TAB is part of the content and half
is part of indentation. The only way the parser can know this is by knowing
how to interpret TABs:
--- #YAML:1.0 #TAB:8 ]
....First line, indented by 4 spaces
--->Second line: indented by 4 spaces plus 4 spaces of content
--- #YAML:1.0 #TAB:8
....- first value
--->- parse error
> So. I was thinking to myself, what happens if we ban "inconsistent"
> indenting. Thus, for any given level of indentation, the characters
> used must be identical _or_ a #TAB directive must be used. This would
> allow for the following use cases without a directive:
>
> (a) The YAML file _only_ uses tabs for indentation.
> (b) The YAML file mixes tabs and spaces but in a manner
> which is not ambiguous.
That's pretty neat for useability. The downside is that it complicates
the parser. Normally, you'd be able to keep a stack of "indentation
levels", like this:
-------------------
indents: | 0 | 1 | 4 | ...
-------------------
Those numbers are the "equivalent number of spaces" corresponding to
each level. Here's a YAML stream corresponding to 0, 1, and 4 levels as
I've drawn it:
--- #YAML:1.0
zero:
one:
four: "done"
When the parser is at level 0 (the top-level node), the indent is 0. The
next level has indent 1, and so on.
Currently, dealing with TABs is really easy: you convert them into an
equivalent number of spaces (either for real or not) and store the new
indentation level in the stack.
If we introduce your change, parsers will have to keep a stack of strings,
and compare each new indent with each string in the stack to determine what
the current level is, which is much more expensive than calculating an
integer and comparing against a list of integers. Not only that, but then
when #TAB:x is seen, it _still_ has to pre-convert TABs to spaces, so that
mixed TABs and space characters will be compared properly.
> So, in general, the rule is that for every indentation
> "context", if a sequence ABCD... of indentation is
> used for the first child, then the same sequence ABCD...
> must be used for all siblings, where A, B, C, and D are
> either a single tab or N<9 spaces.
Don't assume N < 9. If we adopt your method, TABs are to SPACEs as apples are
to oranges (unless #TAB:x is explicitly given). Each "new" indentation string
seen introduces a new level of structure, no matter how it actually appears
in the user's editor. In other words, this is a perfectly valid YAML stream
under the new method, since a single <TAB> is not equal to two <SPACE>s.
--- #YAML:1.0
--->first-key:
..next-level: ~
..same-level:
.--->.third-level: ~
.--->.still-third: ~
..same-again: ~
--->second-key: ~
To most people, that stream would look like this in an editor:
--- #YAML:1.0
first-key:
next-level:
third-level: ~
still-third: ~
same-again: ~
second-key: ~
But the YAML parser would see it like this:
--- #YAML:1.0
first-key:
next-level:
third-level: ~
still-third: ~
same-again: ~
second-key: ~
The following stream has a parse error, since the fourth line introduces a
new indentation level, but no node can possibly use it:
--- #YAML:1.0
--->fish eat:
....bears: and eggs
........without gravy: ~
Right? Because we could re-write that as:
--- #YAML:1.0
fish eat:
bears: and eggs
without gravy: ~
Which is a parse error no matter what.
> The advantage of this, is that one can use tabs
> or spaces (or even mix them on a per indentation
> bases) as long as they do it consistently, and not
> in a way which is ambiguous. In short, I think this
> is both sufficient and necessary to cover the two
> problematic use cases:
>
> (a) since the exact same tab must be used for
> all siblings, one can never have "\t" be equivalent
> to " \t" or "\t ".
>
> (b) also, there is no way for a tab to cross into the
> content boundary since this would cause it to differ
> from its siblings indentation, i.e.,
>
> --- ]
> ....First row
> -------->Indented row
>
> is explicitly an error.
I agree with everything else. The method above deals correctly with indenting
a whole YAML document by one "level" (whatever it may be composed of) and
preserving the structure of the document at the new level.
The only thing I'm objecting to is the extra work the parser has to keep
track of (and extra time for the implementors). With your method the parser
must allocate more memory _and_ spend more time comparing strings, whereas
the current method is very fast. I suppose implementation should never hinder
useability, so maybe my argument is flawed. I _do_ agree that it's nice for
"newbies"... but I can also see this causing confusion, as I alluded to in my
earlier examples:
# Betcha didn't think you were gonna get this, didja?
--- #YAML:1.0
repositories:
--->ActiveState Package Repository:
--->....url: "";
--->CDROM Repository:
....url: "/mnt/cdrom/packages/5.6.1"
Is equivalent to:
--- #YAML:1.0
repositories:
ActiveState Package Repository:
url: "http://...";
CDROM Repository:
url: "/mnt/cdrom/..."
Of course, we can place an additional requirement that for the duration of
the entire node, the same indentation must be repeated for all sub-elements
(which isn't what you said):
--- #YAML:1.0
--->A
--->...B
--->......C
--->......--->D
--->......--->D2
--->A2
In other words, each level's indentation must be _exactly_ the indentation of
the previous level plus some new sequence of indents. That doesn't simplify
the parser, but it does eliminate those confusing visual tricks I was showing
earlier.
What do we do with explicit indents, though?
--- #YAML:1.0
--->hello: |2
--->--->This is a nested node.
--->--->As above.
If you haven't got a #TAB:x marker, you have no way of knowing how to "break"
TABs into two pieces.
Well, that's enough for you all to think about while I keep hacking :)
Later,
Neil
| I say "Why no doc title-date?" and CCE says "No app data in the
| doc header. Why don't you just create a new top layer for your
| doc with a Header and Data field?"
4.3.2 Directive Directives are instructions to the YAML parser.
Like throwaway comments, directives are not reflected in the tree
or graph models.
I don't know how this can be said better. The # thingy is for
parser stuff, like TABS and other syntax level issues. This is
our "escape hatch" for the future. It is not a property of the
application (as it is not in the tree or graph model). These
directives will _not_ be reflectted in the API. I just don't
know how to word this any clearer...
| I could say "It's kludgy" and no one could argue, but not because
| it's true, it's just that there's nothing around to say "This is
| what YAML is for and this is our approach to designing it"
Let us say that we added Title or Date to the parse directives.
Then let's say that we wanted the user to have access to these
directives through the API. Thus, we have to put into our
information model something which matches our parse directives,
that is a non-hierarchical mapping. However, I don't know of
one programming language which has non-hierarchical mapping... thus
we would need a non-native data structure to expose our parse
directives to the application, in direct violation of goal #3
"YAML uses the host language's native data structures."
| On this particular issue, I think it would be helpful of the
| spec to contain recommendations about this top-level layer,
| even if they add nothing to YAML itself..
This is not stated in the goals... but it is rather implied
by our domain. We are a "data serializion language", we are not
a "format for saving documents with titles and dates". ;)
| a flag indicating the existence of a "wrapper array"
| as proposed by Brian.
Certainly we should have some general documents that talk
about "Ways you can use YAML". But given that we don't
even have the C parser done yet (I'm working on it again,
thank god beacuse I need it soon), I think this is a much
lower priority.
Also, it is pretty standard that for serialization, the top
level data structure is a mapping. We didn't want to mandate it,
but this is usually the case. See, for example, Python's __dict__
which provides a map from names to all objects in the current
namespace.
| I think the tab-vs-spaces question should be solved by a
| philosophy statement. IETF insists on an extremely simple
| format for its RFCs: plain ASCII. Do they say why? I hope so.
| Let's steal their explanation.
Ok. We have the first goal, "YAML is readable by humans".
By this we have used the "printer test", if I send the document
to my printer can I determine the structure? If yes over coffee
and a printed page I can figure out what is going on with minimal
work, then we've accomplished this goal.
tabs-vs-spaces is a fight between #1 (readable) vs #6 (expressive),
some people like tabs as they make entering data "faster". ;(
| (BTW it would be easy to mandate that no generator emit tabs,
| even if the parser could recognize them. That would get us
| half-way there, anyway.)
The tabs vs spaces thing is a long drawn out concern. We've taken
a "sufficient" way to handle them in the current spec, I was talking
about a relaxation which is not only "sufficient" but "necessary",
in other words, there are a few cases where we are being overly
restrictive in the current rules:
- If I only use tabs for indentation (and nothing else) then
I unnecessarly have to specify the #TAB directive
- If I never mix tabs and spaces within siblings, but I do
mix between top level items then I also unnecessarly have
to specify the #TAB directive
Anyway, since this is a relaxation, we can do it at any time
without affecting current data. Thus, this is just me musing
a bit... I don't see us acting on spaces any time soon.
| Neil says machine-generated YAML is pretty because it has to
| be. Is this part of the philosophy? If so, there's no question
| of letting an alternative, non-indenting format into the spec.
| It's against our philosophy.
Good point. Would you like to start on our phlisophy document?
I hope this helps...
;) Clark
Dear All,
Now that I've had a bit of a listen to your exchanges, I think
that I see a problem: no philosophy document.
I say "Why no doc title-date?" and CCE says "No app data in the
doc header. Why don't you just create a new top layer for your
doc with a Header and Data field?"
I could say "It's kludgy" and no one could argue, but not because
it's true, it's just that there's nothing around to say "This is
what YAML is for and this is our approach to designing it"
(Sorry, guys, but the bulleted list is not a philosophy document.)
I would say that it's reasonable not to have one at the beginning,
when there wasn't a concensus among developers, but now (I hope)
there is, and the public needs it to begin to understand why
the spec contains all the funny decisions it does.
Also
On this particular issue, I think it would be helpful of the
spec to contain recommendations about this top-level layer,
even if they add nothing to YAML itself. That is, there should
be a recommended structure for the top level to contain
things like doc title and date, and (coming out of my
objection re acyclic graph dumping) a flag indicating the
existence of a "wrapper array" as proposed by Brian.
And
I think the tab-vs-spaces question should be solved by a
philosophy statement. IETF insists on an extremely simple
format for its RFCs: plain ASCII. Do they say why? I hope so.
Let's steal their explanation.
(BTW it would be easy to mandate that no generator emit tabs,
even if the parser could recognize them. That would get us
half-way there, anyway.)
And
Neil says machine-generated YAML is pretty because it has to
be. Is this part of the philosophy? If so, there's no question
of letting an alternative, non-indenting format into the spec.
It's against our philosophy.
Andrew
Arggggghh!!!!
(Rant, you may have guessed, follows.)
>
> Message: 3
> From: Oren Ben-Kiki <orenbk@...>
> Date: Sat, 6 Apr 2002 16:43:34 -0500
> Subject: [Yaml-core] New draft
>
> Is attached..
> >
> >...
>
> Have fun,
>
> Oren Ben-Kiki
>.
Every new version should have a new version number -- and no kidding!
You've already broken this rule, but there's no need to break it
again.
Really, there's no conceivable reason to break the faith of the
user community just in order to put pretty numbers on the releases --
or, for that matter, to release on pretty dates.
First things first. . . . puh-lease.
Andrew
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/yaml/mailman/yaml-core/?viewmonth=200204&style=flat&viewday=9 | CC-MAIN-2017-04 | refinedweb | 3,390 | 72.87 |
There are a lot of JavaScript frameworks for web applications, but few of them are nicely integrated with Ruby on Rails and most of them are quite heavy. This is about crafting your own JS application/framework to interact with a Rails app, or any server side app.
Why am I writing this? Well I was looking for a JS framework tightly bound with Ruby on Rails, but I didn’t find anything that I really liked… Some frameworks are valid but they are not crafted for Rails and many of these are quite heavy. Recently I discovered CompoundJS which is really great, but it is too much client side, as it almost is a Rails porting in JS.
The goal is to have a classic Rails application on the server and a JS interface on the client side, conscious of the routes, the models and the views, so (in JS) I can do something like friends = User.find(10).friends() to receive, all the friends of user 10 as a JSON response and then if I type html = friends.view(‘list’) I render them with the list view, finally I inject the HTML into the DOM.
Routes
I think that the most useful feature is to have access to Rails routes in JS. There exist many gems for this and after some trials I chose js-routes, which creates a JS object (by default called Routes) containing all the routes…simple and effective! If for some reason you want to do it by hand, here’s what I did at the beginning:
MyApp = { paths: { users: function() { return '/users' }, user: function(user) { return '/users/'+user }, user_types:function(u) { return this.user(u)+'/types' }, show_user_type: function(u,type) { return this.user(u)+'/types/'+type }, create_user_type: function(u) { return this.user(u)+'/types' }, update_user_type: function(u,type) { return this.user(u)+'/types/'+type }, destroy_user_type: function(u,type) { return this.user(u)+'/types/'+type }, index_user_activities: function(u) { return this.user(u)+'/activities' }, show_user_activity: function(u,activities) { return this.user(u)+'/activities/'+activities } } }
Then it’s useful to build some helper functions for AJAX calls:
MyApp = { _get: function(path, args, callback) { $.get(this.url.root + path, args, callback, 'json'); }, _post: function(path, args, callback) { $.post(this.url.root + path, args, callback, 'json'); }, _put: function(path, args, callback) { $.put(this.url.root + path, args, callback, 'json'); }, _delete: function(path, args, callback) { args._method = 'delete'; this._post(path, args, callback); } }
Now you need a function for executing actions:
MyApp = { do: function(model, action, args, callback) { if (action == 'index') { // workaround for singular/plural only names MyApp._get(Routes[model+'_index_path']() || Routes[model+'_path']()); } elseif (action == 'show') { MyApp._get(Routes[action+'_'+model+'_path'], args, callback); } elseif (action == 'destroy') { MyApp._delete(Routes[action+'_'+model+'_path'], args, callback); } // etc... } }
…but wait this is just a helper method, you will not call it directly, to see something more useful continue reading…
Models
Now you have routes and you know how to use them, but to build a real framework you need much more! First of all we need all Rails Models available on the client side: as there exists the User Model in Ruby,
class User < ActiveRecord::Base attr_accessible :email, :name, :password, :password_confirmation, :avatar end
here it is in JS…
function User(attr){ this.id = attr.id; this.name = attr.name; this.avatar = attr.avatar; # ...well, not even the password! }; // Inheritance User.prototype = new Model(); User.prototype.constructor = User;
Please, notice the inheritance from Model: I would like to have a handful of methods to call on all Models subclasses for rendering, getting URLs, execute actions (destroy, update) and find them. The Model class (…yeah…prototype!) is also useful for configurations common to all models:
function Model(){ this.some_opts = default_val; }
The most interesting part resides in Models methods:
Model.prototype = { // Views methods view: function(action, layout) {}, // Find methods find: function() {}, // Controllers methods create: function() {}, destroy: function() {} };
Controllers
OK…Now we have Models and Routes…let’s combine them together so when you call MyApp.do(‘user’,’index’, {}, callback) you get back a nice User instance with id, name etc…, But be aware that now you will call Model.do(User, ‘show’, {id: 5}, callback)
Model.do = function(klass, action, args, callback) { var results = []; MyApp.do(klass.name.toLowerCase(), action, args, function(data){ for(i=0; i<data.length; i++) { // Create an instance of the model and initialize it with the data fetched from server results.push(new klass(data[i])); } callback.call(results); } }; Model.index = function (klass, args, callback) { this.do(klass, 'index', args, callback); }
Simple but powerful! It takes as argument a class (User) and a function to call back when the request succeeds.
Views
Well…the missing feature is the .view() function: given an instance of Model or its subclasses, it searches for the right view and call it with the Model instance as argument: the method directly returns HTML code.
The starting point is a file with .jst extension (JS Template) in the JavaScript assets, Rails (sprocket) will treat it as a view template, that is, it takes the content of that file and saves it in the variable JST[‘file_name’] as a string…check it in the browser console on your Rails app! The real power comes when coupled with a template processor, basically you can embed JS code (variables, functions call…) in the view, just like you do in .erb files:
<a href="tesladocet.com/user/<%= id %>"> <h1><%= name %></h1> </a> <img src="<%= avatar %>"><br>
Calling JST[‘user’] will print the exact content of the file, but calling _.template(JST[‘user’], args) will replace the <%= %> with the result of execution of the JS code contained in it. To be honest the manual parsing procedure is boring and slow, as the template must be parsed all the time, so is better to precompile it, so you can just call JST[‘user’](args). The most efficient solution is to automatically precompile server side, so just install the gem of a template engine like EJS, Handlebars, etc., and append the right extension to the JST file (i.e.: app/assets/javascript/user.jst.ejs for EJS): I chose EJS, which is the entry level processor (but works well!) and has the same syntax as ERB.
Now it comes the magic: you can pass as argument a Model itself (JST takes as argument an object, not a list of vars!!)
// Find a user MyApp.show(User,{id:1}, function(u) { // Use it as argument for JST html_to_inject = JST['user'](u); });
<!-- This is the output --> <a href="tesladocet.com/user/1"> <h1>Luca</h1> </a> <img src="my_photo.jpg">
Finally the .view() method of the Model class can be filled:
view: function(action, layout) { action = action || 'show'; this._view_opt.name = this._view_opt.name || this.constructor.name.toLowerCase(); // Draw template html = JST[this._view_opt.name+'/'+action](this) // Draw layout, if any if (layout) return this.drawLayout(layout, html); else return html; } drawLayout(layout, html) { return JST['layout/'+layout](html) } // So this: JST['user'](u) // Becomes this: u.view() // u.view('show')
Note that I structured JST files in folder like app/assets/javascript/<model_name>/<action>.jst.ejs and JST preserves this strucure using / in the template name. The .drawLayout() method uses the layout for layout tempaltes, so if you would create a Model called Layout, just change the folder name to something else!
A little, annoying, problem… When you fetch more than one instance from the server, you get an Array of instances, so the u.view() doesn’t work, the rough solution is to loop the array and call the view on each element…well here’s a trick:
Array.prototype.view = function(action,layout) { this.map(function(inst){ inst.view(action, layout); }) };
Server side
I’m pretty sure the server side shouldn’t be touched for most of you reading this article! Anyway simply check the controller: it needs to serve a XHR requests with JSON responses. Be only aware of Rails associations: for example I have a News model defined by the attributes user_id, action, entity_id…basically a News belongs_to Users and Entities and represents something like <‘User#1′, ‘created’, ‘Post#1′>. So when I retrieve the News I have an useless field user_id = 1 in the JS News Model and I should make a new request for the User#1…don’t worry Rails is smart enough:
def index @news = current_user.news.all(limit: 10, include: [:user,:entity]) respond_to do |f| f.js { render json: @news, # No info about user and entity include: { # Rails belongs_to magic! user: {only: [:name,:avatar]}, # no password or email!! entity: {} # Get every entity's attribute } } f.html {} end end
This automatically include the :user and :entity attributes (with their own name, id etc…) in the News Model and convert to_json everything! To handle the associated Models, a Model must include the appropriate fields:
function News(attr){ this.id = attr.id; this.user_id = attr.user_id; this.user = attr.user; // belongs_to :user this.action = attr.action; this.entity_id = attr.entity_id; this.entity = attr.entity; // <- belongs_to :entity }; News.prototype = new Model();
Well…this is it! Hope to be useful! Please give me some feedback and tell me your solutions! | http://tesladocet.com/programming/javascript-framework-interact-ruby-on-rails/?shared=email&msg=fail | CC-MAIN-2017-34 | refinedweb | 1,526 | 56.55 |
Introduction
In this post we will look at how to access a PosgreSQL database in your C/C++ application. It's not as hard as you might think, but you need to understand the procedure and the functions used.
Functions and method that will be used
To access the database from your C/C++ program, we are going to use a library called libpq-fe. The most basic functions that we'll need in order to access the database are the following:
- PQconnectdb
- PQexec
- PQgetvalue
Getting dirty
The following steps need to be followed in sequence (or out of sequence, but the application needs to understand what you're doing, thus this is only a logical breakdown of what is necessary). So let's start with some hands on...
Step 1 Include the library
This is a rather obvious step, but here it goes:
#include <postgresql/libpq-fe.h>
Depending on the compiler you're using, you might need to drop the .h, and only use #include <postgresql/libpq-fe>
Step 2 Declare the connection
We need to declare a database connection in our program. This is used as a handle throughout the program:
PGconn *dbconn;
Step 3 Initiate the connection
Let's now connect to a physical database:
dbconn = PQconnectdb("dbname = mydatabase");
Off course, mydatabase can be any database you choose. This is only a sample database we're using.
Step 4 Test the connection
You can test the connection to see in what stage or what the connection status is. We will only test to see if the connection was successful or not.
if (PQstatus(dbconn) == CONNECTION_BAD) {
printf("Unable to connect to database\n");
}
Step 5 Declare a query result holder
Now the whole point of accessing the database in your application is to get or store information to and from the database (with the application as a "front-end"). When retrieving data from the database, these data are stored in a variable of the type PGresult*
PGresult *query;
Step 6 Execute a query
So now we execute a simple SELECT statement and store the data in query:
query = PQexec(dbconn, "select * from mytable");
Step 7 Use the values
Now the data is stored in query as a table, but we cannot use it just as is. If we want to use only a single value or row, we have to retrieve it from query. This is done using the PQgetvalue() function.
printf ("%s\n", PQgetvalue(query, 0, 1));
The numbers (0 and 1) indicate the row and column, with counting starting at 0. In other words, this line will display the value in the first row, the second column,
Step 8 Close the connection
Afterwards, like anything else, we should close the connection gracefully:
PQfinish(dbconn);
Warnings
- This post is only for educational purposes for getting to grips with the very basics of using a PosgreSQL database in a C/C++ program. There might be other ways of doing the same thing as described in this post, and a whole lot more options than what was described. Always consult the official vendor documentation.
1 Comment
I ended up going this route instead of fighting with the libpqxx install for windows. Thanks!
Edit:
I had an issue that seems common with this implementation so I want to also add how to fix it. Its an error stating something like "error LNK2019: unresolved external symbol PQstatus referenced in function main"
I am using vs 2010 and postgres 9.2 x64
Under explorer go to your project properties (alt + enter if your project is selected) and change:
C/C++ -> General -> Additional Include Directories
C:\Program Files\PostgreSQL\9.1\include
Linker -> General -> Additional Library Directories
C:\Program Files\PostgreSQL\9.1\lib
Linker -> Input -> Additional Dependencies
libpq.lib
Also if your postgres is x64 build you will need to go to solution properties:
Configuration Properties -> Platfrom -> New
and change it to x64
After that everything will compile.
Another thread with more info:
Share Your Thoughts | https://renatonel.wonderhowto.com/news/accessing-postgresql-database-your-c-c-program-0126884/ | CC-MAIN-2017-30 | refinedweb | 665 | 57.2 |
Hi, i'm a new unity developer, i've a question for my app security. The first question is, when my app is compiled(apk, ipa) is 100% secure? there is a way to encrypt a string with a pubblic key and sent it to the server(aspnet with ssl) for decript whit private key? this question because i've a an idea for game online where user can win real money. for this reason the data send and received to server must be 100% secure and uncraccable. Thanks
Answer by suribe
·
Mar 08, 2014 at 08:14 AM
Security is a broad concept... If what worries you is encrypting your outgoing traffic, then one way would be to use a secure connection (HTTPS) and connect to it from the game using the WWW class. Of course you need to make your server resistant against hacking and DDoS attacks, as security of a system is as strong as its weakest link and if the application makes real money, somebody will try eventually to hack into it.
And truth is, nothing is 100% secure.
thanks for the reply, so even if I make the server secure, it remains the risk of cracks of ipa or apk and then access the link to the API right?
Obtaining the link to your server is actually quite easy; you need only to have some tool that records outgoing URLs for http/https calls. The important thing is to encrypt the traffic in a way that allows both content confidentiality (no eavesdropping, i.e., listening to what you send) and trust (no impersonation, i.e., no sending of fake information by third party applications that are not yours). Of course, this topic far exceeds the Unity Answers. :)
In fact, my idea is to use public and private key between unity and servers for cifrate response if unity permits, but if you can unpack an build app the public key would be stolen
The communication should never be the real problem. The important thing is, rule No1: "Never trust a client". The client is not under your control, never! Strong security can never be implemented on the client.
Also there are two security concerns:
A third party attacker tries to intercept the traffic and manipulate the data.
The client itself tries to manípulate the data.
Transportation security such as HTTPS only works against the first kind of concerns. You can't do anything (100%) against the second.
While the transport of the data from client to server is more of less secure, what data the client sends is not. No one would try to "hack" into your API. Most hackers would simply decompile / alter your app to do what they want.
So all crucial decisions should be made on the server. The client just provides input. Don't tell the client secret information beforehand. For example behind which door is the prize.
You need more defensive programming
@xxstefanoxx: The point of the public key is that it can be known to the public. With the public key you can encrypt data which can only be decrypted with the private key. This only secures the transportation, not the client.
Problem With Saving And Cryptography with AES
1
Answer
Does Unity have any symmetric crypto libraries?
1
Answer
using System.Security.Cryptography;
1
Answer
HMACSHA1 in export to flash
0
Answers
Sha1/2 encryption on Unity 4.2?
2
Answers | https://answers.unity.com/questions/658489/security-and-crypt.html | CC-MAIN-2019-43 | refinedweb | 572 | 72.66 |
Incremental ASP.NET to ASP.NET Core Migration
ASP.NET Core is the modern, unified, web framework for .NET that handles all your web dev needs. It is fully open source, cross-platform, and full of innovative features: Blazor, SignalR, gRPC, minimal APIs, etc. Over the past few years, we have seen many customers wanting to move their application from ASP.NET to ASP.NET Core. Customers that have migrated to ASP.NET Core have achieved huge cost savings, including Azure Cosmos DB, Microsoft Graph, and Azure Active Directory.
We have also seen many of the challenges that customers face as they go through this journey. This ranges from dependencies that are not available on ASP.NET Core as well as the time required for this migration. We have been on a journey ourselves to help ease this migration for you as customers, including work over the past year on the .NET Upgrade Assistant. Today we are announcing more tools, libraries and patterns that will allow applications to make the move to ASP.NET Core with less effort and in an incremental fashion. This work will be done on GitHub in a new repo where we are excited to engage with the community to ensure we build the right set of adapters and tooling.
Check out Mike Rousos’s BUILD session below to see the new incremental ASP.NET migration experience in action, or read on to learn more.
Current Challenges
There are a number of reasons why this process is slow and difficult, and we have taken a step back to look at the examples of external and internal partners as to what is the most pressing concerns for them. This boiled down to a couple key themes we wanted to address:
- How can a large application incrementally move to ASP.NET Core while still innovating and providing value to its business?
- How can libraries that were written against
System.Web.HttpContextbe modernized without duplication and a full rewrite?
Let me dive into each of these issues to share what we have seen and what work we are doing to help.
Incremental Migration
Many large applications are being used daily for business-critical applications. These need to continue to function and cannot be put on hold for a potentially long migration to ASP.NET Core. This means that while a migration is occurring, the application needs to still be production ready and new functionality can be added and deployed as usual.
A pattern that has proven to work for this kind of process is the Strangler Fig Pattern. The Strangler Fig Pattern is used to replace an existing legacy system a piece at a time until the whole system has been updated and the old system can be decommissioned. This pattern is one that is fairly easy to grasp in the abstract, but the question often arises how to actually use this in practice. This is part of the incremental migration journey that we want to provide concrete guidance around.
System.Web.dll usage in supporting libraries
ASP.NET apps depend on APIs in System.Web.dll for accessing things like cookies, headers, session, and other values from the current request. ASP.NET apps often depend on libraries that depends on these APIs, like
HttpContext,
HttpRequest,
HttpResponse, etc. However, these types are not available in ASP.NET Core and refactoring this code in an existing code base is very difficult.
To simplify this part of the migration journey, we are introducing a set of adapters that implement the shape of
System.Web.HttpContext against
Microsoft.AspNetCore.Http.HttpContext. These adapters are contained in the new package
Microsoft.AspNetCore.SystemWebAdapters. This package will allow you to continue using your existing logic and libraries while additionally targeting .NET Standard 2.0, .NET Core 3.1, or .NET 6.0 to support running on ASP.NET Core.
Example
Let’s walk through what an incremental migration might look like for an application. We’ll start with an ASP.NET application that has supporting libraries using System.Web based APIs:
This application is hosted on IIS and has a set of processes around it for deployment and maintenance. The migration process aims to move towards ASP.NET Core without compromising the current deployment.
The first step is to introduce a new application based on ASP.NET Core that will become the entry point. Traffic will enter the ASP.NET Core app and if the app cannot match a route, it will proxy the request to the ASP.NET application via YARP. The majority of code will continue to be in the ASP.NET application, but the ASP.NET Core app is now set up to start migrating routes to.
This new application can be deployed to any place that makes sense. With ASP.NET Core you have multiple options: IIS/Kestrel, Windows/Linux, etc. However, keeping deployment similar to the ASP.NET app will simplify the migration process.
In order to start moving over business logic that relies on
HttpContext, the libraries need to be built against
Microsoft.AspNetCore.SystemWebAdapters. This allows libraries using System.Web APIs to target .NET Framework, .NET Core, or .NET Standard 2.0. This will ensure that the libraries are using surface area that is available with both ASP.NET and ASP.NET Core:
Now we can start moving routes over one at a time to the ASP.NET Core app. These could be MVC or Web API controllers (or even a single method from a controller), Web Forms ASPX pages, HTTP handlers, or some other implementation of a route. Once the route is available in the ASP.NET Core app, it will then be matched and served from there.
During this process, additional services and infrastructure will be identified that must be moved to run on .NET Core. Some options include (listed in order of maintainability):
- Move the code to shared libraries
- Link the code in the new project
- Duplicate the code
Over time, the core app will start processing more of the routes served than the .NET Framework Application:
During this process, you may have the route in both the ASP.NET Core and the ASP.NET Framework applications. This could allow you to perform some A/B testing to ensure functionality is as expected.
Once the .NET Framework Application is no longer needed, it may be removed:
At this point, the application as a whole is running on the ASP.NET Core application stack, but it’s still using the adapters from this repo. At this point, the goal is to remove the use of the adapters until the application is relying solely on the ASP.NET Core application framework:
By getting your application directly on ASP.NET Core APIs, you can access the performance benefits of ASP.NET Core as well as take advantage of new functionality that may not be available behind the adapters.
Getting Started
Now that we’ve laid the groundwork of the Strangler Fig pattern and the System.Web adapters, let’s take an application and see what we need to do to apply this.
In order to work through this, we’ll make use of a preview Visual Studio extension that helps with some of the steps we’ll need to do. You’ll also need the latest Visual Studio Preview to use this extension.
We’re going to take an ASP.NET MVC app and start the migration process. To start, right click on the project and select Migrate Project, which opens a tool window with an option to start migration. The Migrations wizard opens:
You can set up your solution with a new project or you can select an existing ASP.NET Core project to use. This will do a few things to the ASP.NET Core project:
- Add
Yarp.ReverseProxyand add initial configuration for that to access the original framework app (referred to as the
fallback)
- Add an environment variable to launchSettings.json to set the environment variable needed to access the original framework app
- Add
Microsoft.AspNetCore.SystemWebAdapters, registers the service, and inserts the middleware for it
The startup code for the ASP.NET Core app will now look like this:
using Microsoft.AspNetCore.SystemWebAdapters; var builder = WebApplication.CreateBuilder(args); builder.Services.AddSystemWebAdapters(); builder.Services.AddReverseProxy().LoadFromConfig(builder.Configuration.GetSection("ReverseProxy")); // Add services to the container. builder.Services.AddControllersWithViews();.UseSystemWebAdapters(); app.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); app.MapReverseProxy(); app.Run();
At this point, you may run the ASP.NET Core app and it will proxy all requests through to the framework app that do not match in the core app. If you use the default template, you’ll see the following behavior:
If you go to
/, it will show you the
/Home/Index of the ASP.NET Core app:
If you go to a page that doesn’t exist on the ASP.NET Core but does exist on the framework app, it will now surface:
Notice that the URL is the same () but will proxy to the request to the framework app when needed. You are now set up to start bringing routes over to the core app, including libraries referencing System.Web.dll.
Proxy support
The framework app will now be downstream of a reverse proxy. This means that some values, such as the request URL, will be different as it will not be using the public entry point. To update these values, turn on proxy support for the framework app with the following code in Global.asax.cs or Global.asax.vb:
protected void Application_Start() { Application.AddSystemWebAdapters() .AddProxySupport(options => options.UseForwardedHeaders = true); }
This change may cause additional impact on your application. Sorting that out will be part of the initial process of getting the Strangler Fig pattern implemented. Please file issues for challenges encountered here that are not already documented.
Session support
Session works very differently between ASP.NET and ASP.NET Core. In order to provide a bridge between the two, the session support in the adapters is extensible. To have the same session behavior (and shared session state) between ASP.NET Core and ASP.NET, we are providing a way to populate the session state on core with the values from the framework app.
This set up will add a handler into the framework app that will allow querying of session state by the core app. This has potential issues of performance and security that should be taken into account, but it allows for a shared session state between the two apps.
In order to set this up, add the
Microsoft.AspNetCore.SystemWebAdapters.SessionState package to both applications.
Next, add the services on the ASP.NET Core app:
builder.Services.AddSystemWebAdapters() .AddJsonSessionSerializer(options => { // Serialization/deserialization requires each session key to be registered to a type options.RegisterKey<int>("test-value"); options.RegisterKey<SessionDemoModel>("SampleSessionItem"); }) .AddRemoteAppSession(options => { // Provide the URL for the remote app that has enabled session querying options.RemoteApp = new(builder.Configuration["ReverseProxy:Clusters:fallbackCluster:Destinations:fallbackApp:Address"]); // Provide a strong API key that will be used to authenticate the request on the remote app for querying the session options.ApiKey = "strong-api-key"; });
This will register keys so that the session manager will know how to serialize and deserialize a given key, as well as tell it where the remote app is. Note that this now requires that the object be serializable by
System.Text.Json, which may require altering some of the objects that are being stored in session.
Identifying keys may be challenging for a code base that has been using session values ad hoc. The first preview requires you to register them but does not help identify them. In a future update, we plan to log helpful messages and optionally throw if keys are found that are not registered.
Finally, add the following code on the framework app in a similar way in Global.asax:
protected void Application_Start() { Application.AddSystemWebAdapters() .AddRemoteAppSession( options => options.ApiKey = "some-strong-key-value", options => options.RegisterKey<int>("some-key")); }
Once this is set up, you’ll be able to use
(int)HttpContext.Session["some-key"] as you’d expect!
Summary
Today we are introducing some tooling and libraries to help address incremental migration and help you move your ASP.NET applications forward faster and more easily.
There is more to do in this space, and we hope you find this helpful. We are developing this on GitHub at and welcome issues and PRs to move this forward.
will Azure Dev Ops Server upgrade to asp.net core as well , so I can try it in docker containers like GitLab does
“Incremental” migration only further increases complexity and generally should be avoided unless it’s absolutely critical to have both versions of the app live side-by-side, in my opinion. It means that now not only do you need to rewrite your app, you need to make it compatible and possibly share state with the new version.
I strongly encourage you guys at Microsoft to all get on the same page and port WebForms to Core. From the recent blog post, it seems you guys are building a new Web Forms designer anyway. “Porting” a Web Forms app to a modern stack is a total rewrite and frankly a nonstarter for websites which already work perfectly well.
It’s strange to me that WinForms and WPF were ported to .NET Core (and even WCF) but WebForms was not.
Winforms and WPF were ported to .NET Core because there was no client stack at all (and the designer is a MASSIVE rewrite), ASP.NET Core existed and we had a new web stack, porting those client stacks were motivated by filling that gap. CoreWCF is a very different version of WCF that is somewhat compatible but isn’t the same product. It’s built on top of ASP.NET Core and anything using it deeply enough will see those differences. Fortunately, there’s enough usage of “WCF just for RPC between C# things” that it made sense to continue the smoothen the migration effort for some service side components that were very bound to the WCF service contract model or had to continue exposing the soap contract because of an inability to change clients.
There are 2 things that are coupled but should discussed separately:
1. System.Web – The hosting model
2. WebForms – The UI framework on top
System.Web is tightly coupled to IIS and lots of customers application code by now depends on every implicit behavior ever observed. System.Web has tentacles into the CLR hosting APIs, and is an entirely separate hosting model for a console or windows application (which is MUCH simpler in comparison). System.Web is also fundamentally built on AppDomains, which don’t exists in .NET Core and we’ve directionally moved away from them. The compilation system was designed based on some assumptions about machine wide installs and that’s incompatible with .NET 6+ and all of the different modes its designed to run in (installed into Windows, IIS has hard dependencies on the idea of a managed module, different Configuration system coupled to IIS etc etc etc). I could go on, this just the tip of the iceberg. Long story short, we have no plans to pulling System.Web or the existing infrastructure to support it out of windows in order to make it work on .NET Core 6+. We built ASP.NET Core specifically as a new hosting platform built for modern web applications.
WebForms is a different can of worms. It would be possible to build something like CoreWCF, that would be incompatible with the any of the controls you consume today in your existing .NET Framework WebForms application that would run on top of ASP.NET Core. The designer in Visual Studio also wouldn’t work, we’d need to rewrite it to make it work with these new .NET Core based controls and “there be dragons”. The coupling to System.Web would need to be broken, managed IIS modules and module pipeline would no longer work, configuration would need to be re-done, the compilation system would need to be updated. IMHO it would be death by 1000 paper cuts (I am speaking from experience here).
Ultimately though the bigger problem is that we have no plans to move webforms forward as a technology. We’ve built a modern hosting platform (ASP.NET Core) and modern page based models and component models (Razor pages and Blazor) that we want developers building new application or modifying existing ones (like this blog post describes), to be able to take advantage of the new tech from day 0.
Webforms and .NET Framework will continue to exist as it is built into windows and will get security patches and other smaller updates (bug fixes etc).
PS: If there’s interest in creating a CoreWebForms ™ equivalent, a good starting point would be the mono webforms implementation. That is currently decoupled from IIS and can run cross platform today. It’s still coupled to the System.Web abstractions, but the packages we’re shipping in this blog post adapt would help with adapting the HttpContext.
this comment has been deleted.
I agree with MgSam. I will stay on Web Forms with Telerik UI controls for my intranet apps. Microsoft has been reinventing the wheel and creating less functional ways of doing things for the past 15 years (starting with MVC which is just a rip off of Ruby On Rails). The whole approach they took to making .NET multi-platform was a fiasco. The new stuff isn’t any easier either. Way too many design patterns. Logging is a joke also. I’m pretty sure all the original .NET developers at Microsoft left for more money somewhere else. Then, the newbies came in with no knowledge of what was already there and decided to rewrite everything, with breaking changes everywhere. Not to mention, they just want to jam cloud down everyone’s throats to make more money and turn everyone into renters.
Hi MgSam,
I’ve posted a general reply in that might be helpful to your situation.
Best regards, Michael
I highly appreciate the effort of .NET core team, and I completely understand the issues David Fowler talks about (thanks for detailed explanation). Still, as an old developer from early 2000s I have to say that development was more fun those days. WebForms and Winforms are the example of encapsulation done right. I know that many things changed since than, and I don’t want to sound grumpy but, even tho the new technology stack is the most advanced and flexible ever, programmers experience was better back then.
WebForms is great and productive but is an artifact of the time it was made. I agree that web development is way too complicated today (but so are the requirements!). That said, Blazor gives a very close to webforms productivity experience and is modern. DotVVM is also a great alternative to webforms that runs on .NET.
I hear you though, you know and love webforms and want to continue using it. I think that’s fine as long as you don’t expect any big changes to it.
Have an experience of migration of tens apps, including large bank corporate.
I should say HttpContext usually is a smallest problem from possible.
Usually problem is a legacy .net 4.0 dependencies which limits you to migrate on .net core version 2.2 maximum.
Because this is the last one which allows to host asp.net core on .Net framework
Thanks for your comment. It’s a common one we’ve seen internally and externally and also a basic building block of other compatibility efforts that people may want to do. We have also seen legacy dependencies being a challenge – please join us on Github to help us understand what the issues you’re facing are and if there’s things we can do there.
Hi Igor,
I completely agree regarding the scope of the dependency problems. If you can reduce your problems to “just WebForms not being availble”, my general reply in might be helpful to your situation.
Best regards, Michael
I’m trying to temper my excitement here.
This has been my biggest gripe about the direction of .NET:
Developers working on still supported technologies like Web Forms were basically told to rewrite the entire application from scratch or go fly a kite.
Even something as simple as an adaptor/bridge for HttpContext was non-existent.
So even just SystemWebAdapters is huge.
I’m hoping this means that the .NET team is going to be doing more going forward to support teams who would like to use .NET 6+, but are chained to semi-abandoned frameworks.
Maybe one day you’ll even let us share Razor views between Web Forms/MVC5 and Core/NET6, so we can migrate routes/pages that rely on global usercontrols/partials like header/footer etc.
This was definitely Microsoft’s biggest failing for me – 16 years after MVC was made part of ASP.NET Framework, there is still zero upgrade path from WebForms to MVC, whether in .NET Framework or .NET Core, and the only solution is a complete rewrite of the UI. That’s only the beginning of course, because back when WebForms came out, dependency injection etc was not a first-class citizen, so unless your developers were super switched-on and disciplined, then you’ll find so much business logic embedded in the code-behind pages, and disentangling that particular Gordian Knot is even harder and more error-prone.
There’s no reasonable migration path from WebForms to MVC. I think you could make very shallow situations work but ultimately there’s a fundamental impedance mismatch between those programming models and there’s not something you can paper over. It’s not because we don’t like to solve hard problems or because we are intentionally trying to hurt WebForms users, the problem is hard to automate without there being a compatible approach on the other side.
This is why it would be more possible to migrate to something like Blazor from webforms. It wouldn’t be the exact same thing but the component model and life cycle make it similar enough that it would be possible to migrate one to the other. It’s why things like this could be built.
The most reasonable approach I could think of would be more refactoring tools to move chunks of code around the project (extracting business logic for example), but there’s no big bang migration approach that’s going to make moving legacy code easy.
Couldn’t agree more.
Between 406 aspx and 389 ascx files, there’s precisely zero chance we will ever migrate the entire site, which is already a technical debt nightmare that was originally migrated from Classic ASP 15 years ago. I don’t expect Microsoft to fix that, obviously.
But what’s worse is that we have no choice but to continue to add new pages/controls in Web Forms instead of MVC, because of how non-existent the integration is between Razor and WebForms renderers.
We dragged ourselves through the poorly documented and overly complicated process of converting the project from a Web Site to a Web Application Project, added MVC5, etc. We did everything we could to drag ourselves to the future, despite Microsoft’s abandonment.
They “support” WebForms and .NET 4.8, but not developers who still have to develop those applications.
And don’t even get me started on new C# versions.
is there any work being done to share .net identity cookie authentication between .net framework and .net core?
Yes, we’re working on shared auth support (in-progress pull request is here) and hope to be able to release it soon in an update.
This sounds like what i have been needing for several years 🙂
Just to be clear…
i have a .net4.8 mvc5/webapi app which authenticates using the aspnet identity. Since Identity from MVC5 and aspnet core 6 are not compat I could use yarp from an aspnet core 6 app and proxy authentication requests to the .net app using the sytemweb adapter?
Whilst i upgrade and move pages over to the core app? If so, do i have the ability to access the .NET identity objects on the core side?
i.e. i hit NetCore/ProtectedContentController i need to login so the request is sent to .NET app NetFramework/Account/Login, then is the user property etc available to query on aspnet core side, when i am redirected back to /NetCore/ProtectedContentController ?
I am mid migration with a large solution. Everything runs net6, with as much code as possible moved to shared libraries that are multi-targeted net48;net6.0, except a large MVC5 app that relies heavily on MVC htmlhelpers. We’re working on ripping bits out, but a quality of life improvement would be to support SDK projects for MVC5 apps. This project goes a long way to showing it can be done, but I’m not sure I want to bet the business on this clever hack.
Also discussed in this issue:
We (that is, our company RUBICON IT GmbH) face the same challenge with our WebForms-based applications: an incremental migration to another UI stack isn’t a good approach for us, but we still have an interest in using .NET 6 in our daily work. With the existing offerings from Microsoft, we can only choose between keeping some of our code base on .NET Framework for many years to come or start from scratch / do a big-bang migration. Since both of those options aren’t working for us, we needed a third approach, namely to be able to use WebForms inside a .NET 6 / ASP.NET Core application.
So, for past couple of years, I’ve been involved in an effort to port WebForms to ASP.NET Core and we now have a working solution that allows us to integrate an existing ASP.NET WebForms code-base in an ASP.NET Core web application running on .NET 6.
If you want, you can check out our demo application where I actually dual-target both ASP.NET Core and .NET Framework:
The web application as a library:
The web application running with .NET 6 / ASP.NET Core:
The web application running with .NET Framework:
(Please note we don’t actually have made the ported System.Web assemblies publicly available at this time so it’s more of a code-browsing exercise.)
Since we believe this scales also to larger ASP.NET WebForms code bases outside our own company (including those that use 3rd party control libraries such as Telerik Controls), we’re looking into providing this as a product. If you’re interested in getting into contact with us, please write us at coreforms@rubicon.eu
Best regards, Michael
Amazing!
Would you be willing to open source this port? Feels like it could be a great offering for the community!
Hi David,
thanks for the feedback! Daniel already contacted us via e-mail to discuss this further.
Best regards, Michael
This would be an amazing project for open source community.. we will be interested to contribute further…
This is something I have been waiting. Thanks for that effort.
I have a big Asp.Net MVC 4.8 Framework app and want to start doing this migration process
The reverse proxy is working well for me. Did the steps to enable session sharing but I am getting this error when accesing session from the asp.net core app:
On this line:
var Database = System.Web.HttpContext.Current?.Session?[“Database”] as string;
I get nothing
What I did:
Made the configuration on the global.asax
Made the configuration on the program.cs
Ensured that the api key were the same
Ensured that the session variable was registered on both sides with RegisterKey
I tried adding and removing .RequireSystemWebAdapterSession(); on the net core side
Any ideas?
Confirmed, System.Web.HttpContext.Current.Session is always null on the asp.net core project
Can you open an issue on to explore why you’re seeing this?
This is great – thank you for creating this. I think I could use this for a migration I am working on.
How does this need to be deployed/hosted? Do I need to host both the asp.net core app and the .net framework app separately, and update the proxy fallback address somehow to point to the hosted .net framework app? Or can I deploy the .net core project and host it alongside the .net framework dll somehow?
For reference, I am deploying to Azure to an App Service where my current .net framework app is hosted.
In your case, you would want to deploy the new ASP.NET Core app as a separate AppService (but could be on the same plan if you want) and update the proxy fallback address to the current AppService endpoint.
Me and a colleague migrated a big site like this a few months ago, with YARP still in beta, it worked great.
First we migrated the pages that got more traffic.
The new .NET core app is a lot less CPU intensive, so, with the same number of VMs, we are now able to handle more traffic.
It’s a good solution for some cases.
There are many horror stories of a new site introducing so many erros that it is basically a flop.
This avoids that because the old .NET site is still all there, all you need to revert a page to the old temporarily is to remove the route on the new .NET core one. | https://devblogs.microsoft.com/dotnet/incremental-asp-net-to-asp-net-core-migration/?WT.mc_id=DOP-MVP-4025064 | CC-MAIN-2022-33 | refinedweb | 4,960 | 66.13 |
(('/', function() { return View::make('hello'); });('about', function() { return View::make('about'); });
We would need to create a view at app/views/about.php. So create the file and insert the following code in to it:
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> ('contact', 'Pages('hello'); } }:
'mysql' => array( 'driver' => 'mysql', 'host' => 'localhost', 'database' => '<yourdbname>', 'username' => 'root', 'password' => '<yourmysqlpassord>', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', ),
Now we are ready to work with the database in our application. Let's first create the database table Users via the following SQL queries from phpMyAdmin or any MySQL database admin tool;
CREATE TABLE IF NOT EXISTS 'users' ( 'id' int(10) unsigned NOT NULL AUTO_INCREMENT, 'username' varchar(255) COLLATE utf8_unicode_ci NOT NULL, 'password' varchar(255) COLLATE utf8_unicode_ci NOT NULL, 'email' varchar(255) COLLATE utf8_unicode_ci NOT NULL, 'phone' varchar(255) COLLATE utf8_unicode_ci NOT NULL, 'name' varchar(255) COLLATE utf8_unicode_ci NOT NULL, 'created_at' timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', 'updated_at' timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY ('id') ) 'users' ('id', 'username', 'password', 'email', 'phone',
'name', 'created_at', 'updated_at') VALUES (1, 'john', 'johndoe', 'johndoe@gmail.com', '123456', 'John',
'2013-06-07 08:13:28', '2013-06-07 08:13:28'), (2, 'amy', 'amy.deg', 'amy@outlook.com', '1234567', 'amy',
'2013-06-07 08:14:49', '2013('users', 'UserC('/register', 'UserController@showUserRegistration'); Route::post('/register', 'UserC('users.index', compact('users')); }('main') <h1>All Users</h1> <p>{{ link_to_route('users.create', 'Add('users.edit', 'Edit',
array($user->id), array('class' => 'btn btn-info')) }}</td> <td> {{ Form::open(array('method' => 'DELETE', 'route' => array('users.destroy', $user->id))) }} {{ Form::submit('Delete', array('class'
=> 'btn('message')) <div class="flash alert"> <p>{{ Session::get('message') }}</p> </div> @endif @yield('main') </div> </body> </html>
Now in this file we are loading the Twitter bootstrap framework for styling our page, and via yield('main')('main'), which will be used by Laravel to load it into our layout file. This section will be merged into the layout file where we have put the @yield ('main'):
Creating new users
Now as we have listed our users, let's write the code for creating new users. To create a new user, we will need to create the Controller method and bind the view for displaying the new user form. We would need to create the Controller method for saving the user too. Now as we have bound the resourceful Controller, we don't need to create separate routes for each of our request. Laravel will handle that part if we use REST methods.
So first let's edit the controller at /app/controllers/UsersController.php to add a method for displaying the view:
public function create() { return View::make('users.create'); }
This will call a view at /app/views/users/create.blade.php. So let's define our create.blade.php view as follows:
@extends('layouts.users') @section('main') <h1>Create User</h1> {{ Form::open(array('route' => 'users.store')) }} <ul> <li> {{ Form::label('name', 'Name:') }} {{ Form::text('name') }} </li> <li> {{ Form::label('username', 'Username:') }} {{ Form::text('username') }} </li> <li> {{ Form::label('password', 'Password:') }} {{ Form::password('password') }} </li> <li> {{ Form::label('password', 'Confirm Password:') }} {{ Form::password('password_confirmation') }} </li> <li> {{ Form::label('email', 'Email:') }} {{ Form::text('email') }} </li> <li> {{ Form::label('phone', 'Phone:') }} {{ Form::text('phone') }} </li> <li> {{ Form::submit('Submit', array('class' => 'btn')) }} </li> </ul> {{ Form::close() }} @if ($errors->any()) <ul> {{ implode('', $errors->all('<li class="error">:message</li>')) }} </ul> @endif @stop
Let's try to understand our preceding view. Here we are extending the users layout we created in our List Users section. Now in the main section, we are using Laravel's Form helper to generate our form. This helper generates HTML code via its methods such as label, text, and submit.
Refer to the following code:
{{ Form::open(array('route' => 'users.store')) }}
The preceding code will generate the following HTML code:
<form method="POST" action="" accept-
As you can see it's really convenient for us to not worry about linking things correctly. Now let's create our store method to store our form data into our users table:
public function store() { $input = Input::all(); $validation = Validator::make($input, User::$rules); if ($validation->passes()) { User::create($input); return Redirect::route('users.index'); } return Redirect::route('users.create') ->withInput() ->withErrors($validation) ->with('message', 'There were validation errors.'); }
Here we are first validating all the input that came from the user. The Input::all () function fetches all the $_GET and $_POST variables and puts it into a single array. The reason why we are creating the single input array is so we can check that array against validation rules' array. Laravel provides a very simple Validation class that can be used to check validations. We could use it to check whether validations provided in the rules array are followed by the input array by using the following line of code:
$validation = Validator::make ($input, User::$rules);
Rules can be defined in an array with validation attributes separated by the column "|". Here we are using User::$rules where User is our Model and it will have following code:
class User extends Eloquent { protected $guarded = array('id'); protected $fillable = array('name', 'email'); public static $rules = array( 'name' => 'required|min:5', 'email' => 'required|email' ); }
As you can observe we have defined two rules mainly for name and e-mail input fields. If you are wondering about $guarded and $fillable variables, these variables are used to prevent mass assignment. When you pass an array into your Model's create and update methods, Laravel tries to match the right columns and sets values in the database. Now for instance, if a malicious user sends a hidden input named id and changes his ID via the update method of your form, it could be a huge security hole; to prevent this, we should define the $guarded and $fillable arrays. The $guarded array will guard the columns defined in the guarded array, that is, it will prevent anyone from changing values in that column. The $fillable array will only allow elements defined in $fillable to be updated.
Now we can use the $validation instance we created to check for validations.
$result = $validation->passes(); echo $result; // True or false
If you see our code now, we are checking for validation via the passes() method in our Store() method of UserController. Now if validation gets passed, we can use our user Model to store data into our database. All you need to do is call the Create method of the Model class with the $input array. So refer to the following code:
User::create($input);
The preceding code will store our $input array into the database; yes, it's equivalent to your SQL query.
Insert into user(name,password,email,city) values (x,x,..,x);
Here we have to fill either the $fillable or $guarded array in the model, otherwise, Laravel will throw a mass assignment exception. Laravel's Eloquent object automatically matches our input array with the database and creates a query based on our input array. Don't you think this is a simple way to store input into the database? If user data is inserted, we are using Laravel's redirect method to redirect it to our list of users' pages. If validation fails, we are sending all of the input with errors from the validation object into our create users form.
Editing user information
Now as we learned how easy it is to add and list users. Let's jump into editing a user. In our list users view we have the edit link with the following code:
{{ link_to_route('users.edit', 'Edit', array($user->id),
array('class' => 'btn btn-info')) }}
Here, the link_to_route function will generate a link /users/<id>/edit, which will call the resourceful Controller user, and Controller will bind it with the edit method.
So here is the code for editing a user. First of all we are handling the edit request by adding the following code to our UsersController:
public function edit($id) { $user = User::find($id); if (is_null($user)) { return Redirect::route('users.index'); } return View::make('users.edit', compact('user')); }
So when the edit request is fired, it will hit the edit method described in the preceding code snippet. We would need to find whether the user exists in the database. So we use our user model to query the ID using the following line of code:
$user = User::find($id);
Eloquent object's find method will query the database just like a normal SQL.
Select * from users where id = $id
Then we will check whether the object we received is empty or not. If it is empty, we would just redirect the user to our list user's interface. If it is not empty, we would direct the user to the user's edit view with our Eloquent object as a compact array.
So let's create our edit user view at app/views/users/edit.blade.php, as follows:
@extends('users.scaffold') @section('main') <h1>Edit User</h1> {{ Form::model($user, array('method' => 'PATCH', 'route' =>
array('users.update', $user->id))) }} <ul> <li> {{ Form::label('username', 'Username:') }} {{ Form::text('username') }} </li> <li> {{ Form::label('password', 'Password:') }} {{ Form::text('password') }} </li> <li> {{ Form::label('email', 'Email:') }} {{ Form::text('email') }} </li> <li> {{ Form::label('phone', 'Phone:') }} {{ Form::text('phone') }} </li> <li> {{ Form::label('name', 'Name:') }} {{ Form::text('name') }} </li> <li> {{ Form::submit('Update', array('class' => 'btn btn-info')) }} {{ link_to_route('users.show', 'Cancel', $user->
id, array('class' => 'btn')) }} </li> </ul> {{ Form::close() }} @if ($errors->any()) <ul> {{ implode('', $errors->all('<li class="error">:message</li>')) }} </ul> @endif @stop
Here we are extending our users' layout as always and defining the main section. Now in the main section, we are using the Form helper to generate a proper REST request for our controller.
{{ Form::model($user, array('method' => 'PATCH', 'route' =>
array('users.update', $user->id))) }}
Now, you may have not dealt with the method PATCH as we only know of two protocols, GET and POST, as most browsers generally support only these two methods. The REST method for editing is PATCH, and what Laravel does is that it creates a hidden token so it knows which method to call. So the preceding code generates the following code:
<form method="POST" action="" accept- <input name="_method" type="hidden" value="PATCH">
It actually fires a POST method for browsers that are not capable for handling the PATCH method. Now, when a user submits this form, it will send a request to the update method of UsersController via the resourceful Controller we set in routes.php.
Here is the update method of UsersController:
public function update($id) { $input = Input::all(); $validation = Validator::make($input, User::$rules); if ($validation->passes()) { $user = User::find($id); $user->update($input); return Redirect::route('users.show', $id); } return Redirect::route('users.edit', $id) ->withInput() ->withErrors($validation) ->with('message', 'There were validation errors.'); }
Here Laravel will pass the ID of the user we are editing in the update method. We can use this ID to find the user via our user model's Eloquent object's find method. Then we will update the Eloquent object with an input array just like we did in the insert operation.
Deleting user information
To delete a user we can use the destroy method. If you go to our user lists view, you can find the following delete link's generation code:
{{ Form::open(array('method' => 'DELETE', 'route' =>
array('users.destroy', $user->id))) }} {{ Form::submit('Delete', array('class' => 'btn btn-danger')) }} {{ Form::close() }}
The preceding code is handled by Laravel similar to the way in which it handles the PATCH method. Laravel will generate a post request with the hidden method token set as PATCH, which it can recognize when it hits the Laravel request object.
At UsersController this request will hit the destroy() method as follows:
public function destroy($id) { User::find($id)->delete(); return Redirect::route('users.index'); }
Laravel will directly send id to the destroy method, so all we have to do is use our user model and delete the record with its delete method. If you noticed Eloquent allows us to chain methods. Isn't it sweet? So there would be no queries but just one line to delete a user.
That's one of the reasons to use Eloquent objects in your projects. It allows you to quickly interact with the database and you can use objects to match your business logic.
Adding pagination to our list users
One of the painful tasks most developers face often is that of pagination. With Laravel it's no more the case, as Laravel provides a simple approach to set pagination to your pages.
Let's try to implement pagination to our list user's method. To set pagination we can use the paginate method with Laravel's Eloquent object. Here is how we can do that:
public function index() { $users = User::paginate(5); return View::make('users.index', compact('users')); }
The preceding code is the index method of the UsersController class, which we were using previously for getting all the users with User::all(). We just used the paginate method to find five records from the database. Now in our list users view, we can use the following code to display pagination links:
{{ echo $users->links(); }} Here the links() method will generate pagination links for you.
And best part, Laravel will manage the code for pagination.
So all you have to do is use paginate method with
your eloquent object and links method to display generated links.
Summary
So we have set up our simple CRUD application and now we know how easy it is with Laravel to set up CRUD operations. We have seen Eloquent Laravel's database ORM that makes working with a database simple and easy. We have learned how to list users, create new users, edit users, delete users, and how to add pagination to our application.
Resources for article:
Further resources on this subject:
- Laravel tech page
- Creating and Using Composer Packages
- Eloquent relationships
- An Introduction to PHP-Nuke | https://www.packtpub.com/books/content/crud-applications-using-laravel-4 | CC-MAIN-2017-51 | refinedweb | 2,340 | 52.19 |
When we create python functions, sometimes we do not need to define python functions explicitly, and it is more convenient to pass them into anonymous functions directly. This saves us the trouble of trying to name functions, and we can also write less code. Many programming languages provide this feature. The so-called anonymity means that a function is no longer defined in the standard form of def statement.
Python uses the lambda keyword to create anonymous functions. A lambda is just an expression, not a block of code, and the body of the function is much simpler than def. But only limited logic can be encapsulated in lambda expressions. And lambda functions have their own namespace. The form is usually something like this: lambda argument: expression.
For example: lambda x: x + x is equivalent to the following function. Keyword lambda represents anonymous function, x before colon represents function parameter, and x + x represents the executing code.
def sum(x): return x + x
Below is the summary of python anonymous function characteristics.
- An anonymous function can have only one expression, the return statement is not used or written, and the result of the expression is the anonymous function’s return value.
- Anonymous functions don’t have function names, so you don’t have to worry about function name collisions to save semantic space.
- Anonymous function is also a function object. You can assign anonymous function to a variable, and then call the function by using the variable.
>>> sum = lambda x: x + x >>> sum <function <lambda> at 0x3216fef44> >>> sum(6) 12 | https://www.code-learner.com/how-to-define-python-anonymous-function-example/ | CC-MAIN-2021-43 | refinedweb | 260 | 64.81 |
Data Types
Layout API
Bounds
- JavaScript Type:
Object
- TypeScript Type:
tabris.Bounds
The bounds of a rectangle in relation to the top-left corner of a containing element in DIP (device independent pixel). This is a plain object implementing the following interface:
interface Bounds { left: number; top: number; width: number; height: number; }
Explanation:
Example:
const buttonRight = button.bounds.left + button.bounds.width;
BoxDimensions
- JavaScript Type:
Objector
stringor
Array.
- TypeScript Type:
tabris.BoxDimensions
The bounds of a rectangle in relation to the four edges of a containing element in DIP (device independent pixel). By default it is a plain object implementing the following interface:
interface BoxDimensions { left?: number; right?: number; top?: number; bottom?: number; }
All properties are
dimension and optional. Omitted properties are treated as
0.
As a shorthand a list of four dimensions is also accepted. This follow the order of
[top, right, bottom, left], with missing entries being filled in by the entry of the opposing dimension. If only one entry is given it is used for all dimensions:
[1, 2, 3, 4] // {top: 1, right: 2, bottom: 3, left: 4}; [1, 2, 3] // {top: 1, right: 2, bottom: 3, left: 2}; [1, 2] // {top: 1, right: 2, bottom: 1, left: 2}; [1] // {top: 1, right: 1, bottom: 1, left: 1};
A space separated string list is also accepted instead of an array, with or without
px as a unit.
Examples:
widget.padding = {left: 8, right: 8, top: 0, bottom: 0}; widget.padding = {left: 10, right: 10}; widget.padding = [0, 8]; widget.padding = [1, 10, 2, 10]; widget.padding = '10px 11px 12px 13px'; widget.padding = '10 11 12 13'; widget.padding = '0 8';
ConstraintValue
- JavaScript Type:
tabris.Constraint,
tabris.Widget,
tabris.Percent,
Symbol,
Array,
Object,
string,
numberor
true.
- TypeScript Type:
tabris.ConstraintValue
A
ConstraintValue represents a constraint on the layout of a widget that the parent uses to determine the position of one of its edges. This type allows various expressions that can all be used in place of a
Constraint instance for convenience. All API that accept these expressions will convert them to a
Constraint object. (With the exception of
CanvasContext.)
Every expression of
ConstraintValue consists of a
reference value and/or an
offset value. The following are all valid
ConstraintValue types:
Offset-only constraints
Simply the
Offset number by itself, a positive float including zero. A value of
true is also accepted and treated like zero.
Examples:
widget.left = 12.5; widget.right = 8; widget.top = 0; widget.bottom = true;
Reference-only constraints
Either a
PercentValue or a
SiblingReferenceValue.
Examples:
widget.left = '12%'; widget.right = 'prev()'; widget.top = new Percent(50); widget.bottom = '#foo';
Constraint instance
An instance of the
Constraint class naturally is also a valid
ConstraintValue. It may be created via its constructor or the less strict
Constraint.from factory.
ConstraintLikeObject
An object implementing the following interface:
interface ConstraintLikeObject { reference?: SiblingReferenceValue | PercentValue; offset?: Offset; }
An instances of
Constraint is a valid
ConstraintLikeObject, but
ConstraintLikeObject is less strict: The
reference property can be a
PercentValue or a
SiblingReferenceValue, or can be omitted if
offset is given. Either of the two entries may be omitted, but not both.
Examples:
widget.left = {reference: sibling, offset: 12}; widget.right = {reference: '23%', offset: 12}; widget.top = {reference: Constraint.prev}; widget.bottom = {offset: 12};
ConstraintArrayValue
An array tuple in the format of
[reference, offset], where
reference is either a
PercentValue or a
SiblingReferenceValue, and offset is an
Offset, i.e. a
number.
Examples:
widget.left = [sibling, 0]; widget.right = ['#foo', 0]; widget.top = [{percent: 23}, 12]; widget.bottom = [Constraint.prev, 12];
Constraint String
This is often the most compact way to express a constraint, but it may not be the preferred way in TypeScript projects if type safety is a priority. The string consists of a space separated list of two values in the pattern of
'reference offset'. The reference part may be of any string as accepted by
SiblingReferenceValue or
PercentValue. The offset has to be a positive (including zero) float, just like
Offset.
Examples:
widget.left = '.bar 0'; widget.right = '#foo 0' widget.top = '23% 12'; widget.bottom = 'prev() 12';
Dimension
- JavaScript Type:
number
- TypeScript Type:
tabris.Dimension, an alias for
number
A positive float, or 0, representing device independent pixels (DIP).
LayoutDataValue
- JavaScript Type:
tabris.LayoutData,
Object
- TypeScript Type:
tabris.LayoutDataValue
A
LayoutDataValue provides layout information for a widget to be used its parent when determining its size and position. It allows various expressions that can all be used in place of a
LayoutData instance for convenience. All API that accepts these expressions will convert them to a
LayoutData object.
The following are all valid
LayoutDataValue types:
LayoutData instance
An instance of the
LayoutData class naturally is also a valid
LayoutDataValue. It may be created via its constructor or the less strict
LayoutData.from factory.
LayoutDataLikeObject
An object containing implementing the following interface:
interface LayoutDataLikeObject { left?: 'auto' | ConstraintValue; right?: 'auto' | ConstraintValue; top?: 'auto' | ConstraintValue; bottom?: 'auto' | ConstraintValue; centerX?: 'auto' | Offset | true; centerY?: 'auto' | Offset | true; baseline?: 'auto' | SiblingReferenceValue | true; width?: 'auto' | Dimension; height?: 'auto' | Dimension; }
An instance of
LayoutData is a valid
LayoutDataLikeObject, but in
LayoutDataLikeObject all properties are optional and less strict. For example
left,
top,
right and
bottom accept
ConstraintValue (e.g. a
number) in place of a
Constraint instance.
A value of
true is also accepted for all fields except
width and
height. For
left,
right,
top,
bottom,
centerX and
centerY it means
0. For
baseline it means
'prev()'.
Example:
widget.layoutData = { baseline: 'prev()', left: 10, width: 100 }; widget.layoutData = { top: '25%', centerX: true };
LayoutData string
There are 4 alias strings that can be used in place of a LayoutData object:
widget.layoutData = 'stretch';
Offset
- JavaScript Type:
number
- TypeScript Type:
tabris.Offset, an alias for
number
A positive or negative float, or 0, representing device independent pixels (DIP).
PercentValue
- JavaScript Type:
tabris.Percent,
Object,
string
- TypeScript Type:
tabris.PercentValue
Represents a percentage. This type includes various expressions that can all be used in place of a
Percent instance for convenience. All APIs that accept these expressions will convert them to a
Percent object.
In TypeScript you can import this type as a union with
import {PercentValue} from 'tabris'; or use
tabris.PercentValue. A Type guard for
PercentValue is available as
Percent.isValidPercentValue.
Percent instance
An instance of the
Percent class naturally is also a valid
PercentValue. It may be created via its constructor or the more versatile
Percent.from factory.
PercentLikeObject
A plain object in the format of
{percent: number}, where
100 presents 100%. An instance of
Percent is a valid
PercentLikeObject.
Examples:
widget.left = {percent: 50};
Percent String
A number followed by
%.
Example:
'50%'
SiblingReference
- JavaScript Type:
tabris.Widget,
Symbol,
string
- TypeScript Type:
tabris.SiblingReference
A
SiblingReference indicates a single sibling of a given Widget. Differs from the type
SiblingReferenceValue in that it does not include
'next() and
'prev()' as selectors strings. It uses symbols instead. There are three variants of
SiblingReference:
Sibling instance
Any widget instance that has the same parent.
Sibling Selector String
A simple selector string of the format
'#Type',
'#id',
'.class'. No child selectors. The first matching sibling is selected.
Sibling Reference Symbol
The constants
Constraint.prev and
Constraint.next (also available as
LayoutData.prev and
LayoutData.next) may be used to point to the sibling directly before/after the reference widget in the parents children list.
SiblingReferenceValue
- JavaScript Type:
tabris.Widget,
Symbol,
string
- TypeScript Type:
tabris.SiblingReferenceValue
Same as
SiblingReference, but less strict in that it also allows the strings
'next() and
'prev()' in place of the
prev and
next symbols.
Styling Related Types
Types related to the visual presentation of a widget.
ColorValue
- JavaScript Type:
tabris.Color,
Object,
Array,
string
- TypeScript Type:
tabris.ColorValue
A
ColorValue represents a 24 bit color, plus an alpha channel for opacity. This type allows various expressions that can all be used in place of a
Color instance for convenience. All API that accept these expressions will convert them to a
Color object. (With the exception of
CanvasContext.) Setting a ColorValue property to null resets it to the default.
In TypeScript you can import this type as a union with
import {ColorValue} from 'tabris'; or use
tabris.ColorValue. Type guards for
ColorValue are available as
Color.isColorValue and
Color.isValidColorValue.
The following are all valid
ColorValue types:
Color instance
An instance of the
Color class may be created via its constructor or the less strict
Color.from factory.
Examples:
new Color(255, 0, 0) new Color(255, 0, 0, 200) Color.from("rgba(255, 0, 0, 0.8)")
ColorLikeObject
An object implementing the following interface:
interface ColorLikeObject { red: number; green: number; blue: number; alpha?: number; }
An instance of
Color is a valid
ColorLikeObject.
Examples:
{red: 255, green: 255, blue: 255} {red: 255, green: 255, blue: 255, alpha: 200}
ColorArray
An array in the shape of
[red, green, blue, alpha]. All entries should be natural number between (and including) 0 and 255. If omitted, alpha is 255.
Examples:
[255, 0, 0] [255, 0, 0, 200]
Color string
Any string in the following format:
Color names from the CSS3 specification are also accepted. They are available as static string properties of
Color, e.g.
Color.lime. These exist just to help with autocompletion.
Examples:
"#f00" "#ff0000" "#ff000080" // 50% opacity red "#ff06" // 40% opacity yellow "rgb(255, 0, 0)" "rgba(255, 0, 0, 0.8)" "red" "initial" // same as null
FontValue
A
FontValue describes a font by size, family, weight and style. This type allows various expressions that can all be used in place of a
Font instance for convenience. All API that accept these expressions will convert them to a
Font object. (With the exception of
CanvasContext.) Setting a FontValue property to null resets it to the default.
Generic font size is always given as DIP (device independent pixels), though the string shorthand expects
"px" as a unit. It’s still DIPs.
Generic font families are supported across all platforms:
"serif",
"sans-serif",
"condensed" and
"monospace". These are available as static string properties of
Font, e.g.
Font.serif. These exist just to help with autocompletion. More families can be added via
app.registerFont. If no family is given for a font the system default is used. If no font family is given the default system font will be used. The string
"initial" represents the platform default.
Supported font weights are
"light",
"thin",
"normal",
"medium",
"bold" and
"black". The default is
"normal"
Supported font styles are
"italic" and
"normal". The default is
"normal"
In TypeScript you can import this type as a union with
import {FontValue} from 'tabris'; or use
tabris.FontValue. Type guards for
FontValue are available as
Font.isFontValue and
Font.isValidFontValue.
The following are all valid
FontValue types:
Font instance
An instance of the
Font class may be created via its constructor or the less strict
Font.from factory.
Examples:
new Font({size: 16, family: Font.sansSerif}) Font.from("16px san-serif");
FontLikeObject
An object implementing the following interface:
interface FontLikeObject { size: number; family?: string[]; weight?: FontWeight; style?: FontStyle; }
An instance of
Font is a valid
FontLikeObject.
Examples:
{size: 16, weight: 'bold'} {size: 24, family: 'sans-serif', style: 'italic'}
Font string
As a string, a subset of the shorthand syntax known from CSS is used:
"font-style font-weight font-size font-family", where every value except size is optional. The size also need to have a
"px" postfix. Multiple families may be given separated by commas. Families with spaces in their name need to be put in single or double quotes.
Examples:
"bold 24px" "12px sans-serif" "italic thin 12px sans-serif" "24px 'My Font', sans-serif" "initial"
ImageValue
A
ImageValue describes an image file path and that image’s dimension or scale. This type allows various expressions that can all be used in place of a
Image instance for convenience. All API that accept these expressions will convert them to a
Image object.
The source (shortened to
src) is a File system path, relative path or URL. The data URI scheme is also supported. Relative paths are resolved relative to the projects ‘package.json’. On Android the name of a bundled drawable resource can be provided with the url scheme
android-drawable, e.g.
android-drawable://ic_info_black.
The width and height of an image are specified in DIP (device independent pixel). If none are given (e.g. value is
"auto") the dimensions from the image file are used in combination with the given scale.
The scale is a positive float or
'auto'. The image will be scaled down by this factor. Ignored if width or height are given. If neither scale, width or height are given the scale may be extracted from image file name if it follows.
The following are all valid
ImageValue types:
Image instance
An instance of the
Image class may be created via its constructor or the less strict
Image.from factory.
Examples:
new Image({src: "", scale: 2}) new Image({src: "", width: 100, height: 200}) Image.from("images/catseye@2x.jpg");
ImageLikeObject
An object implementing the following interface:
interface ImageLikeObject { src: string; scale?: number | "auto"; width?: number | "auto"; height?: number | "auto"; }
An instance of
Image class is a valid
ImageLikeObject.
Examples:
{src: "images/catseye.jpg", width: 300, height: 200} {src: "", scale: 2}
LinearGradientValue
A
LinearGradientValue specifies a set of colors, their relative position along a straight line, and the angle of that line. This describes a color gradient that can be drawn to fill any area, usually the background of a widget. This type allows various expressions that can all be used in place of a
LinearGradient instance for convenience. All API that accept these expressions will convert them to a
LinearGradient object.
In TypeScript you can import this type as a union with
import {LinearGradientValue} from 'tabris'; or use
tabris.LinearGradientValue. Type guards for
LinearGradientValue are available as
LinearGradient.isLinearGradientValue and
LinearGradient.isValidLinearGradientValue.
The following are all valid
LinearGradientValue types:
LinearGradient instance
An instance of the
LinearGradient class may be created via its constructor or the less strict
LinearGradient.from factory.
Examples:
new LinearGradient([Color.red, Color.green]); new LinearGradient([[Color.red, new Percent(5)], Color.green], 90); LinearGradient.from({colorStops: [['red', '5%'], 'green'], direction: 'left'}); LinearGradient.from('linear-gradient(45deg, red 5%, green)');
LinearGradientLikeObject
An object implementing the following interface:
interface LinearGradientLikeObject { colorStops: Array<ColorValue | [ColorValue, PercentValue]>, direction?: number | 'left' | 'top' | 'right' | 'bottom' }
An instances of
LinearGradient is a valid
LinearGradientLikeObject, but
LinearGradientLikeObject is less strict as it accepts more expressions for
colorStops and
direction.
Examples:
{colorStops: [['red', '5%'], 'green'], direction: 'left'} {colorStops: [['red', '5%'], 'green'], direction: 45}
LinearGradient string
As a string, a subset of the CSS syntax is used:
<color-stop> ::= <color> [ <number>% ] <linear-gradient> ::= linear-gradient( [ <number>deg | to ( left | top | right | bottom ), ] <color-stop> {, <color-stop>} )
Examples:
"linear-gradient(red, green)" "linear-gradient(to left, red 5%, green)" "linear-gradient(45deg, red 5%, green)"
Binary Types
ImageData
Represents the underlying pixel data of an area of a
Canvas widget. It is created using the creator methods on the CanvasContext:
createImageData() and
getImageData(). It can also be used to set a part of the canvas by using
putImageData().
An ImageData object implements the following interface:
interface ImageData { data: Uint8ClampedArray; width: number; height: number; }
Explanation:
Selector API
Selector
See this article.
Animation API
AnimationOptions
Options of the
animate() method. They have to implement the following interface:
interface AnimationOptions { delay?: number; duration?: number; easing?: "linear" | "ease-in" | "ease-out" | "ease-in-out"; repeat?: number; reverse?: boolean; name?: string; }
Each property has a default value if omitted:
Transformation
A Transformation is any object implementing the following interface:
interface Transformation { rotation?: number; scaleX?: number; scaleY?: number; translationX?: number; translationY?: number; translationZ?: number; }
Each property has a default value if omitted:
Example:
{scaleX: 2, scaleY: 2, rotation: Math.PI * 0.75}
This transformation will make the widget twice as big and rotate it by 135°.
Event Handling
PropertyChangedEvent
An event object fired when an object property changes. It is an instance of
EventObject that provides an additional property
value containing the new value. | http://docs.tabris.com/latest/types.html | CC-MAIN-2019-26 | refinedweb | 2,657 | 50.94 |
Customizable, lightweight React Native carousel component with accessibility support.
Pinar is a lightweight and customizable React Native carousel component that works well when creating simple image sliders or app onboarding flows.
If you need more advanced things like animations, lazy loading of images, or parallax, then please consider using a library like react-native-snap-carousel.
<ScrollView />
yarn add pinar --save ## or ## npm install pinar --save
import React from "react"; import { Text, View } from "react-native"; import Carousel from "pinar"; const styles = { slide1: { flex: 1, justifyContent: "center", alignItems: "center", backgroundColor: "#a3c9a8" }, slide2: { flex: 1, justifyContent: "center", alignItems: "center", backgroundColor: "#84b59f" }, slide3: { flex: 1, justifyContent: "center", alignItems: "center", backgroundColor: "#69a297" }, text: { color: "#1f2d3d", opacity: 0.7, fontSize: 48, fontWeight: "bold" } }; export default () => ( <Carousel> <View style={styles.slide1}> <Text style={styles.text}>1</Text> </View> <View style={styles.slide2}> <Text style={styles.text}>2</Text> </View> <View style={styles.slide3}> <Text style={styles.text}>3</Text> </View> </Carousel> );
Result:
The
/examples folder has a React Native app that you can run on your machine to see the carousel being used with a lot of different options.
If you don't want to run the app, you can have a look at the components folder for example components.
Use these properties to be notified when the user scrolls the carousel or changes the page.
To use methods you need to get a reference to the carousel inside your React class component.
<Carousel ref={carousel => { this.carousel = carousel; }} />
You can then call the method from outside the carousel:
<Button title="scroll to next page" onPress={() => { this.carousel.scrollToNext(); }} />
Use these properties to customize how the carousel is styled.
Set the
mergeStyles property to
true if you want to merge your custom styles with the default ones instead of having define all the needed styles. You can also
import { defaulStyles } from "pinar" to get access to the default styles and use them as defaults.
Have a look at the "custom styles" component and "custom styles with merge" component for an example.
Use these properties to provide your own functions render custom elements instead of the default ones. Have a look at the custom rendering component for an example.
<ScrollView />
These properties are exposed from
<ScrollView />. You can provide your own properties if you want to customize it.
for more info:
No other dependencies than React Native.
If you want help out with the development of this library, bug reports and fixes are very welcome. If you are thinking about a new feature, please open a feature request issue first to verify that implementing it makes sense.
First make sure that you have Node.js, Yarn and React Native installed. It is also a good idea to have Xcode and/or Android Studio installed to be able to run the iOS simulators / Android emulators.
If you choose to install emulators or simulators, you can use the example app to test your changes in a React Native app.
When making changes to the code, please add a unit test or a functional test to verify that the code is working. The test runner that the project uses is Jest, Enzyme is used to test React Components, and Detox is used to run functional tests against the project's example app. The command to run unit tests is
yarn test and the command to run functional tests is
yarn functional.
Before you submit the code for a Pull Request, make sure that you run
yarn test,
yarn tsc, and
yarn lint to verify that unit tests pass and both the Typescript type checking and ESLint linting are not printing any errors.
Special thanks for these libraries for providing inspiration for code and other things: | https://awesomeopensource.com/project/kristerkari/pinar | CC-MAIN-2022-05 | refinedweb | 616 | 63.49 |
What You Really Need Is a Smart Client
Introduction
Yesterday, while working on some Web clients, I caught myself thinking if it were only a Windows Form application... The natural follow-up to that is whatever you happen to be doing would be easier to do in a Windows Forms application. However, because it was a Web application, I knew I had reached a small crossroad. The natural next step might be to use a Windows Forms control in a Web page. We called this embedding ActiveX controls pre-.NET, and it is something that technically can be done in ASP.NET.
In this article, you will learn the basics of embedding a Windows Forms control in ASP.NET, and then you will learn why you don't want to do it. By the time you have finished reading, I hope you will understand that the problem is really Microsoft's to solve. Microsoft has an obligation and it makes good sense to merge the two technologies—ASP.NET and Windows forms—and completely hide whether one is programming for a network or not. From a user's perspective, it shouldn't matter anyway.
Adding a Windows Forms Control to an ASP.NET Page
Suppose you have a Windows Forms control that is difficult or too expensive to reproduce for Web Forms. You can use the actual Windows Forms control in a Web Form (ASP.NET) application by adding the Windows Forms control to a Windows Control Library, copying the Windows Control Library to the Web Application's root folder, and we call the UserControl namespace and class, but, we provide an ID for the control and its size. We need to provide a class ID, which can be a URN or GUID. We used a URN (or URL) that includes the HTTP moniker and the relative path of the DLL followed by a pound sign (#) and the namespace and class of the control. VIEWASTEXT is used by the designer to figure out how to show the text. Next, we.
Limitations
There are real limitations to using Windows Forms controls in a Web application. The first is that the <OBJECT> tag does not support the runat="server" attribute. This means no code-behind, which is a compelling reason to use ASP.NET in the first place. Consequently, we must manufacture dynamic interaction with our embedded UserControl using script. In practice, this means that you can set the date in the control but will find it very difficult to know a client has changed the date or get
When you find yourself desiring the flexibility of Windows Forms and the ease of deployment of a Web application, what you really want are smart clients. For all intents and purposes, a smart client is a Windows Form application that dynamically updates client assemblies using the Assembly class to download assemblies over HTTP. The result is a Windows Form application (that can talk to your server through Web Services, for example), and it can be deployed and updated over HTTP just like a Web application.
The ingredients you will likely need for a smart client application are XML Web Services to transport data to and from clients to server, an HTTP updater that automatically looks for assembly updates on your server and downloads them to clients, and at least a Windows Forms application kernel that downloads the assemblies initially and requests updates at some prescribed interval. Finally, clients will need to modify their security policy to support running downloaded assemblies, but the results are fantastic. Your customers will get a Windows Form application with all of the expressivity they will have come to expect but ease of deployment just like the Web provides.
Summary
Some things can be done but really represent a bastardization or severe programmatic distortions to do.
ProgrammerPosted by Russ on 06/22/2004 06:22pm
Interesting, but left me hanging. It seemed like you were just getting to the meat when suddenly there is the summary. In the beginning you implied that you really could not do smart clients yet, but in the summary you say it is not hard - but you don't tell us how. HOW? The whole concept sounds wonderful. As one who is struggling trying to learn HTML, .NET, ASP, C#, and scripting all at once, I long for the days of MFC and C++! RussReply | http://www.codeguru.com/columns/vb/article.php/c7463/What-You-Really-Need-Is-a-Smart-Client.htm | CC-MAIN-2014-10 | refinedweb | 731 | 60.45 |
0
OK Can anyone help me understand what a tokenizer does? And why I have to put *tokenPtr? What is the * for?
I am having a heck of a time figuring out how to write a program that takes the last two letters of a word in a sentence puts them on the front of a new word and adds 'ay' to the end of the word then moves to the next word in the sentence and starts over. It is an online class so I can't ask the teacher for help in class and the assignment is due tomorrow. I have some sample code from the book but it isn't helping me. The following is my start.
#include <iostream> using std::cin; using std::cout; using std::endl; #include <cstring> using std::strtok; using std::strlen; const int SIZE = 80; // function prototype void printLatinWord( const char *token ); int main() { char sentence[ SIZE ]; char *tokenPtr; cout << "Enter a sentence:\n"; cin >> sentence; *tokenPtr = strtok( sentence, " " ); while ( *tokenPtr != NULL ) { printLatinWord( *tokenPtr ) *tokenPtr = strtok( NULL, " " );//get next token } return 0; } void printLatinWord ( const char *token ) { cout << strlen( token ); }
Thanks for any help!:?: | https://www.daniweb.com/programming/software-development/threads/62029/another-piglatin-question-c | CC-MAIN-2018-43 | refinedweb | 192 | 67.69 |
Hello,
I have built the MPI binaries many times without issue... until now. I have two machines with the same Ubuntu build, openmpi, and site.settings file on them. The build goes fine on one, but fails on the other (I did the openmpi installation tests and they succeed).
In the build output I see: "'MPI' has not been declared". Below is more of the output... thank you very much in advance for your time!
src/protocols/mpi_refinement/MPI_Refine_Master.cc: In member function 'virtual void protocols::mpi_refinement::MPI_Refine_Master::init()':
src/protocols/mpi_refinement/MPI_Refine_Master.cc:204:15: error: 'MPI' has not been declared
int ncores = MPI::COMM_WORLD.Get_size();
^
.....
scons: *** [build/src/release/linux/4.4/64/x86/gcc/5.4/mpi/protocols/mpi_refinement/MPI_Refine_Master.os] Error 1
scons: building terminated because of errors."
What does "which mpicc" return? What do the scons lines look like (the ones that probably start with mpicc)? The individual scons lines should show paths to libraries - are the mpi libraries showing up like they should? (You can determine "should" by comparison to the machine that works).
I assume the problem is that whatever the system is finding as MPI libraries aren't right, if they don't define MPI. (I assume if it wasn't finding the libraries at all, it would complain that the library files weren't found).
It compiles fine without MPI, right?
Thank you!
"which mpicc" returns: "/home/starone/openmpi/bin/mpicc"
Here is an individual line:
"
Yes, it builds fine without MPI.
Update, fixed:
I started looking through threads and found the following are needed... the machine I had the error on was a clean install of the OS so they were missing:
sudo apt-get install libopenmpi-dev
I also needed:
sudo apt-get install zlib1g-dev
Are these things always necessary?
You will always need to install MPI to compile in MPI. libopenmpi-dev is the stuff that gets #included, which is why you got those MPI not defiend errors. I am updating the build documentation to clarify you do need the -dev package here.
You will always need zlib support for Rosetta. zlib1g-dev is the usual ubuntu package that's necessary (and it's not usually present on ubuntu; it varies by system). That's the only thing we consider an external dependency other than "a compiler". (The feature this buys you is that Rosetta can basically always interpret gzipped inputs natively, and can optionally output many things as .gz as well). Usually a missing zlib is exposed by "cannot find -lz", explained in the build documentation ()
Great! Thanks for the info and the update to the docs.
I actually thought I was in good shape because I saw no errors, but I also don't see any .mpi executables... : ( I'll have to look into that tonight and tomorrow.
Actually the standard binaries built (not sure what I messed up)... the MPI versions did not. The error is the same "MPI has not been declared".
I thought maybe something went wrong with the libdev install so I ran it again but it appears to be fine unless I'm misinterpreting the following... so where else am I missing something?
"sudo apt-get install libopenmpi-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
libopenmpi-dev is already the newest version (1.10.2-8ubuntu1).
The following packages were automatically installed and are no longer required:
libpango1.0-0 libpangox-1.0-0 linux-headers-4.4.0-21 linux-headers-4.4.0-21-generic linux-headers-4.4.0-24 linux-headers-4.4.0-24-generic
linux-image-4.4.0-21-generic linux-image-4.4.0-24-generic linux-image-extra-4.4.0-21-generic linux-image-extra-4.4.0-24-generic
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 29 not upgraded."
Thanks!
On my VM here on my laptop, it builds fine… I noticed this difference between the build statements, but I don’t know why the path is missing from the build statement on my workstation... ($LD_LIBRARY_PATH and $PATH are set the same way on both machines)
Laptop:
“mpiCC -o build/src/release/linux/4.4/64/x86/gcc/5.4/mpi/AnchoredDesign/interface_design/anchored_design/AnchoredDesign.o -Lexternal/lib -Lbuild/src/release/linux/4.4/64/x86/gcc/5.4/mpi -Lsrc -Lbuild/external/release/linux/4.4/64/x86/gcc/5.4/mpi -Lexternal -L/home/starone/openmpi/lib -L/home/starone/Public/PyRosetta.Namespace -L/home/starone/Public/PyRosetta.Namespace/rosetta ….”
Workstation: (-L/home/starone/openmpi/lib is missing)
”
The first thing to try when there are apparent pathing issues is to `ln -s site.settings.killdevil site.settings`. This adds some of your enviroment variables into SCons in a different way. (Those files are in source/tools/build).
I tried the step you suggested (thank you!), but nothing changed. One thing that is striking is the difference in the parameters... on my laptop I see "-L" parameters indicated which include all the elements of the LD LIBRARY PATH... they aren't present on the workstation complie option list.
Why would this be?
I'm surprised that the site.settings change did nothing - usually it forces a full recompile. (I guess if it wasn't compiling before that's not noticeable).
Does the workstation have something unusual set up w/r/t the shell you are calling scons from versus the default shell for your user account? Perhaps the environment variables don't exist in the scons environment if they aren't being set in your .zshrc or whatever? (I'm guessing here.)
I'm not a Linux person so I just accept whatever is installed when I installed the OS on the machines, the only changes I made were in the .bashrc files regarding the paths. They are both Intel machines.
This is what I added to that file: (sorry for the strange characters... hopefully you can figure it out. I must be inadvertantly hitting on some escape characters or something)
source /home/starone/Public/PyRosetta.Namespace/SetPyRosettaEnvironment.sh
export PATH=/opt/ncbi-blast-2.3.0+/bin:$PATH
export BLASTDB=/opt/ncbi-blast-2.3.0+/db
export PATH=/opt/blast-2.2.26/bin:$PATH
export PATH=$HOME/openmpi/bin:$PATH
export LD_LIBRARY_PATH=$HOME/openmpi/lib:$LD_LIBRARY_PATH
These are the contents of the site.settings file I have been using on both machines:
import os
settings = {
"site" : {
"prepends" : {
"program_path" : os.environ["PATH"].split(":"),
"library_path" : os.environ["LD_LIBRARY_PATH"].split(":"),
},
"appends" : {
},
"overrides" : {
},
"removes" : {
},
},
}
The SetPyRosettaEnvironment.sh shouldn't do anything with respect to an MPI compile - that just sets things up for PyRosetta, and the compilation of commandline Rosetta is completely separate from it.
Just to confirm, the error message you're getting is still the same as the one at the top of this thread, right? The "error: 'MPI' has not been declared" in MPI_Refine_Master.cc (or similar), right?
If that's the case, that's a header issue, and not a library issue -- the -L settings and the LD_LIBRARY_PATH shouldn't affect that. I'd focus more on the "-I" settings for the include path. (One complication here is that you showed a linker commandline for the laptop compile, but a compile commandline for the workstation - that's why you see the -L's in one but not in the other.)
My initial guess would be that the path to the MPI includes is missing. That'd be a little odd, though, as you would expect that you'd get a different error in that case. But it might be an issue of *where* the MPI libraries you're using are located.
If you're using the Ubuntu system libopenmpi, then it looks like the headers should be (for Xenial) in /usr/lib/openmpi/include/ It doesn't look like you have that enabled. I'm not sure where it's pulling the mpi.hh from, though: probably not from where you expect it. Try adding
To the "prepends" section of your site.settings file and recompiling.
I'm not sure why it's working on your laptop, though, if you're using the same packages. Perhaps because you did a manual install of the library in /home/starone/openmpi/ and it's pulling from that. (If you do want to use the manually installed version rather than the system version, you'll need to change the paths.)
yes, same error
Ok... I think I see what you are getting at. I will try it in the morning.
(sorry if there is and I just don't know about it): I haven't been an engineer for many years, but when I have to build something in Linux I always wonder why there isn't something slick like MS's Visual Studio. I did Microsoft development for a long time before moving into management and the ability to visualize things from within a development studio is so much more helpful to me than using command line interactions... feel like I'm back in the MS-DOS era : )
Thanks again for your help!
Progress! Well, the compilation looks like its succeeding now, but the linking is failing... pretty much as expected I suppose. I think you're right that I used different methods for installing openmpi (I installed on the laptop a while ago), but it wasn't by choice. There is a good deal of conflicting info on the web on this stuff as I'm sure you know. On the workstation I downloaded the package from the OpenMPI website and followed the steps in the YouTube video linked there.
I noticed that there are about 80 items in openmpi/lib directory on my laptop, but only about 20 on the workstation.
I documented the steps I followed... appearently they are incorrect, can you tell me the proper method.
Go to:
Download the latest stable build tar.gz
Make directory Public/openmpi
Copy the compressed file to the directory
Open a terminal window
Change to the openmpi directory
Execute: ./configure --prefix=$HOME/openmpi
Execute: make all
Execute: make install
Change to your home directory
Execute: sudo gedit .bashrc
Add the following lines to the end of the file:
export PATH=$HOME/openmpi/bin:$PATH
export LD_LIBRARY_PATH=$HOME/openmpi/lib:$LD_LIBRARY_PATH
Save and close the editor
Execute: mpirun -np n hostname (where 'n' is the number of processors in your machine)
These are the errors I'm getting now:
mpiCC -o build/src/release/linux/4.4/64/x86/gcc/5.4/mpi/per_residue_energies/analysis/per_residue_energies.o -Lexternal/lib -Lbuild/src/release/linux/4.4/64/x86/gcc/5.4/mpi -Lsrc -Lbuild/external/release/linux/4.4/64/x86/gcc/5.4/mpi -Lexternal -L/home/starone/Public/PyRosetta.Namespace -L/home/starone/Public/PyRosetta.Namespace/rosetta -L/home/starone/openmpi/lib -lxml2
build/src/release/linux/4.4/64/x86/gcc/5.4/mpi/libprotocols.3.so: undefined reference to `ompi_mpi_cxx_op_intercept'
build/src/release/linux/4.4/64/x86/gcc/5.4/mpi/libprotocols.3.so: undefined reference to `MPI::Win::Free()'
build/src/release/linux/4.4/64/x86/gcc/5.4/mpi/libprotocols.3.3.so: undefined reference to `MPI::Comm::Comm()'
collect2: error: ld returned 1 exit status
scons: *** [build/src/release/linux/4.4/64/x86/gcc/5.4/mpi/helix_from_sequence.mpi.linuxgccrelease] Error 1
build/src/release/linux/4.4/64/x86/gcc/5.4/mpi/apps/public/design/pmut_scan_parallel.o: In function `MPI::Op::Init(void (*)(void const*, void*, int, MPI::Datatype const&), bool)':
pmut_scan_parallel.cc:(.text._ZN3MPI2Op4InitEPFvPKvPviRKNS_8DatatypeEEb[_ZN3MPI2Op4InitEPFvPKvPviRKNS_8DatatypeEEb]+0x17): undefined reference to `ompi_mpi_cxx_op_intercept'
build/src/release/linux/4.4/64/x86/gcc/5.4/mpi/apps/public/design/pmut_scan_parallel.o: In function `MPI::Intracomm::Clone() const':
pmut_scan_parallel.cc:(.text._ZNK3MPI9Intracomm5CloneEv[_ZNK3MPI9Intracomm5CloneEv]+0x3a): undefined reference to `MPI::Comm::Comm()'
build/src/release/linux/4.4/64/x86/gcc/5.4/mpi/apps/public/design/pmut_scan_parallel.o: In function `MPI::Graphcomm::Clone() const':
pmut_scan_parallel.cc:(.text._ZNK3MPI9Graphcomm5CloneEv[_ZNK3MPI9Graphcomm5CloneEv]+0x35): undefined reference to `MPI::Comm::Comm()'
build/src/release/linux/4.4/64/x86/gcc/5.4/mpi/apps/public/design/pmut_scan_parallel.o: In function `MPI::Cartcomm::Sub(bool const*) const':
pmut_scan_parallel.cc:(.text._ZNK3MPI8Cartcomm3SubEPKb[_ZNK3MPI8Cartcomm3SubEPKb]+0x194): undefined reference to `MPI::Comm::Comm()'
Wait, why are we talking about manually installed openmpi? I thought you installed it via apt? "sudo apt-get install openmpi openmpi-dev" or something similar?
Not on the workstation... I followed those steps because when I tried sudo apt-get install openmpi I think I remember it saying it wasn't found. I found a page today that indicates that I have to use 'sudo apt-get install openmpi-bin'... is that right?
I can't tell you what's right; I haven't installed MPI on linux in years. What you just said is similar to what I suggested so it's worth trying. You'll want the -dev package too, remember. You should be able to do something like "apt list | grep mpi" on the machine that works to see which mpi packages you installed, and just do the same on the other machine...?
Thanks! I'll give it a try
I'd definitely recommend using the system versions (the one from apt-get) if you can. MPI is a little bit finicky at times, and it's a lot easier if you leave setting things up properly to people who know the operating system well, rather than trying to get things set up appropriately yourself. In fact, if you continue to have issues, I'd recommend removing/uninstalling the manually installed version, to make sure that having two versions of the MPI libraries aren't confusing things. (You can get issues if Rosetta is picking up the headers of one and the libraries from the other.)
I tried using sudo apt-get... it just reports that the packages are already installed.
These errors are different than I was getting before... now I'm seeing alot of this:
scons: *** [build/src/release/linux/4.4/64/x86/gcc/5.4/mpi/beta_peptide_modeling.mpi.linuxgccrelease] Error 1
build/src/release/linux/4.4/64/x86/gcc/5.4/mpi/libutility.so: undefined reference to `ompi_mpi_cxx_op_intercept'
build/src/release/linux/4.4/64/x86/gcc/5.4/mpi/libutility.so: undefined reference to `MPI::Datatype::Free()'
build/src/release/linux/4.4/64/x86/gcc/5.4/mpi/libutility.so: undefined reference to `MPI::Comm::Comm()'
build/src/release/linux/4.4/64/x86/gcc/5.4/mpi/libutility.so: undefined reference to `MPI::Win::Free()'
collect2: error: ld returned 1 exit status
scons: *** [build/src/release/linux/4.4/64/x86/gcc/5.4/mpi/antibody.mpi.linuxgccrelease] Error 1
build/src/release/linux/4.4/64/x86/gcc/5.4/mpi/libprotocols.1.so: undefined reference to `ompi_mpi_cxx_op_intercept'
build/src/release/linux/4.4/64/x86/gcc/5.4/mpi/libprotocols.1.so: undefined reference to `MPI::Win::Free()'
build/src/release/linux/4.4/64/x86/gcc/5.4/mpi/libprotocols.1.1.so: undefined reference to `MPI::Comm::Comm()'
collect2: error: ld returned 1 exit status
Okay, *now* you're getting issues with your -L settings. The killdevil settings should have fixed this, but you might have to supplement this with the openmpi location
If that works for compilation, in order to run things successfully, you may need to actually add /usr/lib/openmpi/lib/ to your LD_LIBRARY path
You can do this either any time you need to run MPI, or you could add it to your .bashrc to have it on permanently.
Thank you! I will give that a try in the morning.
One odd thing I noticed is that on my laptop there are about 79 items in the openmpi bin folder but on the workstation there are less than half that number. I looked at the build lines and openmpi is one of the -L options.
I will try what you suggested but I was hoping for your thoughts on the differening file counts... maybe the path is correct but the libraries are missing somehow?
Are these both apt-get installed packages? Or are you comparing a manual install to the apt-get install?
I would not be surprised if the apt-get install is smaller (or larger). The people who do the Ubuntu packaging probably know which files are required and which are extra, and remove anything that is not really necessary for general Ubuntu usage. (Or alternatively, there may be multiple ways to do the build, and the Ubuntu packagers do all of them, as they don't know which ones would really be needed for your particular use case.)
On the workstation (problem machine) I first did a manual install using the steps listed in #16 above that I found in a video linked from the openmpi website. The generated fewer files. On my laptop I did the apt-get method there are more files and everything works fine.
Sorry I didn't get to try your suggestion as I woke up this morning feeling horrible and went back to bed after the kids were off to school. Hopefully I'll be feeling better tomorrow so I can have at it.
Thanks, but no changes...
Ok, as I see it I have one machine where the build process can find, for example, "MPI::COMM_WORLD" and another on which it can't. Both machines have the same OpenMPI package installed and both have the same library paths defined.
So, what I'd like to do is find out from which library file, on the machine where the build works, exports "MPI::COMM_WORLD". This way I can see if it exists on the machine where it wont build.
Maybe this explains something?
Both machines are running Ubuntu 16.04, but my laptop (where everthing builds fine) was an upgrade, while I did a clean install on my workstation (where the build fails). Everything else between the machines in terms of software, shells, settings, etc, are the same.
Does anyone know about installing OpenMPI? I ran 'ompi_info' on both machines and the installation options and version info are different. I attached both files for review.
CatalayseU: Laptop, build successful
SynthaseU: Workstation, build fails
Thank you!!
Could this "C++ bindings: no" be the problem?
If it is, does anyone know how to change it and rebuild?
Thanks
Ok, looks like this is what happened... The C++ bindings are off by default when building OpenMPI (though I can't imagine why!). So I redid the build with this added to the ./configure command: "--enable-mpi-cxx".
Then I redid the remaining steps as I outlined above. I then did the MPI build of Rosetta and it was successful.
How do I mark this as answered?
Thanks for your help guys. | https://www.rosettacommons.org/node/9783 | CC-MAIN-2022-05 | refinedweb | 3,154 | 50.12 |
But integers are immutable. If names could be rebound as a side-effect of a function call, you would be creating some difficult to debug connections in your program. If you are deliberately creating a special environment for communicating between functions sharing that environment (closures), it probably makes sense to use a dictionary or class to separate those variable names from the "general" variables. A list works, since it is mutable. I guess I'm not a closure purist. On Sat, 2004-11-13 at 15:57, Kent Johnson wrote: > I think the idea is that x in the enclosing scope should be changed when > _ is called. To closure purists :-) a language doesn't have closures if > it can't do this. > > Python will bind the *values* of variables in an enclosing scope into a > closure, which is good enough for many uses :-) > > Personally I haven't found much need for 'true' closures. orbitz, can > you say why this is such a pain? How would you use a true closure? > > A workaround is to store the variable in a list, but it's a bit ugly: > > x = [3] > def fn(x): > def _(): > x[0] += 1 > return x[0] > return _ > > Kent > > Lloyd Kvam wrote: > > It DOES work in current versions of Python, exactly as you coded it. > > > > In older Pythons (e.g. 1.52) you would have had to specifying the > > enclosing variables explicitly > > def _(x=x): > > > > A lot of old critiques are still present on the web. wikipedia has a > > terrific article describing Python that is current (at least 2.3.3). > > > > > > > > > > > > On Sat, 2004-11-13 at 14:07, orbitz wrote: > > > >>In my opinion, this behavior really sucks too. Like when it comes to > >>closures. As far as I know, Python does not *really* support closures, > >>like you would get with something like lisp. Correct me if I'm wrong. > >>This means code like: > >> > >>def fn(x): > >> def _(): > >> x += 1 > >> return x > >> return _ > >> > >>Will not work, which can be a pain in the ass. > >> > >> > >>Kent Johnson wrote: > >> > >> > >>>Liam, > >>> > >>>When you make any assignment to a variable inside a function, Python > >>>assumes that the variable is local to the function. Then any use of > >>>the variable before it's first assignment is an error. > >>> > >>>To force a variable in a function to be global, put a 'global' > >>>statement in the function. You need to add > >>> global badConnectCycle > >>>to your function getReturns > >>> > >>>If you don't make any assignment to a variable, then the global > >>>(module) namespace is searched. That is why badUserList works fine - > >>>you never assign it, you just access the list methods. > >>> > >>>Kent > >>> > >>>Liam Clarke wrote: > >>> > >>> > >>>>Hi all, > >>>>Having trouble with something, it is 3:30am in the morning, so this > >>>>may be a dumb problem, if so, I apologise. > >>>> > >>>>In my prog, there's two variables created right at the get go - > >>>> > >>>>import imaplib > >>>>import email.Parser > >>>>import os > >>>>import os.path > >>>>import datetime > >>>>import md5 > >>>>from pause import * > >>>> > >>>>badUserList=[] > >>>>badConnectCycle=0 > >>>> > >>>>as I want them to be global within this module, so that another module > >>>>can pick them out easily. > >>>> > >>>>Now, I just added badConnectCycle, badUserList has been there awhile, > >>>>and it's used in > >>>> > >>>>the function connectToImap which is called by getReturns which is > >>>>called by main(), and my other module can get it no problem, so > >>>>badUserList is fine. > >>>> > >>>>badConnectCycle... is giving me errors - > >>>> > >>>>badConnectCycle is used in getReturns, as so - > >>>>if session == "NoConnect" : badConnectCycle += 1 > >>>> continue > >>>> > >>>> > >>>>function getReturns ends as follows - > >>>>if badConnectCycle == len(user) and badConnectCycle > 0: return > >>>>("NoConnect","") > >>>>if badUserList and not sender: return ('NoLogin',"") > >>>>if matchindex[0] and not sender: return ('NoNew', '') > >>>>if not sender: return ("NoMatch","") > >>>>return (sender, msgdata) > >>>> > >>>>and it's at that line > >>>> > >>>> if badConnectCycle == len(user) and badConnectCycle > 0: > >>>> > >>>>that I get this error: > >>>> > >>>>UnboundLocalError: local variable 'badConnectCycle' referenced before > >>>>assignment. > >>>> > >>>>Which is confusing me because badUserList is used within a function > >>>>called by getReturns, and I've had no problem with it. > >>>> > >>>>Help anyone? Much appreciated if you can. > >>>> > >>>>Regards, > >>>> > >>>>Liam Clarke > >>> > >>>_______________________________________________ > >>>Tutor maillist - Tutor at python.org > >>> > >>> > >> > >>_______________________________________________ > >>Tutor maillist - Tutor at python.org > >> > _______________________________________________ > Tutor maillist - Tutor at python.org > -- Lloyd Kvam Venix Corp | https://mail.python.org/pipermail/tutor/2004-November/033227.html | CC-MAIN-2018-05 | refinedweb | 698 | 69.82 |
This project use the Social Security Administration's baby names data set - names of babies born in the US going back more than 100 years.
All parts of HW6 are due Wed Feb 26th 11:55pm. The file babynames.zip contains a "babynames" folder to get started. In a later project, you will build upon the data capabilities here.
Here are some warmup problems to get started. (The first two are dict problems which relate to the Baby Names project. The other problems relate to the Fri lecture.)
> Dict Warmups
Let's see what form the data is in to start with. At the Social Security baby names site, you can visit a different web page for each year. Here's what the data looks like in a web page (indeed, this is pretty close to the birth year for many students in CS106A - hey there Emily and Jacob!)
In this data set, rank 1 means the most popular name, rank 2 means next most popular, and so on down through rank 1000. The data is divided into "male" and "female" columns. (To be strictly accurate, at birth when this data is collected, not all babies are categorized as male or female. That's rare enough to not affect the numbers at this level.)
A web page is encoded as - you guessed it! - plain text in a format called HTML. For your project, we have done a superficial clean up of the HTML text and stored it in files "baby-2000.txt", which look
A door is what a dog is perpetually on the wrong side of. - Ogden Nash
Data in the real world is very often not in the form you need. Reasonably for the Social Security Administration, their data is organized by year. Each year they get all those forms filled out by parents, they crunch it all together, and eventually publish the data for that year, such as we have as baby-2000.txt.
However, the most interesting analysis of the data requires organizing it by name, across many years. This real-world mismatch is part of the challenge for this project.
We'll say that the "names" dict structure for this program has a key for every name. The value for each name is a nested dict, mapping int year to int rank:
{ 'Aaden': {2010: 560}, 'Aaliyah': {2000: 211, 2010: 56}, ... }
Each name has data for 1 or more years, but which years have data for each name jumps around. In the above data, 'Aaliyah' jumped from rank 211 in 2000 to 56 in 2010 (these names are alphabetically first in the 2000 + 2010 data set). An empty dict is a valid names data structure - it just has zero names in it.
Functions below will work on this "names" data structure.
The add_name() function takes in a single name of data, and adds it into the names dict. Later phases can call this function in a loop to build up the whole data set.
The dict is passed in as a parameter. Python never passes a copy, but instead passes a reference to the one dict in memory. In this way, if add_name() modifies the passed in "names" dict, that's the same dict being used by the caller. The function also returns the names dict to facilitate writing Doctests.
The starter code includes a single Doctest as an example (below). The test passes in the empty dict as the input names, and some fake data for baby 'abe'.
def add_name(names, year, rank, name): """ Add the given data: int year, int rank, str name to the given names dict and return it. (1 test provided, more tests TBD) >>> add_name({}, 2000, 10, 'abe') {'abe': {2000: 10}} """
Write at least 2 additional tests for add_name(). Pass in a non-empty names dicts for at least 1 Doctest to test that names and years accumulate in the dict correctly. This function is short but dense. Doctests are a good fit for this situation, letting you explicitly identify and work on the tricky cases.
In rare cases a name, e.g. 'Christian', appears twice in the data: once as a male name and once as a female name. We need a policy for how to handle that case. Our policy will be to keep whatever rank number for that name/year is read first (in effect the smaller number). For example for the baby-200.txt data 'Christian' comes in as a male name at rank 22. Then it comes in as a female name at rank 576. We will disregard the 576. Your tests should include this case. This sort of rare case in the data is more likely to cause bugs; it doesn't fit the common data pattern you have in mind as you write the code.
CS Observation — if 99% of the data is one way, and 1% is some other way .. that doesn't mean the 1% is going to require less work just because it's rare. A hallmark of computer code is that it forces you to handle 100% of the cases.
The simple baby text format for this data looks
The year is on the first line. The later lines each have the rank, male name, female name separated from each other by commas. There may be superfluous whitespace chars separating the data as in line 2 above. Don't assume the data runs to exactly 1000, which would make the function too single-purpose. Just process all the lines there are.
Write the code to add the contents of one file.txt to the names dict parameter, which is returned. Tests are provided for this function, using the feature that a Doctest can refer to a file in the same directory. Here the tests use the relatively small test files "small-2000.txt" and "small-2010.txt" to build a names dict.
In this case, you want to treat the first line of the file differently than all the other lines. Therefore the standard for-line-in-file is a little awkward, but there are other ways to get the lines of a text file. Here is a friendly reminder of three ways in Python to read a file:
# Always open the file first with open(filename) as f: # 1. Go through all the lines, the super common pattern for line in f: ... # 2. Alternative: read the entire file contents into 1 text string text = f.read() # 3. Alternative: read the entire file contents in as a list of strings, # one string for each line. Similar to #1, but a list that can be # processed with a later foreach loop, you can grab a subset of the lines # with a slice, etc. lines = f.readlines() # Reading data out a file works once per file-open. So calling f.read() or # f.readlines() a second time does not read the data in again. You could open the # file a second time to read the lines in a second time. Another approach is # taking care to keep the list of lines around from the first call of f.readlines().
Write code for read_files() which takes a list of filenames, building and returning a names dict of all their data. This function is called by main() to build up the names dict from all the files mentioned on the command line. No tests are required this short function.
Write code for search_names() which searches for a target string and returns a sorted list of all the name strings that match the target (no year or rank data). In this case, the target matches a name, not-case sensitive, if the target appears anywhere in the name. For example the target strings 'aa' and 'AA' both match 'Aaliyah' and 'Ayaan'. Return the empty list if no names match the target string. This function is called by main() for the -search command line argument.
Write at least 3 Doctests for search_names() which is the most algorithmic. You can make up a tiny names dict just for the tests.
We've provided the main() function. Given 1 or more baby data file arguments, main() reads them in with your read_files() function, and then calls the provided print_names() function (2 lines long!) to print all the data out.
The files small-2000.txt small-2010.txt have just a few test names, A B C D E, so they are good to hand-check that your output is correct, and of course your Doctests are working on your decomposed functions to check them individually. The output should be the same if small-2010.txt is loaded before small-2000.txt.
Running your code to load multiple files:
$ python3 babynames.py small-2000.txt small-2010.txt A [(2000, 1), (2010, 2)] B [(2000, 1)] C [(2000, 2), (2010, 1)] D [(2010, 1)] E [(2010, 2)]
For reference, here is the contents of the small files:
small-2000.txt:
2000 1 , A , B 2,C,A
small-2010.txt:
2010 1,C,D 2 , A , E
I believe this is the correct meme for this part of the homework.
The small files test that the code is working correctly, but are no fun. The provided main() function looks at all the files listed on the command line, and loads them all by calling your read_files() function in a loop. You can take a look at 4 decades of data with the following command in the terminal (use the tab-key to complete file names without all the typing).
$ python3 babynames.py baby-1980.txt baby-1990.txt baby-2000.txt baby-2010.txt ...tons of output!...
(optional experiment to try) Windows users - I apologize, this key command line feature does not work in the Windows terminal. You can install the Windows Linux Subsystem to get a terminal on Windows where this works.
A handy feature of the terminal is that you can enter baby-*.txt to mean all the filenames with that pattern: baby-1900.txt baby-1910.txt ... baby-2010.txt. This is an incredibly handy shorthand when you are working through a big-data problem with many files. This may also explain why CS and data-science people tend to use patterns to name their data files, so the filenames work with this * feature. You can demonstrate this with the "ls" command, which prints out filenames, like this (in Windows PowerShell, this and the "ls" command works):
$ ls baby-*.txt baby-1900.txt baby-1930.txt baby-1960.txt baby-1990.txt baby-1910.txt baby-1940.txt baby-1970.txt baby-2000.txt baby-1920.txt baby-1950.txt baby-1980.txt baby-2010.txt
This * feature fits perfectly with babynames.py. The following terminal command loads all 12 baby-xxx.txt files without typing in anything else:
$ python3 babynames.py baby-*.txt
This terminal command is expanding the * to hit all the files, running the 24,000 odd data points through your functions to get it all organized in the blink of an eye .. that's how the data scientists to it.
Organizing all the data and dumping it out is impressive, but it is a blunt instrument. Main() connects to your search function like this: if the first 2 command line args are "-search target", then main() reads in all the data and calls your search_names() function to find matching names and print them. Here is an example with the search target "aa":
$ python3 babynames.py -search aa baby-2000.txt baby-2010.txt Aaden Aaliyah Aarav Aaron Aarush Ayaan Isaac Isaak Ishaan Sanaa
When everything is cleaned up and working nicely, please turn in your babynames.py on Paperless. We'll do something fun with this data and code in the next homework, but for now you've solved the key part of reading and organizing a realistic mass of data. | https://web.stanford.edu/class/cs106a/handouts/homework-6-babynames.html | CC-MAIN-2020-16 | refinedweb | 1,979 | 81.63 |
some time ago, I and other people asked about NetMF support for Phidgets. I will present you my solution to this "problem".
My goal was to be able to control Phidgets boards from an autonomous .NetMF board, such as FEZ Domino (an Arduino 2000 clone). This board can act as a USB Host, so I thought that it should work almost straigth forward.
This wasn't really the case, but it finally works !
Here's a video of a demo : ... r_embedded
The setup is :
- a Phidget 1018 connected to a FEZ Domino board
- a button on one input of the 1018
- a LED on one output of the 1018
- a LED and a button on the FEZ Domino board
The FEZ Domino runs a C# program I've made and does the following :
- when the button on the 1018 is pressed, the led on its output is lit and the led on the FEZ Domino is lit
- when the button on the FEZ Domino is pressed, it shuts off both leds
This small example of "simple" Led lighting indicates nothing less than communication and interaction between the two boards...
The program in the FEZ board is quite simple :
Code: Select all
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using System.Threading;
using GHIElectronics.NETMF.FEZ;
using FEZPhidgets; // My driver
namespace MFConsoleApplication1
{
public class Program
{
static Phidget1018 IF1018 = new Phidget1018();
static OutputPort Led = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, false); // Led on Domino board
static InterruptPort Bouton = new InterruptPort((Cpu.Pin)FEZ_Pin.Interrupt.LDR, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth); // Button on Domino board
// Main program
public static void Main()
{
Bouton.OnInterrupt += Bouton_OnInterrupt;
IF1018.InputChange += Phidget1018_InputChange;
Thread.Sleep(Timeout.Infinite);
}
// Event thrown when the button on the FEZ Domino is pressed
static void Bouton_OnInterrupt(uint data1, uint data2, System.DateTime time)
{
IF1018.Output(7, false); // Shutdown 1018 LED
Led.Write(false); // And FEZ Domino LED
}
// Phidget 1018 button pressed
static void Phidget1018_InputChange(object sender, Phidget1018InputChangeEventArgs e)
{
if (e.Index == 6) { IF1018.Output(7, true); Led.Write(true); } // Light on both LEDs
}
}
}
I've tried to stay as near as possible to Phidgets assemblies. That's why properties/methods/events are almost the same.
But to achieve this, I had to write drivers for the USB Host on the Domino board.
The driver is C# code and is the result of try & fail ... Using USB sniffer and C code from Phidgets...
The driver is available here : ... idgets.rar
Please note that this is not complete and that it "just works". No more promise on this code
You will also notice that there's a 1052 class that permits the use of the Phidgets 1052 Digital encoder.
A more complete page about this project is available on the FEZ Domino site : ... e=Phidgets
If I write here, that's because of two things :
- some people here (like me
and, most of all :
- Phidgets staff has just sent me unvaluable information so that I will be able to code a driver for the 1062 & 1060 boards.
I couldn't make less than also sharing what I've done. Both teams (Phidgets & GHI Electronics) were so kind in provinding info and support ! I hadn't seen this since a long time, for sure
So, I will now code the drivers for these boards and revise the structure of the whole thing to be more consistent.
If you have any question regarding this project, you're welcome !
And again, a big THANK YOU to the Phidgets team for its very good boards and the associated incredible support, and also to GHI Electronics for the same reasons
| https://www.phidgets.com/phorum/viewtopic.php?p=13719 | CC-MAIN-2019-43 | refinedweb | 602 | 65.62 |
2 Replies
when i look at a video on my mac its fine looks normal but once i put the same video in imovie or click get info and look at the preview its as if it took the video duplicated it and stuck it next to the original in the same frame.. any thoughts on how to fix this?
this is a link to the picure to see what i mean.
http:/i.imgur.com/Y58U9xq.jpg
you used the GoPros own importer/converter, CineformStudio, set to '3D' mode.
this creates a 'squeezed, side by side' frame.
import straight from camera.......
okay thank you very much! | https://discussions.apple.com/thread/5141862 | CC-MAIN-2016-07 | refinedweb | 107 | 90.7 |
Classes in Scala are blueprints for creating objects. They can contain methods, values, variables, types, objects, traits, and classes which are collectively called members. Types, objects, and traits will be covered later in the tour.
A minimal class definition is simply the keyword
class and
an identifier. Class names should be capitalized.
class User val user1 = new User
The keyword
new is used to create an instance of the class.
User has a default constructor which takes no arguments because no constructor was defined. However, you’ll often want a constructor and class body. Here is an example class definition for a point:
class Point(var x: Int, var y: Int) { def move(dx: Int, dy: Int): Unit = { x = x + dx y = y + dy } override def toString: String = s"($x, $y)" } val point1 = new Point(2, 3) point1.x // 2 println(point1) // prints (x, y)
This
Point class has four members: the variables
x and
y and the methods
move and
toString. Unlike many other languages, the primary constructor is in the class signature
(var x: Int, var y: Int). The
move method takes two integer arguments and returns the Unit value
(), which carries no information. This corresponds roughly with
void in Java-like languages.
toString, on the other hand, does not take any arguments but returns a
String value. Since
toString overrides
toString from
AnyRef, it is tagged with the
override keyword.
Constructors can have optional parameters by providing a default value like so:
class Point(var x: Int = 0, var y: Int = 0) val origin = new Point // x and y are both set to 0 val point1 = new Point(1) println(point1.x) // prints 1
In this version of the
Point class,
x and
y have the default value
0 so no arguments are required. However, because the constructor reads arguments left to right, if you just wanted to pass in a
y value, you would need to name the parameter.
class Point(var x: Int = 0, var y: Int = 0) val point2 = new Point(y=2) println(point2.y) // prints 2
This is also a good practice to enhance clarity.
Members are public by default. Use the
private access modifier
to hide them from outside of the class.
class Point { private var _x = 0 private var _y = 0 private val bound = 100 def x = _x def x_= (newValue: Int): Unit = { if (newValue < bound) _x = newValue else printWarning } def y = _y def y_= (newValue: Int): Unit = { if (newValue < bound) _y = newValue else printWarning } private def printWarning = println("WARNING: Out of bounds") } val point1 = new Point point1.x = 99 point1.y = 101 // prints the warning
In this version of the
Point class, the data is stored in private variables
_x and
_y. There are methods
def x and
def y for accessing the private data.
def x_= and
def y_= are for validating and setting the value of
_x and
_y. Notice the special syntax for the setters: the method has
_= appended to the identifier of the getter and the parameters come after.
Primary constructor parameters with
val and
var are public. However, because
vals are immutable, you can’t write the following.
class Point(val x: Int, val y: Int) val point = new Point(1, 2) point.x = 3 // <-- does not compile
Parameters without
val or
var are private values, visible only within the class.
class Point(x: Int, y: Int) val point = new Point(1, 2) point.x // <-- does not compile
Contents | https://docs.scala-lang.org/tutorials/tour/classes.html.html | CC-MAIN-2018-51 | refinedweb | 576 | 72.05 |
I am on the section in the tutorials about an indeterminate amount of function arguments. I have tried to change the example to allow user input and have ran into a problem with it. It is just a simple average calculator that is supposed to get user input for numbers to find the average of. It is probably an easy fix but i'm still learning and can't figure out what is wrong with the code. If i leave it as is there are no errors from the compiler. If I enter one number it returns the value "inf" if more than one the program crashes. Any help would be greatly appreciated.
Code:
#include <cstdarg>
#include <iostream>
using namespace std;
char numbers[150];
double average ( int num, ... )
{
va_list numbers[2];
double sum = 0;
va_start (numbers[2], num);
for (int x=0;x<num;x++)
sum += va_arg (numbers[2], double);
va_end (numbers[2]);
return sum / num;
}
int main()
{
cout<<"Please enter numbers to find the average): "<<endl;
cin.getline ( numbers, 150);
cout<<average (numbers[2])<<endl;
} | http://cboard.cprogramming.com/cplusplus-programming/129564-beginner-help-printable-thread.html | CC-MAIN-2013-48 | refinedweb | 176 | 63.7 |
In addition to ensuring your app meets its functional requirements by building tests, it's important that you also ensure your code has no structural problems by running the code through lint. The lint tool helps find poorly structured code that can impact the reliability and efficiency of your Android apps and make your code harder to maintain.
For example, if your XML resource files contain unused namespaces, this takes up space and incurs unnecessary processing. Other structural issues, such as use of deprecated elements or API calls that are not supported by the target API versions, might lead to code failing to run correctly. Lint can help you clean up these issues.
To further improve linting performance, you should also add annotations to your code.
Overview
Android Studio provides a code scanning tool called lint that can help you to identify and correct problems with the structural quality of your code without. When using Android Studio, configured lint and IDE inspections run whenever you build your app. However, you can manually run inspections or run lint from the command line.
Note: When your code is compiled in Android Studio, additional IntelliJ code inspections run to streamline code review.
Figure 1 shows how the lint tool processes the application source files.
- Application source files
- The source files consist of files that make up your Android project, including Java, Kotlin, and XML files, icons, and ProGuard configuration files.
- The
lint.xmlfile
- A configuration file that you can use to specify any lint checks that you want to exclude and to customize problem severity levels.
- The lint tool
- A static code scanning tool that you can run on your Android project either from the command line or in Android Studio (see Manually run inspections). The lint tool checks for structural code problems that could affect the quality and performance of your Android application. It is strongly recommended that you correct any errors that lint detects before publishing your application.
- Results of lint checking
- You can view the results from lint either in the console or in the Inspection Results window in Android Studio. See Manually run inspections.
Run lint from the command line
If you're using Android Studio or Gradle, you can use the Gradle wrapper to invoke the
lint task for your project by
entering one of the following commands from the root directory of your project:
- On Windows:
gradlew lint
- On Linux or Mac:
./gradlew lint
You should see output similar to the following:
> Task :app:lintDebug Wrote HTML report to file:<path-to-project>/app/build/reports/lint-results-debug.html
When the lint tool completes its checks, it provides paths to the XML and HTML versions of the lint report. You can then navigate to the HTML report and open it in your browser, as shown in figure 2.
If your project includes build variants, running lint checks only the default variant. If you want to run lint on a different variant, you must capitalize the variant name and prefix it with `lint`.
./gradlew lintRelease
To learn more about running Gradle tasks from the command line, read Build Your App from the Command Line.
Run lint using the standalone tool
If you're not using Android Studio or Gradle, you can use the standalone lint tool after you
install the Android SDK Tools from the
SDK Manager. You can then locate the lint tool
in the
android_sdk/tools/ directory.
To run lint against a list of files in a project directory, use the following command:
lint [flags] <project directory>
For example, you can issue the following command to scan the files under the
myproject directory and its subdirectories. The issue ID
MissingPrefix
tells lint to only scan for XML attributes that are missing the Android namespace prefix.
lint --check MissingPrefix myproject
To see the full list of flags and command-line arguments supported by the tool, use the following command:
lint --help
The following example shows the console output when the lint command is run against a project called Earthquake.
$ lint Earthquake Scanning Earthquake: ............................................................................................................................... Scanning Earthquake (Phase 2): ....... AndroidManifest.xml:23: Warning: <uses-sdk> tag appears after <application> tag [ManifestOrder] <uses-sdk android: ^ AndroidManifest.xml:23: Warning: <uses-sdk> tag should specify a target API level (the highest verified version; when running on later versions, compatibility behaviors may be enabled) with android: ^ res/layout/preferences.xml: Warning: The resource R.layout.preferences appears to be unused [UnusedResources] res: Warning: Missing density variation folders in res: drawable-xhdpi [IconMissingDensityFolder] 0 errors, 4 warnings
The output above lists four warnings and no errors: three warnings
(
ManifestOrder,
UsesMinSdkAttributes, and
UnusedResources)
in
the project's
AndroidManifest.xml file, and one warning
(
IconMissingDensityFolder) in the
Preferences.xml layout file.
Configure lint to suppress warnings
By default when you run a lint scan, the tool checks for all issues that lint supports. You can also restrict the issues for lint to check and assign the severity level for those issues. For example, you can suppress lint checking for specific issues that are not relevant to your project and, you can configure lint to report non-critical issues at a lower severity level.
You can configure lint checking for different levels:
- Globally (entire project)
- Project module
- Production module
- Test module
- Open files
- Class hierarchy
- Version Control System (VCS) scopes underlines the code in red.
- In the lint Inspection Results window after you click Analyze > Inspect Code. See Manually run inspections.
Configure the lint file
You can specify your lint checking preferences in the
lint.xml file. If you
are creating this file manually, place it in the root directory of your Android project.
The
lint.xml file consists of an enclosing
<lint> parent tag that
contains one or more children
<issue> elements. Lint defines a unique
id attribute value for each
<issue>.
<?xml version="1.0" encoding="UTF-8"?> <lint> <!-- list of issues to configure --> </lint>
You can change an issue's severity level or disable lint checking for the issue by
setting the severity attribute in the
<issue> tag.
Tip: For a full list of lint-supported issues and their corresponding
issue IDs, run the
lint --list command.
Sample lint.xml file
The following example shows the contents of a
lint.xml file.
<?xml version="1.0" encoding="UTF-8"?> <lint> <!-- Disable the given check in this project --> <issue id="IconMissingDensityFolder" severity="ignore" /> <!-- Ignore the ObsoleteLayoutParam issue in the specified files --> <issue id="ObsoleteLayoutParam"> <ignore path="res/layout/activation.xml" /> <ignore path="res/layout-xlarge/activation.xml" /> </issue> <!-- Ignore the UselessLeaf issue in the specified file --> <issue id="UselessLeaf"> <ignore path="res/layout/main.xml" /> </issue> <!-- Change the severity of hardcoded strings to "error" --> <issue id="HardcodedText" severity="error" /> </lint>
Configure lint checking for Java, Kotlin, and XML source files
You can disable lint from checking your Java, Kotlin, and XML source files.
Tip: You can manage the lint checking feature for your Java, Kotlin, or XML source files in the Default Preferences dialog. Select File > Other Settings > Default Settings, and then in the left pane of the Default Preferences dialog, select Editor > Inspections.
Configuring lint checking in Java or Kotlin
To disable lint checking specifically for a class or method in your Android project,
add the
@SuppressLint annotation to that code.
The following example shows how you can turn off lint checking for the
NewApi
issue in the
onCreate method. The lint tool continues to check for the
NewApi issue in other methods of this class.
Kotlin
@SuppressLint("NewApi") override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.main)
Java
@SuppressLint("NewApi") @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);
The following example shows how to turn off lint checking for the
ParserError
issue in the
FeedProvider class:
Kotlin
@SuppressLint("ParserError") class FeedProvider : ContentProvider() {
Java
@SuppressLint("ParserError") public class FeedProvider extends ContentProvider {
To suppress checking for all lint issues in the file, use the
all keyword,
like this:
Kotlin
@SuppressLint("all")
Java
@SuppressLint("all")
Configuring lint checking in XML
You can use the
tools:ignore attribute to disable lint checking for specific
sections of your XML files. Put the following namespace value in the
lint.xml file
so the lint tool recognizes the attribute:
namespace xmlns:tools="
The following example shows how you can turn off lint checking for the
UnusedResources issue in the
<LinearLayout> element of an XML
layout file. The
ignore attribute is inherited by the children elements of the parent
element in which the attribute is declared. In this example, the lint check is also disabled for the
child
<TextView> element.
<LinearLayout xmlns: <TextView android: </LinearLayout>
To disable more than one issue, list the issues to disable in a comma-separated string. For example:
tools:ignore="NewApi,StringFormatInvalid"
To suppress checking for all lint issues in the XML element, use the
all keyword,
like this:
tools:ignore="all"
Configure lint options with Gradle
The Android plugin for Gradle allows you to configure certain lint options,
such as which checks to run or ignore, using the
lint{} block in your module-level
build.gradle file. The following code snippet shows you some of
the properties you can configure:
Groovy
android { ... lint { // Turns off checks for the issue IDs you specify. disable 'TypographyFractions','TypographyQuotes' // Turns on checks for the issue IDs you specify. These checks are in // addition to the default lint checks. enable 'RtlHardcoded','RtlCompat', . checkDependencies true } } ...
Kotlin
android { ... lintOptions { // Turns off checks for the issue IDs you specify. disable("TypographyFractions") disable("TypographyQuotes") // Turns on checks for the issue IDs you specify. These checks are in // addition to the default lint checks. enable("RtlHardcoded") enable("RtlCompat") enable(. isCheckDependencies = true } } ...
All lint methods that override the given severity level of an issue—
enable,
disable/
ignore,
informational,
warning,
error,
fatal—respect the
order of configuration. For example, setting an issue as fatal in
finalizeDsl()
overrides disabling it in the main DSL.
Create warnings baseline
You can take a snapshot of your project's current set of warnings, and then use the snapshot as a baseline for future inspection runs so that only new issues are reported. The baseline snapshot lets you start using lint to fail the build without having to go back and address all existing issues first.
To create a baseline snapshot, modify your project's
build.gradle file as follows.
Groovy
android { lintOptions { baseline file("lint-baseline.xml") } }
Kotlin
android { lintOptions { baseline(file("lint-baseline.xml")) } }
When you first add this line, the
lint-baseline.xml file is created to establish
your baseline. From then on, the tools only read the file to determine the baseline. If you want
to create a new baseline, manually delete the file and run lint again to recreate it.
Then, run lint from the IDE (Analyze > Inspect Code) or from the command line
as follows. The output prints the location of the
lint-baseline.xml file. The
file location for your setup might be different from what is shown here.
$ ./gradlew lintDebug ... Wrote XML report to Created baseline file /app/lint-baseline.xml
Running
lint records all of the
current issues in the
lint-baseline.xml file. The set of current issues is
called the baseline, and you can check the
lint-baseline.xml
file into version control if you want to share it with others.
Customize the baseline
If you want to add some issue types to the baseline, but not all of them, you can specify the
issues to add by editing your project's
build.gradle, as follows.
Groovy
android { lintOptions { checkOnly 'NewApi', 'HandlerLeak' baseline file("lint-baseline.xml") } }
Kotlin
android { lintOptions { checkOnly("NewApi", "HandlerLeak") baseline = file("lint-baseline.xml") } }
After you create the baseline, if you add any new warnings to the codebase, lint lists only the newly introduced bugs.
Baseline warning
When baselines are in effect, you get an informational warning that tells you that one or more issues were filtered out because they were already listed in the baseline. The reason for this warning is to help you remember that you have configured a baseline, because ideally, you would want to fix all of the issues at some point.
This informational warning does not only tell you the exact number of errors and warnings that were filtered out, it also keeps track of issues that are not reported anymore. This information lets you know if you have actually fixed issues, so you can optionally re-create the baseline to prevent the error from coming back undetected.
Note: Baselines are enabled when you run inspections in batch mode in the IDE, but they are ignored for the in-editor checks that run in the background when you are editing a file. The reason is that baselines are intended for the case where a codebase has a massive number of existing warnings, but you do want to fix issues locally while you touch the code.
Manually run inspections
You can manually run configured lint and other IDE inspections by selecting Analyze > Inspect Code. The results of the inspection appear in the Inspection Results window.
Set the inspection scope and profile
Select the files you want to analyze (inspection scope) and the inspections you want to run (inspection profile), as follows:
- In the Android view, open your project and select the project, a folder, or a file that you want to analyze.
- From the menu bar, select Analyze > Inspect Code.
- In the Specify Inspection Scope dialog, review the settings.
The combination of options that appear in the Specify Inspection Scope dialog varies depending on whether you selected a project, folder, or file. You can change what to inspect by selecting one of the other radio buttons. See Specify inspection scope dialog for a description of all of the possible fields on the Specify Inspection Scope dialog.
- When you select one project, file, or directory, the Specify Inspection Scope dialog displays the path to the Project, File, or Directory you selected.
- When you select more than one project, file, or directory, the Specify Inspection Scope dialog displays a checked radio button for Selected files.
- Under Inspection profile, keep the default profile (Project Default).
- Click OK to run the inspection. Figure 4 shows lint and other IDE inspection results from the Inspect Code run:
- In the left pane tree view, view the inspection results by expanding and selecting error categories, types, and issues.
The right pane displays the inspection report for the selected error category, type, or issue and provides the name and location of the error. Where applicable, the inspection report displays other information such as a problem synopsis to help you correct the problem.
- In the left pane tree view, right-click a category, type, or issue to display the context menu.
Depending on the context, you can do all or some of the following: jump to source, exclude and include selected items, suppress problems, edit settings, manage inspection alerts, and rerun an inspection.
For descriptions of the left-side Toolbar buttons, context menu items, and inspection report fields, see Inspection Tool Window.
Use a custom scope
You can use one of the custom scopes provided in Android Studio, as follows:
- In the Specify Inspection Scope dialog, click Custom scope.
- Click the Custom scope drop-down list to display your options.
- Project Files: All of the files in the current project.
- Project Production Files: Only the production files in the current project.
- Project Test Files: Only the test files in the current project. See Test types and location.
- Open Files: Only the files you have open in the current project.
- Module <your-module>: Only the files in the corresponding module folder in your current project.
- Current File: Only the current file in your current project. Appears when you have a file or folder selected.
- Class Hierarchy: When you select this one and click OK, a dialog appears with all of the classes in the current project. Use the Search by Name field in the dialog to filter and select the classes to inspect. If you do not filter the classes list, code inspection inspects all of the classes.
- Click OK.
Create a custom scope
When you want to inspect a selection of files and directories that is not covered by any of the currently available custom scopes, you can create a custom scope.
- In the Specify Inspection Scope dialog, select Custom scope.
- Click the three dots after the Custom Scope drop-down list.
The Scopes dialog appears.
- Click Add to define a new scope.
- In the resulting Add Scope drop-down list, select Local.
Both the local and shared scopes are used within the project for the Inspect Code feature. A Shared scope can also be used with other project features that have a scope field. For example, when you click Edit Settings to change the settings for Find Usages, the resulting dialog has a Scope field where you can select a shared scope.
- Give the scope a name and click OK.
The right pane of the Scopes dialog populates with options that enable you to define the custom scope.
- From the drop-down list, select Project.
A list of available projects appears.
Note: You can create the custom scope for projects or packages. The steps are the same either way.
- Expand the project folders, select what you want to add to the custom scope, and click one of the buttons on the right.
- Include: Include this folder and its files, but do not include any of its subfolders.
- Include Recursively: Include this folder and all of its files and subfolders and their files.
- Exclude: Exclude this folder and its files, but do not exclude any of its subfolders.
- Exclude Recursively: Exclude ths folder and all of its files and subfolders and their files.
Figure 10 shows that the main folder is included, and that the java folder is included recursively. The blue indicates partially included folders and the green indicates recursively included folders and files.
- If you select the java folder and click Exclude Recursively, the green highlighting goes away on the java folder and all folders and files under it.
- If you instead select the green highlighted MainActivity.java file and click Exclude, MainActivity.java is no longer green highlighted but everything else under the java folder is green highlighted.
- Click OK. The custom scope appears at the bottom of the drop-down list.
Review and edit inspection profiles
Android Studio comes with a selection of lint and other inspection profiles that are updated through Android updates. You can use these profiles as is or edit their names, descriptions, severities, and scopes. You can also activate and deactivate entire groups of profiles or individual profiles within a group.
To access the Inspections dialog:
- Select Analyze > Inspect Code.
- In the Specify Scope dialog under Inspection Profile, click More.
The Inspections dialog appears with a list of the supported inspections and their descriptions.
- Select the Profile drop-down list to toggle between Default (Android Studio) and Project Default (the active project) inspections. For more information, see this IntelliJ Specify Inspection Scope Dialog page.
- In the Inspections dialog in the left pane, select a top-level profile category, or expand a group and select a specific profile. When you select a profile category, you can edit all of the inspections in that category as a single inspection.
- Select the Manage drop-down list to copy, rename, add descriptions to, export, and import inspections.
- When you're done, click OK. | https://developer.android.com/studio/write/lint?hl=sr | CC-MAIN-2022-21 | refinedweb | 3,235 | 53.92 |
What is Servlet vs GenericServlet vs HttpServlet?
Servlets are platform-independent server-side components, being written in Java. Before going for differences, first let us see how the three Servlet, GenericServlet, HttpServlet are related, their signatures and also at the end similarities.
See how to write a Servlet.
public class Validation extends HttpServlet
To write a servlet, everyone goes to extend the abstract class HttpServlet, like Frame is required to extend to create a frame.
Following figure shows the hierarchy of Servlet vs GenericServlet vs HttpServlet and to know from where HttpServlet comes.
Figure on Servlet vs GenericServlet vs HttpServlet
Observe the hierarchy and understand the relationship between the three (involved in multilevel inheritance). With the observation, a conclusion can be arrived, to write a Servlet three ways exist.
a) by implementing Servlet (it is interface)
b) by extending GenericServlet (it is abstract class)
c) by extending HttpServlet (it is abstract class)
The minus point of the first way is, all the 5 abstract methods of the interface Servlet should be overridden eventhough Programmer is not interested in all (like the interface WindowListener to close the frame). A smart approach is inheriting GenericServlet (like using WindowAdapter) and overriding its only one abstract method service(). It is enough to the programmer to override only this method. It is a callback method (called implicitly). Still better way is extending HttpServlet and need not to override any methods as HttpServlet contains no abstract methods. Eventhough the HttpServlet does not contain any abstract methods, it is declared as abstract class by the Designers to not to allow the Programmer to create an object directly because a Servlet object is created by the system (here system is Servlet Container).
1. Servlet interface
It is the super interface for the remaining two – GenericServlet and HttpServlet. It contains 5 abstract methods and all inherited by GenericServlet and HttpServlet. Programmers implement Servlet interface who would like to develop their own container.
2. GenericServlet
It is the immediate subclass of Servlet interface. In this class, only one abstract method service() exist. Other 4 abstract methods of Servlet interface are given implementation (given body). Anyone who extends this GenericServlet should override service() method. It was used by the Programmers when the Web was not standardized to HTTP protocol. It is protocol independent; it can be used with any protocol, say, SMTP, FTP, CGI including HTTP etc.
Signature:
public abstract class GenericServlet extends java.lang.Object implements Servlet, ServletConfig, java.io.Serializable
3. HttpServlet
When HTTP protocol was developed by W3C people to suit more Web requirements, the Servlet designers introduced HttpServlet to suit more for HTTP protocol. HttpServlet is protocol dependent and used specific to HTTP protocol only.
The immediate super class of HttpServlet is GenericServlet. HttpServlet overrides the service() method of GenericServlet. HttpServlet is abstract class but without any abstract methods.
With HttpServlet extension, service() method can be replaced by doGet() or doPost() with the same parameters of service() method.
Signature:
public abstract class HttpServlet extends GenericServlet implements java.io.Serializable
Being subclass of GenericServlet, the HttpServlet inherits all the properties (methods) of GenericServlet. So, if you extend HttpServlet, you can get the functionality of both.
Let us tabulate the differences for easy understanding and remembering.
Similarities :
1. One common feature is both the classes are abstract classes.
2. Used with Servlets only.
3 thoughts on “Servlet vs GenericServlet vs HttpServlet”
Generic servlet has abstract method service(),http servlet is a sub class of generic servlet,so http servlet also contains abstract method service().but sir u wrote http servlet has no abstract method
Yes, the abstract method service() of GenericServlet is overridden by HttpServlet. That is, in HttpServlet, the service() is concrete method. This helps the Developer to use doGet() or doPost(), instead of service().
Http servlet has no abstract methods even service() is implemented in it but still, it is declared as abstract method.just because to avoid anyone to create an object of it only a servlet container can create an object of it | https://way2java.com/servlets/java-made-clear-difference-servlet-genericservlet-httpservlet/ | CC-MAIN-2022-33 | refinedweb | 668 | 55.95 |
Important: Please read the Qt Code of Conduct -
Building Qt application for a custom linux distribution (with Buildroot) - window manager problem
Welcome everyone!
I'd like to ask you a question concerning building Qt application for a custom embedded linux distribution that I built with the buildroot tools.
I built a basic window Qt application, with a 'Hello World' label. Of course to do so, I used qmake -project + qmake which in turn was built by the buildroot tools for a selected architecture. I enabled (in the menuconfig) the Qt (4.x) standard X11 with Gui Module and the X.org X Window System with xorg-server and rather all necessary libraries, required by Qt for Embedded Linux. The application is being built and installed on the target mechine (which is RPi-3 64bit) without any errors by make all tool from buildroot.
Here are the listings from the main files (without .pro file, if it is necessary I can post it as well but it is considerably long):
packages/helloworld/helloworld.mk:
HELLOWORLD_VERSION:= 1.0.0 HELLOWORLD_SITE:= /home/marek/Projects/qt-embedded/helloworld HELLOWORLD_SITE_METHOD:=local HELLOWORLD_INSTALL_TARGET:=YES define HELLOWORLD_CONFIGURE_CMDS cd $(@D); $(TARGET_MAKE_ENV) $(QT_QMAKE) endef define HELLOWORLD_BUILD_CMDS $(TARGET_MAKE_ENV) $(MAKE) -C $(@D) endef define HELLOWORLD_INSTALL_TARGET_CMDS $(INSTALL) -D -m 0755 $(@D)/helloworld $(TARGET_DIR)/bin endef define HELLOWORLD_PERMISSIONS /bin/helloworld f 4755 0 0 - - - - - endef $(eval $(generic-package))
main.cpp:
#include <QApplication> #include <QLabel> #include <QWSServer> int main(int argc, char **argv) { QApplication app(argc, argv, QApplication::GuiServer); QLabel label("Hello world"); label.show(); return app.exec(); }
When I run the Openbox window manager and execute my helloworld application it obviously runs, but I cannot interact with it and I get a problem shown in the attached picture (see below). The xterm was built also within this distribution. I can move the terminal but it brushes my application, so the mouse pointer does :) You can see the application in the top-left corner of the screen, but if I move the cursor over there it cleans it.
I'm looking forward for any help coming from you. I do not know what I could do more. I'd like to run this application like analogously it happens on my host machine (in this case it is ubuntu 16.04), i.e. to interact with it, add eventually some controls etc.
Thank you in advance!
Marek | https://forum.qt.io/topic/79625/building-qt-application-for-a-custom-linux-distribution-with-buildroot-window-manager-problem | CC-MAIN-2021-31 | refinedweb | 392 | 54.93 |
Generate points along great circles
The
pygmt.project method can generate points along a great circle
whose center and end points can be defined via the
center and
endpoint
parameters, respectively. Using the
generate parameter allows to generate
(r, s, p) points every dist units of p along a profile as
output. By default all units (r, s and p) are set to degrees while
unit=True allows to set the unit for p to km.
Out:
<IPython.core.display.Image object>
import pygmt fig = pygmt.Figure() # generate points every 10 degrees along a great circle from 10N,50W to 30N,5W points1 = pygmt.project(center=[-50, 10], endpoint=[-5, 30], generate=10) # generate points every 750 km along a great circle from 10N,50W to 57.5N,90W points2 = pygmt.project(center=[-50, 10], endpoint=[-90, 57.5], generate=750, unit=True) # generate points every 350 km along a great circle from 10N,50W to 68N,5W points3 = pygmt.project(center=[-50, 10], endpoint=[-5, 68], generate=350, unit=True) # create a plot with coast and Mercator projection (M) fig.basemap(region=[-100, 0, 0, 70], projection="M12c", frame=True) fig.coast(shorelines=True, area_thresh=5000) # plot individual points of first great circle as seagreen line fig.plot(x=points1.r, y=points1.s, pen="2p,seagreen") # plot individual points as seagreen squares atop fig.plot(x=points1.r, y=points1.s, style="s.45c", color="seagreen", pen="1p") # plot individual points of second great circle as orange line fig.plot(x=points2.r, y=points2.s, pen="2p,orange") # plot individual points as orange inverted triangles atop fig.plot(x=points2.r, y=points2.s, style="i.6c", color="orange", pen="1p") # plot individual points of third great circle as red line fig.plot(x=points3.r, y=points3.s, pen="2p,red3") # plot individual points as red circles atop fig.plot(x=points3.r, y=points3.s, style="c.3c", color="red3", pen="1p") fig.show()
Total running time of the script: ( 0 minutes 2.364 seconds)
Gallery generated by Sphinx-Gallery | https://www.pygmt.org/latest/gallery/lines/great_circles.html | CC-MAIN-2022-27 | refinedweb | 345 | 59.5 |
Clicking "set" button of constraint tag from pyGen
On 13/04/2016 at 10:19, xxxxxxxx wrote:
Hello, hello.
I'm trying to attach generated splines to objects within my generator. I'm able to attach constraint and spline dynamics tags to my generated spline within the python generator, but the one step that I'm worried about is selecting a point on my spline and [clicking, setting True] the "set" button of the spline's constraint tag. I think what i'm looking for is something like
tag[[c4d.HAIR_CONSTRAINTS_TAG_SET] = True
but am unable to drag the buttons into the script editor like other parameters. Can anyone give me some pointers?
I can do this manually, but for procedural reasons would prefer it to be done within the generator.
PS.
How can I select a point on a spline? Can't find it in the API at the moment but once I get this then I can start hacking away.
Thanks in advance for any help.
On 14/04/2016 at 09:02, xxxxxxxx wrote:
Hi,
last things first. Selecting points on a spline (which is basically a PointObject) is just a matter of a point selection. Use GetPointS() to get the BaseSelect and you should be good to go.
In order to find out button IDs you have several options. One would be to scan the resource files in <C4D program directory>/resource/modules. Another is to consult the C++ SDK documentation.
So in your case it is HAIR_CONSTRAINTS_TAG_SET_ANCHOR.
But you can't simply assign true to that ID to push the button. Instead you need to use CallButton(), like so:
c4d.CallButton(hairConstraintTag, c4d.HAIR_CONSTRAINTS_TAG_SET_ANCHOR)
On 14/04/2016 at 09:35, xxxxxxxx wrote:
Andreas, thank you yet again!
CallButton and pulling stuff from the C++ SDK, this is a huge help. Thanks for adding that - very much appreciated :)
On 15/04/2016 at 07:56, xxxxxxxx wrote:
Hey again,
I'm having some difficulty with this. It seems like the GetPointS() solution above just return the points that are selected in my scene..? I'm trying to actually select the individual spline points from my generator to set constraints of all splines in my scene at once.
I found this bit in the python api about selecting edges that uses SetSelectedEdges(). Since there's no SetSelectedPoints() function, am I donezo?
def main() : nbr = utils.Neighbor() nbr.Init(op) # Initialize neighbor with a polygon object edges = c4d.BaseSelect() edges.SelectAll(nbr.GetEdgeCount()) # Select all edges in the range [0, nbr.GetEdgeCount()] op.SetSelectedEdges(nbr, edges, c4d.EDGESELECTIONTYPE_SELECTION) # Select edges from our edges selection c4d.EventAdd() # Update Cinema 4D
On 15/04/2016 at 11:58, xxxxxxxx wrote:
Hi Tanzola,
can you show me some of your GetPointS() code. I can't believe, it's returning all points selected in a scene.
Also do not forget, that code in the Python Generator is like code in GetVirtualObjects(). So you will have to make sure you are not modifying the scene in any way.
If unsure, rather post more code than less ;)
On 15/04/2016 at 12:21, xxxxxxxx wrote:
I'd trust your instincts on this one, as I have no idea what I'm doing! This is what I was doing when I assumed points already selected were being returned - you could put it into an empty scene with a generator:
import c4d def main() : try: doc.SearchObject("Spline").Remove() except: pass spline = c4d.SplineObject(2, c4d.SPLINETYPE_LINEAR) pts = [c4d.Vector(), c4d.Vector(0, 200, 0)] spline.SetAllPoints(pts) doc.InsertObject(spline) c4d.EventAdd() bs = doc.SearchObject("Spline").GetPointS() print bs.GetAll(2)
I just get a list of [0, 0] in the console so I assumed it was saying [pt 0 is not selected, pt 1 is not selected].
Were you saying that there is in fact a way to select pts from the generator?
Also... I modify objects in my scene all the time! Point / object positions mostly. You're saying this is a no-no? As you can tell, I'm a big noob.
Thanks for the help
On 15/04/2016 at 12:57, xxxxxxxx wrote:
Yeah, that's what GetAll() on a base select is, a list of 0 if not selected and 1 if it is.
Andreas, I think Tanz is looking for a way to *select*, like one would with the live selection tool, points so as to automate attaching them to other points via the Set button on a (presumably Hair) Constraint.
On 15/04/2016 at 14:10, xxxxxxxx wrote:
That's exactly right - and with hair constraints, yes. Sorry if I was unclear.
On 18/04/2016 at 11:33, xxxxxxxx wrote:
Hi Tanzola,
I just want to double check, we are talking about the Python Generator here, right?
The following explanations apply, if the answer is yes.
In general the Python Generator is very much like an ObjectData plugin with the Python script running in GetVirtualObjects(). So, as mentioned before in this thread, all the constraints that apply to GVO are also true for the Python Generator. Most important, you are not allowed to do any changes to the scene. Instead you are generating an object (this may also be an object hierarchy), optionally based on (user data) parameters of your Python Generator, and this object will be returned in the end of your Python script. Cinema will take care of the insertion into the scene, so you neither have to, nor should you do this on your own (remember, no changes to the scene).
Let's quickly walk through your code:
try: doc.SearchObject("Spline").Remove() except: pass
You are not allowed to do this, nor is there a need to do so. Cinema takes care of this, actually you are rebuilding the same object in your Python Generator script.
spline = c4d.SplineObject(2, c4d.SPLINETYPE_LINEAR) pts = [c4d.Vector(), c4d.Vector(0, 200, 0)] spline.SetAllPoints(pts)
Almost all fine and dandy, in the end you will return this spline.
Be aware of the note on SetAllPoints() it needs to be followed by a MSG_UPDATE, like so:
spline.Message(c4d.MSG_UPDATE)
doc.InsertObject(spline) c4d.EventAdd()
Again, you are not allowed to do this. Neither the object insertion, nor the EventAdd(). And you don't need it, either, as Cinema will take care of inserting your spline into the scene, when you are returning it at the end of your script.
bs = doc.SearchObject("Spline").GetPointS() print bs.GetAll(2)
No need to search for the spline, you just created it, so simply use it. You want to select a point, do it like this:
bs = spline.GetPointS() bc.Select(1) # to select the second point in your spline
And then in the end:
return spline
So your script should actually look like this:
import c4d def main() : spline = c4d.SplineObject(3, c4d.SPLINETYPE_LINEAR) pts = [c4d.Vector(), c4d.Vector(0, 200, 0), c4d.Vector(200, 200, 0)] spline.SetAllPoints(pts) spline.Message(c4d.MSG_UPDATE) bs = spline.GetPointS() bs.Select(1) # select the second point return spline
As said in the beginning, you can also generate object hierarchies and you can also add tags to the generated objects.
I hope this helps a bit.
On 18/04/2016 at 11:37, xxxxxxxx wrote:
Now, that I'm thinking about it (sorry, I should have come up with this earlier), I'm not really sure, it will work to press the "Set Anchor" button from within a Python Generator. You might run into a limitation there, as user interaction is also one of the things, that usually aren't happening in GVO.
On 18/04/2016 at 11:45, xxxxxxxx wrote:
Thanks, Andreas.
I figured that some things would need to be added to the doc because I'm using spline dynamics. I never thought about spline dynamics working with python generated splines each frame... I've run into some dead object errors in the past when I tried carrying objects over into the next frame via global lists, but nevertheless I'll have to give this a shot. Everything I've come here to ask about has just been answered, it seems, so I'll give this a go shortly and post about how it goes. Many thanks for the help and additional tips! | https://plugincafe.maxon.net/topic/9445/12661_clicking-set-button-of-constraint-tag-from-pygen | CC-MAIN-2020-40 | refinedweb | 1,389 | 65.42 |
#include "lttwn.h"
L_LTTWN_API L_INT L_TwainAcquireList (hSession, hBitmap, lpszTemplateFile, uFlags)
Acquires one or more pages from a TWAIN source and stores the images in the specified bitmap list.
SUCCESS The function was successful.
! = SUCCESS An error occurred. Refer to Return Codes.
This function acquires one or more images from a TWAIN source and stores them in the specified bitmap list. If the user wants to acquire one or more images and process each one individually, he or she should use the L_TwainAcquire function an provide a LTWAINBITMAPCALLBACK function for processing each image.
The number of pages to acquire can be determined by getting the TWAIN source's capabilities. To change the number of pages to acquire, set the appropriate capability to the desired number.
The LTWAIN_KEEPOPEN flag works only in the following cases:
Required DLLs and Libraries
For an example, refer to L_IsTwainAvailable. | https://www.leadtools.com/help/leadtools/v19/twain/api/l-twainacquirelist.html | CC-MAIN-2018-13 | refinedweb | 143 | 55.54 |
MP4Optimize - Optimize the layout of an mp4 file
#include <mp4.h>
bool MP4Optimize(
const char* existingfileName,
const char* newfileName = NULL,
u_int32_t verbosity = 0
);
Upon success, true (1). Upon an error, false (0).
MP4Optimize reads an existing mp4 file and writes a new version of the file with the two important changes:
First, the mp4 control information is moved to the beginning of the file. (Frequenty it is at the end of the file due to it being constantly modified as track samples are added to an mp4 file.) This optimization is useful in that in allows the mp4 file to be HTTP streamed.
Second, the track samples are interleaved so that the samples for a particular instant in time are colocated within the file. This eliminates disk seeks during playback of the file which results in better performance.
There are also two important side effects of MP4Optimize():
First, any free blocks within the mp4 file are eliminated.
Second, as a side effect of the sample interleaving process any media data chunks that are not actually referenced by the mp4 control structures are deleted. This is useful if you have called MP4DeleteTrack() which only deletes the control information for a track, and not the actual media data.
MP4(3) | http://www.makelinux.net/man/3/M/MP4Optimize | CC-MAIN-2016-07 | refinedweb | 208 | 60.95 |
Introduction
Cryptocurrency serves as a digital asset and is a medium of exchange between individuals where coin ownership records are stored in a secure computerized database. They are named as such because complicated cryptography helps in creating and processing these digital currencies and transactions across decentralized systems.
Note: The article is written at the end of May 2021. Current conditions will be different.
Overview of Cryptocurrencies
Cryptocurrencies do not belong to any nation or so. Traditional currencies are usually related to the central banks of nations or the government, India has Indian Rupee, the USA has US Dollar, Japan has Yen, the EU has Euro and the list goes on.
(Image Source:)
Cryptocurrencies are designed to be free from the control of any Government or Central bank. The Crypto market has always been highly unstable and erratic and a variety of factors determine the overall direction.
Crypto Fall of May 2021
The Crypto market was on the rise in the pandemic season. Since mid-2020, almost all cryptocurrencies were on the rise. The social media was all buzzed up on bitcoin and the other cryptocurrencies.
Memes spread all over social media regarding the rise of cryptocurrencies. One of the major factors about the cryptocurrency trends was Elon Musk. In February 2021, Tesla bought $1.5 billion in bitcoin, and Elon musk even mentioned that Tesla would accept cryptocurrency as payment.
In early February 2021, the bitcoin price was about 32000 USD, and by February end, it had crossed 50000 INR. Elon Musk also added the hashtag #bitcoin to his Twitter bio, which did help in the rise of cryptocurrency prices.
The cryptocurrency had become the new “cool” thing among youngsters and people wanted to buy as much crypto as possible.
Dogecoin
Similarly, Dogecoin was another cryptocurrency that rose to fame was Dogecoin. In February 2021, when Elon Musk and many other celebrities tweeted about Dogecoin, the value of the coin shot up suddenly. And Dogecoin, unlike Bitcoin or Ethereum has technically no use. It is a meme cryptocurrency.
In 2013, a Japanese Shiba Inu dog was immensely viral and Dogecoin was started, as a joke. And it was just a fun experiment.
On 1st April 2021, Elon Musk tweeted that SpaceX will put a literal Dogecoin on the moon. This immediately became an internet meme, and the price of Dogecoin suddenly soared.
( Image Source:)
Images like this spread all over the internet. The world might have been physically apart due to the Covid19 pandemic, but through the internet, everyone was together. Bitcoin and Dogecoin gained the limelight and this ultimately pushed the prices of most other cryptocurrencies. People got hyped up that crypto is the new future and will replace traditional currencies soon.
Musk then tweeted SpaceX’snew satellite will be called Doge-1. In an unexpected move, it was also said that the entire mission will be paid in DogeCoin. This meant Doge would be the first cryptocurrency to contribute to space exploration and also be the first meme in space.
All this social media hype and jokes lead to an increase in prices in the whole crypto market.
The Great Crash:
On 13th May 2021, Elon Musk announced that Tesla will suspend Vehicle purchases using Bitcoin.
So what are these climate concerns?
Well, Bitcoin mining involves using high-powered computers to solve complex algorithms. This involves multiple computers and involves high electricity and bandwidth consumption.
On the other hand, China banned financial institutions and payment companies from providing services to buy/sell cryptocurrency or provide any other services. Investors were also warned against crypto trading.
A report from JP Morgan also mentioned that investors were moving away from Crypto and back to Gold. Many other factors also contributed, and suddenly the massive fall in cryptocurrency prices wiped out $1 trillion of wealth.
Let us try to look at the data of some important cryptocurrencies and have a look at what really happened.
Getting started with Python for Finance:
We will extract various crypto prices from Yahoo finance. Let us get started by importing the libraries.
import warnings warnings.filterwarnings('ignore') # Hide warnings import datetime as dt import pandas as pd pd.core.common.is_list_like = pd.api.types.is_list_like import pandas_datareader.data as web import numpy as np import matplotlib.pyplot as plt import seaborn as sns import matplotlib.dates as mdates
import plotly.express as px
start = dt.datetime(2021, 1, 1) end = dt.datetime(2021,5,29)
We set the starting and ending dates of the data.
btc = web.DataReader("BTC-USD", 'yahoo', start, end) # Collects data btc.reset_index(inplace=True)
Bitcoin
“BTC-USD” indicates Bitcoin prices in US dollars. So we extract bitcoin prices.
#bitcoin crypto= btc[['Date','Adj Close']] crypto= crypto.rename(columns = {'Adj Close':'BTC'})
# 7 day moving average crypto[ 'BTC_7DAY_MA' ] = crypto.BTC.rolling( 7).mean()
A rolling average or moving average is a way to analyze data points by creating a series of averages of the data already present in the data. Here we calculate average prices based on the previous 7 days’ data of Bitcoin price. Moving averages are often used in technical analysis.
To read more on moving averages, visit this link.
Ethereum
Next, we try Ethereum. Ethereum is the 2nd largest cryptocurrency by market cap, after bitcoin. Ethereum went live on 30 July 2015 with 72 million coins.
#Ethereum eth = web.DataReader("ETH-USD", 'yahoo', start, end) # Collects data eth.reset_index(inplace=True) crypto["ETH"]= eth["Adj Close"] # 7 day moving average crypto[ 'ETH_7DAY_MA' ] = crypto.ETH.rolling( 7).mean()
Dogecoin
Next up is Dogecoin. We already discussed Dogecoin. It was introduced on Dec 6, 2013.
#doge coin doge = web.DataReader("DOGE-USD", 'yahoo', start, end) # Collects data doge.reset_index(inplace=True) crypto["DOGE"]= doge["Adj Close"] # 7 day moving average crypto[ 'DOGE_7DAY_MA' ] = crypto.DOGE.rolling( 7).mean()
BinanceCoin
Next, we proceed with Binance Coin. Binance was launched in July 2017 and is based on the Ethereum network. But Binance has its own blockchain, the Binance chain.
#BinanceCoin bnb = web.DataReader("BNB-USD", 'yahoo', start, end) # Collects data bnb.reset_index(inplace=True) crypto["BNB"]= bnb["Adj Close"] # 7 day moving average crypto[ 'BNB_7DAY_MA' ] = crypto.BNB.rolling( 7).mean()
Cardano
Next, we take Cardano. Cardano is a public blockchain platform and peer-to-peer transactions are facilitated by its cryptocurrency ADA. It was launched in September 2017.
#Cardano ada = web.DataReader("ADA-USD", 'yahoo', start, end) # Collects data ada.reset_index(inplace=True) crypto["ADA"]= ada["Adj Close"] # 7 day moving average crypto[ 'ADA_7DAY_MA' ] = crypto.ADA.rolling( 7).mean()
Ripple is a payment system and currency exchange platform that can be used to process transactions all over the globe. XRP is deducted as a small fee, whenever users make a transaction using Ripple.
#XRP xrp = web.DataReader("XRP-USD", 'yahoo', start, end) # Collects data xrp.reset_index(inplace=True) crypto["XRP"]= xrp["Adj Close"] # 7 day moving average crypto[ 'XRP_7DAY_MA' ] = crypto.XRP.rolling( 7).mean()
Dash
Dash is an open-source cryptocurrency. It was forked from the Bitcoin protocol. It was launched in January 2014.
#Dash dash = web.DataReader("DASH-USD", 'yahoo', start, end) # Collects data dash.reset_index(inplace=True) crypto["DASH"]= dash["Adj Close"] # 7 day moving average
crypto[ ‘DASH_7DAY_MA’ ] = crypto.DASH.rolling( 7).mean()
Now, with the data at hand, we format the dates.
#getting the dates crypto.set_index("Date", inplace=True)
Now, let us have a look at the data.
crypto[['BTC','ETH','DOGE','BNB','ADA','XRP','DASH']].head()
As we can see all the data has been properly extracted.
Now, let us check the correlation between the data.
crypto[['BTC','ETH','DOGE','BNB','ADA','XRP','DASH']].corr()
Now, we have some interesting revelations. All the data points have a high correlation with each other. Let us just compare bitcoin to the others, even the lowest correlation with DOGE is 0.237, which is quite a good value. Dash being forked from BTC, has the highest correlation with BTC at 0.77.
Looking at other data points, BNB and XRP have a high correlation of 0.93 which is extremely high. It is as if, they are the same value.
Now let us understand why? Well, it is simple. The crypto market follows trends. When Bitcoin and Dogecoin were rising, other coins also increased in value. This was mainly due to public sentiment regarding crypto. Who doesn’t want to look cool in front of friends saying that they brought cryptocurrency?
And similarly, when the values of BTC and DOGE fell, others also fell. It was like a chain reaction.
Let us look at the correlation heatmap.
#heatmap plt.figure(figsize = (10,10)) sns.heatmap(crypto[['BTC','ETH','DOGE','BNB','ADA','XRP','DASH']].corr(),annot=True, cmap='Blues')
The heatmap clearly shows the high correlation between the prices of all cryptocurrencies.
Let us plot the data using Plotly express.
fig = px.line(crypto, y=["BTC",'ETH','DOGE','BNB','ADA','XRP','DASH'] ) fig.show()
Well, only the BTC crash in mid-May 2021 is clear. But let us have a look at BTC 7 day moving average values.
fig = px.line(crypto, y=['BTC_7DAY_MA'] ) fig.show()
An interesting thing about Plotly is that we can interact with the Plot and get the exact values, kind of like we can do in Power BI.
Here, it is clearly visible that the BTC price suddenly increased in Feb 2021 after all those tweets and social media buzz. And suddenly in May 2021, everything came crashing.
Let us try Ethereum.
fig = px.line(crypto, y=['ETH'] ) fig.show()
And, it is clear that ETH also follows a similar pattern. In April 2021 end, everyone saw the sudden rise in prices of BTC and DOGE and bought ETH. This led to a sudden increase in the price of ETH as well.
Moving Average values:
fig = px.line(crypto, y=['ETH_7DAY_MA'] ) fig.show()
The mountain fell down as quickly as it rose. People who bought at the high faced enormous losses.
DOGE:
fig = px.line(crypto, y=['DOGE'] ) fig.show()
The rise and fall of DOGE is also interesting. In Jan 2021, DOGE was nothing, and in early May 2021, it had risen a lot. And its fall was also sudden.
Moving Average Values:
fig = px.line(crypto, y=['DOGE_7DAY_MA'] ) fig.show()
The code for plotting all the other data is pretty much the same. I will leave a link to the Kaggle notebook where I coded all this in the end.
Conclusion
We now pretty much understand what caused the crash. The entire crypto market seems to related to each other. People see someone buying BTC, they go buy ETH. Someone sells DOGE, they also sell their BTC. It is all interrelated.
The crypto market is highly volatile, various factors lead to the frenzied selloff. One of the largest cryptocurrency exchanges in the world, Coinbase faced service disruptions during this selloff. Many Crypto investors had invested because they thought Tesla and Elon musk was into Bitcoin and thought of it as the next thing in finance and currency.
Many critics have said that this lack of regulation and price manipulation makes Crypto risky for new investors, and many people lost their money this fall.
Code Link: Analyzing the Crypto Crash of May 2021
| https://www.analyticsvidhya.com/blog/2021/05/analyzing-the-cryptocurrency-of-may-2021-python-for-finance-basics/ | CC-MAIN-2021-25 | refinedweb | 1,867 | 60.61 |
IWbemServices::DeleteInstance method
The IWbemServices::DeleteInstance method deletes an instance of an existing class in the current namespace.
Syntax
HRESULT DeleteInstance( const BSTR strObjectPath, long lFlags, IWbemContext *pCtx, IWbemCallResult **ppCallResult );
Parameters
strObjectPath
Valid BSTR containing the object path to the instance to be deleted.
lFlags
One of the following values are valid.
WBEM_FLAG_RETURN_IMMEDIATELY
This flag causes this to be a semisynchronous call. For more information, see Calling a Method.
pCtx
Typically NULL. Otherwise, this is a pointer to an IWbemContext object that may be used by the provider that is deleting the instance. The values in the context object must be specified in the documentation for the provider in question.
ppCallResult
If NULL, this parameter is not used. If ppCallResult is specified, it must be set to point to NULL on entry..
Return value
This method returns an HRESULT that indicates.
Remarks
The IWbemServices::DeleteInstance method is called to delete an existing instance in the current namespace. Instances in other namespaces cannot be deleted. When DeleteInstance is called to delete an instance that belongs to a class in a hierarchy, Windows Management calls the DeleteInstanceAsync method for all of the providers responsible for non-abstract classes in the hierarchy. That is, if the strObjectPath parameter identifies an instance of ClassB, and ClassB derives from ClassA, a non-abstract class, and is the parent class of ClassC and ClassD, also non-abstract classes, the providers for all four classes are called.
Windows Management calls each provider with an object path that is modified to point to their class. For example, if strObjectPath for the original call is set to "ClassB.k=1", the call to the provider of ClassA would set strObjectPath to "ClassA.k=1".
The success of a DeleteInstance call depends only on the success of a DeleteInstanceAsync call to the provider of the topmost non-abstract class. A non-abstract class has an abstract class as its parent. If the provider for any one of such classes succeeds, the operation succeeds; if all such classes fail, the operation fails.
For example, assume that ClassX is the base class for the following hierarchy:
- ClassA derives from ClassX.
- ClassB derives from ClassA.
- ClassC and ClassD derive from ClassB.
If ClassX, ClassA, and ClassB are all abstract and the strObjectPath parameter in DeleteInstance again points to an instance of ClassB, either the provider for ClassC or the provider for ClassD must succeed.
Requirements
See also
Describing an Instance Object Path
IWbemServices::DeleteInstanceAsync | https://docs.microsoft.com/en-us/windows/win32/api/wbemcli/nf-wbemcli-iwbemservices-deleteinstance?redirectedfrom=MSDN | CC-MAIN-2020-05 | refinedweb | 411 | 55.95 |
.
54 thoughts on “Tips and Tricks for the C Pre-processor”
I’ll be that old fart: the C preprocessor should be avoided as much as possible. It is legacy; the value it provides is relatively weak as far as generating code goes. For common uses, there are typesafe and namespace-friendly mechanisms to provide the same behavior with const, enum, and/or inline functions.
In this case, you dont need to wrap with a zany do {…}while(0). You can simply explicitly declare scope with {…}.
One of the few reasons is to use a macro is something like an ASSERT, where the macro can expand to include the file, line, function, expression, etc.
Save yourself the bugs, dont use macros!
I agree whole-heartedly.
My coworker and I work in embedded C regularly, and I find his code nearly impossible to read. The C preprocessor needs to die.
I don’t agree. I work in embedded C as well and I find that using #defines inside of the .c file (i.e., not in the header) for very simple macros (e.g., MIN/MAX) or constant values works great.
this is what enum is for
How do you use an enum to avoid using macros?
Honest question. As an engineer I know just enough c to be dangerous.
Here is the ADC channels on my circuit where 0-7 are hooked up to external hardware and 0x0e, 0x0f are internal to the chip.
enum ADC_HW_Channels { VBAT1, IBAT1, IBAT0, VBAT0, THERM1, THERM0, VIN, BUTTONS_IN, VBG=0x0e, VGND=0x0f };
It is very compact and also allow you to explicitly assign values. I also used enum as different states to my state machine.
You can write clear code using the preprocessor, and you can write the most impenetrable crap without it. Personally I use it (embedded C here as well), but I’m quite careful with how it’s applied.
I agree, I mainly use it for constants or to remove magic numbers and bitmath that makes more sense with a name than a load of logic and bit shift operations, but doesn’t need the overhead of calling a function.
Again, enum people
I agree that macros are to be avoided if possible. Especially ‘clever’ macros that would be much clearer as a function. The do {} while() wrapper is necessary though, see.
For example, if you just used {} scoping in the macros above, this code would not compile:
if (something)
uart1_reset();
else
something_else();
I’m glad you always get to work with a modern, working compiler that can do things like inline cleanly.
Some of us embedded guys are stuck with half-working pieces of crap where macros are the only way to inline code.
No compiler support for alternatives is a perfectly good reason to use preprocessor macros; it’s also a good reason to find another compiler :-)
If you have a compiler with good C++ support, then inline template functions are also interesting; you could ‘templatize’ the above to support generic UARTs and, again with a good compiler, suffer no extra code.
It’s easy enough to write a simple case and look at the object code generated.
Here’s a good intro on C++ ‘inline’ (not specific to embedded stuff) (sorry, don’t know how to drive links here…)
You don’t have to use the C preprocessor that comes with your development tools, you can use a better one instead and pipe the output into your old C compiler.
Just because it’s an antiquated concept doesn’t mean it’s functions are entirely replaced. In my shader system I have a file which uses the C pre-processor to construct the material based on parameters defined in the shader it’s used in. Used a similar thing when I made a small OS as a hobby venture, it’s a wonderful system when your dealing with static branching for each of a components uses.
If the C compiler honors the inline keyword, I’d use that over these macros … but if it doesn’t, and I’m even remotely concerned about performance, these macros are less ugly than the alternative.
Also: do {…} while 0 has a well-documented reason why you HAVE to do it that way (no semicolon) and can’t just use {}. JFGI.
That said, given the wrapped syntax, this looks like PIC stuff; be careful because at least on the lesser members of their product line, you can’t modify RXIF directly.
That reason being (mostly) that if people use an expandable macro after an if statement with no brackets bad things will happen. If the macro has its own semicolon and they add the macro with an extra semicolon that’ll cause more trouble.
The “inline” keyword does have it’s issues. GCC changed the inline keyword to be a hint instead of a forced action and gcc will inline and not-inline at will. Linux has a nice rant about it somewhere online.
(I still usually do inline functions instead of macros. But sometimes macros can do things that functions cannot)
Writing unmanageable code as demonstrated above keeps consultants like me in business.
Please, by all means, keep using CPP and remember — no comments.
; #)
There’s nothing ‘unmanageable’ about this code, and adding a comment for a single line macro that explains itself through the name only adds clutter.
C++ templates are better in every way. Once you try them you will never go back.
What makes C++ templates so much better than the examples using macros, or inline C functions ?
Are you saying you tried C++ templates and got back? :-)
Well, let’s compare the options: with macros, I need to end each end of line of my “inline function” with backslash character and make sure there aren’t any blanks (invisible, duh) on the line past them. Trivial, but burns my time unnecessarily. There is no type checking, which may look like a not big deal, since you generally define type as macro, but it won’t warn you if you use an identificator for type which is already assigned as something else.
Second option, inline functions: much better, no pesky backslashes, but you have to fix the types. OK, you can repeat the trick of defining types as macros, but it suffers the same drawback as previous option.
Third option, templates … hmm, I don’t like the syntax with “”, it stands out like a sore thumb, but watchya gonna do?
“” should contain less-then and greater-then characters to illustrate my (non-)point.
< >
I tried C++ for embedded software. At first I thought it was great, and then I started to look at all the code bloat that was generated under the hood. At first, I tried to remedy that with clever C++ tricks but I started to notice how much effort it was compared to just writing everything in C, so I went back.
Most of my C macros are just simple one-liners that don’t require backslashes. And the occasional macro that uses backslashes couldn’t be converted to C++ anyway.
stm32plus manages to get by with roughly 600 bytes of overhead for C++.
Maybe you should look at how they do it.
For backslash-free macros (Boost Method):
Place your macro function in its own header file, then define your macro like so:
#define MYMACRO() “mymacro.h”
Then call like this:
#include MYMACRO()
Arguments can be handled as follows:
MYMACRO_ARGUMENTS(A1, A2, A3)
#include MYMACRO()
Obviously this multiline approach may annoy some people. However, with “Large” macros, the benefit of macro readability is worth the visual warts….
“not liking syntax” is a pretty weak excuse. If you are thinking in terms of syntax instead of structure, you are not doing it right.
Except that templates make for horrible compiler errors/warnings, which makes them tricky to use (next to templates solving a totally different issues then inline functions and macros)
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\ext\new_allocator.h|83|error: ‘const _Tp* __gnu_cxx::new_allocator::address(__gnu_cxx::new_allocator::const_reference) const [with _Tp = const CSG::Vector; __gnu_cxx::new_allocator::const_pointer = const CSG::Vector*; __gnu_cxx::new_allocator::const_reference = const CSG::Vector&]’ cannot be overloaded|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\ext\new_allocator.h|79|error: with ‘_Tp* __gnu_cxx::new_allocator::address(__gnu_cxx::new_allocator::reference) const [with _Tp = const CSG::Vector; __gnu_cxx::new_allocator::pointer = const CSG::Vector*; __gnu_cxx::new_allocator::reference = const CSG::Vector&]’|
(if you try to make a std::vector)
You can certainly choose to go the route of failure like you did. Every language has features that will cause head-scratching and obscure error messages IF YOU CHOOSE TO GO THAT WAY.
Or you can treat templates as smarter macros and start simple and achieve smaller code size and reduced complexity.
You really need to surf over to Dr.Dobbs magazine and see how to actually use templates effectively. They have a series of articles on how to FFTs using C++ templates, their solution is faster than any known C implementation.
m4 is a pretty nice preprocessor for non-C code. A shell script with sed commands is not too bad either, depending on what you want to do.
C++ templates are nice except for the fact that they require C++, which is ugly. So the advantage of C++ templates are completely overwhelmed by the rubbish that is C++.
On the topic of not using C preprocessor, for embedded I consider it the way Linus considers C++ for systems programming: if you can’t understand my C preprocessor code, I don’t want you on the project anyway. Sorry, but it’s true. Good programs are good because they are written by good programmers, simple as that.
And good programmers don’t waste their time writing “efficient” code that a compiler will do for you and hide all of the gory details. In many cases C++ can be much more efficient especially if you’re trying to write generic, reusable code.
Only if a programmer doesn’t know what he’s doing, is C++ more efficient. And for hard real time embedded work, you don’t want to hide the gory details. You want them in plain sight, so you can verify that the program is correct.
You know what, you’re right. Lets go back to assembly!
Not at all. C is about optimal. It combines the convenience of a higher language, while still giving the (competent) programmer complete control and insight. With C++ too much happens under the hood, which is especially dangerous when dealing with code from somebody else. In C++, I have no idea what a = b + c means.
Slyclops: I had a pretty lucrative time as an embedded consultant, mostly thanks to people who care more about maintainability than actually getting the job done in the first place. So, company X would develop their FW using C++ best practices, and they would fail to meet benchmarks, and then they would hire me to undo it all and implement it in close-to-the-metal C.
Well best practices should have been in quotas there. If they really did, then they would not fail to meet the benchmarks. C++ is not only C with classes and there is no reason other than lack of knowledge that the end product be slower/bigger/etc compared to C.
I suggest those companies get their best practices right, i.e. take an embedded C++ training from Scott Meyers, for instance.
Of course C++ is not only the language specification but also the compiler and the standard library. There are now much more compact libraries like newlib and newlib-nano for use in embedded systems.
You DO NOT have to use C++ features, nobody is forcing you. You can write very efficient code in C++. You ARE NOT REQUIRED to write obfuscated C++ code. C++ is a SUPERSET of C, you are free to pick and choose which C++ features you use.
Yes it takes RESTRAINT to keep from going overboard and writing code where a = b+c is obfuscated. But it CAN be done. And you CAN enforce such restraint on your fellow developers.
Sure, it’s possible to use C++ as C, but then why not stick with C? And, I get the added advantage that C++ devs will be less inclined to pollute the codebase.
I don’t know C and don’t really have any intent to learn it, but I love reading about it. I’m especially a big fan of insane art-coding that uses pre-processor to implement the whole program.
If you want “insane art programming” for C++ then check out “template meta-programming” or extreme uses of operator overrides :-)
One very useful C preprocessor trick was not mentioned here: X macros:
Yup…. all the above posters write code. One can tell because to understand any more than 25% of the total postings requires excessive scrolling up and down in desperation trying to figure out what the heck is going on. Final confirmation comes from following the provided links for more information and this is as likely to confuse things more as it is to clear anything up. The quality of the programmer(s) (is|are) nearly proportional to the strength of headache you get making these almost futile attempts to understand what is going on, and your conclusion is pretty much confirmed if at the same time you feel like you’ve been watching Laurel and Hardy doing their “Who’s on first” routine!
It all makes me very happy to know a few programmers, (always great folk), and have just scant enough of my own coding skills to barely make my shiny new scratchbuilt widget board pound nails in like it should.
I understand aspirin a lot better since I met programmers!
your lack of understanding is somehow someone else’s fault.
Guess you must work in management?
Oh, I understand fully. Most of my coding was in machine code and assembly back in the late 70’s and it was just a required part of the electronics work cause ya haveta make the darn thing work once you designed and built it. What you all got now with C is a beautiful language but flush with so many features, conveniences, and capabilities that only a few can understand it all and make proper use of it, (as per testimony given in the thread) and it will drive the rest to baldness. I feel for ya. Only coding I do now is for personal entertainment and is FUN!
Management? Darn, no! Glass ceiling effect. Disqualified due to too much ability to produce actual usable $$$ work product without bs. Only perk I got was they assigned me a secretary so my time stopped being lost to paperwork, policies, and procedures.
F is a very smart person!
Biomed: You’re wrong – it wasn’t Laurel and Hardy – it was Abbott and Costello… :-)
Was wondering if anyone would catch that!
I don’t understand the big argument over assembly vs c vs c++.
Each language has good and bad features, and areas of application (Which do overlap).
I routinely use all three in my embedded projects, which lets me write better code, faster.
The same is said for using Macros vs Inline Functions vs Templates. They all have benefits, so I use them when they are needed :).
(I also use the BOOST Preprocessor Library, which helps with macro wizardry. Its also “documented”, and could be considered a “de-facto” standard)
There is a lot of the “I can’t figure out how to use it correctly, so therefore it is bad” mentality going on here.
There are a lot of those in the hardware world too. I have seen
“engineers” doing/avoid certain things to the point of superstitions.
Oh… it’s not superstition…. you’re seeing the effect of learning about anode-cathode potential by personal experience! The guy that influenced me most while learning was called “Fuzz” and he had an accuracy to within 10v over a 1500v range between two fingers. Had the shakes just about as much as some of the better programmers I know today but they lack the crew-cut.
You are exactly right. And then you have credible sources writing nonsense like this:.
I noticed one problem in this site – he doesn’t parenthesize macro arguments.
#define foo(x) ((x)*3)
Why? Because of things like this, which don’t work properly:
foo(y+2)
Without the parens, that expans to:
(y+2*3), which clearly is not what you want.
With parens, it expands to:
((y+2)*3), which is probably what you want.
Other suggestions: macros should only use their arguments once, and arguments to macros should never contain side effects (pre or post increment), for example:
#define foo(x) ((x)*(x))
What happens when you call:
foo(x++)
LIkewise, make your macro names all caps so you know they are macros.
#define FOO(x) (x*3) | https://hackaday.com/2013/10/17/tips-and-tricks-for-the-c-pre-processor/ | CC-MAIN-2017-43 | refinedweb | 2,847 | 70.94 |
How to: Define a Custom Modeling Toolbox Item
To make it easy to create an element or group of elements according to a pattern that you often use, you can add new tools to the toolbox of modeling diagrams in Visual Studio Ultimate. You can distribute these toolbox items to other Visual Studio Ultimate users.
A custom tool creates one or more new elements in a diagram. You cannot create custom connection tools.
For example, you could make a custom tool to create elements such as these:
A package linked to the .NET profile, and a class with the .NET stereotype.
A pair of classes linked by an association to represent the Observer pattern.
You can use this method to create element tools. That is, you can create tools that you drag from the toolbox onto a diagram. You cannot create connector tools.
To define a custom modeling tool
Create a UML diagram that contains an element or group of elements.
These elements can have relationships between them, and can have subsidiary elements such as ports, attributes, operations or pins.
Save the diagram using the name that you want to give the new tool. On the File menu, use Save…As.
Using Windows Explorer, copy the two diagram files to the following folder or any subfolder:
YourDocuments \Visual Studio 2012\Architecture Tools\Custom Toolbox Items
Create this folder if it does not already exist. You might have to create both Architecture Tools and Custom Toolbox Items.
Copy both diagram files, one with a name that ends "…diagram" and the other with a name that ends "…diagram.layout"
You can make as many custom tools as you like. Use one diagram for each tool.
(Optional) Create a .tbxinfo file as described in How to Define the Properties of Custom Tools, and add it to the same directory. This allows you to define a toolbox icon, tooltip, and so on.
A single .tbxinfo file can be used to define several tools. It can refer to diagram files that are in subfolders.
Restart Visual Studio. The additional tool will appear in the toolbox for the appropriate type of diagram.
A custom tool will replicate most of the features of the source diagram:
Names. When an item is created from the toolbox, a number is added to the end of the name if necessary to avoid duplicate names in the same namespace.
Colors, sizes and shapes
Stereotypes and package profiles
Property values such as Is Abstract
Linked work items
Multiplicities and other properties of relationships
The relative positions of shapes.
The following features will not be preserved in a custom tool:
Simple shapes. These are shapes that are not related to model elements, that you can draw on some kinds of diagrams.
Connector routing. If you route connectors manually, the routing will not be preserved when your tool is used. The positions of some nested shapes, such as Ports, are not preserved relative to their owners.
A toolbox information (.tbxinfo) file allows you to specify a toolbox name, icon, tooltip, tab, and help keyword for one or more custom tools. Give it any name, such as MyTools.tbxinfo.
The general form of the file is as follows:
<?xml version="1.0" encoding="utf-8" ?> <customToolboxItems xmlns=""> <customToolboxItem fileName="MyObserverTool.classdiagram"> <displayName> <value>Observer Pattern</value> </displayName> <tabName> <value>UML Class Diagram</value> </tabName> <image><bmp fileName="ObserverPatternIcon.bmp"/></image> <f1Keyword> <value>ObserverPatternHelp</value> </f1Keyword> <tooltip> <value>Create a pair of classes</value> </tooltip> </customToolboxItem> </customToolboxItems>
The value of each item can be either:
As shown in the example, <bmp fileName="…"/> for the toolbox icon and <value>string</value> for the other items.
- or -
<resource fileName="Resources.dll"
baseName="Observer.resources" id="Observer.tabname" />
In this case, you supply a compiled assembly in which the string values have been compiled as resources.
Add a <customToolboxItem> node for each toolbox item you want to define.
The nodes in the .tbxinfo file are as follows. There is a default value for each node.
You can edit the bitmap file in Visual Studio, and set its height and width to 16 in the Properties window.
You can distribute toolbox items to other Visual Studio users by packaging them into a Visual Studio Extension (VSIX). You can package commands, profiles, and other extensions into the same VSIX file. For more information, see Deploying Visual Studio Extensions.
The usual way to build a Visual Studio extension is to use the VSIX project template. To do this, you must have installed Visual Studio SDK.
To add a Toolbox Item to a Visual Studio extension
Create and test one or more custom tools.
Create a .tbxinfo file that references the tools.
Open an existing Visual Studio extension project.
- or -
Define a new Visual Studio extension project.
On the File menu, choose New, Project.
In the New Project dialog box, under Installed Templates, choose Visual C#, Extensibility, VSIX project.
Add your toolbox definitions to the project. Include the .tbxinfo file, the diagram files, bitmap files, and any resource files, and make sure that they are included in the VSIX.
In Solution Explorer, on the shortcut menu of the VSIX project, choose Add, Existing Item. In the dialog box, set Objects of Type: All Files. Locate the files, select them all, and then choose Add.
Set the following properties of all the files that you have just added. You can set their properties at the same time by selecting them all in Solution Explorer. Be careful not to change the properties of the other files in the project.
Copy to Output Directory = Copy Always
Build Action = Content
Include in VSIX = true
Open source.extension.vsixmanifest. It opens in the extension manifest editor.
Under Metadata, add a description for the custom tools.
Under Assets, choose New and then set the fields in the dialog as follows:
Type = Custom Extension Type
Type = Microsoft.VisualStudio.ArchitectureTools.CustomToolboxItems
Source = File on filesystem.
Path = your .tbxinfo file, for example MyTools.tbxinfo
Build the project.
To verify that the extension works, press F5. The experimental instance of Visual Studio starts.
In the experimental instance, create or open a UML diagram of the relevant type. Verify that your new tool appears in the toolbox and that it creates elements correctly.
To obtain a VSIX file for deployment: In Windows Explorer, open the folder .\bin\Debug or .\bin\Release to find the .vsix file. This is a Visual Studio Extension file. It can be installed on your computer, and also sent to other Visual Studio users.
To install custom tools from a Visual Studio Extension
Open the .vsix file in Windows Explorer or in Visual Studio.
Choose Install in the dialog box that appears.
To uninstall or temporarily disable the extension, open Extension Manager from the Tools menu.
You can make an extension that, when it is installed on another computer, will display tool names and tooltips in the language of the target computer.
To provide versions of the tool in more than one language
Create a Visual Studio Extension project that contains one or more custom tools.
In the .tbxinfo file, use the resource file method to define the tool's displayName, toolbox tabName, and the tooltip. Create a resource file in which these strings are defined, compile it into an assembly, and refer to it from the tbxinfo file.
Create additional assemblies that contain resource files with strings in other languages.
Place each additional assembly in a folder whose name is the culture code for the language. For example, place a French version of the assembly inside a folder that is named fr.
You should use a neutral culture code, typically two letters, not a specific culture such as fr-CA. For more information about culture codes, see CultureInfo.GetCultures method, which provides a complete list of culture codes.
Build the Visual Studio Extension, and distribute it.
When the extension is installed on another computer, the version of the resource file for the user's local culture will be automatically loaded. If you have not provided a version for the user's culture, the default resources will be used.
You cannot use this method to install different versions of the prototype diagram. The names of elements and connectors will be the same in every installation.
Ordinarily, in Visual Studio, you can personalize the toolbox by renaming tools, moving them to different toolbox tabs, and deleting them. But these changes do not persist for custom modeling tools created with the procedures that are described in this topic. When you restart Visual Studio, custom tools will reappear with their defined names and toolbox locations.
Furthermore, your custom tools will disappear if you perform the Reset Toolbox command. However, they will reappear when you restart Visual Studio. | http://msdn.microsoft.com/en-us/library/vstudio/ee292090.aspx | CC-MAIN-2014-15 | refinedweb | 1,454 | 57.87 |
Last updated by admin 4 years ago
Auto ReloadingWhen a Grails application is executed via the 'grails run-app' command it is configured for auto-reloading (development mode). This mode is disabled when a WAR is created via the 'grails war' command.Most Grails artifacts (controllers, tag libs, services etc.) are reloadable in Grails, however there are some quirks:
def testService // works TestService testService // will thrown an error when reloading
-
- In Grails 0.6 and beyond, classes under src/java and src/groovy are reloaded, but the way this work is the run a continuous look that checks for changes and then restarts the container. On slower machines this can be quite processor intensive and can also result in occasional OutOfMemory or OutOfPermGenSpace type errors. If you don't want this feature then you can disable it with:
grails -Ddisable.auto.recompile=true run-app | http://www.grails.org/Auto+Reloading | crawl-003 | refinedweb | 145 | 52.09 |
When considering optimisation of multiple objectives, the Pareto front is that collection of points where one objective cannot be improved without detriment to another objective*. These points are also called ‘non-dominated’. In contrast, points not on the Pareto front, or ‘dominated’ points represents points where it is possible to improve one or more objectives without loss of performance of another objective.
*An example of this type of problem is the planning of emergency department (ED) services. Ideally we all like to be close to an ED, but we also want that ED to be large enough to sustained 24/7 consultant physician presence. So we might for example have two objectives: the proportion of patients living with 30 minutes of an ED, and the proportion of patients who attend an ED with 24/7 consultant presence. The more EDs we have in England the more patients will be within 30 minutes of one, but as we plan for more EDs those EDs get smaller and fewer will be able to sustain 24/7 consultant presence. We may be interested in seeing the nature of the trade-off. We therefore explore lots of potential solutions (i.e. change the number and location of ED departments) and we identify the Pareto frontier.
Here we present code to identify points on the Pareto front. We will use an example with just two objectives (as that is easy to visualise) but the Pareto front principle works for any number of simultaneous objectives.
import numpy as np import pandas as pd import matplotlib.pyplot as plt # Some dummy data: Each item has two scores scores = np.array([[97, 23], [55, 77], [34, 76], [80, 60], [99, 4], [81, 5], [ 5, 81], [30, 79], [15, 80], [70, 65], [90, 40], [40, 30], [30, 40], [20, 60], [60, 50], [20, 20], [30, 1], [60, 40], [70, 25], [44, 62], [55, 55], [55, 10], [15, 45], [83, 22], [76, 46], [56, 32], [45, 55], [10, 70], [10, 30], [79, 50]])
And now let’s plot that data.
x = scores[:, 0] y = scores[:, 1] plt.scatter(x, y) plt.xlabel('Objective A') plt.ylabel('Objective B') plt.show()
Now we will define our function to identify those points that are on the Pareto front. We start off by assuming all points are on the Pareto front and then change the status of those that are not on the Pareto front. We use two loops. The outer loop (‘i’) will loop through all points in order to compare them to all other points (the comparison is made using the inner loop, ‘j’). For any given point ‘i’, if any other point is at least as good in all objectives and is better in one, that point ‘i’ is known as ‘dominated’ and is not on the Pareto front. As soon as a better point is found another (point is at least as good in all objectives and is better in one), point i is marked as not on the Pareto front and the inner loop can stop.
The function returns the index numbers of points in the original array that are on the Pareto front.
def identify_pareto(scores): # Count number of items population_size = scores.shape[0] # Create a NumPy index for scores on the pareto front (zero indexed) population_ids = np.arange(population_size) # Create a starting list of items on the Pareto front # All items start off as being labelled as on the Parteo front pareto_front = np.ones(population_size, dtype=bool) # Loop through each item. This will then be compared with all other items for i in range(population_size): # Loop through all other items for j in range(population_size): # Check if our 'i' pint is dominated by out 'j' point if all(scores[j] >= scores[i]) and any(scores[j] > scores[i]): # j dominates i. Label 'i' point as not on Pareto front pareto_front[i] = 0 # Stop further comparisons with 'i' (no more comparisons needed) break # Return ids of scenarios on pareto front return population_ids[pareto_front]
We’ll now apply the function and print out our Pareto front index numbers and scores.
pareto = identify_pareto(scores) print ('Pareto front index vales') print ('Points on Pareto front: \n',pareto) pareto_front = scores[pareto] print ('\nPareto front scores') print (pareto_front) OUT: Pareto front index vales Points on Pareto front: [ 0 1 3 4 6 7 8 9 10] Pareto front scores [[97 23] [55 77] [80 60] [99 4] [ 5 81] [30 79] [15 80] [70 65] [90 40]]
To aid plotting, we’ll sort our Pareto front scores in ascending oder of first item. We’ll use a Pandas DataFrame to make sorting easy.
pareto_front_df = pd.DataFrame(pareto_front) pareto_front_df.sort_values(0, inplace=True) pareto_front = pareto_front_df.values
And now we can print plot our data again, showing the Pareto front.
x_all = scores[:, 0] y_all = scores[:, 1] x_pareto = pareto_front[:, 0] y_pareto = pareto_front[:, 1] plt.scatter(x_all, y_all) plt.plot(x_pareto, y_pareto, color='r') plt.xlabel('Objective A') plt.ylabel('Objective B') plt.show()
3 thoughts on “93. Exploring the best possible trade-off between competing objectives: identifying the Pareto Front” | https://pythonhealthcare.org/2018/09/27/93-exploring-the-best-possible-trade-off-between-competing-objectives-identifying-the-pareto-front/ | CC-MAIN-2020-29 | refinedweb | 845 | 61.36 |
On Tue, Aug 14, 2012 at 12:22:49PM -0400, Mark Salter wrote:> On Tue, 2012-08-14 at 23:34 +0800, Fengguang Wu wrote:> > Sorry I have no compilers for build testing these changes, however the> > risk looks low and it's much better than to leave the arch broken,> > considering that Eric will do atomic64_t in the core fs/namespace.c> > code.> > > > CC: "Eric W. Biederman" <ebiederm@xmission.com>> > Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>> > ---> > > > Andrew: the arch maintainers have been CCed. Best is the maintainers> > respond, test and perhaps take the corresponding change. Let's see how> > this will work out..> > > > > > arch/c6x/Kconfig | 1 +> > The c6x port also needs this:> > C6X: add L*_CACHE_SHIFT defines> > C6X currently lacks L*_CACHE_SHIFT defines which are used in a few> places in the generic kernel. This patch adds those missing defines.> > Signed-off-by: Mark Salter <msalter@redhat.com>Thanks for the quick fix! git grep shows this: lib/atomic64.c: addr >>= L1_CACHE_SHIFT;So this patch is a prerequisite for the GENERIC_ATOMIC64 patch.git grep also shows arch/score/include/asm/cache.h:#define L1_CACHE_SHIFT 4 arch/unicore32/include/asm/cache.h:#define L1_CACHE_SHIFT (5)So the other two archs are fine.Thanks,Fengguang | http://lkml.org/lkml/2012/8/14/651 | CC-MAIN-2015-06 | refinedweb | 208 | 68.87 |
Cachectl Syscall
From LinuxMIPS
NAME
cachectl - control cachebility of memory areas
SYNOPSIS
#include <sys/cachectl.h> int cachectl (void *addr, size_t nbytes, int op);
DESCRIPTION
The cachectl syscall allows a process to control cachebility of it's address space at page granularity. Cachability is initially choosen by a heuristc at mmap mmap time. The op parameter may be one of:
- CACHEABLE
- Make the indicated area cacheable
- UNCACHEABLE
- Make the indicated area uncacheable
RETURN VALUE
- EINVAL
- the op argument was none of CACHABLE and UNCACHEABLE or was not acceptable due to special hardware constraints or the address range specified by addr and nbytes was not page aligned.
HISTORY
A cachectl syscall appeared in RISC/OS and later in IRIX. It differs in taking an int for the nbytes argument.
BUGS
Even though the syscall is part of the kernel's syscall interface since the earliest days of Linux it has never actually been implemented since the defaults used by mmap seem to work sufficiently well. | http://www.linux-mips.org/wiki?title=Cachectl_Syscall&oldid=2829 | CC-MAIN-2015-18 | refinedweb | 164 | 56.89 |
Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Namespaces and Routes4:19 with Naomi Freeman
Our API is going to live under the "API" namespace in our application. In this video, we'll see how to apply namespaces in our rails routes.
Setting up the Project
Please see the following guide to download and install the Treehouse Virtual Machine to follow along with this course:
Treehouse VM Installation
Code Samples
Namespace a series of routes in a rails application:
namespace :api do resources :todo_lists end
The above snipped of code, which belongs in config/routes.rb, creates namespaced routes in a Rails application. The routes nested under the
api namespace above would all live in
/api/todo_lists.
- 0:01
To begin our API, we are going to create a namespace for it in our routes.
- 0:06
Namespacing is one way to uniquely identify things.
- 0:09
We can namespace our API routes to keep them separate from
- 0:12
other routes in our app.
- 0:14
This would make everything in the API name space live under /API.
- 0:19
So lets go into our routes file, which is under config > routes.
- 0:26
To namespace, we will begin by adding namespace,
- 0:31
followed by the name of the namespace we would like to create.
- 0:34
In our case, this is api.
- 0:37
It follows the same pattern as the resources block, so we add in do and end.
- 0:43
Now if we went and did rake routes,
- 0:44
we wouldn't see any changes because the namespace is still empty.
- 0:48
So, let's add some resources so that there's something in our namespace.
- 0:53
To do that, we're just going to type resources, todo_lists.
- 0:59
We already have a todo_lists resource below, but what this is going
- 1:02
to do is create a resource below the API namespace we just created.
- 1:06
So this will live at /api/todo_lists.
- 1:10
Now if we go and rake routes now and
- 1:15
scroll up to the top, you'll see that we have done something.
- 1:19
You'll see there are many new routes there that weren't there before,
- 1:22
all beginning with api followed by /todo_lists, and
- 1:27
then with all the URIs we had in our original routes.
- 1:31
Now, it's not quite enough to just add the namespacing in the routes.
- 1:35
What we've done is defined a URL, but nothing exists there yet.
- 1:40
We will have to create an API directory, and add some files to it.
- 1:44
I'm using Sublime Text, but you don't have to.
- 1:47
In fact, your editor may have a different way of accomplishing the same thing.
- 1:52
In your text editor, go to the directory on the far left,
- 1:55
into app > controllers, and then you're going to create a new
- 2:00
directory by right-clicking controllers and going into New Folder.
- 2:04
The new directory name will open as a box at the very bottom of your text editor.
- 2:08
Name this directory API and hit Enter.
- 2:13
Now that we have a directory for our API, let's create some files to put in it.
- 2:18
Let's go back to where we just created that API folder and
- 2:21
create the API todo_lists_controller.
- 2:24
We already have a todo_lists_controller, but this one will be inside our API.
- 2:28
Right click your API directory and select New File.
- 2:33
Then save the file as todo_lists_controller,
- 2:37
and note that is inside the API directory.
- 2:40
Now that we have a file, let's add some code.
- 2:45
We're going to set this up like any other controller class,
- 2:51
which will inherit from our application controller.
- 2:56
But since we're inside of the API namespace,
- 2:58
we need to tell this todo_lists_controller to be inside of the API namespace as well.
- 3:03
So we do that, by adding, API.
- 3:08
Make sure you remember both colons here.
- 3:12
We need to start building our API at some point, so a good point to start is by
- 3:15
getting it to return all of the to do lists in the application.
- 3:19
We will do that inside of an index method.
- 3:22
This is just like any other index method you've set up in other controllers.
- 3:27
Now, we want to return all of the to do lists, so
- 3:29
we would do that by typing the following.
- 3:31
TodoList.all.
- 3:35
And we need to send that back to people.
- 3:37
We're going to do that in JSON format, so we're going to use the render method
- 3:41
to send back a JSON collection of thes to do lists.
- 3:45
We're just going to add render json.
- 3:49
So, now we're going to make sure all this works and check it out in our browser.
- 3:53
First, let's make sure our server is running.
- 4:00
And then we'll go to localhost:3000/api/todolists.
- 4:06
And since it's in the JSON format, we'll have to add .json, then it should render.
- 4:13
Yay!
- 4:13
Great work, everyone!
- 4:15
In the next video,
- 4:16
we're going to learn a bit about the curl command in the terminal. | https://teamtreehouse.com/library/build-a-rails-api/namespacing-routes-and-json/namespaces-and-routes | CC-MAIN-2019-09 | refinedweb | 961 | 80.72 |
Opened 5 years ago
Closed 5 years ago
Last modified 5 years ago
#28058 closed Bug (fixed)
Empty Select widget (no choices) evaluates to False
Description (last modified by )
Hey guys,
I'm not sure I catched a bug, but I discovered a change between
Django==1.10.6 and 1.11.
When you initialize a form with a
Select widget, and the select widget has no choices (basically an empty tuple), when evaluating the field with
bool(), it will evaluate to
False. This causes the
django_widget_tweaks module not to render a widget when trying to modify it from within a template, as it uses a bool-like evaluation to check if anything is passed to the set_attr.
code to reproduce:
from django import forms class MyForm(forms.Form): select = forms.ChoiceField(choices=()) x = MyForm() for item in x: print(bool(item))
It will print
True with
Django==1.10.6, and
False with
Django==1.11.
The underlying problem is that
len() for a Boundfield with no choices will return 0 in the newer version, whereas it returns 1 in the older version.
the template code that fails to render with
Django==1.11
{{ widget|set_attr('style:width: 100%') }}
Like I said, I'm not sure if this change is intended, nevertheless I reported it. Please let me know if this is intended, so I can let the creator of
django_widget_tweaks know.
Cheers
Bisected to b52c73008a9d67e9ddbb841872dc15cdd3d6ee01 (template-based widget rendering) though I haven't identified the cause of the change. | https://code.djangoproject.com/ticket/28058 | CC-MAIN-2022-40 | refinedweb | 251 | 62.27 |
> Hello, World Again! krabhishek 2011-05-30T23:07:04+00:00 2011-05-30T23:07:04+00:00 <p><p>It is nice to be back on blogs.. it's been ages since I wrote my last entry and when I did, it was a <a href="">blogs.sun.com</a> blog.. now its on <a href="">blogs.oracle.com</a>! So a welcome change. I intend to keep the blogs updated so stay tuned.. And just for a kicker, check out this lovely <a href="" target="_blank" title="Crossbow VNIC Demo">wiki</a> which eloquently demonstrate the capabilities of Crossbow, the newest kid in the Solaris town. And while going through this, you may as well want to download the "Network in the Box" Virtual Machine from OTN by going <a href="" target="_blank" title="Network in a Box Virtual Machine">here</a>. </p><br/> <p>Have any questions about Network Virtualization with Solaris 11? Just drop a comment below and let us get the discussion started! <img src="" class="smiley" alt=":-)" title=":-)" /> <br /></p></p> Deep Dive into what is new in Solaris 11 Express - Sysadmin wise! krabhishek 2010-11-20T03:07:20+00:00 2010-11-20T11:20:18+00:00 <p><p>Solaris 11 Express is <a href="" target="_blank" title="Click to download Solaris 11 Express">now here for you to download</a>!!</p> <br/> <p><object height="322" width="486"="322" width="486" src="" bgcolor="#FFFFFF" flashvars=" base="" name="flashObj" seamlesstabbing="false" type="application/x-shockwave-flash" allowfullscreen="true" swliveconnect="true" allowscriptaccess="always" pluginspage="" /></object></p> <br/> <p>This video is full of use cases and I strongly recommend you to watch the video if you want to learn more about how you and your organization can take advantage of the new features of Solaris 11 Express.</p> <br/> <p>Just to give you a peek: Some of the features discussed in this video include</p> <br/> <ul> <br/> <li>Solaris 11 Express can send you an email notification if a software of a hardware fails</li> <br/> <li>How you can export a physical Solaris 10 instance into a Solaris 11 Express zone and run it without any modification</li> <br/> <li>How you can do upgrades on Solaris 11 Express with a single command! </li> <br/> </ul>And of course, much more! Enjoy! And for more such informative videos, check out the <a href="" target="_blank" title="Oracle Solaris Video blog!">Oracle Solaris Video</a> blog!<br /></p> My new start at Sun/Oracle krabhishek 2010-10-26T17:16:45+00:00 2010-10-27T00:16:46+00:00 <p><p. </p><br/> <p!! <img src="" class="smiley" alt=";)" title=";)" /><br /></p><br/> <p> I am super excited about this new role and I am looking forward to go out in the field and do the thing that I like the most - advocating Sun (and now Oracle) technologies!!! <img src="" class="smiley" alt=":-)" title=":-)" /></p><br/> <p>Keep tuned to this blog as through this blog, I would now be sharing what I learn about systems!</p><br/> <p>Cheers! <br /></p></p> Using DTrace to profile function flows in your C programs krabhishek 2010-08-26T23:32:11+00:00 2010-08-27T06:32:11+00:00 <p><p>Quite often, you may would have come across scenarios where you would want to prepare a trace of your own program and understand what is the execution flow of a particular function in your C program. In this example I will show you how exactly you can do that using DTrace.</p> <br/> <p> </p> <br/> <p>Here is a simple C Program which implements two functions (add and sub).</p> <br/> <p> <font face="courier new,courier,monospace">#include <stdio.h><br />int add(int a, int b);<br />int sub(int a, int b);<br />int main()<br />{<br /> int a;<br /> int b;<br /> int c;<br /> printf("\\nEnter A and B: "<img src="" class="smiley" alt=";)" title=";)" />;<br /> scanf("%d%d", &a, &b);<br /> c = add(a, b);<br /> printf ("\\n Val - %d", c);<br /> <br />}<br /><br />int add(int a, int b)<br />{<br /> return (sub(a, b));<br /> <br />}<br /><br />int sub(int a, int b)<br />{<br /> int c = a - b;<br /> return (c);<br />}</font></p> <br/> <p>Now I would like to trace the function add in this program and see what functions, in turn, are invoked when add is executed.</p> <br/> <p> </p> <br/> <p>DTrace Code:</p> <br/> <p><font face="courier new,courier,monospace">pid$1:test:$2:entry<br />{<br /> self->trace = 1;<br />}<br /><br />pid$1::$2:return<br />/self->trace/<br />{<br /> self->trace = 0;<br />}<br /><br />pid$1:::entry,<br />pid$1:::return<br />/self->trace/<br />{<br />}</font></p> <br/> <p> </p> <br/> <p>I will my binary test (using -o flag) and I will be exacuting this<br/> binary by ./test. In another terminal, I will execute this DTrace<br/> script, which uses the <a target="_blank" href="">pid</a> provider.<br/> Notice the probe description, the module part of it carries the name of<br/> my program binary (this way only those function calls made in the<br/> context of my program will be traced. If you leave the module part<br/> blank in the probe description, all function calls (including system<br/> calls) will be included in the trace).</p> Let us compile this application (I am using Sun compiler, you can use gcc as well)</p> <p> <p><font face="courier new,courier,monospace">kumar@sunsolaris:~/Desktop$ cc -o test myc.c</font></p> <br/> <p>Now let us run the DTrace script in another terminal window:</p> <br/> <p> <font face="courier new,courier,monospace">kumar@sunsolaris:~/Desktop$ dtrace -F -s myfunc.d `pgrep test` add</font><br /></p> <br/> <p> </p><br/> <p> And here is the output:</p> <br/> <p> <img border="2" align="middle" height="521" width="831" src="/krabhishek/resource/userfunction.png" /></p> <br/> <p>As you can see, the script tells me that add function calls sub. Just imagine your C application having 1000 functions, and the simplicity that you can bring to the whole debugging process if you can understand the flow with this ease.</p> <br/> <p> </p> <br/> <p> </p></p> What Sun means to me... krabhishek 2010-02-16T10:39:55+00:00 2010-02-16T18:42:45+00:00 <p><p...</p> <br/> <p><object height="340" width="560"><param name="movie" value="" /><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><embed height="340" width="560" src="" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" /></object><br /!<br /></p></p> Fast Track to OpenSolaris minibook - Now available for download krabhishek 2010-02-10T08:26:39+00:00 2010-09-06T09:25:12+00:00 <p><b>EDIT: </b>If you are having troubles downloading the PDF of the book from Scribd, you can download it from my personal server (follow <a href="" target="_blank" title="Click to download Fast Track to OpenSolaris PDF">this link</a>). </p> <p>Last month was pretty happening. I, in capacity of being leader for Mumbai OpenSolaris User Group (<a href=""></a>), spent last month working with the editorial team of Digit Magazine (<a href="" target="_blank" title="Digit's website"></a>).<br /></p> <p>Now Fast Track to OpenSolaris is available for download: <a href="" target="_blank" title="Read Fast Track to OpenSolaris online"></a> </p> <p><a title="View Fast Track to OpenSolaris;">Fast Track to OpenSolaris</a> <object width="100%" height="600" id="doc_766219790383219" name="doc_766219790383219" type="application/x-shockwave-flash" data="" style="outline-color: -moz-use-text-color; outline-style: none; outline-width: medium;"> <param name="movie" value="" /> <param name="wmode" value="opaque" /> <param name="bgcolor" value="#ffffff" /> <param name="allowFullScreen" value="true" /> <param name="allowScriptAccess" value="always" /> <param name="FlashVars" value="document_id=26659478&access_key=key-zcuq4hmhfxs42ig6f6o&page=1&viewMode=list" /> </object><br /></p> <p>Digit and Mumbai OSUG are jointly running a online Quiz competition (OpenSolaris Geek Hunt) at <a href=""></a> Participate in this quiz to test your OpenSolaris skills and even win a Acer Aspire One Netbook, 1 TB or 500 GB external hard disk and many more OpenSolaris goodies!</p> <p align="center"> <img alt="OpenSolaris Geek Hunt" src="" /></p> <p align="left"> </p> <p> <br /></p> !<br /></p> What happens under the hood when you execute your C Programs? krabhishek 2009-12-20T02:21:09+00:00 2009-12-20T10:21:47+00:00 <p><p>I was a little curious to find out how my program gets executed. In order to find that out, I decided to write a simple c program which is here:</p> <br/> <blockquote> <br/> <p><font face="courier new,courier,monospace"> #include <stdio.h><br />int main()<br />{<br /> sleep(30);<br /> printf("Just testing an application!");<br />}</font></p> <br/> </blockquote> <br/> <p>I have kept the sleep(30) in the beginning of the program so as to give me time to execute the DTrace script, about which I will be talking a little later. <br /></p> <br/> <p>Now i complied it with Sun Compiler and GCC<br /></p> <br/> <blockquote> <br/> <p> <font face="courier new,courier,monospace">kumar@myosbox:~/Desktop/Demos$ suncc -o sunCCOutput simplec.c </font></p> <br/> <p><font face="courier new,courier,monospace">kumar@myosbox:~/Desktop/Demos$ gcc -o gccOutput simplec.c </font></p> <br/> </blockquote> <br/> <p>Now I wrote a simple DTrace script using the pid provider in order to figure out how printf is implemented (execution detail - functions which get invoked when printf function is called) in these compilers. The dtrace script is below:</p> <br/> <blockquote> <br/> <p><font face="courier new,courier,monospace">pid$1::$2:entry<br />{<br /> self->trace = 1;<br />}<br /><br />pid$1::$2:return<br />/self->trace/<br />{<br /> self->trace = 0;<br />}<br /><br />pid$1:::entry,<br />pid$1:::return<br />/self->trace/<br />{<br />}</font></p> <br/> </blockquote> <br/> <p>Now it was the time to execute this script and compare the outputs. I am going to redirect the output of this script into two text files (sunCCOutput.txt and gccOutput.txt).</p> <br/> <blockquote> <br/> <pre><font face="courier new,courier,monospace" size="2">kumar@myosbox:~/Desktop/Demos$ ./sunCCOutput <br/> kumar@myosbox:~/Desktop/Demos$ pfexec dtrace -F -s pid.d `pgrep sunCCOutput` printf > SunCCOutput.txt<br/> dtrace: script 'pid.d' matched 6712 probes<br/> kumar@myosbox:~/Desktop/Demos$ ./gccOutput <br/> kumar@myosbox:~/Desktop/Demos$ pfexec dtrace -F -s pid.d `pgrep gccOutput` printf > gccOutput.txt<br/> dtrace: script 'pid.d' matched 6714 probes</font></p> <p></pre> <br/> </blockquote> <br/> <p>Now, the content of the file SunCC> <br/> <p>Contents of the file gcc>So you can see that there is no difference between gcc and suncc when if comes to implement the printf function. But its is so interesting to see that there are 19 function calls made everytime I use a printf in my c program! WOW! ;) I wonder if I could know it this easily if there was no Dtrace!<br /></p> Create a ZFS Storage pool on a Pen drive / USB Stick in OpenSolaris krabhishek 2009-12-11T06:06:21+00:00 2009-12-11T14:06:23+00:00 <p><p )</p><br/> <p>You will need two things for this:</p><br/> <p>1. <a href="" target="_blank">Install OpenSolaris </a></p><br/> <p>2. Get two or more 2 GB (or of whatever size) pen drives / USB sticks (I do not have 2 pen drives with me so I will use one pen drive and one file to act like a pen drive. Process remains the same)</p><br/> <p>Step 1: Find out the device ID of your pen drive:</p><br/> <blockquote><br/> <p><font size="2" face="courier new,courier,monospace">root@opensolaris:~# format -e<br />Searching for disks...done<br /><br /><br />AVAILABLE DISK SELECTIONS:<br /> 0. c7d0 <DEFAULT cyl 3271 alt 2 hd 255 sec 63><br /> /pci@0,0/pci-ide@1,1/ide@0/cmdk@0,0<br /> 1. c9t0d0 <Generic-Flash Disk-8.07-1.87GB><br /> /pci@0,0/pci8086,265c@b/storage@1/disk@0,0<br />Specify disk (enter its number):</font></p><br/> </blockquote><br/> <p>In this case, the disk 0 is my hard disk, and 1 with device ID <font size="2" face="courier new,courier,monospace">c9t0d0 </font>is the USB stick. If I had two pen drives I would have had one more entry. However, I am going to create a new file of 2 GB under the name disk1 and use it. </p><br/> <p>Step 2: Create a new zpool on these devices. If you are using many multiple pen drives then instead of /root/disk2 use the device ID of the devices.<br /></p><br/> <blockquote><br/> <p><font size="2" face="courier new,courier,monospace">root@opensolaris:~# zpool create randomZpool c9t0d0 /root/disk2 <br />root@opensolaris:~# zpool status -v<br /> pool: randomZpool<br /> state: ONLINE<br /> scrub: none requested<br />config:<br /><br /> NAME STATE READ WRITE CKSUM<br /> randomZpool ONLINE 0 0 0<br /> c9t0d0 ONLINE 0 0 0<br /> /root/disk2 ONLINE 0 0 0<br /><br />errors: No known data errors<br /><br /> pool: rpool<br /> state: ONLINE<br /> scrub: none requested<br />config:<br /><br /> NAME STATE READ WRITE CKSUM<br /> rpool ONLINE 0 0 0<br /> c7d0s0 ONLINE 0 0 0<br /><br />errors: No known data errors</font></p><br/> </blockquote><br/> <p> Step 3: Create a ZFS filesystem on the storage pool</p><br/> <blockquote><br/> <p><font size="2" face="courier new,courier,monospace">root@opensolaris:~# zfs list | grep randomZpool<br />randomZpool 101K 3.77G 19K /randomZpool<br />randomZpool/dummy 19K 3.77G 19K /randomZpool/dummy</font><br /></p><br/> </blockquote><br/> <p>Now you can see, that I have a ZFS filesystem of 3.77GB under the name randomZpool/dummy. Now let us define a mount point for the same.</p><br/> <p>Step 4: Define a mountpoint for the ZFS Filesystem.</p><br/> <blockquote><font size="2" face="courier new,courier,monospace">root@opensolaris:~# zfs set mountpoint=/export/movies randomZpool/dummy<br />root@opensolaris:~# df -h /export/movies<br />Filesystem Size Used Avail Use% Mounted on<br />randomZpool/dummy 3.8G 19K 3.8G 1% /export/movies<br /></font></blockquote><br/> <p> Now you have the backup of your 3.5 GB movie file on two pen drives <img src="" class="smiley" alt=":)" title=":)" /></p><br/> <p>How you can use this small arrangement to do much bigger (and crazier) stuff is limited only by your creativity <img src="" class="smiley" alt=";)" title=";)" /> </p><br/> <p>Happy hacking to all!<br /></p><br/> <p><br /></p></p> FOSS.IN 09 - Abhishek was here! krabhishek 2009-12-06T01:43:05+00:00 2009-12-06T09:49:01+00:00 <p><p><a href="" target="_blank" title="FOSS.IN 2009 website">FOSS.IN 2009</a> was pinnacle of geekfests and it was after a long time that I saw so many open source fanatics under one roof!! Thanks to <a href="" target="_blank" title="BOSUG page">Bangalore OpenSolaris User Group</a> (specially <a href="" target="_blank" title="Sriram's blog">Sriram Narayanan</a> and <a href="" target="_blank" title="Anil's blog">Anil Gulecha</a>) OpenSolaris platform was successful beyond expectations in making hackers heads turn!</p> <br/> <p align="center"><img vspace="2" hspace="2" border="2" align="middle" src="" /></p> <br/> <p align="center">Sriram explaining stuff about OpenSolaris to interested participants of FOSS.IN</p> <br/> .</p> <br/> <p>!</p> <br/> <p align="center"><img vspace="2" hspace="2" border="2" src="" alt="Me giving our first winner the opensolaris t-shirt" /></p> <br/> <p align="center">Me giving a OpenSolaris T-Shirt to our first winner</p> <br/> <p align="left"!</p> <br/> <p align="center"><img vspace="2" hspace="2" border="2" src="" alt="One guy trying out his assignment to win Opensolaris t-shirt while others listen to Sriram" /></p> <br/> <p align="center">One of the participants using my laptop to complete his assignments while others listen are taking their assignments from Sriram</p><br/> <p align="center"><img vspace="2" hspace="2" border="2" src="" alt="Foss.in" /> </p><br/> <p align="center">Keynote from <a href="" target="_blank">Philip Tellis</a> of Yahoo! in FOSS.IN <br /></p> <br/> <p align="left">A few GNU skeptics who walked to us commenting on the CDDL were sent back satisfied by examples like <a href="" target="_blank" title="Belenix">Belenix</a> and <a href="" target="_blank" title="Nexenta">Nexenta</a>. Over all, it was a great event and we learned many new lessons too! I hope hackers who drool on cool technologies will continue to fall in love with OpenSolaris!</p><br/> <p align="left"><br /></p></p> Shining new Sun Cluster 3.2 11/09 is now available krabhishek 2009-12-06T00:34:25+00:00 2009-12-06T08:34:26+00:00 <p><p.</p><br/> <p> Read more about it on Sun Cluster Oasis - <a href="" target="_blank" title="Sun Cluster Oasis"></a></p><br/> <p> </p></p> OpenSolaris 2009.06 exclusive booklet in Indian Press krabhishek 2009-07-08T06:51:10+00:00 2009-07-08T13:52:36+00:00 <p><p <b>120,000 readers in India would have a copy of something to give them a head start on OpenSolaris and a Live CD to play around with. <img src="" class="smiley" alt=":)" title=":)" /> A total of more than 250,000 Live Disks of OpenSolaris has hit Indian newsstands this month</b> and I hope it would give a good push to our community in India.</p> <br/> <p><img width="756" vspace="2" hspace="2" height="1220" border="3" align="middle" src="" /><br /></p> <br/> <p>Feel free to download the<a title="Link to download the OpenSolaris Booklet" href=""> OpenSolaris booklet here</a> and distribute if you want. It features new features of OpenSolaris 2009.06, Installation guide, guide to setup Web development and Java Development environment and develop an example project in each, and an interview of <a title="Glynn's Blog" href="">Glynn Foster</a> . It also includes details on OpenSolaris communities and <a href="">OSUM</a>! Good work by the magazine team and our OpenSolaris people! I hope you enjoy reading it <img src="" class="smiley" alt=";)" title=";)" /> </p></p> And We are back again! With Education, Open Source, Tech Days and Joe! krabhishek 2009-02-24T01:51:10+00:00 2009-02-24T09:52:55+00:00 <p><p>Hello!! Its been more than 6 months since I made my last blog entry... Sorry for that as I was busy working with loads of stuff in Sun Clusters, OpenSolaris Marketing and in Campus Ambassador Program.. But now I am back with some interesting stuff...</p> <br/> <p> <a title="Sun Tech Days" target="_blank" href="">Sun Tech Days</a> happened at Hyderabad from 18th Feb to 20th Feb which was attended by many many people! Many legends including <a title="James Goslings Bio" target="_blank" href="">James Gosling</a> were there for the show! <a title="Joe Hartley's Bio" target="_blank" href="">Joe Hartley</a> <a title="OSUM" target="_blank" href="">OSUM</a> and penetration of the network. With help from <a target="_blank" title="Vasudha's Blog" href="/vasudha">Vasudha</a> who is our campus ambassador at Manipal University, we recorded this pool side talk <img src="" class="smiley" alt=":-)" title=":-)" /> Here is the video:</p> <br/> <p> </p><embed type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" style="width: 400px; height: 326px;" src="" id="VideoPlayback" /> <br />It was very interesting to talk to Joe after an year of <a title="WWERC Blog" target="_blank" href="/wwerc08/">WWERC 2008 </a>held at San Francisco where I got a chance to interview him on similar lines. Watch that <a title="Interview with Joe Hartley" target="_blank" href="/krabhishek/entry/this_advice_you_gotta_take">video here</a>!<br /></p> GLOSS gets the First Feel of Second Life! krabhishek 2008-07-10T21:01:24+00:00 2008-07-11T04:01:24+00:00 <p><p>On 9th of July, 450 members of GLOSS got to experience one (or I should say two) of the most amazing things of our ages! It was the OpenSolaris in Second Life! </p> <br/> <p><img hspace="1" vspace="1" border="2" src="" /> </p> <br/> <p>Thanks to <a target="_blank" href="/theopenwaters/">Terri</a>, GLOSS got a chance to be a part of the OpenSolaris Chat in second life and we got a VIP pass! You can see the <a title="Chat presentation" target="_blank" href="">chat presentation here</a>..!)</p> <br/> <p> <img src="" class="smiley" alt=":-(" title=":-(" /> So the chat was moved to Text mode... And you know how we students are.. <img src="" class="smiley" alt=":)" title=":)" />! </p> <br/> <p>All this while I was in the Nirman Vihar auditorium, and then towards the end I switched to TIFAC audi! The moment I walked in, I was welcomed with so many question!! <img src="" class="smiley" alt=":)" title=":)" />)<br /></p> <br/> <p <img src="" class="smiley" alt=":(" title=":(" /> <br /></p> <br/> <p>Everyone in the Sun SL team did a great job... Check out <a target="_blank" href="/theopenwaters/entry/photos_and_script_opensolaris_live">Terri's blog</a> for the complete transcript of the OpenSolaris chat and also <a target="_blank" href="/angad/entry/a_virtual_rendezvous_with_the">Angad's blog</a> for the pictures. <br /></p></p> OHAC talk at GLOSS krabhishek 2008-07-01T00:12:02+00:00 2008-07-01T07:12:02+00:00 <p><p>After almost a month long vacation, when college reopened, we at GLOSS could not wait to do something exciting!! And what could be more exciting than Open High Availability Clusters (OHAC). I attended a talk on OHAC by <a title="Tirthankar's Blog" target="_blank" href="/tirthankar">Tirthankar<.</p> <br/> <p>Now about the talk! There was a decent audience of more than 40 students who came to attend the talk. I started the talk with playing the <a title="Big Buck's Bunny download" target="_blank" href="">Big Bucks Bunny</a> movie, which set up the mood of the audience and also allowed me to introduce them to <a title="Network.COM" target="_blank" href="">Network.Com</a> and from there pick up the topic of difference between grids and clusters. </p> <br/> <p><img hspace="1" height="648" width="728" vspace="1" border="2" src="/krabhishek/resource/images/crowd1.JPG" /> </p> <br/> <p> Then I moved to the slides and I explained the architecture of OHAC and details of its functioning. It was an engrossing session, as explaining the functioning of a cluster and concepts like Disk Fencing can get tricky <img src="" class="smiley" alt=":)" title=":)" /> But it was nice to see every one interacting and asking questions to me!</p> <br/> <p><img hspace="1" height="648" width="728" vspace="1" border="2" src="/krabhishek/resource/images/ohac1.JPG" /></p> <br/> <p> <img hspace="1" height="648" width="728" vspace="1" border="2" src="/krabhishek/resource/images/arch.JPG" /></p> <br/> </p> <br/> <p><img hspace="1" vspace="1" border="2" style="width: 819px; height: 656px;" src="/krabhishek/resource/images/step1.png" alt="Cluster resource right now online on the zone" /></p> <br/> <p> Now when I reboot the zone, the cluster resource becomes online on the physical node</p> <br/> <p><img hspace="1" vspace="1" border="2" style="width: 815px; height: 656px;" src="/krabhishek/resource/images/step2.png" /></p> <br/> <p>I will soon be doing one more follow up talk on OHAC where I would discuss how to setup clusters and write agents for OHAC! Once again... thanks to Tirthankar and Swathi for helping me out with OHAC! <br /></p></p> 5 OpenSource Goodies to get you going! krabhishek 2008-06-09T10:05:54+00:00 2008-06-09T17:05:55+00:00 <p><p>There can be many a times when you cannot afford to spend those valuable $$$ to prove your concept or express yourself or give you the start you are looking for <img src="" class="smiley" alt=";)" title=";)" /> <img src="" class="smiley" alt=":-P" title=":-P" />)!! Anyways, here I would like to recommend 5 open source application which can get you rolling with your concept.... Note that, each of these projects are mature enough that they can be used for every mission critical operations and you can trust them to run your whole business.</p> <br/> <ul> <br/> <li><a href="" target="_blank"><img src="" /></a></li> <br/> <ul> <br/> <li <img src="" class="smiley" alt=";)" title=";)" /> Not to forget, if you are planning to create a nifty mobile application which you can use to adore your cell phone then look nowhere else. Many other things like Ruby, C and C++ etc. runs smoothly! <br /></li> <br/> </ul> <br/> <li><a target="_blank" href=""><img hspace="2" vspace="2" border="1" src="" /></a></li> <br/> <ul> <br/> <li!</li> <br/> </ul> <br/> <li><a title="VirtualBox" target="_blank" href=""><img hspace="2" height="101" width="102" vspace="2" border="1" src="" /></a></li> <br/> <ul> <br/> <li.<br /></li> <br/> </ul> <br/> <li><a target="_blank" href=""><img hspace="2" height="59" width="180" vspace="2" border="1" src="" /></a></li> <br/> <ul> <br/> <li!</li> <br/> </ul> <br/> <li><a target="_blank" href=""><img hspace="2" vspace="2" border="1" src="" /></a></li> <br/> <ul> <br/> <li>XAMPP would allow you to install the comple Apache, MySQL and PHP part of the xAMPP platform. Its a simple to use and easy to download!</li> <br/> </ul> <br/> </ul> <br/> <p <a title="OpenSolaris Home" target="_blank" href="">OpenSolaris</a>, which would cost you nothing and provide you a reliable, feature full and stable development environment. And if you are considering to do a next facebook or something then check out <a title="OpenSolaris Web Stack" target="_blank" href="">OpenSolaris Web Stack</a> which would give you a SAMP platform on a platter! <img src="" class="smiley" alt=":)" title=":)" /></p> <br/> <p> These are some of the applications I like a lot in the OpenSource ecosystem. There are million others and almost any of your needs can be fulfilled in the OpenSource world! </p> <br/> <p>Now tell me, doesn't open source deserve the title of biggest enabler of our century??? <img src="" class="smiley" alt=":)" title=":)" /><br /></p><br/> <p><a href="" rel="me">Technorati Profile<> Now let me tell you what we did last summer :-) krabhishek 2008-05-28T23:52:24+00:00 2008-06-09T15:09:08+00:00 <p><p>I got a secret to share <img src="" class="smiley" alt=":-P" title=":-P" /> When everyone around the globe was impatiently waiting for OpenSolaris 2008.05 to release, on April 13, 2008, we at GLOSS got lucky!! Thanks to Micheline and Charlie, I could obtain a copy of OpenSolaris Release Candidate 0!!! Yes! we were one of the first one's to see OpenSolaris 2008.05 (exactly the way you see a baby through the ultrasound <img src="" class="smiley" alt=":-D" title=":-D" />) and we got our hands on RC0 before any other group outside Sun <img src="" class="smiley" alt=":-)" title=":-)" /> And then how could we wait to find out how the new desto has come out!! We did and we did it with lots of passion and zeal. 200 students tried their hands on OpenSolaris RC0, and even though RC0 only had the skeleton, (like there were no images during installation, but only the ImagePlaceHolder label was there!) everyone was deeply impressed with the ease with which they could install the distro. We collected the feedbacks towards the end of the test drive and by running through the feedback forms I we knew what the everyday user of OpenSolaris 2008.05 would like and what more they would expect! Angad did a similar thing at his campus in a very innovative way! His <a href="/angad/" target="_blank" title="Angad's Blog">blog</a> about this virtual install fest of RC0 is a must-see.<br /></p><br/> <p>As I told you, it was a matter of pride for us to see and test OpenSolaris RC0 and everyone was overjoyed after we were done. Here is one clip which one of us shot.. </p><br/> <p><object height="355" width="425"><param name="movie" value="" /><param name="wmode" value="transparent" /><embed height="355" width="425" src="" type="application/x-shockwave-flash" wmode="transparent" /></object> <br /></p><br/> <p>I guess it will give you an idea of how passionate we, at GLOSS, feel about OpenSolaris! <img src="" class="smiley" alt=":-)" title=":-)" /></p><br/> <p> <br /></p> <a rel="me" href="">Technorati Profile</a></p> The GLOSS Newsletter krabhishek 2008-05-26T05:28:54+00:00 2008-07-04T07:49:04+00:00 <p><p><b>GLOSS has its newsletter out!!!!</b></p><br/> <p>The past academic year was very eventful at GLOSS and we decided to put the major events in form of a newsletter. So here we are, with the first issue of <i><b>OpenView</b></i> !<i><b> </b></i><a href="" target="_blank" title="Download OpenView.pdf (6 MB)">Get your copy here!</a></p><br/> <p> </p><br/> <p>I deeply apperciate the efforts put in by <a href="" target="_blank" title="Harish's Blog">Harish</a>,who was instrumental in designing the Newsletter. Efforts put in by Sanjeev, Abhilash and Vikas has also been very significant. Good work guys!</p><br/> <p> </p><br/> <p>Do let us know how you found OpenView and things happening at SASTRA! Cheers!<br /></p></p> And that's how GLOSS celebrates technology! krabhishek 2008-05-13T07:21:06+00:00 2008-05-13T14:21:06+00:00 <p><p>Everyone was celebrating the release of OpenSolaris on May 5th, and at GLOSS, we have been busy planning the same for quite some time.. It was no doubt one of the most awaited event since Project Indiana was declared. So.. as I told everyone before.. we celebrated May 5th as Opensolaris Birthday... <img src="" class="smiley" alt=":-)" title=":-)" /> There was cake.. there was decorations.. there were people with celebration mood and there was the latest Technology!!!</p><p> <object width="425" height="355"><param value="" name="movie" /><param value="transparent" name="wmode" /><embed width="425" height="355" wmode="transparent" type="application/x-shockwave-flash" src="" /></object></p> Thanks to my folks at GLOSS who made this celebration possible, even though from next day on we were having our final exams! (Now I think you know why this post came so late <img src="" class="smiley" alt=":-P" title=":-P" /> ) Watch the video and enjoy the power of communities!<br /></p> Powerful OS running on Powerful Processor consuming less POWER! krabhishek 2008-05-13T07:13:12+00:00 2008-05-13T14:13:12+00:00 <p><p>Opensolaris is a powerful Operating System and Intel Xeon is no doubt one of the most powerful x86 server platform! Now, in the poweful community of Opensolaris there are some serious work going on towards optimizing this powerful Operating System on powerful Xeon so that we can cut down on Power Consumption.. If too much of "Power" has left you confused then go ahead and watch this video in which (Intel) Dave talks about the on-going efforts of optimizing Opensolaris on Xeon. <img src="" class="smiley" alt=":-D" title=":-D" /></p><p><br /><object width="425" height="355"><param name="movie" value="" /><param name="wmode" value="transparent" /><embed width="425" height="355" src="" type="application/x-shockwave-flash" wmode="transparent" /></object></p><p>He also explains some of the cool internals of relationship between power consumption and operating system. Thanks to<a title="Terri's Blog" target="_blank" href=""> Terri</a> for bringing this video to me. Check this video out and find out more on whats happening at <a href="">Opensolaris.org!</a><span style="text-decoration: underline;"></span><a title="Terri's Blog" href=""><br /></a></p><> Much is happening on May 5th!! krabhishek 2008-04-23T15:10:02+00:00 2008-04-23T22:10:03+00:00 <p><p>May 5th is going to be such a happening date that you might get dazzled! First and foremost, of course, its because May 5th is Birthday of OpenSolaris!! But then OpenSolaris is coming out on the occasion of the CommunityOne which itself is one of the most important events in the OpenSource Calender! </p><p>There is one place where you can catch up with everything which is going to happen on May 5th. Thanks to Terri Wischmann, who is soon going to write all about what is happening on May 5th and beyond... giving us the plug-point to all the buzz of May 5th. Visit her blog '<a href="" title="Terry's Blog">The Open Waters</a>' where she will be updating (rather unleashing) everything about May 5th. So don't miss out on all the excitement and make sure you keep yourself updated on the most happening day of this year which would be... no points for guessing.. MAY 5th!<br /></p></p> Its gonna be a festive day on May 5th! krabhishek 2008-04-23T07:07:01+00:00 2008-04-23T14:26:18+00:00 <p><p>May 5th is the most sought after day in this calender year! And do I need to tell you why is that?? Its Birthday of Opensolaris!! On May 5th, the much awaited Project Indiana will mature and would come out in open as the brand new OPEN SOLARIS!!</p><p>Me along with my folks at <a title="GLOSS Blog" href="">GLOSS</a> are going to celebrate this in a big way!! We have long plans for this day... Even though we will be having exams going on (needless to say, \*exams\* are the most dreaded \*things\* in a student's life <img src="" class="smiley" alt=":-P" title=":-P" />) we have planned to celebrate the Opensolaris B'day in style! The agenda for the day is:</p><ul><li>Put up 5 Laptops with placards which would read "Convert your CD<br/> into Souvenir"</li><li>Cut a Birthday Cake in name of Opensolaris <br /></li><li>Do a small presentation on new features of Opensolaris</li><li>Have Lunch together</li><li>Do a installation demo<br/> </li><li> At the end, invite students to come up and give a talk on what they<br/> feel about future of Opensolaris</li><li>Promise "Opensolaris" that we will work towards "Rearing it To<br/> become the Best Desktop OS"!<br/> </li></ul>Everyone at GLOSS is excited about this! After all.. OpenSolaris is "OUR OWN" Operating System and we want to be nice "Uncle GLOSS" and we want to take good care of the new kid!!! <img src="" class="smiley" alt=":)" title=":)" /> Its all in the family you see <img src="" class="smiley" alt=":)" title=":)" /><br /></p> Education 3.0 at SRM University, Channai krabhishek 2008-03-09T21:39:15+00:00 2008-03-25T14:46:18+00:00 <p><p>On 6th of March 2008, I addressed the largest crowd I had ever done before!! It was more than 2000 students who turned up for the Sun University Day at <a href="">SRM University </a><span style="text-decoration: underline;"></span> Chennai. K. Nageshwara Rao, who is Site Lead of India Engineering Center (IEC) Bangalore was the chief guest for the event. He was accompanied by Ganesh and senior professors from SRM. Those who don't know, <a title="Ganesh Blog" href="">Ganesh Hiregoudar</a> manages the Sun CA program for the APAC region.</p><p>!!</p><p!!</p></p> Students should expect to soon become the "Alice" as the "Wonderland" comes out! krabhishek 2008-02-27T12:48:12+00:00 2008-02-27T20:48:14+00:00 <p><p>I'm just out of a panel discussion over the "<a title="Sun Immersion Special Interest Group" target="_blank" href="">Immersive Education</a>" and from what I saw, two things where every evident. 1st, its not late that classrooms will no longer be required to teach and learn and 2nd- learning is going to be whole lot fun!</p><p>Things like project wonderland, which had enabled virtual collaboration seamless and boundless, the way we look at student-teacher relationship, it is sure to change. Project Wonderland enables application sharing, voice chat, and many other "out-of-this-world" features in a virtual world setup. Combine them together you will see that we have everything that you would need in order to establish a very effective learning tool in order to execute a practical and effective course on almost anything which can be taught to any other soul!! Just to get a feel of it, you can see the following videos which are the examples of where the project wonderland is heading to.</p><p><object width="425" height="355"><param value="" name="movie" /><param value="transparent" name="wmode" /><embed width="425" height="355" wmode="transparent" type="application/x-shockwave-flash" src="" /><><br/> <p>Explore more is all what I can say.. because the \*\*possibilities\*\* in this \*\*wonderland\*\* is making "unlimited" look a "dwarf" word!!</p> This advice you gotta take!! - Joe Hartley to new age students and teachers! krabhishek 2008-02-27T12:07:45+00:00 2008-02-27T20:12:02+00:00 <p><p>One thing which came out very clearly during the panel discussion held during the Worldwide Education and Research Conference 2008 is that the learning methodologies and principals are changing everywhere in the world. Education is getting more and more into collaborative learning and sharing of knowledge and resources. So to sum it up, I did a quick interview of Joe Hartley (for those who don't know, he is the Vice President -Government, Education and Healthcare for Sun Microsystems). Even though being hard pressed with his busy schedule took out time for two quick questions at the end of the day. Thanks to my fellow ambassador Sergay, we recorded the interview. And here is what he would advice to the students and teachers of today who would have to take up the burden of transition from the classic style "leacture based, half duplex learning" to "full duplex, community based collaborative learning." Watch the video:</p><p><object width="425" height="355"><param value="" name="movie" /><param value="transparent" name="wmode" /><embed width="425" height="355" wmode="transparent" type="application/x-shockwave-flash" src="" /></object><br /></p></p> Open up.. or Close down!! krabhishek 2008-02-27T07:13:08+00:00 2008-02-27T15:31:17+00:00 <p><p>Things are getting good to great at Worldwide Education and Research Conference 2008! I got a chance to interview Mr. Zack Urlocker, (for those who don't know, Zack is the Executive Vice President - Products, for MySQL) the dynamic leader of MySQL! Earlier in the evening, Zack was on the panel of "Enabling Communities" along with Barry Libert, the famous author of We are Smarter Than Me, and Michael Keller who is the University Librarian and Director of Academic Information Resources at Stanford University. For everyone in the hall, the session was so informative that I could as well call it an "Eye Opener".</p><p>In the interview, Zack told me many things about the business model around open source. Everyone knows that the best business model is that model in which each of its component are in a win-win situation. Zack very well justified how open source is exactly the same kind of model where every one is in a win-win!</p><p><br/> </p><embed src="" type="application/x-shockwave-flash" id="VideoPlayback" style="width: 400px; height: 326px;" /><p> </p><p>Personally, I always felt that the way businesses around the globe are migrating towards the collaborative model for production and distribution, and with collaboration tools becoming more and more common amongst the internet users, the day is not far when everything will have to move towards the collaborative model. And after talking to Zack I'm even more convinced that if someone would like to remain close and try to make money the traditional way, then for them might be its a good time to take the message - either "Open Up" or, sorry to say but, "Close Down"!</p><p> Watch the video for more!<br /></p></p> Worldwide Education And Research Conference 2008 Teaser :) krabhishek 2008-02-23T22:57:38+00:00 2008-02-24T06:59:34+00:00 <p><p>With just 1 day 12 hours and 13 minutes left to the grand event I have been waiting for, I am rubbing my palms in excitement!!! Yes folks.. the wait would end soon and the Worldwide Education and Research Conference (WWERC '08) is finally just a day away!! I'm very excited to be a part of a conference which has the potential to redefine the way we look at education and role of technology in education today! With personalities like Scott McNealy, the chairman of Sun Microsystems and Larry Penley who is the President of Colorado State University System coming and giving their insight and gyan on technology and education, education and technology, amazing new perspectives on the topics of discussion can be guaranteed!! If you want to know what all are on the discussion-cards... just visit the <a title="the WWERC 08 Agenda Page" target="_blank" href=""> WWERC agenda page</a>.. There you can also get the the list of people who will be present. And trust me thats one of the most impressive list of the intellectual minds of our times! <img src="" class="smiley" alt=":)" title=":)" /></p><p> Now after going through the agenda if you realized that logistics and any other engagement in making you miss out on such a great learning experience.. then don't worry.. like always let Internet save the day <img src="" class="smiley" alt=":-P" title=":-P" /> Sun will be webcasting the proceedings of WWERC and you can hook to that by visiting <a href="" title="link for the webcast of WWERC 08" target="_blank">.</a> If you can't catch up live, you still needn't worry because all the keynote and special sessions will be later vodcasted and podcasted! </p><p> So, the stage is all set for the most happening gathering of education and technology, The WWERC 2008 and it is best matched with its happening host city.. San Francisco!! See you in San Francisco!!<br />> | http://blogs.oracle.com/krabhishek/feed/entries/atom | CC-MAIN-2014-15 | refinedweb | 7,170 | 59.33 |
Working with Google Protocol Buffers and .NET
WEBINAR: On-demand webcast
How to Boost Database Development Productivity on Linux, Docker, and Kubernetes with Microsoft SQL Server 2017 REGISTER >
This month, I was asked to include the topic of the "The Internet of Things," or IoT if you're one of these folks who watches all the buzz words as one of my posts. I happen to know that Windows 10 and its support for the "Internet of Things" is quite big news, and lots of developers are chomping at the bit to share their experiences of playing with all this new stuff. So, when I was asked about this, I quietly thought to myself, but WHY should Windows 10 have all the fun? After all, the IoT is not exactly new; we've been connecting all manner of things to various networks for well over a decade now!
That got me thinking, what "Things" do I know, that already exist that could be "Useful" to those non-Windows 10 folks who might be playing with regular .NET implementations, but wanting to build and communicate with things that are out there in this brave new world of IoT?
This post, I'm going to show you something called "Google Protocol Buffers," and then over the next three posts, I'll pick subjects that broadly fall into the IoT category and will help you build great .NET IoT implementations on any .NET enabled platform.
What Exactly Is "Google Protocol Buffers?"
Google Protocol Buffers (or Protobufs for short) are a data serialization and transmission technology that Google invented quite some time ago now.
As you can well imagine, with a network of machines the size that Google has, they needed a way to perform very high speed data transmission of structured data between nodes in their network.
At the time, like many people, they were using various mechanisms such as XML and Json, and even with relatively lightweight data packets such as those produced by Json, they wanted to shave even more milliseconds off things.
The result of wanting an even faster method led to the birth of Protobufs, and an implementation of the core libraries for just about every platform under the sun, including .NET
Okay, I Get That, but What Makes It So Special, and for That Matter So Ideally Suited for the IoT?
To answer that, I'll have to deviate just ever so slightly into the world of finance, or more specifically credit and debit card transaction processing.
In the world of finance, ATMs have to communicate with banks, credit card terminals have to communicate with merchants, and all manner of things in between, all very fast and very reliably.
To do this, they employ a transmission method known as "BER-TLV".
Stripping off the "BER" part where left with "Tag Length Value" which is essentially a very, very compact and efficient binary protocol composed of three parts, as follows:
- TAG: This is 1 or 2 bytes holding some kind of message identification number that the communicating terminals understand to mean an account number, or transaction amount or some other "Thing" being transmitted.
- LENGTH: This is a 1, 2, or 3 byte value telling the receiving terminal exactly how long the message that follows is, in terms of the number of bytes.
- VALUE: This is the actual payload of the message.
Google protobuffers is a very similar way of sending data between communicating entities and, when employed correctly, can allow you to serialise and encapsulate an ENTIRE .NET class into something as small as a few hundred binary bytes, which then can be very efficiently streamed over a UDP or TCP socket connection, or out via a traditional serial port.
If you're working on an Arduino or a RaspberryPi, you could easily connect something to a Gpio pin and just stream this as a simple digital bit stream. I've even used this to send complex structured data between mobile devices using traditional SMS messages over the mobile network.
Put simply, you send ONLY what you need to send, and because of the way it works everything the receiver needs to know is sent in front of the data. This means unpacking it at the other end is very simple and in no way CPU intensive, meaning it's fast and flexible, even on the most low-power devices.
Enough. Okay… Gimme Some Code ….
Fire up Visual Studio, and start a console program (I should label this as a pre-requisite for my posts ☺).
Once you have a project open, head to NuGet and search for "protobuf-net", as shown in Figure 1:
Figure 1: Protobuf-net in NuGet
You'll find there are a couple of different implementations, many of which are designed for inclusion in different frameworks, such as "Service Stack".
I generally use "Marc Garvell's" implementation. It's the one I know and the one this post will use.
Once you have the NuGet package installed, head back to your project and add a class called 'Employee.cs', as follows:
namespace Protobuffers{ public class Employee { public int EmployeeId { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public int Salary { get; set; } } }
Nothing special here, just a normal plain old C# class. We now need to make it aware of Google Protobuf and vice versa.
To do this, we add "attributes" to the class which, if you're used to using things like entity framework, should feel quite natural. Change your class so it looks as follows:
using ProtoBuf; namespace Protobuffers { [ProtoContract] public class Employee { [ProtoMember(1)] public int EmployeeId { get; set; } [ProtoMember(2)] public string FirstName { get; set; } [ProtoMember(3)] public string LastName { get; set; } [ProtoMember(4)] public int Salary { get; set; } } }
The first thing that most people ask when they see this is "What's with the numbers?" Protobuf doesn't serialize the names of members in your classes. Instead, to make the message as small as possible, it uses a numerical index, which it relies on you to tell it.
I could, if I wanted, put all the integers first, followed by the strings if I wanted. In practice, what you normally want to do is just proceed down the class in a linear fashion.
There are a couple of other ways supported by the .NET lib we're using, including an automatic one that will let Protobuf work this stuff out on its own. Personally, I prefer to tell it, that way I can be 100% sure that I'm getting the exact data in the exact order that I want.
Once you've marked up your Protobuf enabled class, you're then ready to make use of it.
For the purposes of this post, we'll simply just save the bytes to disk and reload them. In the real world, however, you'd likely send them somewhere else by some different medium.
Make sure your program.cs file looks as follows:
using System; using System.IO; using ProtoBuf; namespace Protobuffers { class Program { static void Main(string[] args) { Employee myEmployee = new Employee { EmployeeId = 1024, FirstName = "Peter", LastName = "Shaw", Salary = 100000 }; Console.WriteLine("Saving employee:"); Console.WriteLine("\tEmployee ID: {0}", myEmployee.EmployeeId); Console.WriteLine("\tFirst Name: {0}", myEmployee.FirstName); Console.WriteLine("\tLast Name: {0}", myEmployee.LastName); Console.WriteLine("\tSalary: {0}", myEmployee.Salary); Console.WriteLine(); using(var outputFile = File.Create("outputdata.bin")) { Serializer.Serialize(outputFile, myEmployee); } Console.WriteLine("Employee serialized, press return to load it back in"); Console.ReadLine(); Employee reloadedEmployee; using(var inputFile = File.OpenRead("outputdata.bin")) { reloadedEmployee = Serializer.Deserialize<Employee>(inputFile); } Console.WriteLine("Reloaded employee:"); Console.WriteLine("\tEmployee ID: {0}", reloadedEmployee.EmployeeId); Console.WriteLine("\tFirst Name: {0}", reloadedEmployee.FirstName); Console.WriteLine("\tLast Name: {0}", reloadedEmployee.LastName); Console.WriteLine("\tSalary: {0}", reloadedEmployee.Salary); } } }
As you can see, a lot of the code is actually made up of WriteLine statements to output the class data. You can serialize and deserialize the actual class by using the simple calls that the Protobuf library provides.
Before we finish this post, however, there is one small last thing.
YES, you can use this to serialise Lists and Arrays, but I personally would recommend against it.
If you're using something like Protobuf to send large amounts of data, such as lists of records directly from a database, in my own personal opinion you're likely not architecting your systems correctly.
Most devices that you would class as being IoT devices will very likely have relatively slow CPUs and quite a small amount of memory. Sending huge amounts of data to these devices will probably make them mis-behave. If you do need to send that level of data, my advice is to get the device to make a request to a JSON endpoint at its own pace and consume what it is able to.
If, however, you want a way to send relatively small, highly efficient structured messages, Protobuf is the perfect choice.
In our earlier example, the binary data generated from our class stands at only 20 bytes long:
Figure 2: The output from the preceding code
This is perfect to send via something like SMS to an IoT device with nothing more than a GSM Modem attached.
Found a strange .NET library that makes no sense to you, or want to know if there's an API for that? Drop me a message in the comments below or come find me on Twitter as @shawty_ds and I'll see if I can write a post on it for you.
Mr.Posted by Jesse Chisholm on 09/23/2016 08:49am
Excellent article. . . If you are using protobuf.net Can you please do a similar article for using the NuGet packages "Google.Protobuf" and "Google.Protobuf.Tools" and compiling from *.proto files? Thanks.Reply | https://www.codeguru.com/columns/dotnet/working-with-google-protocol-buffers-and-.net.html | CC-MAIN-2017-47 | refinedweb | 1,633 | 61.36 |
We will cover the following recipes in this chapter:
- Using style sheets with Qt Designer
- Customizing basic style sheets
- Creating a login screen using style sheets
- Using resources in style sheets
- Customizing properties and sub-controls
- Styling in Qt Modeling Language (QML)
- Exposing the QML object pointer to C++
Qt 5 allows us to easily design our program's user interface through a method most people are familiar with. Qt not only provides us with a powerful user interface toolkit, called Qt Designer, which enables us to design our user interface without writing a single line of code, but it also allows advanced users to customize their user interface components through a simple scripting language calledQt Style Sheets.
The technical requirements for this chapter include Qt 5.11.2 MinGW 32 bit, Qt Creator 4.8.2, and Windows 10.
Â
All the code used in this chapter can be downloaded from the following GitHub repository, at:Â.
Check out the following video to see the code in action:Â.
Let's get started by learning how to create a new project and get ourselves familiar with the Qt Designer:
- Open up Qt Creator and create a new project. If this is the first time you have used Qt Creator, you can either click the big button, which readsÂ
+Â New Project, or simply go to
File|
New File
or Project.
Applicationunder the
Projectswindow, and select
Qt Widgets Application.
- Click the
Choose...button at the bottom. A window will pop out and ask you to insert the project name and its location.
- Click
Nextseveral times, and click the
Finishbutton to create the project. We will stick with the default settings for now. Once the project has been created, the first thing you will see is the panel with tons of big icons on the left side of the window, which is called the mode selector panel; we will discuss this more later in the How it works... section.
- You will see all your source files listed on the sidebar panel which is located next to the mode selector panel. This is where you can select which file you want to edit, which in this case is
mainwindow.ui, because we are about to start designing the program's UI.
- Double-click theÂ
mainwindow.ui file, and you will see an entirely different interface appear out of nowhere. Qt Creator actually helped you to switch from the script editor to the UI editor (Qt Designer) because it detected the
.uiextension on the file you're trying to open.
- You will also notice that the highlighted button on the mode selector panel has changed from the
Editbutton to the
Designbutton. You can switch back to the script editor or change to any other tools by clicking one of the buttons located in the upper half of the mode selector panel.
- Let's go back to the Qt Designer and look at the
mainwindow.uifile. This is basically the main window of our program (as the filename implies) and it's empty by default, without any widget on it. You can try to compile and run the program by pressing the Run button (the green arrow button) at the bottom of the mode selector panel, and you will see an empty window pop up once the compilation is complete.
- Let's add a push button to our program's UI by clicking on the
Push Buttonitem in the
Widget Box(under the
Buttonscategory) and dragging it to your main window in the form editor. Keep the push button selected, and now you will see all the properties of this button inside the
Property Editoron the right side of your window. Scroll down to the middle and look for a property called
styleSheet. This is where you apply styles to your widget, which may or may not inherit to its children or grandchildren recursively, depending on how you set your style sheet. Alternatively, you can right-click on any widget in your UI at the form editor and select
Change styleSheet... from the pop-up menu.
- You can click on the input field of the
styleSheetproperty to directly write the style sheet code, or click on the
â¦button beside the input field to open up the
Edit Style Sheetwindow, which has a bigger space for writing longer code for style sheets. At the top of the window, you can find several buttons, such as
Add Resource,
Add Gradient,
Add Color, and
Add Font, that can help you to kickstart your coding if you can't remember the properties' names. Let's try to do some simple styling with the
Edit Style Sheetwindow.
- Click
Add Colorand choose a color.
- Pick a random color from the color picker window; let's say, a pure red color. Then click
OK.
- A line of code has been added to the text field on the
Edit Style Sheetwindow, which in my case is as follows:
color: rgb(255, 0, 0);
- Click the
OKbutton and the text on your push button should have changed to red.
Let's take a bit of time to get familiar with Qt Designer's interface before we start learning how to design our own UI:
The explanation for the preceding screenshot is as follows:
- Menu bar: The menu bar houses application-specific menus that provide easy access to essential functions such as creating new projects, saving files, undoing, redoing, copying, and pasting. It also allows you to access development tools that come with Qt Creator, such as the compiler, debugger, and profiler.
Widget Box: This is where you can find all the different types of widget provided by Qt Designer. You can add a widget to your program's UI by clicking one of the widgets from the
Widget Boxand dragging it to the form editor.
- Mode selector: The mode selector is a side panel that places shortcut buttons for easy access to different tools. You can quickly switch between the script editor and form editor by clicking the
Editor
Designbuttons on the mode selector panel, which is very useful for multitasking. You can also easily navigate to the debugger and profiler tools in the same speed and manner.
- Build shortcuts: The build shortcuts are located at the bottom of the mode selector panel. You can build, run, and debug your project easily by pressing the shortcut buttons here.
- Form editor: The form editor is where you edit your program's UI. You can add different widgets to your program by selecting a widget from the
Widget Boxand dragging it to the form editor.
- Form toolbar: From here, you can quickly select a different form to edit. Click the drop-down box located on top of the
Widget Boxand select the file you want to open with Qt Designer. Beside the drop-down box are buttons to switch between the different modes of the form editor, and also buttons to change the layout of your UI.
Object Inspector: The
Object Inspectorlists all the widgets within your current
.uifile. All the widgets are arranged according to their parent-child relationship in the hierarchy. You can select a widget from the
Object Inspectorto display its properties in the
Property Editor.
Property Editor: TheÂ
Property Editorwill display all the properties of the widget you selected from either the
Object Inspectorwindow or the form editor window.
Action Editorand theÂ
Signals & Slots Editor: This window contains two editors, theÂ
Action Editorand theÂ
Signals & Slots Editor, which can be accessed from the tabs beneath the window. The
Action Editoris where you create actions that can be added to a menu bar or toolbar in your program's UI.
- Output panes: Output panes consist of several different windows that display information and output messages related to script compilation and debugging. You can switch between different output panes by pressing the buttons that carry a number before them, such as
1 Issues,
2 Search Results, orÂ
3 Application Output.
Â
Â
In the previous section, we discussed how to apply style sheets to Qt Widgets through C++ coding. Although that method works really well, most of the time, the person who is in charge of designing the program's UI is not the programmer, but rather an accurate visual representation of the final result, which means whatever you design with Qt Designer will turn out exactly the same visually when the program is compiled and run.
The similarities between Qt Style Sheets and CSS are as follows:
- This is how a typical piece of CSS code looks:
h1 { color: red; background-color: white;}
- This is how Qt Style Sheets look, which is almost the same as the preceding CSS:
QLineEdit { color: red; background-color: white;}
As you can see, both of them contain a selector and a declaration block. Each declaration contains a property and a value, separated by a colon. In Qt, a style sheet can be applied to a single widget by calling theÂ
QObject::setStyleSheet() function in C++ code. Consider the following, for example:
myPushButton->setStyleSheet("color : blue");
The preceding code will turn the text of a button with theÂ
myPushButton variable name to blue. You can achieve the same result by writing the declaration in the style sheet property field in Qt Designer. We will discuss Qt Designer more in the following Customizing basic style sheets section.
Qt Style Sheets also supports all the different types of selectors defined in the CSS2 standard, including the universal selector, type selector, class selector, and ID selector, which allows us to apply styling to a very specific individual widget or group of widgets. For instance, if we want to change the background color of a specific line-edit widget with theÂ
usernameEdit object name, we can do this by using an ID selector to refer to it:
QLineEdit#usernameEdit { background-color: blue }
Note
To learn about all the selectors available in CSS2 (which are also supported by Qt Style Sheets), please refer to this document:.
In the previous recipe, the long run.
In the following example, we will format different types of widgets on the canvas and add some code to the style sheet to change its appearance:
- Remove the style sheet fromÂ
PushButtonby selecting it and clicking the small arrow button beside the
styleSheetproperty. This button will revert the property to the default value, which in this case is the empty style sheet.
- Add a few more widgets to the UI by dragging them one by one from the
Widget Boxto the form editor. I've added a line edit, combo box, horizontal slider, radio button, and a check box.
- For the sake of simplicity, delete the
menuBar,
mainToolBar, and the
statusBarfrom your UI by selecting them from the
Object Inspector, right-click, and choose
Remove. Now, your UI should look similar to this:
- Select the main window from either the form editor or the
Object Inspector, then right-click and choose
Change styleSheet...to open up the
Edit Style Sheetwindow. Insert the following into the style sheet:
border: 2px solid gray; border-radius: 10px; padding: 0 8px; background: yellow;
- You will see a; }
- This happens because we specifically tell the selector to apply the style to all the widgets with the
QPushButton class. We can also apply the style to just one of the push buttons by mentioning its name in the style sheet, as in the following code:
QPushButton#pushButton_3 { border: 2px solid gray; border-radius: 10px; padding: 0 8px; background: yellow; }
QPushButton { color: red; border: 0px; padding: 0 8px; background: white; } QPushButton#pushButton_2 { border: 1px solid red; border-radius: 10px; }
- This code basically changes the style of all the push buttons, as well as some properties of the
pushButton_2Â button. We keep the style sheet ofÂ
pushButton_3as it is. Now the buttons will look like this:
- The first set of style sheets will change all widgets of theÂ
QPushButtontype to a white rectangular button with no border and red text. The second set of style sheets changes only the border of a specific
QPushButtonwidget called
pushButton_2. Notice that the background color and text color of
pushButton_2remain white and red, respectively, because we didn't override them in the second set of style sheets, hence it will return to the style described in the first set of style sheets since it's applicable to all theÂ
QPushButtonwidgets. The text of the third button has also changed to red because we didn't describe the
Colorproperty in the third set of style sheets.
- Create another set of style sheets that use the universal selector, using the following code:
* { background: qradialgradient(cx: 0.3, cy: -0.4, fx: 0.3, fy: -0.4, radius: 1.35, stop: 0 #fff, stop: 1 #888); color: rgb(255, 255, 255); border: 1px solid #ffffff; }
- The universal selector will affect all the widgets, regardless of their type. Therefore, the preceding style sheet will apply a nice gradient color to all the widgets' backgrounds and set their text to white with a one-pixel solid outline that is also white. Instead of writing the name of the color (that is, white), we can use the
rgbfunction (
rgb(255, 255, 255)) or hex code (
#ffffff) to describe the color value.
- with an influence on a widget. This is how the UI will look now:
Â
Â
If you are ever involved in web development using HTML and CSS, Qt's style sheet works exactly the same way as CSS. Style sheets provide the definitions to describe the presentation of the widgets â what the colors are for each element in the widget group, how thick the border should be, and so on and so forth. If you specify the name of the widget to the style sheet, it will change the style of the particular
PushButton widget with the name you provide. None of the other widgets will be affected and will remain as the default style.
To change the name of a widget, select the widget from eitherÂ.
Next, we will learn how to put all the knowledge we've.
Let's get started by following these steps:
- We need:
- Go back to Qt Designer again.
- We will be placing the widgets at the top panel first, then the logo and the login form beneath it.
- Select the main window and change its width and height from
400and
300to
800and
600, respectively, because we'll need a bigger space in which to place all the widgets.
- Click and drag a label under the
Display Widgetscategory from the
Widget Boxto the form editor.
- Change the
objectNameproperty of the label to
currentDateTimeand change its
textproperty to the current date and time just for display purposes, such asÂ
Monday, 25-10-2015 3:14 PM.
- Click and drag a
PushButtonunder the
Buttonscategory to the form editor. Repeat this process once more because we have two buttons on the top panel. Rename the two buttons
restartButtonand
shutdownButton.
- Select the main window and click the small icon button on the form toolbar that says Lay Out Vertically when you mouse over it. You will see the widgets are automatically arranged on the main window, but it's not exactly what we want yet.
- Click and drag a
Horizontal Layoutwidget under the
Layoutscategory to the main window.
- Click and drag the two push buttons and the text label into the horizontal layout. You will see the three widgets being arranged in a horizontal row, but vertically they are located in the middle of the screen. The horizontal arrangement is almost correct, but the vertical position is totally off.
- Click and drag a
Vertical Spacerfrom the
Spacerscategory and place it beneath the
Horizontal Layoutwe created previously in step 9 (under the red rectangular outline). All the widgets are pushed to the top by the spacer.
- Place a
Horizontal Spacerbetween the text label and the two buttons to keep them apart. This will ensure the text label always sticks to the left and the buttons align to the right.
- Set both the
Horizontal Policyand
Vertical Policyproperties of the two buttons to
Fixedand set the
minimumSizeproperty to
55 x 55. Set the
textproperty of the buttons to empty, as we will be using icons instead of text. We will learn how to place an icon in the button widgets in the following Using resources in style sheets section.
- Your UI should look similar to this:
Next, we will be adding the logo using the following steps:
- Add a
Horizontal Layoutbetween the top panel and the
Vertical Spacerto serve as a container for the logo.
- After adding the
Horizontal Layout, you will find the layout is way too thin in height (almost zero height) to be able to add any widgets to it. This is because the layout is empty and it's being pushed by the vertical spacer under it into zero height. To solve this problem, we can set its vertical margin (either
layoutTopMarginor
layoutBottomMargin) to be temporarily bigger until a widget is added to the layout.
- Add a
Labelto the
Horizontal Layoutthat you just created and rename itÂ
logo. We will learn more about how to insert an image into the label to use it as a logo in the following Using resources in style sheets section. For now, just empty out the
textproperty and set both its
Horizontal Policyand
Vertical Policyproperties to
Fixed. Set the
minimumSizeproperty to
150 x 150.
- Set the vertical margin of the layout back to zero if you haven't already done so.
- The logo now appears to be invisible, so we will just place a temporary style sheet to make it visible until we add an image to it in the following Using resources in style sheets section. The style sheet is really simple:
border: 1px solid;
- Your UI should look similar to this:
Now, let's create the login form using the following steps:
- Add a
Horizontal Layoutbetween the logo's layout and the
Vertical Spacer. Set theÂ
layoutTopMarginproperty to a large number (that is,
100), so that you can add a widget to it more easily.
- Add a
V
ertical Layoutinside the
Horizontal Layoutyou just created. This layout will be used as a container for the login form. Set its
layoutTopMarginto a number lower than that of the horizontal layout (that is,
20) so that we can place widgets in it.
- Right-click the
Vertical Layoutyou just created and choose
Morph into |Â
QWidget. The
Vertical Layoutis makes sense, considering that it does not have any size properties. After you have converted the layout to a
QWidgetobject, it will automatically inherit all the properties from the widget class, and so we are now able to adjust its size to suit our needs.
- Rename the
QWidgetobject, which we just converted from the layout, to
loginFormand change both its
Horizontal Policyand
Vertical Policyproperties to
Fixed. Set the
minimumSize parameter to
350 x 200.
- Since we already placed the
loginFormwidget inside the
Horizontal Layout, we can now set its
layoutTopMarginproperty back to zero.
- Add the same style sheet as for the logo to the
loginFormwidget to make it visible temporarily, except this time we need to add an ID selector in front, so that it will only apply the style to
loginFormand not its children widgets:
#loginForm { border: 1px solid; }
- Your UI should look something like this:
We are not done with the login form yet. Now that we have created the container for the login form, it's time to put more widgets into the form:
- Place two horizontal layouts into the login form container. We need two layouts: one for the username field and another for the password field.
- Add a
Labeland a
Line Editto each of the layouts you just added. Change the
textproperty of the upper label to
Username:Â and the one beneath toÂ
Password:. Rename the two line edits to
usernameand
password, respectively.
- Add a push button beneath the password layout and change its
textproperty to
Login. Rename it toÂ
loginButton.
- You can add a Vertical Spacer between the password layout and the Login button to distance them slightly. After the Vertical Spacer has been placed, change its sizeType property to Fixed and change the Height to 5.
- Select the
loginFormcontainer and set all its margins to
35. This is to make the login form look better by adding some space to all its sides.
- Set the
Heightproperty of the
Username,
Password, and
loginButtonwidgets to
25so that they don't look so cramped.
- Your UI should look something like this:
We're not done yet! As you can see, the login form and the logo are both sticking to the top of the main window due to the
Vertical Spacer beneath them. The logo and the login form should be placed at the center of the main window instead of the top. To fix this problem, use the following steps:
- Add another
Vertical Spacerbetween the top panel and the logo's layout, which will counter the spacer at the bottom that balances out the alignment.
- If you think that the logo is sticking too close to the login form, you can add a
Vertical Spacerbetween the logo's layout and the login form's layout. Set its
sizeTypeproperty to
Fixedand the
Heightproperty to
10.
- Right-click the top panel's layout and choose
Morph into |Â
QWidget. Rename it
topPanel. The layout has to be converted into
QWidgetbecause we cannot apply style sheets to a layout, as it doesn't have any properties other than margins.
- There is a little bit of a margin around the edges of the main windowâwe don't want that. To remove the margins, select the
centralWidgetobject from the
Object Inspectorwindow, which is right under the
MainWindowpanel, and set all the margin values to zero.
- Run the project by clicking the Run button (with the green arrow icon) to see what your program looks like. If everything went well, you should see something like this:
- Let's decor.
- Right-click on
MainWindowfrom the
Object Inspectorwindow and choose
Change styleSheet....
- Add the following code to the style sheet:
#centralWidget { background: rgba(32, 80, 96, 100); }
- The background of the main window changes its color. We will learn how to use an image for the background in the following Using resources in style sheets section. So the color is just temporary.
- In Qt, if you want to apply styles to the main window itself, you must apply them to its
centralWidget, instead of the main window because the window is just a container.
- Add a nice gradient color to the top panel:
#topPanel { background-color: qlineargradient(spread:reflect, x1:0.5, y1:0, x2:0, y2:0, stop:0 rgba(91, 204, 233, 100), stop:1 rgba(32, 80, 96, 100)); }
#loginForm { background: rgba(0, 0, 0, 80); border-radius: 8px; }
- Apply styles to the general types of widgets:
QLabel { color: white; } QLineEdit { border-radius: 3px; }
- The preceding style sheets will change all the labels' texts to a white color, which includes the text on the widgets as well because, internally, Qt uses the same type of label on the widgets that have text on them. Also, we made the corners of the line edit widgets slightly rounded.
- Apply style sheets to all the push buttons on our UI:
QPushButton { color: white; background-color: #27a9e3; border-width: 0px; border-radius: 3px; }
- The preceding style sheet changes the text of all the buttons to a white color, then sets its background color to blue, and makes its corners slightly rounded as well.
- To push things even further, we will make it so that the color of the push buttons changes when we mouse over it, using the
hoverkeyword:
QPushButton:hover { background-color: #66c011; }
- The preceding style sheet will change the background color of the push buttons to green when we mouse over them. We will talk more about this in the following Customizing properties and sub-controls section.
- You can further adjust the size and margins of the widgets to make them look even better. Remember to remove the border line of the login form by removing the style sheet that we applied directly to it earlier in step 6.
- Your login screen should look something like this:
This example focuses more on the layout system of Qt. Qt's layout system allows our application GUI to automatically arrange itself within the given space by arranging the children objects of each widget. one on the right side of the widget. The widget will then be pushed to the middle of the layout by the two spacers.
Qt provides us with a platform-independent resource system that allows us to store any type of files in our program's executable for later use. There is no limit to the types of files we can store in our executable â images, audio, video, HTML, XML, text files, binary files, and so on are all permitted.
The resource system is really useful for embedding resource files (such as icons and translation files) into the executable so that it can be accessed by the application at any time. To achieve this, we must tell Qt which files we want to add to its resource system in the
.qrc file and Qt will handle the rest during the build process. now be created and automatically opened by Qt Creator. You don't have to edit the
.qrc file directly in XML format as Qt Creator provides you the user interface to manage your resources.
To add images and icons to your project, you need to make sure that the images and icons are being placed in your project's directory. While the
.qrc file is opened in Qt Creator, click the
Add button, followed by
Add Prefix button. The prefix is used to categorize your resources so that they can be better managed when you have a ton of resources in your project:
- Rename the prefix you just created to
/icons.
- Create another prefix by clicking
Add, followed by
Add Prefix.
- Rename the new prefix toÂ
/images.
- Select the
/iconprefix and click
Add, followed by
Add Files.
- A file selection window will appear; use that to select all the icon files. You can select multiple files at a time by holding the Ctrl key on your keyboard while clicking on the files to select them. Click
Openonce you're done.
- Select the
/imagesprefix and click the
Addbutton, followed by the
Add Filesbutton. The file-selection window will pop up again, and this time we will select the background image.
- Repeat the preceding steps, but this time we will add the logo image to the
/imagesprefix. Don't forget to save once you're done by pressing Ctrl + S. Your
.qrcfile should now look like this:
- Go back to theÂ
mainwindow.uifile; let's make use of the resources we have just added to our project. Select the restart button located on the top panel. Scroll down the
Property Editoruntil you see the icon property. Click the little button with a drop-down arrow icon and click
Choose Resourcesfrom its menu.
- The
Select Resourcewindow will pop up. Click on the icons prefix on the left panel and select the restart icon on the right panel. Press
OK.
- A tiny icon will appear on the button. The icon looks very tiny because the default icon size is set to 16 x 16. Change the
iconSizeproperty to
50 x 50and you will see the icon appear bigger. Repeat the preceding steps for the shutdown button, except this time, choose the shutdown icon instead.
- The two buttons should now look like this:
- Let's use the image we added to the resource file as our logo. Select the logo widget and remove the style sheet that we added earlier to render its outline.
- Scroll down the
Property Editoruntil you see the
pixmapproperty.
- Click the little drop-down button behind the
pixmapproperty and select
Choose Resourcesfrom the menu. Select the logo image and click
OK. The logo size no longer follows the dimension you set previously; it follows the actual dimension of the image instead. We cannot change its dimension because this is simply how theÂ
pixmap property works.
- If you want more control over the logo's dimension, you can remove the image from the
pixmapproperty and use a style sheet instead. You can use the following code to apply an image to the icon container:
border-image: url(:/images/logo.png);
Â
- To obtain the path of the image, right-click the image's name on the file list window and choose
Copy path. The path will be saved to your operating system's clipboard and now you can just paste it into the preceding style sheet. Using this method will ensure that the image fits the dimensions of the widget that you applied the style to. Your logo should now appear like that in the following screenshot:
Â
Â
- Apply the wallpaper image to the background using a style sheet. Since the background dimension will change according to the window size, we cannot use
pixmap here. Instead, we will use the
border-imageproperty in a style sheet. Right-click the main window and select
Change styleSheet...to open up the
Edit Style Sheetwindow. We will add a new line under the style sheet of the
centralWidget:
#centralWidget { background: rgba(32, 80, 96, 100); border-image: url(:/images/login_bg.png); }
- It's really that simple and easy! Your login screen should now look like this:
The resource system in Qt stores binary files, such as images and translation files, in the executable when it gets compiled. It reads the resource collection files (
.qrc) in your project to locate the files that need to be stored in the executable and include them in the build process. A
.qrc file looks something like this:
<>
It uses the XML format to store the paths of the resource files, which are relative to the directory that contains them. The listed resource files must be located in the same directory as the
.qrc file, or one of its subdirectories.
Qt's style sheet system enables us to create stunning and professional-looking UIs with ease. In this example, we will learn how to set custom properties to our widgets and use them to switch between different styles.
Let's follow these steps to customize widget properties and sub-controls:
- Let's create a new Qt project. I have prepared the UI for this purpose. The UI contains three buttons on the left side and a
Tab Widgetwith three pages located on the right side, as shown in the following screenshot:
- The three buttons are blue because I've added the following style sheet to the main window (not to the individual button):
QPushButton { color: white; background-color: #27a9e3; border-width: 0px; border-radius: 3px; }
- I will explain what pseudo-states are in Qt by adding the following style sheet to the main window, which you might be familiar with:
QPushButton:hover { color: white; background-color: #66c011; border-width: 0px; border-radius: 3px; }
- We used the preceding style sheet in the previous Creating a login screen using style sheets recipe, to make the buttons change color when there is a mouse-over event. This is made possible by Qt Style Sheet's pseudo-state, which in this case is the word hover separated from the
QPushButtonclass by a colon. Every widget has a set of generic pseudo-states, such as active, disabled, and enabled, and also a set of pseudo states that are applicable to their widget type. For example, states such as open and flat are available for
QPushButton, but not for
QLineEdit. Let's add the
pressedpseudo-state to change the buttons' color to
yellowwhen the user clicks on it:
QPushButton:pressed { color: white; background-color: yellow; border-width: 0px; border-radius: 3px; }
- Pseudo-states allow the users to load a different set of style sheets; }
- This changes the push button's background color to red if the
pagematches property returns true. Obviously, this property does not exist in the
QPushButtonclass. However, we can add it to our buttons using
QObject::setProperty():
- In your
mainwindow.cppsource code, add the following code right after
ui->setupUi(this):
ui->button1->setProperty("pagematches", true);
- The preceding code will add a custom property called
pagematchesto the first button and set its value as
true. This will make the first button turn red by default.
- After that, right-click on the
Tab Widgetand choose
Go to slot.... A window will then pop up; select the
currentChanged(int)option from the list and click
OK. Qt will generate a slot function for you, which looks something like this:
private slots: void on_tabWidget_currentChanged(int index);); }
- The preceding code sets the
pagematchesproperties of all three buttons to
false when theÂ
Tab Widget switches its current page. Be sure to reset everything before we decide which button should change to red.
- Check the
indexvariable supplied by the event signal, which will tell you the index number of the current page. Set the
pagematchesproperty of one of the buttons to
true, based on the index number.
- Refresh the style of all three buttons by calling
polish(). You may also want to add the following header to
mainwindow.h:
#include <QStyle>, there is no way the buttons would know when they should change their color, because Qt itself has no built-in context for this type of situation. To solve this issue, Qt gives us a method to add our own properties to the widgets, which uses a generic function called
QObject::setProperty(). To read the custom property, we can use another function calledÂ
QObject::property().
Next, we will talk about sub-controls in Qt Style Sheets. Often, a widget is not just a single object, but a combination of more than one object or control, used to form a more complex widget. sub-control using a style sheet if we wanted to. We can do so by specifying the name of the sub-control behind the widget's class name, separated by a double colon. For instance, if I want to change the image of the down button to a spin box, I can write my style sheet as follows:.
Note
Visit the following link to learn more about pseudo-states and sub-controls in Qt:.
Qt Meta Language or Qt Modeling Language (QML) is a JavaScript-inspired user interface markup language used by Qt to design.
Â
Let's follow these steps to learn about styling in QML:
- Create a new project by going to
File|
New File or Project. Select
Applicationunder theÂ
Projectscategory and choose
Qt Quick Application - Empty.
- Press the
Choose...button, which will bring you to the next window. Insert a name for your project and click the
Nextbutton again.
- Another window will appear and ask you to choose the minimum Qt version required. Pick the latest version installed on your computer and click
- Click
Nextagain, followed by
Finish. Qt Creator will now create a new project for you.
- There are some differences between a QML project and a C++ Qt project. You will see aÂ
main.qml file inside the project resource. This
.qmlfile is the UI description file written using the QML mark-up language. If you double-click theÂ
main.qmlfile, Qt Creator will open up the script editor and you will see something like this:
import QtQuick 2.5 import QtQuick.Window 2.2 Window { visible: true width: 640 height: 480 title: qsTr("Hello World") }
- This file tells Qt to create an empty window with 640 x 480 resolution and a window title that says
Hello World.
- If you open up the
main.cppfile in your project, you will see this line of code:
QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
- The preceding code tells Qt's QML engine to load the
main.qmlfile when the program starts. If you want to load the other
.qmlfile, you know where to look for the code.
- If you build the project now, all you get is an empty window. To add in UI elements, let's first create a
QtQuick UI Fileby going to
File|
New File or Projectand selectingÂ
QtQuick UI Fileunder theÂ
Files and Classes|
Qtcategory:
- Enter the component name as
Main, followed by the component form name as
MainForm. Click
Next, followed by
Finish:
- A new file calledÂ
MainForm.ui.qmlhas been added to your project resources. Try to open theÂ
MainForm.ui.qml file by double-clicking on it, if it hasn't been automatically opened by Qt Designer (UI editor) upon creation. You will see a completely different UI editor compared to the C++ project we did in all previous recipes. This editor is also called the Qt Quick Designer; it is specially designed for editing QML-based UIs only.
- When
main.qmlis loaded by the QML engine, it will also import
MainForm.ui.qmlinto the UI, since
MainFormis being called in the
main.qmlfile. Qt will check whetherÂ
MainFormis a valid UI by searching for its
.qmlfile based on the naming convention. The concept is similar to the C++ project we did in all our previous recipes; the
main.qmlfile acts like the
main.cppfile and
MainForm.ui.qmlacts like the
MainWindowclass. You can also create other UI templates and use them in
main.qml. Hopefully, this comparison will make it easier to understand how QML works.
- Open up
MainForm.ui.qml. You should see only one item listed on the
Navigatorwindow:
Item. TheÂ
Item item is basically the base layout of the window, which shouldn't be deleted. It is similar to theÂ
centralWidget we used in the previous section.
- The canvas is really empty at the moment, let's drag a
M
ouse Areaand
Textitems, to the canvas from the
QML Typespanel on the left. Resize the
M
ouse Areato fill the entire canvas. Also, make sure that both
M
ouse Areaand
Textitems are being placed under the
Item item in the
Navigatorpanel, as in the following screenshot:
- The
M
ouse Areaitem is an invincible item that gets triggered when the mouse is clicking on it, or when a finger is touching it (for mobile platforms). The
Mouse Areaitem is also used in a button component, which we will be using in a while. The
Textitem is self-explanatory: it is a label that displays a block of text on the application.
- On the
Navigatorwindow, we can hide or show an item by clicking on the icon, beside the item, that resembles an eye. When an item is hidden, it will not show on the canvas nor the compiled application. Just like the widgets in a C++ Qt project, Qt Quick Components are arranged in a hierarchy based on the parent-child relationship. All the child items will be placed under the parent item with an indented position. In our case, you can see the
Mouse Areaand
Textitems are positioned slightly to the right compared to the
Item item, because they are both the children of the
Item item. We can rearrange the parent-child relationship, as well as their position in the hierarchy, by using a click-and-drag method from the
Navigatorwindow. You can try clicking on the
Textitem and dragging it on top of the mouse area. You will then see that the
Textitem changes its position and is now located beneath the mouse area with a wider indentation:
- We can rearrange them by using the arrow buttons located on top of the
Navigatorwindow, as shown in the preceding screenshot. Anything that happens to the parent item will also affect all its children, such as moving the parent item, and hiding and showing the parent item.
Note the horizontal scroll bar of the canvas, scrolling the mouse will move the view to the left and right.
- Delete both the
Mouse Areaand
Textitems as we will be learning how to create a user interface from scratch using QML and Qt Quick.
- Set the
Item item's size to
800 x 600, as we're going to need a bigger space for the widgets.
- Copy the images we used in the previous C++ project, the Using resources in style sheets recipe, over to the QML project's folder, because we are going recreate the same login screen, with QML.
- Add the images to the resource file so that we can use them for our UI.
- Open up Qt Quick Designer and switch to the
Resourceswindow. Click and drag the background image directly to the canvas. Switch over to the
Layouttab on the
Propertiespane and click the fill anchor button, indicated here by a red circle. This will make the background image always stick to the window size:
- Click and drag a
Rectanglecomponent from the
Librarywindow to the canvas. We will use this as the top panel for our program.
- For the top panel, enable the top anchor, left anchor, and right anchor so that the panel sticks to the top of the window and follows its width. Make sure all the margins are set to zero.
- Go to the
Colorproperty of the top panel and select theÂ
Gradientmode. Set the first color to
#805bcce9and the second color to
#80000000. This will create a half-transparent panel with a blue gradient.
- Add a
Textwidget to the canvas and make it a child of the top panel. Set its
textproperty to the current date and time (for example,
Monday, 26-10-2015 3:14Â PM) for display purposes. Then, set the
text colorto
white.
- Switch over to the
Layouttab and enable top anchor and left anchor so that the text widget will always stick to the top-left corner of the screen.
- Add a
Mouse Areato the screen and set its size to
50 x 50. Then, make it a child of the top panel by dragging it on top of the top panel in the
Navigatorwindow.
- Set the color of the mouse area to blue (
#27a9e3) and set its radius to
2to make its corners slightly rounded. Enable the top anchor and right anchor to make it stick to the top-right corner of the window. Set the top anchor's margin to
8and the right anchor's margin to
10to create some space.
- Open up the
Resourceswindow and drag the shutdown icon to the canvas. Make it a child of the
Mouse Areaitem we created a moment ago. Then, enable the fill anchor to make it fit the size of the mouse area.
- Phew, that's a lot of steps! Now your items should be arranged as follows on the navigator window:
- The parent-child relationship and the layout anchors are both very important to keep the widgets in the correct positions when the main window changes its size. Your top panel should look something like this:
- Let's work on the login form. Add a new
Rectangleto the canvas by dragging it from the
Librarywindow. Resize the rectangle to
360 x 200and set its radius to
15.
- Set its color to
#80000000, which will change it to black with 50% transparency.
- Enable the vertical center anchor and the horizontal center anchor to make the rectangle always align to the center of the window. Then, set the margin of the vertical center anchor to
100so that it moves slightly lower to the bottom, so that we have the space to place the logo. The following screenshot illustrates the settings of the
Anchors:
- Add the text objects to the canvas. Make them children of the login form (
Rectanglewidget) and set their
textproperty to
Username:and
Password:. Change their
text colorto
whiteand position them accordingly. We don't need to set a margin this time because they will follow the rectangle's position.
- Add two text input objects to the canvas and place them next to the text widgets we just created. Make sure the text input are also the children of the login form. Since the text input don't contain any background color property, we need to add two rectangles to the canvas to use as their background.
- Add two rectangles to the canvas and make each of them a child of one of the text input we just created. Set the radius property to
5to give them some rounded corners. After that, enable fill anchors on both of the rectangles so that they will follow the size of the text input widgets.
- Let's create the login button beneath the password field. Add a mouse area to the canvas and make it a child of the login form. Resize it to your preferred dimension and move it into place.
- Since the mouse area does not contain any background color property, we need to add a
Rectanglewidget and make it a child of the mouse area. Set the color of the rectangle to blue (
#27a9e3) and enable the fill anchor so that it fits nicely with the mouse area.
- Add a text object to the canvas and make it a child of the login button. Change its text color to white and set its
textproperty to
Login. Finally, enable the horizontal center anchor and the vertical center anchor to align it to the center of the button.
- It's time to add the logo, which is actually very simple. Open up the
Resourceswindow and drag the logo image to the canvas.
- Make it a child of the login form and set its size to
512 x 200.
- Position it on top of the login form and you're done.
- This is what the entire UI looks like when compiled. We have successfully recreated the login screen from the C++ project, but this time we did it with QML and Qt Quick:
Â
Â
Qt Quick editor uses a very different approach for placing widgets in the application compared to the form editor. The user can decide which method is best suited to their purposes. The following screenshot shows what the Qt Quick Designer looks like:
We will now look at the various elements of the editor's UI:
Navigator: The
Navigatorwindow displays the items in the current QML file as a tree structure. It's similar to the object operator window in the other Qt Designer we used in the previous Using style sheets with Qt Designer section.
Library: The
Librarywindow displays all the Qt Quick Components or Qt Quick Controls available in QML. You can click and drag it to the canvas window to add to your UI. You can also create your own custom QML components and display it here.
- Resources: The Resources window displays all the resources in a list that can then be used in your UI design.
- Imports: The Imports window allows you to import different QML modules into your current QML file, such as a Bluetooth module, a WebKit module, or a positioning module, to add additional functionality to your QML project.
- Properties pane: Similar to the Property Editor we used in previous recipe, the Properties pane in QML Designer displays the properties of the selected item. You can also change the properties of the items in the code editor.
- anvas:Â The canvas is the working area where you create QML components and design applications.
- tate pane: The State pane displays the different states in the QML project, describing UI configurations, such as the UI controls, their properties and behavior, and the available actions.
- onnections: This panel is where you set the signal handlers for each QML component in your canvas, which empowers the signals and slots mechanism provided by Qt.
Sometimes, we want to modify the properties of a QML object through C++ scripting, such as changing the text of a label, hiding/showing the widget, or changing its size. Qt's QML engine allows you to register your QML objects to C++ types, which automatically exposes all its properties.
We want to create a label in QML and change its text occasionally. In order to expose the label object to C++, we can do the following steps:
- Create a C++ class called
MyLabelthat extends from theÂ
QObjectclass insource file, define a function called
SetMyObject()to save the object pointer. This function will later be called in QML in
mylabel.cpp:
void MyLabel::SetMyObject(QObject* obj) { // Set the object pointer myObject = obj; }
- In
main.cpp, include theÂ
MyLabelheader and register it to the QML engine using the
qmlRegisterType()Â function:
include "mylabel.h" int main(int argc, char *argv[]) { // Register your class to QML qmlRegisterType<MyLabel>( to import your class to QML.
- Map the QML engine to our label object in QML and import the class library we defined earlier in step 3 by calling
import MyLabelLib 1.0in our QML file. Notice that the library name and its version number have to match the one you declared in
main.cpp, otherwise it will throw an error. After declaring
MyLabelin QML and setting its ID as
mylabels, call
mylabel.SetMyObject(myLabel)to expose its pointer to C/C++ right after the label is initialized:
import MyLabelLib 1.0 ApplicationWindow { id: mainWindow width: 480 height: 640 MyLabel { id: mylabel } Label { id: helloWorldLabel text: qsTr("Hello World!") Component.onCompleted: { mylabel.SetMyObject(hellowWorldLabel); } } }
- Wait until the label is fully initiated before exposing its pointer to C/C++, otherwise you may cause the program to crash. To make sure it's fully initiated, call theÂ
SetMyObject()Â function within
Component.onCompletedand not in any other functions or event callbacks. Now that the QML label has been exposed to C/C++, we can change any of its properties by calling theÂ
setProperty()function. For instance, we can set its visibility to
trueand change its text to
Bye bye world!:
// QVariant automatically detects your data type myObject->setProperty("visible", QVariant(true)); myObject->setProperty("text", QVariant("Bye bye world!"));
- Besides changing the properties, we can also call its functions by calling the following:, we can call the
invokedMethod()function with only two parameters if we do not expect any values to be returned from it:
QMetaObject::invokeMethod(myObject, "myQMLFunction");
Â
Â
QML is designed in such a way that it can be expanded through C++ code. The classes in the Qt QML module permit QML objects to be used and operate from C++, and the capability of the QML engine's united with Qt's meta-object system allows C++ functionality to be called directly from QML. To add some C++ data or usage to QML, it should come forward from a QObject-derived class. QML object types could be instituted from C++ and supervised to access their properties, appeal their methods, and get their signal alerts. This is possible because all QML object types are executed using QObject-derived classes, allowing the QML engine to forcibly load and inspect objects through the Qt meta-object system. | https://www.packtpub.com/product/qt5-c-gui-programming-cookbook-second-edition/9781789803822 | CC-MAIN-2020-50 | refinedweb | 8,481 | 60.75 |
Does anyone know what header file needs to be included to use the matrix class?
ex:
Im trying to use
matrix<int> x(2,3)
is this an STL class? is this included in VC++ 6 ?
its suppose to create a 2D int-array with 2 Rows and 3 Columns
I also have another question regarding the #include in VC++..
I noticed my usage of #include<vector> requires me to use the namespace std, why ?
what is the difference between #include<vector.h> and #include<vector>
ouch thats a lot of questions.
Hopefully there is a Jedi brave enough for this challenge
Thanks guys.
Forum Rules | http://forums.codeguru.com/showthread.php?280989-matrix-class-STL&p=886499&mode=threaded | CC-MAIN-2017-26 | refinedweb | 106 | 75.91 |
- Data flow
- Changing the job logs local location
- Uploading logs to object storage
- Prevent local disk usage
- How to remove job logs
- Incremental logging architecture
Job logs
Renamed from job traces to job logs in GitLab 12.5.
Job logs are sent by a runner while it’s processing a job. You can see logs in job pages, pipelines, email notifications, and so on.
Data
To change the location where the job logs.
Alternatively, if you have existing job logs you can follow these steps to move the logs to a new location without losing any data.
Pause continuous integration data processing by updating this setting in
/etc/gitlab/gitlab.rb. Jobs in progress are not affected, based on how data flow works.
sidekiq['queue_selector'] = true sidekiq['queue_groups'] = [ "feature_category!=continuous_integration" ]
- Save the file and reconfigure GitLab for the changes to take effect.
Set the new storage location in
/etc/gitlab/gitlab.rb:
gitlab_ci['builds_directory'] = '/mnt/to/gitlab-ci/builds'
- Save the file and reconfigure GitLab for the changes to take effect.
Use
rsyncto move job logs from the current location to the new location:
sudo rsync -avzh --remove-source-files --ignore-existing --progress /var/opt/gitlab/gitlab-ci/builds/ /mnt/to/gitlab-ci/builds`
Use
--ignore-existingso you don’t override new job logs with older versions of the same log.
- Resume continuous integration data processing by editing
/etc/gitlab/gitlab.rband removing the
sidekiqsetting you updated earlier.
- Save the file and reconfigure GitLab for the changes to take effect.
Remove the old job logs storage location:
sudo rm -rf /var/opt/gitlab/gitlab-ci/builds`
Archived logs are considered as job artifacts. Therefore, when you set up the object storage integration, job logs are automatically migrated to it along with the other job artifacts.
See “Phase 3: uploading” in Data flow to learn about the process.
Prevent local disk usage
If you want to avoid any local disk usage for job logs, you can do so using one of the following options:
- Enable the incremental logging feature.
- Set the job logs location to an NFS drive.
How to remove job logs
There isn’t a way to automatically expire old job logs, but it’s safe to remove them if they’re taking up too much space. If you remove the logs manually, the job output in the UI is empty.
For example, to delete all job logs older than 60 days, run the following from a shell in your GitLab instance:
find /var/opt/gitlab/gitlab-rails/shared/artifacts -name "job.log" -mtime +60 -delete
sudo gitlab-rake gitlab:artifacts:check. For more information, see delete references to missing artifacts.
Incremental details. After the full chunk is sent, it is flushed to a persistent store, either object storage (temporary directory) or database. After a while, the data in Redis and a persistent store is archived to object storage.
The data are stored in the following Redis namespace:
Gitlab::Redis::TraceChunks.
Here is the detailed data flow:
- The runner picks a job from GitLab
- The runner sends a piece of log to GitLab
- GitLab appends the data to Redis
- After the data in Redis reaches 128KB, the data is flushed to a persistent store (object storage or the database).
- The above steps are repeated until the job is finished.
- After the job is finished, GitLab schedules a Sidekiq worker to archive the log.
- The Sidekiq worker archives the log to object storage and cleans up the log in Redis and a persistent store (object storage or the database).
Limitations
-. | https://docs.gitlab.com/14.10/ee/administration/job_logs.html | CC-MAIN-2022-27 | refinedweb | 590 | 54.42 |
- NAME
- DESCRIPTION
- METHODS
- SUPPORT
- AUTHORS
NAME
JSAN::Parse::FileDeps - Parse file-level dependencies from JSAN modules
DESCRIPTION
As in Perl, two types of dependencies exist in JSAN. Distribution-level install-time dependencies, and run-time file-level dependencies.
Because JSAN modules aren't explicitly required to provide the file-level dependencies, this package was created to provide a single common module by which to determine what these dependencies are, so that all processes at all stages of the JSAN module lifecycle will have a common understanding of the dependencies that a file has, and provide certainty for the module developer.
METHODS
library_deps $file
The
library_deps method finds a list of all the libary dependencies for a given file, where a library is specified in the form
"Foo.Bar" (using the pseudo-namespaces common to JSAN).
Returns a list of libraries, or throws an exception on error.
file_deps $file
The
library_deps method finds a list of all the file dependencies for a given file, where a file is specified in the form
"Foo/Bar.js" (that is, relative to the root of the lib path for the modules).
The list is identical to, and is calculated from, the list of libraries returned by
library_deps.
Returns a list of local filesytem relative paths, or throws an exception on error.
find_deps_js $file
The
find_deps_js method is used to extract the header content from a file, to be searched for dependencies, and potentially written to a
module_deps.js file.
Returns the content as a list of lines, or throws an exception on error.
make_deps_js $file
The
make_deps_js method takes a JSAN module filename in the form
"foo/bar.js" and extracts the dependency header, writing it to
"foo/bar_deps.js".
Returns true on success, or throws an exception on error.
SUPPORT
Bugs should always be submitted via the CPAN bug tracker
For other issues, contact the maintainer
AUTHORS
Completed and maintained by Adam Kennedy <cpan@ali.as>,
Original written by Rob Kinyon <rob.kinyon@iinteractive.com>
Copyright 2005, 2006 Rob Kinyon and Adam Kennedy. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module. | https://metacpan.org/pod/JSAN::Parse::FileDeps | CC-MAIN-2019-04 | refinedweb | 380 | 54.22 |
Transcript
Laverack: I'm here to talk about Kubernetes and operators in etcd. A lot of what I'm going to be talking about is pretty generic to operators. It's really about what an operator is, and what problems it can solve, and why you would actually want to build one. Also, how you can build one. I'll be using etcd as an example. This isn't really specific to etcd at all.
Overview
I work for a company called Jetstack. We are primarily a consultancy. We also provide training. We do open source work. We're most well-known for cert-manager, which is an operator for TLS certificates. I mostly work on the consulting side of things. That's where this story comes from. This is based on a consulting engagement we started at the end of last year. We were working with a company called Improbable. They're based here in London. They're a software company. They make software for massively multiplayer games. They came to us with this problem statement, "We need to run etcd in Kubernetes." They were running part of their platform in Kubernetes. They wanted etcd alongside of it to simplify their management story.
Etcd
Let's take a bit of a step back and figure out why this is difficult at all. Why am I even talking about this? First of all, was etcd itself. Etcd is famous for being the backing store for Kubernetes. Everything you put in Kubernetes is stored in there. That's where you mostly see people talking about it. This is not that use case. It's something else. The project itself is a completely generic, distributed key value store. It's a CNCF hosted project. It's been going along for a couple of years now, originally made by CoreOS.
Why it's Difficult to Put in Kubernetes
Why is this difficult to put in Kubernetes in the first place? Let's take a look at the traditional case. This is if you're running this on either bare metal, or VMs, or cloud VMs like EC2, or something like that, so no orchestration layer of any kind. In this, we've deployed three machines. We have three etcd instances running. They have a little bit of local disk each. They can contact each other. That's all you need to configure. Once you tell them about each other using their domain names, or hardcoded IP addresses if you have static IPs, they will find each other and they will use the Raft consensus protocol internally to elect a leader. Then from there, they can start serving requests. Client applications can connect and they'll usually connect to either all of them, and they'll pick one and do client-side load balancing. Or, you can tell it, just give a single domain name with a bunch of A records, one per node, which can then do the load balancing that way. That's pretty simple.
What about a Stateful Set?
If you've used Kubernetes at all, and you're looking at this, the thing you're probably thinking is, we need some persistent disk. We need some persistent network identity. There's a stateful set. Kubernetes has a native component to handle this task. What's wrong with that? This is the example diagram from the Kubernetes Icons Set of a stateful set. We have pods which are running containers, which have our application in it. In this case, etcd. We have a service that's effectively providing the DNS resolution to this. It has a service name. It helps us provide static DNS names to all of the individual pods. We have those PVCs, Persistent Volume Claims, which then your cloud provider will go and then bind those to actual disk over on the side there. As a user, you don't really need to worry about it. They end up on a disk somewhere. The stateful set orchestrates that side of things. They'll make sure that they always get reattached to the same disk. They'll make sure they always get the same name. What's wrong with this? Why doesn't it work? If you just want a completely static cluster, it does work. It stands up fine. There's no particular issues immediately.
Let's talk about something slightly more advanced, you might want to do with etcd, where this starts to fall apart. One feature it has is runtime reconfiguration. You can, while it's running, add or remove nodes from your etcd cluster. How you would do this is, you have to tell etcd about the new node first. Etcd has this internal knowledge of all its members because it's not designed to run with an orchestration layer. The first thing you have to do is actually tell it you're going to add a new one. Then you can bring the new one online. The new one will then join to the cluster, if you don't do this, the new one will be rejected. It won't join the cluster. It won't perform quorum. It won't perform consensus. You'll get a lot of errors. It's not a nice place to be. The scale down is exactly the same in the inverse. The first thing you do, going back to our three-node cluster, is you tell it you're going to remove a peer. It will then unregister it. It will stop replicating to it. If it was the leader you removed, it will redo a leader election. Then you take it offline. That's pretty simple. This is encoded in the operations guide documentation for etcd. This is how they recommend that you do this.
Let's go back to our stateful set, and think how we might implement some of these problems. If you scale up, we're going to add a new pod. Then before we turn it on, we need to do something to the etcd cluster. In Kubernetes, we have the concept of Init container. You can add an extra container that will execute strictly before your application starts. It'll perform some logic. We also have a concept of a pre-stop hook. This is where before Kubernetes will stop your container, you can have it execute something. You can have it exec a script in a container or whatever. We can start doing this. Already, you can look and see, what happens if you have comms failures? What happens if you stand up and you can't contact the cluster? How do we determine whether this is the first time we've launched or not? What do we do if we have an error removing a peer? Do we stop blocking? Do we not let it shut down? What do we do? Then the real thing you start to realize is that this pre-stop hook is going to get executed every time we shut down one of these pods, not just when we scale down. If Kubernetes decides to reallocate the pod somewhere, and a node gets drained, and wants to put it on another machine, it will run that hook before it stops the container. We're going to be constantly resizing this cluster, even when we're not meaning to. That goes out the window slightly. That's a complete disaster. Then if you think about it leaving, if you could find another way of doing this, there are a whole slew of other issues that come out of this. Things that could go wrong. Things that you're going to have to handle and deal with. It starts to come with a lot of overhead. Potentially, it's going to be overhead on the operations team that's going to be managing this. They're going to have to know how this thing works. Understand how it could go wrong. Understand what to do to fix it when it inevitably does go wrong at 3 a.m.
We Need an Operator
What can we do better? We decided we need an operator. To briefly outline the definition of an operator in Kubernetes. If you go to the official documentation, and you ask it what an operator is, it tells you this. It can extend the API. Which is nice, but how did that help us? If you read down the page a little bit, this is a quote that is to capture the key aim of a human operator. It is to take the knowledge of how the system ought to behave, and deploy it, and react if there are problems. That's a bit more like it. That's our operations guide. We have pages of documentation from the etcd project telling us how to run this thing. We want to do that. Why don't we encode it?
An Operator Encodes Knowledge
That's what the operator really does here. It encodes operational knowledge of an existing application. This is just one use case for running an operator. People use these things to build completely cloud native applications. This is slightly different. This is taking an application that was never designed to run in an orchestration system, it was never meant to run in Kubernetes, and making it work with the Kubernetes system. The project has become pretty popular. Other concepts have become pretty popular. There are a bunch of them out there. OperatorHub has been mentioned by some. We've lists of hundreds of these things. Cert-manager made by Jetstack is the one for TLS certificates. Strimzi is another good example that's actually written in Java. That one is for Apache Kafka. There are a whole bunch of these things out there that are used to run complex applications in Kubernetes. One interesting tidbit is when the operator concept was first introduced back in November of 2016, in the blog post by CoreOS, they actually use etcd as the canonical example of why you might need an operator. Which of course begs the question of, if there's already an etcd operator, why are we building one? The reality is that we looked at it and it didn't quite meet our production use case with Improbable. We decided the changes we needed to do were too big. We decided to write something slightly different. A slightly different focus for us. It's very interesting that we're going back to this use case again.
How to Actually Build an Operator
How do you actually construct one of these things? We know we want one but how do you actually make one? The core thing that makes this possible is the custom resource definition. This is something part of Kubernetes that lets you tell Kubernetes that there is a new thing it knows about. You can specify the shape of it. You can specify a spec. You can have it do basic validation. This is the thing that really enables this. Once you specify a custom resource definition, load it into your cluster, it works just like a native resource. You can ask, in this case, kubectl to list the API resources available, as well as the things that are built in like deployments, and replicasets, and pods. It's listed my etcd cluster resource. It knows about it. This means all the tooling knows about it, too. Kubectl works perfectly well with it. If you're using GKE or something like that, their web console knows about it. If you're using one of the visual systems for interacting with Kubernetes like VMware's Options, that will also show it to you just alongside everything else. All your existing tooling, GitOps, even things like OPA Gatekeeper, if you're using something like that to enforce policy, will work with these tools. That's pretty good.
Now that we've defined this, how do we actually build the operator to do anything? Just like everything else in Kubernetes, it's just a pod running in Kubernetes. That pod right there is our operator. We put it in its own namespace. We've got a deployment there to make sure it comes up. We give it a service account. I mention the service account, because it's particularly important. It's what gives it the ability to do everything it needs to do. If you look at what's in there, we have permissions to look at etcd cluster resources. We have permissions to make the things we need in response, replicaset services, whatever we need. In particular, there's watch right there. This is a great feature with operators. Instead of having to sit there and poll Kubernetes asking it, what's there? What does it need to do? It can get notified when things change. Those write really efficient cacheable code. You create an etcd cluster and the operator will be woken up by Kubernetes and asked to do things.
What's in that pod? What has the operator actually implemented? It's the miracle of containers. It can be anything. You could write an operator using a bash script in Curl if you wanted to. I wouldn't necessarily recommend it, but you could. This is where I start talking about the exact specifics of our project. For our team, we chose to do this in Go. This is for two reasons. Firstly, Go has a lot of really good ecosystem tools for building these things. Go is what Kubernetes itself is written in. It's natural. There will be a lot of support for it. The other, and probably the biggest reason, is really about our team. The team of people who worked on this, which is a bunch of us at Jetstack, and a bunch of us in Improbable. We all knew Go. We were all familiar with it. We were all happy with it. It worked for us. Had that not been the case, if we were working with a company that likes Java, I would have had no problem writing this thing in Java. Pretty much you can use whatever you want. There are lots of examples out there. There's operators built in Java, in Rust, whatever you need.
The other thing we did was kubebuilder. This is what I was talking about with Go ecosystem. This is a project that can help you scaffold out and create a lot of resources, and merge these things in Go projects. This isn't the only thing like this. There are a bunch of them out there. The Operator SDK by CoreOS and now Red Hat, is another operator framework, which the Operator SDK is one part. It is another very good example. Other languages have other examples as well of things that really help you do all the things you need to do, manage your CRDs, manage your versioning, all these stuff. We chose to use kubebuilder, largely because we really liked the documentation. That kubebuilder book goes into a lot of detail about the why of how you want to do things. It's quite opinionated. That's something that we liked, we agreed with its opinions. We moved in that way. We also found the testing stories really good.
Operator Logic
We decided that we are going to make it. We're going to build this thing. Make no mistake, this is an engineering effort. It took us a few months to build this. It was mostly working full-time. It's not a small project that you do in one week. It's something you actually have to build and maintain as any other software project. Now that we're building, and we decided we're going to do it. We know how we're going to do it. What are we actually going to make it do? The core of any operator is this reconciler loop. This is how Kubernetes itself works internally. Where the first thing the operator in this pod will do is it will ask the API server about these etcd clusters that got woken up by them when it changes. From that it will get the desired state of the world. You have told it that you want an etcd cluster. You want three replicas. You want this version. Then based on that, it will go and make that happen. It will make the underlying resources. It will do the things it needs to do, to make that in reality based on what's already there. This is the core loop. The idea is that if you change your definition, then it will update accordingly. If you fiddle with some of those things on the side, it will correct them for you. It'll put them back in the desired state. It is always moving the world towards the state, as you told it you wanted it. This is how, pretty much every operator works. Ours was actually fractionally different. It all goes back to that etcd internal state thing. We need to tell etcd about things. Etcd has its own view of what the world should look like. What things need to be there, and what peers it needs to know about. We built this into our design. We actually have an almost double loop. The first thing we do is we take our desired state and then we go talk to the etcd cluster that we're managing it. Make sure that it's in line with what we wanted to have. If we need to add a new peer, the first thing we'll do is tell etcd about it. Once we've done that, we can go and we can take what etcd expects of the world and implement that. That means etcd is always the first to know. It means that we are moving with its expectations. We are implementing what the operations guide told us to do.
In order to help with this, we actually split that logic out. We actually built two CRDs. We actually built one for a cluster and one for a peer. This is largely a code clarity thing. It means that we have two different code paths. One for managing clusters, which then create the peer. Then one for managing the peers. It also means that this is exposed in our API. As an administrator, if you want to know what's really going on, you can ask the API, what etcd peers exist? It can tell you. It means that when we expose status of individual peers, you can use kubectl to describe a peer, and you can get its status information right there in the API just for you. This helps us leverage that first thing in the first quote I got from the documentation of extending the API to help an administrator run this thing. That means that the actual reconciliation loop for us looks more like this. We view a desired cluster. We talk to etcd. We create the peers and the service, because the service is per cluster not per peer. Then we respond to the peer existing, and go through this as a second loop. Then we create the replicasets, persistent volume claims, and things like this. It's a slightly different take on it. That core, reconciler observe state, actual state loop is still there.
Design Considerations
Some design considerations. These are things that we thought about at the start, based on our experience with operators, based on my colleagues' experience with cert-manager, things like this. Things we really wanted to make sure we get right at the start. These are things that worked for us. These are not hard and fast rules. This is just our experience.
Be Level-Triggered
The first thing was to be level-triggered. This is a piece of terminology that has been co-opted from people working on low-level embedded signal systems with voltages and things at that level. This is the idea that you should be level-triggered, not edge-triggered. I'm not going to explain exactly what this means for signal processing. For us, it means that you shouldn't react to changes in state, you need to react to the state itself. If you scale your cluster up from three to five, you shouldn't interpret that as add two. You should interpret that as I want five, I have two. That seems like a really subtle distinction. It seems like I've just said the same thing twice. It's important in certain failure conditions. It is important, if you lose connectivity, if your operator pod gets restarted, when it comes back it may have missed that scale up event. It might not have known that this happened. Instead, it just has to look without being told to look. It has noticed that this thing is wrong, and do it. That means, look at state, not look at the change in that state.
Do One Thing at a Time
The other thing is to do one thing at a time. Our operator reconciler loop starts by deciding what to do. Does one thing, and then exits. Then next time around when it gets invoked again, which is usually immediately, it will do the next thing. This seems weird. When you first do it, you think, I know I need to make three things. Why am I doing this three times just to make my three things? Why don't I just make them? The answer is that it makes it more resilient this way. It makes it easier to understand what the code is doing. It makes it easier to test. It makes it easier to debug. It means that if you then go and change one of those things, and it re-reconciles, it will only do the one thing it needs to do. If you group these changes together into larger changes, then you might miss things if you're in a partial state, which can help you in certain failure conditions. It's not something that you'll notice necessarily, but when you need it, you'll know.
The Cache Might Lie to You
The other thing is caching behavior. Another one of the things that a load of the Go logic and kubebuilder gives you is it will cache things. You pull information from the API about what replicasets are already there because you need to make one. Your cache might be out of date. You might get lied to. You might ask it, do I have a replicaset? The answer will be no. When you go to create it, you'll get an error telling you it already exists. This can happen. This isn't necessarily something to be afraid of. It just means that you have to make sure that all of your operations are reproducible. It means when you create names for things, they have to be deterministic. It means you have to accept that sometimes you might just try to create something and it's already there, because you've already done it last time. That's ok. Just wait, do it again. Then, eventually, your cache will update. They don't have to worry about it. The canonical example where this could be a problem is if you're making randomized names for peers. By the time you have caches ready, you could have created five of them. Then you have to notice that you created five and it's going back down again. It's much easier just to have a deterministic name, try to create it a second time, fail. Then wait to update your cache.
Deploying an ectd Cluster
Let's actually talk through how this solves our etcd problem. It is going back to our etcd example. You want to deploy it, you can create a resource like this. This is a really minimal example. You can specify more things in this spec. You can specify storage information. You can specify the version of etcd you want, things like this. In this simple example, I just said I want three of them. I'll let the operator to develop the rest. This is what we get. We get a cluster resource that someone just created. We make a service, which is going to give network identity to all of our etcd's. Then we'll create three peer resources. Those of you who remember my original diagram are wondering how we just did this, because the first thing we do is we talk to etcd. Etcd isn't there yet. We haven't made it. How can we do this? We have this state. We're just trying to dial etcd and there's nothing because we haven't made it. For this particular case, we have a bootstrap mode. If your operator sees that there is a cluster desiring peers and it hasn't made the peers yet, so it can't find the peers. It can't contact etcd. Then it assumes it's bootstrapping. Assumes it needs to add more peers. It will speculatively create them, and add those peers. This can go wrong. If you have a network outage, your operator pod might not be able to talk to etcd, even if it's already there. This can fail. That's ok, because the operator will recover. If you accidentally create too many pods, eventually this theoretical network fault will heal. You could talk to etcd again, even though your etcd is confused because it has a bunch of things trying to talk to it. It doesn't know that they're there. It doesn't expect them, at which point the operator will reconcile the state of the world to etcd's expectation and get rid of them. This will eventually heal, which is why we're comfortable with having this bootstrap mode. The other thing to bear in mind is we never delete things in bootstrap mode. We only ever add peers, which means we can't delete data by accident. You can scale this down and then accidentally drop all your pods, because it's all they needed to.
These peer resources look a bit like this. It's pretty simple. The two things to be aware of is the initialClusterState there. That's actually something that can be either new or existing. This is what etcd wants. There is a configuration flag that you give to etcd to tell it whether it should try to bootstrap a cluster, or whether it should join an existing one. We're really just fulfilling what the operations guy told us to do. This is what I showed you to provide. We also need to tell the other nodes, they have peers in this cluster. Here, we've actually done something a little bit interesting. We've predicted what its names are going to be, because we haven't made any of these things yet. This is the point where we've created the FCP resources, the underlying pods, and replicasets, and everything else don't exist. We're predicting based on the service that we've already created, what its DNS name is going to end up being. This is achieved by the hostname field on a pod. If you've set that, it will get a DNS name regardless of its name. That's how we do that.
What does the peer create? We make a replicaset. We get the pod with its hostname set, because we set out on the pod template and replicaset. We create a PVC. To clarify, that's one replicaset per peer, not a replicaset for all of the individual etcds. The reason we're using a replicaset is because we had concerns about HA constraints in production. We didn't want our operator that was directly managing pods to have to be alive in order to bring a cluster back up in a failure condition. Instead, we use a replicaset. Operator doesn't even have to be running and the cluster will heal itself because Kubernetes will restart the pod for it, because we use a replicaset to hold it to. You don't have to do this. You can directly address pods if you want. This was a take it or leave it decision for us. It is one thing we do slightly differently. The takeaway is that you can use these higher order Kubernetes things with your operator, you just have to go all the way down to start managing pods and things like this.
I've drawn the line to a PVC slightly differently, that's because we don't set an owner reference. Normally, with Kubernetes resources, you can tell it that one resource is the owner of the other. When you delete the parent, it will delete the children too. We wanted to avoid the case where if you accidentally, or someone maliciously did a kubectl delete as the cluster of my cluster on my etcd, it will delete everything. We didn't want it to drop the data. This means that if you do that, the PVCs will be left behind. Your data will still be there. You can recover from doing that.
Now that we've got all of this, where does it deploy? If you just deployed that YAML I showed you, you'll get this. You will get three pods running in etcd each, with hostnames like that, with a PVC each and a PV each. That's its internal view of what the world is. This is pretty much exactly what that on-prem traditional VM slide I had at the beginning looked like just with pod written around it rather than a machine. That's pretty good.
Scale Up
Let's go into things that were difficult before, what was hard. Scale up was awkward. We could have done it, but it was awkward. How do we do it now? We edit our resource. We tell it that instead of wanting three of these things, we want five of these things. This could just be a few kubectl edits. This could be from some GitOps pipeline, redeploying it because you've changed it. This could be through kubectl apply. We also implement the scale sub-resource. You can actually just use tooling that understands this concept of scaling, to scale these things. You can just say, kubectl scale, I want five of them now. It will understand that and it will work in exactly the same way.
The first thing we do, we reconcile to etcd. We can contact etcd. We're not in bootstrap mode. We go to it and we tell it we're going to create a new peer. Again, we've predicted its name. We know we're going to call it -3, because that's the next ordinal number. It is a deterministic name. We tell it. This is going to come into existence. We create a new peer resource, because now we reconcile etcd against the world, and etcd expects a my-etcd-3. There isn't one, so we make one for it. This now looks like this, at this time. The only real difference is that initialClusterState is now existing. We know this because we populated from etcd. We know we can talk to etcd at the time, so the operator knows this must be an existing cluster. We just give it the names of all the other peers so it can talk to them and find out, and bootstrap with them. If you draw everything on one slide, you get this. You get our namespace. We have our cluster resources, and our peer resources, and all of our nodes, and replicasets, and PVCs, and everything else we need. Then of course it would go on and it would do the fifth one.
Scale Down
What about scale down? This was a big problem before. This was really painful. How do we do this? If we go back to the three-node case, and we say scale it down to one. We go to etcd, and we tell it we want to remove one. Then we get to remove it. There's a problem. We don't want to delete the PVC. If you just delete the resource, it'll clean up the replicasets in the pods, but the PVC, we don't set its owner reference, so we're not going to get rid of it. This is an issue because if you scale down and then scale up again, because the PVC is deterministically named, it'll use the same PVC. Which means that you could have a scale down, and a few weeks, a month later, scale back on the same cluster, pick up stale data. A property of etcd is that if you already have a data directory, it ignores bootstrap instructions, or even worse, this new etcd you've created will be completely stale. We take care of this case, in particular, in response to a scale down when the operator has intentionally decided to scale something down as distinct from just deleting the resource. It will go, and before it deletes it, it will attach a finalizer. This is a hook you can attach to any resource in Kubernetes to tell it to do something before it gets deleted. Then we delete it. Then Kubernetes calls back in to us, to ask us to do the thing that we said we were going to do. In which case, we delete the PVC. We clean it up. Then we get rid of it. Then we'll get rid of number one as well. Then we'll be down to our desired state of having only one replica.
Other Features
I've covered those features. I mostly gave worked examples. This operator does a whole bunch of other stuff too. We have version upgrade. You can specify a version and a spec, and it will do a rolling upgrade. You can do backup. You can tell it to back up your cluster while it's running into a cloud bucket. You can do restore. You can't do a restore in place. You need to create a new cluster, again, following the operations guide. You create a restore resource and then it will go and it will pre-populate the PVCs for you. It will create an etcd cluster on top of it to make sure it comes up correctly. These are all just implementing what etcd told us to do in their documentation.
Testing
The last thing I really wanted to touch on was testing. I mentioned it earlier when I talked about kubebuilder, and what a testing story was like. It looks like this. I will go to the biplane over there, which is our Go process on your laptop or on your CI node. That was a big driving factor for us. We wanted all these tests to run on a laptop as well as in CI. We didn't want to be tied into needing a GCP cluster, a GKE cluster, or something like that in order to run our tests. Kubebuilder's default test harness does is it will stand up the API. It'll stand up, ironically, an etcd, in order to back our API. This is not the etcd on the test. This is just an etcd to back the API server. It just downloads the binaries, these things that runs it. There's no pods. There's no Docker. There's no container runtime. There's no nothing. You don't get to actually run things. You can create resources. You can watch them, and listen to them, and do all these things. In that code, our controller loop is running. Then we go in and test. We're going to create an etcd peer. We go [inaudible 00:31:23] API in response.
We created a replicaset. We created a PVC. We can assert on its properties. We can assert that we made it. We can test what happens if we start deleting stuff, or changing things, and how it responds. Of course, part of our reconciliation logic is we go out to etcd. We end up just mocking that. We have a little mock stub for the etcd, so we can pretend that the etcd is behaving, or pretend the etcd is not behaving, that you can't contact in order to trigger that bootstrap mode or non-bootstrap mode in order to cover our behavior. This is great. These are just a little bit heavier than unit tests. They are not quite as fast because it has to actually launch the API server and the etcd binaries. Those things are pretty efficient. These don't take very long.
The last piece of this is a real end-to-end test. We actually run this and actually stand up etcd pods. For that, we use kind. This is another CNCF SIG hosted project. It stands for Kubernetes in Docker. People can and have done entire talks on how this thing works. It's a really interesting project. I recommend you check out the documentation. The really short version, for our purposes, is just that it lets you stand up Kubernetes on any host that has Docker. You don't need anything beforehand. These things are small. They come up in a few minutes and are entirely reproducible. It's perfect for our testing. We can run these on CI nodes. We can run these on laptops. This is great.
Putting this all together, we have this. This is everything we do, if you try to run an end-to-end test using this thing. The first thing we do is we create a kind cluster. That stands up the control plane and everything else we need for the whole Kubernetes thing. Then we go and we run Docker build in order to build the images that actually have our operator inside of it. Then we go and we load the operators in, load the images in. Deploy the operator, and do things like that, in order to get our CRD and everything else. Then we can deploy an etcd cluster. Step back and just watch it bootstrap everything, in the way I described. Then we can start poking it. We can start asserting on it. This is because it is actually running real containers in actual pods. It's actually running etcd and talking to it. Verifying that our communication to etcd is working as we expect. Verifying that our reconcile loop is doing the correct thing in the correct cases. We can go in and start blowing things up and removing things to make sure it works. This is how we handle that end-to-end testing part of building this thing, to make sure it does actually work.
Lessons Learned
What do we learn from doing all of this? What are our key takeaways from this process of trying to implement this operator? They provide value for applications with complex runbooks. This was complicated. The operations guide is quite long. That meant that there was value in writing this code to implement that for us. We learned that we can work with the existing tooling. If you're using GitOps to deploy a bunch of YAML files, or a Helm chart, it will still work with this. If you're using Gatekeepers to enforce security policy on these things, it will work with this. It will work with those CRDs. We learned that you can use any stack. Go worked for us. This was a result of our team. Our experience. What we were comfortable with. What we wanted to do. If you're a Java company, go write this in Java. Or Python, go write it in Python. You don't have to use Go. You don't have to use that tooling. It's completely agnostic. We learned that you can end-to-end test them with kind. I can do this on my laptop. My laptop isn't that powerful but it can still run it. We can do this in CI. It is reproducible testing between a local development environment and a remote one. The operator itself is MIT licensed. It's available on GitHub.
Questions and Answers
Participant 1: I assume when you talk about scale, that means you can plug it in to [inaudible 00:35:58] scaling, and it's just going to work.
Laverack: You could, but you probably don't want to.
Participant 1: Do I get that [inaudible 00:36:06]?
Laverack: It's really a property of etcd that you don't scale up to increase load, because of the way etcd works. You scale to increase resiliency. If you scale up, actually, your write performance will get worse, and your read performance will get only fractionally better. If you could autoscale on some dynamic resiliency metric, you probably want to do that. You completely could if you wanted to.
Participant 1: How much does it depend upon introspection in that platform? It sounds like you're talking to etcd and you're telling it about stuff that's happening. Does this whole thing depend upon that or would you recommend to get away with that space that doesn't have any bounds set, or less bounds set?
Laverack: We did it in this case because a load of the problems we had doing this without it was just that etcd's internal state would get confused, and wouldn't match the world. That's where we went on that path. If your database didn't do that, and it would accept whatever its environment would, or dynamically figure it out, you probably don't need to. It would depend on the use case. Most operators don't really do this. They don't need to, so they don't bother.
Participant 2: I was quite interested in your concept of doing one unit of work per reconcile loop, monthly. If you're adding five nodes, you add one, go on to the next reconcile loop and add another. Could you go into a bit more details about why you decided to go that way? What the major benefits were versus the drawbacks? In OperatorHub, for instance, we don't do that. We do unit operation after unit operation. It would be quite interesting to see what your thinking was on that.
Laverack: The canonical example was talking about, if you need to create two things. Let's say you need to create a service and a pod, for example, then you might have a piece of logic that goes, if service does not exist, then create service and create pod. Of course, if you delete the pods, you'll never rerun this. You have to figure it out. I knew of this logic, which is, if any of these things do not exist, try to create all of them. Of course, many of them may already exist and they have to handle that. It just worked out to being a little bit easier for that case. Typically, what happens is you're going to run multiple times anyway. Because when we create most of these resources, we set owner references. For example, when the cluster controller creates the service, it sets itself as the owner. When anything changes in something you own, we get woken up again by that watch. What actually happens is we go and we create a service, and then as a result of that service being created, we get invoked again. Which means we immediately get invoked at which point we start doing the next thing. Whereas if you created 10 things, you create your 10 things and then you'd run 10 more times as you could have re-reconciled every time. It's actually more efficient in most of these cases to actually just do it one by one, and just let the reconcile loop just re-run.
Participant 3: How much effort did it take your team to create this operator? You mentioned that it is a big project. It's not a small part. You didn't mention any scales.
Laverack: I think the team was probably about three or four people. Not quite full-time. I think about 80% of the time for a few months. This was over Christmas, and a load of us were around for one time. Nothing much happened then. In total, it's probably a few people for a couple of months to be able to get it to this stage, which we consider to be pretty stable. It's not completely small. We think it was a price worth paying for making the operation side of things easier. It's definitely not something you could bang out in a week. You could bang out a prototype. I think the original prototype was written overnight in about three hours by one guy. Of course, that's just a prototype. It doesn't have documentation, or testing, or anything like that. To actually bring it to a production ready state took much longer, as is true for most software projects.
Moderator: I presume you write this because there wasn't an operator already available? Maybe it's worth sharing that there's hundreds available? This etcd one that you built, is that available to people in this room?
Laverack: Yes. There was an operator available. The CoreOS one is still out there. It didn't quite meet our use case, which is why we decided to go slightly different. We evaluated the concept of contributing upstream to it and trying to make the changes that way. We realized that in order to do everything we wanted, we would have to change, basically, the entire codebase anyway. We decided just to do it, take this approach. The code is available. It's on GitHub, if you want to take a look. It is MIT licensed. You can use it if you want to. We welcome contributions, all sorts of stuff.
I mentioned OperatorHub. I don't think we're on there yet. I think we need to talk to them about it. There are hundreds of these things out there. Lots of databases, in particular, have these things. CockroachDB have one. There's one for CouchDB, I think. I think it is three for Postgres that do have various different focuses. There are a bunch out there for these things. They're very popular for databases, just because databases require this extra special stateful management.
Participant 4: Were you doing this through a test client. Is this something you'll be able to work in, or you experienced doing operators already?
Laverack: Me personally?
Participant 4: Your team.
Laverack: Jetstack have done operators before. One of my colleagues, James Munnelly wrote cert-manager, and that's an operator. He's been working in this space for some time, a few years now. I myself had not written an operator before. A bunch of my colleagues had done so. We did have experience in the team to draw on.
Participant 4: Relatively easy to get into it?
Laverack: Yes. I mentioned the kubebuilder documentation, the kubebuilder book. That was pretty good. It does spend a lot of time talking about why we do certain things, because it has all these opinions. It goes into some detail about why the authors of kubebuilder think you should do things in this way. That helped quite a lot.
Participant 5: Because obviously you guys actually you've got state, what happens especially early in the project when you have to start upgrading, adding fields to your CRD? That's going to get quite painful, I imagine.
Participant 5: Yes, we get stung by it.
Laverack: If you looked, our current API version is V1, alpha 1, which means that we're comfortable making breaking changes. We don't really want to. We can and we have. Once you stabilize into beta, you can't really do that. It does get easier. Kubernetes has a feature called a conversion webhook. You can register a piece of logic that will run whenever you create or update something that can actually run a version conversion for you. If your version is only you've moved a field or you've done certain categories of changes, you can automatically migrate those forward for your users. That's possible. Sometimes you can't do that. I think it's actually happened. I'm not actually involved in the cert-manager project. Of course, I talk to James who is. They actually had some change recently where they had to make a breaking change because they changed a thing about their API, which wasn't convertible. I think they split a CRD out. They had to go through some documentation. They had to notify users. It can be difficult, especially if you have a lot of users out there, to do that thing.
Participant 5: It's good to know we're not the only ones there.
Laverack: It's not a perfectly solved problem, certainly. The conversion webhooks help.
See more presentations with transcripts
Community comments | https://www.infoq.com/presentations/kubernetes-operator-etcd/?itm_source=infoq&itm_medium=QCon_EarlyAccessVideos&itm_campaign=QConLondon2020 | CC-MAIN-2020-50 | refinedweb | 8,285 | 77.03 |
hough circle detection problem
MY CODE IS :
i want to detect outer circle is it possible ?
// SYDNIA DYNAMICS 2015 #include <iostream> #include <stdio.h> #include <vector> #include <thread> #include <opencv2/opencv.hpp> #include "opencv2/core/core.hpp" #include "opencv2/features2d/features2d.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/calib3d/calib3d.hpp" #include "opencv2/nonfree/nonfree.hpp" using namespace cv; Mat src, src_gray; Mat dst, detected_edges; int threshold_value = 11; int threshold_type = 0;; int max_value = 255; int max_type = 4; const char * window_name = "CCC"; string trackbar_type = "Tbin"; string trackbar_value = "Value"; int main(int argc, char *argv[]) { VideoCapture cap; cap = VideoCapture("D:/SYDNIA/1.AVI"); if (!cap.isOpened()) // if not success, exit program { std::cout << " !! --->> camera problem " << std::endl; return -1; } namedWindow(window_name); cvMoveWindow(window_name, 5, 5); int MAX = 130; createTrackbar("MAX", window_name, &MAX, 300); int MIN = 100; createTrackbar("MIN", window_name, &MIN, 300); int BLACKLEVEL = 47; for (;;) { if (!cap.read(src)) { std::cout << "GRAB FAILURE" << std::endl; exit(EXIT_FAILURE); } cvtColor(src, src_gray, CV_RGB2GRAY); blur(src_gray, src_gray, Size(15, 15)); threshold(src_gray, dst, 11, 255, 0); //tareshold vector<Vec3f> circles; HoughCircles(dst, circles, CV_HOUGH_GRADIENT, 1, dst.rows, 20, 7, MIN, MAX); string status = ""; for (size_t i = 0; i < circles.size(); i++) { Point center(cvRound(circles[i][0]), cvRound(circles[i][1])); bool ok = false; int r = src.at<Vec3b>(center.y, center.x)[0]; int g = src.at<Vec3b>(center.y, center.x)[1]; int b = src.at<Vec3b>(center.y, center.x)[2]; if ((r<BLACKLEVEL) && (g<BLACKLEVEL) && (b<BLACKLEVEL))ok = true; if (ok) { int radius = cvRound(circles[0][2]); circle(src, center, 2, Scalar(30, 255, 140), -1, 3, 0); circle(src, center, radius, Scalar(30, 255, 0), 3, 8, 0); status = "2"; break; } else { status = "0"; } } imshow(window_name, src); imshow("HSV", dst); if (waitKey(1) == 27)break; } return 0; }
source picture :
code output center:
is it possible to make it :
May be you can use only thresholding. Calculate ellipse moment and use a projection to enlarge your shape. You don't detect outside circle but you use a parametric model to find it.
Interesting problem. But do you really need the second circle? I guess you want to fill the truck (?) automatically, so you only need the xy-coordinates of the hole. Do you know the z-position of the hole (e.g. the height of the truck?) Could you specify the problem a bit better? Could you use two cameras for a stereo setup?
yes i want to fill truck automatically but we dont know Z(the height of the truck) its variable so circle center is not correct stereo setup is good for me ?
If your camera is not at vertical of hhole, you 've got an ellipse with axis a and b. (hole is in the truck is supposed to be a circular disc). If all truck have got same size then I think ratio a/b give you distance camera-truck. Ratio a/b give you too how many pixels you have to enlarge your ellipse to find outside ellipse.
Truck must follow same trajectory relative to camera axis
A stereo setup would simplfy the problem. Do you know the radius of the hole? In this case you could just find the upmost point off the black hole in both images. If you have two cameras, you can compute the 3d coordinate of this point in 3d. And your final goal has just a distance of the radius from this point. This also works with a single camera: The upper half of the black area is an ellipse (not mathematically exact, but good enough). If you know the radius, you can again compute the position of your hole.
radius of hole between 500-700 (cm) but is it impossible to work with one camera | https://answers.opencv.org/question/58960/hough-circle-detection-problem/ | CC-MAIN-2020-05 | refinedweb | 627 | 66.03 |
06 July 2012 11:16 [Source: ICIS news]
By Ong Sheau Ling
?xml:namespace>
The open-spec Asian naphtha contract for the second half of August rose to a five-week high of $825.00-827.00/tonne (€668-670/tonne) CFR (cost and freight) Japan on Friday, rising by $75.00/tonne from the previous week, according to ICIS.
The naphtha crack spread versus August Brent crude futures was also at a five-week high of $76.53/tonne, up 43% from the previous week, ICIS data showed.
“Naphtha [prices] are moving up much faster than its derivatives. This is not a good sign,” a Singapore-based trader said.
Asian naphtha prices have gained 18.4% or $128.50/tonne in two weeks’ time from a 21-month low on 22 June, according to ICIS.
“This uptrend is not sustainable since there is no improvement in physical demand heading downstream,” a South Korean cracker operator said.
There are concerns that petrochemical margins will deteriorate once again if naphtha prices continued to rise at a more brisk pace compared with those of downstream products.
On Friday, spot ethylene were quoted at $1,040-1,060/tonne CFR NE (northeast) Asia, compared with $1,000-1,050/tonne CFR NE Asia last week. Butadiene, on the other hand, was at above $2,300/tonne
“There is still a little stocking-up in inventories in the [petrochemical] sector,” a trader based in
Demand is expected to wane as working hours in the predominantly Muslim countries in
“[Naphtha] prices have been going up steadily, partly because of the buying activity going on with the South Korean and Southeast Asian cracker operators,” another trader based in
The cargoes fetched premiums of $22.50-28.00/tonne to
Kuwait Petroleum Corp (KPC) sold 75,000 tonnes of full-range naphtha (FRN) on 5 July at a premium of around $20.00/tonne to
On 2 July, Honam bought a total of four 25,000-tonne cargoes for first-half August delivery. Three lots, heading to Yeosu, was purchased at a premium of $2.00/tonne to Japan quotes CFR, while the fourth parcel, bound for Daesan, was bought at a premium of $1.00-1.50/tonne to Japan quotes CFR.
Fewer supplies from Europe in August because of lower run rates are refineries have kept supply in
“Some crackers are ramping up. This will increase the physical demand for naphtha,” he said.
But once European refineries ramp up production, and with the current influx of Middle East spot material, a supply overhang may again plague the Asian market, another Singapore-based trader said.
Qatar International Petroleum Marketing Co (Tasweeq) offered by tender late on 5 July 50,000 tonnes of full-range naphtha and 50,000 tonnes of plant condensate for second half of August delivery, which was a leftover from its unsold one-year term supplies that was offered in May.
“The key focus here is the demand. Unless demand improves, prices cannot be supported,” another South Korean cracker operator said.
“With FPCC still out of the picture, it is hard to see the firm uptrend,” another Southeast Asian cracker operator said.
( | http://www.icis.com/Articles/2012/07/06/9575874/weak-petrochemical-demand-to-cap-asia-naphtha-gains.html | CC-MAIN-2014-52 | refinedweb | 529 | 62.07 |
import java.util.*; public class SumOfAllEvens { public static void main (String[] args) { Scanner s = new Scanner (System.in); //for (int i=1; i<4; i++){ int usernumber; int sum=0; System.out.print ("Please enter an integer: "); // Prompt usernumber = s.nextInt(); for (int j=2; j<=usernumber; j=j+2){ if (usernumber<2) System.out.println ("Error"); else System.out.println ("The sum of all evens from 2 to " + usernumber + " (inclusive) is " + (j+usernumber) + " ."); //sum=sum+j; //} } } }
I'm supposed to use a for loop that runs until it reaches the number input by the user, but I'm not sure how to tell the program to add the user's number along with all of the even numbers in between the user input and 2. | http://www.javaprogrammingforums.com/whats-wrong-my-code/37111-how-add-all-even-numbers-between-2-user-input-number-included-addition.html | CC-MAIN-2015-35 | refinedweb | 126 | 65.01 |
Identify the Language of Text using Python
Text Language Identification is the process of predicting the language of a given piece of text. You might have encountered it when Chrome shows a popup to translate a webpage when it detects that the content is not in English. Behind the scenes, Chrome is using a model to predict the language of text used on a webpage.
When working with a dataset for NLP, the corpus may contain a mixed set of languages. Here, language identification can be useful to either filter out a few languages or to translate the corpus to a single language and then use it for your downstream tasks.
In this post, I will explain the working mechanism and usage of various language detection libraries.
Facebook’s Fasttext library
Fasttext is an open-source library in Python for word embeddings and text classification. It is built for production use cases rather than research and hence is optimized for performance and size. It extends the Word2Vec model with ideas such as using subword information and model compression.
For our purpose of language identification, we can use the pre-trained fasttext language identification models. The model was trained on a dataset drawn from Wikipedia, Tatoeba, and SETimes. The basic idea is to prepare training data of (text, language) pairs and then train a classifier on it.
The benchmark below shows that these pre-trained language detection models are better than langid.py, another popular python language detection library. Fasttext has better accuracy and also the inference time is very fast. It supports a wide variety of languages including French, German, English, Spanish, Chinese.
Using Fasttext for Language Detection
- Install the
Fasttextlibrary using pip.
pip install fasttext
- There are two versions of the pre-trained models. Choose the model which fits your memory and space requirements:
- lid.176.bin: faster and slightly more accurate but 126MB in size
- lid.176.ftz: a compressed version of the model, with a file size of 917kB
- Download the pre-trained model from Fasttext to some location. You’ll need to specify this location later in the code. In our example, we download it to the /tmp directory.
wget -O /tmp/lid.176.bin
- Now, we import fasttext and then load the model from the pretrained path we downloaded earlier.
import fasttext PRETRAINED_MODEL_PATH = '/tmp/lid.176.bin' model = fasttext.load_model(PRETRAINED_MODEL_PATH)
- Let’s take an example sentence in French which means ‘I eat food’. To detect language with fasttext, just pass a list of sentences to the predict function. The sentences should be in the UTF-8 format.
sentences = ['je mange de la nourriture'] predictions = model.predict(sentences) print(predictions) # ([['__label__fr']], array([[0.96568173]]))
The model returns two tuples. One of them is an array of language labels and the other is the confidence for each sentence. Here
fris the
ISO 639code for French. The model is 96.56% confident that the language is French.
Fasttext returns the ISO code for the most probable one among the 170 languages. You can refer to the page on ISO 639 codes to find language for each symbol.
af als am an ar arz as ast av az azb ba bar bcl be bg bh bn bo bpy br bs bxr ca cbk ce ceb ckb co cs cv cy da de diq dsb dty dv el eml en eo es et eu fa fi fr frr fy ga gd gl gn gom gu gv he hi hif hr hsb ht hu hy ia id ie ilo io is it ja jbo jv ka kk km kn ko krc ku kv kw ky la lb lez li lmo lo lrc lt lv mai mg mhr min mk ml mn mr mrj ms mt mwl my myv mzn nah nap nds ne new nl nn no oc or os pa pam pfl pl pms pnb ps pt qu rm ro ru rue sa sah sc scn sco sd sh si sk sl so sq sr su sv sw ta te tg th tk tl tr tt tyv ug uk ur uz vec vep vi vls vo wa war wuu xal xmf yi yo yue zh
- To programmatically convert language symbols back to the language name, you can use pycountry package. Install the package using pip.
pip install pycountry
- Now, pass the symbol to pycountry and you will get back the language name.
from pycountry import languages lang_name = languages.get(alpha_2='fr').name print(lang_name) # french
Google Compact Language Detector v3 (CLD3)
Google also provides a compact pretrained model for language identification called cld3. It supports 107 languages.
To use it, first install
gcld3 from pip as:
pip install gcld3
After installation, you can initialize the model as shown below.
import gcld3 detector = gcld3.NNetLanguageIdentifier(min_num_bytes=0, max_num_bytes=1000)
Feature 1: Predict Single Language
Once loaded, the model can be used to predict the language of a text as shown below:
text = "This text is written in English" result = detector.FindLanguage(text=text)
From the returned result, you can get the language BCP-47 style language code. The mapping of code to language is available here.
print(result.language)
'en'
You can also get the confidence of the model from the result.
print(result.probability)
0.9996357560157776
You can also get the reliability of the prediction from the result object.
print(result.is_reliable)
True
Feature 2: Get the top-N predicted languages
Instead of predicting a single language,
gcld3 also provides a method to get confidence over multiple languages.
For example, we can get the top-2 predicted languages as:
import gcld3 detector = gcld3.NNetLanguageIdentifier(min_num_bytes=0, max_num_bytes=1000) text = "This text is written in English" results = detector.FindTopNMostFreqLangs(text=text, num_langs=2) for result in results: print(result.language, result.probability)
en 0.9996357560157776 und 0.0
Conclusion
Thus, we learned how pretrained models can be used for language detection in Python. This is very useful to filter out non-English responses in NLP projects and handle them. | https://amitness.com/2019/07/identify-text-language-python/ | CC-MAIN-2021-43 | refinedweb | 999 | 64.1 |
Ray reflection inaccuracy [SOLVED]
On 28/01/2015 at 04:44, xxxxxxxx wrote:
Hi
I'm in the middle of writing some code to calculate the ray reflections around tight corners inside a geometric object. Sometimes the reflected ray bounces outside the object because it misses a close adjoining corner. Anyway, do do this I need to manually test along the path of the reflected ray to see if it meets a new collision. The code I'm using below is working toward this - but there's a general inaccuracy of the final position that ReflectRay calculates and the same position I calculate by taking the collision point and extrapolating along it.
I'm pretty sure my math and code are correct, but my value (mypos) and ReflectRay's value (pos) are very slightly different and it's bugging me - for example,
Vector(-95.939, -75.666, -19.324) Vector(-97.445, -75.666, -19.324)
global pos, vel
predictedPos = pos + vel.GetNormalized() #The direction the ray points.
raylength = 1000
CollisionState = ray.Intersect(start, direction, raylength)
if CollisionState:
hitpos = ray.GetIntersection(0)["hitpos"]
collDist = c4d.Vector(hitpos - pos).GetLength()
norm = ray.GetIntersection(0)["f_normal"]
distance = ray.GetIntersection(0)["distance"]
predDist = c4d.Vector(predictedPos - pos).GetLength()
if collDist < predDist:
norm.Normalize()
reflect = ReflectRay(vel,norm)
mypos = hitpos + ( reflect.GetNormalized() * (vel.GetLength() - distance) )
vel = reflect
pos = pos + vel
print pos, mypos
else:
pos = pos + vel
else:
pos = pos + vel
On 28/01/2015 at 06:31, xxxxxxxx wrote:
Hi Glenn,
can you perhaps give me a little more information. The two vectors you provide upfront are to be used as input data for your code example? In which way? And what is the expected result?
Without having done any testing, I have a feeling in my guts, that you might have run into problems with floating point arithmetic. So while answering my questions, you may also want to have a look at the article about Floating-Point Weirdness on our PluginCafe blog.
On 28/01/2015 at 06:51, xxxxxxxx wrote:
Hi Andreas,
The two vectors I listed are the results of 'print pos, mypos' in the code. They should be exactly the same but either one of x,y,z is always slightly off. I suspected a floating point issue myself. If that's the case that's fine. I was just worried my calculations were wrong.
On 28/01/2015 at 17:22, xxxxxxxx wrote:
Hi Glenn,
checking your code it seems not to be a floating point issue.
I can´t see exactly why you are doing this, but only adding the position to the whole reflected ray can´t give you the same result as there is no information of where the ray hits the surface.
With utils.ReflectRay you´ll get the direction and the intensity of the ray just reflected.
Your mypos calculation is right, a normalized reflection vector multiplied by the distance difference and added to the hitposition.
The problems you have with the ray collider might come from just checking the first hit, which also can be a point or an edge and won´t have the normal you might need for your calculation. Just a guess...
Best wishes
Martin
On 29/01/2015 at 00:46, xxxxxxxx wrote:
Thanks Martin,
The thing is even when my object hits a perfectly flat surface - it still shows a slight discrepancy - it shows every collision no matter where in fact.
Anyway, I cobbled this code together - it's a recursive call which takes an incoming position and velocity, and tries to work out all collisions. From looking at it it seems to work - catching small tight corners etc. It also doesn't make use of my manual calculations, but uses ReflectRay entirely. (I've left in the debug code which compares my mypos error though)
If you spot any errors in this - I'd be grateful to learn, thank you.
def getAllCollisions(pos,vel2,count) :
# print vel
predictedPos = pos + vel2
#2.GetNormalized() #The direction the ray points.
raylength = 1000
CollisionState = ray.Intersect(start, direction, raylength)
if CollisionState:
print '........................'
hitpos = ray.GetIntersection(0)["hitpos"]
norm = ray.GetIntersection(0)["f_normal"]
distance = ray.GetIntersection(0)["distance"]
if distance < vel2.GetLength() :
norm.Normalize()
reflect = ReflectRay(vel2,norm)
mypos = hitpos + ( reflect.GetNormalized() * (vel2.GetLength() - distance) )
print mypos
print pos + reflect # correct value ?
vel2 = reflect
count += 1
if count < 10:
vel2 = getAllCollisions(pos,vel2,count)
return vel2
On 29/01/2015 at 06:42, xxxxxxxx wrote:
Hi Glenn,
you again assume that ReflectRay will give you the right position without feeding the necessary hitposition into the equation.
I attached a small snippet which deals with all collisions you can get from a given velocity, position and a bounce limit.
The precision value is needed otherwise you will end up not to know if your are inside or outside the volume and therefore heading in the wrong direction, as you "stick on the surface".
The code is heavily commented I hope this helps?
Best wishes
Martin
import c4d from c4d import utils def getAllCollisions(pos,vel,count,bounceList) : print pos, "the start position" print vel, "the velocity vector" print count, "the bounce count limit to ten" precision = 0.000001 #distance tolerance to the surface avoiding unwanted catch at the surface # initialize the ray collider with the target targetobj = doc.SearchObject("Cube") # The object the ray collides with ray = utils.GeRayCollider() # Create a new GeRayCollider object ray.Init(targetobj, True) # Assign the object to a variable # velocity values direction = vel.GetNormalized() #The direction the ray points. intensity = vel.GetLength() #The constant speed(intensitiy) the ray traverses print direction, "direction" print intensity, "the new raylength" # raylength is the velocity intensity and will decrease the longer the ray is on his way when reflecting. raylength = intensity #check collisions CollisionState = ray.Intersect(pos, direction, raylength) if CollisionState and count < 10: print '........................' #take the nearest collision hitpos = ray.GetNearestIntersection()["hitpos"] norm = ray.GetNearestIntersection()["f_normal"] norm.Normalize() distance = ray.GetNearestIntersection()["distance"] #the normalized reflection vector reflect = utils.ReflectRay(direction,norm) #the collision point refined by the precision value to avoid catch at surface given in targetobj local space hitpos = (hitpos + precision*reflect) print hitpos,"the collision point" mypos = hitpos + ( reflect * (intensity - distance) ) print mypos ,"the new calculated endposition------------" vel2 = mypos-hitpos print vel2 ,"the new velocity vector" #the new calculated position and velocity for the next possible bounce bounceList.append([hitpos,vel2]) count += 1 #recursivly searching for more bounces getAllCollisions(hitpos,vel2,count,bounceList) return bounceList else: return [] def main() : sourceobj = doc.SearchObject("Null") pos = sourceobj.GetAbsPos() vel = c4d.Vector(0,0,800) count = 0 bounceList = [] #store all collision points with their velocities print getAllCollisions(pos,vel,count,bounceList) if __name__=='__main__': main()
On 29/01/2015 at 09:03, xxxxxxxx wrote:
Hi Martin,
Thanks so much for this - the code works perfectly and is well explained.
I see what you mean about ReflectRay and my assumption of a hitpoint.
Anyway - in my main loop (running every frame), if there has been any collisions then I update my new pos and vel like so
global pos, vel
bounceList = [] #store all collision points with their velocities
getAllCollisions(pos,vel,0,bounceList)
if len(bounceList) > 0:
newpos = bounceList[-1][0]
bounceVel = bounceList[-1][1]
pos = newpos + bounceVel
vel = vel.GetLength() * bounceVel.GetNormalized()
else:
pos = pos + vel
Incidentally, the reason I shied away from using raylength for testing is because I saw this
there seems to be problems if it is less than 100, but I haven't noticed anything so far.
Thanks again!
Glenn.
On 29/01/2015 at 11:18, xxxxxxxx wrote:
Hi Glenn,
I´m glad this helped.
For your task there should´nt be any problem with the raylength.
Another approach for other tasks could be to compare every collision in one "shot" and delete the double ones.
It´s important to know that ray collider works in local space of the collision object.
regarding your main loop:
I assume that you have precalculated your velocity vector in the dimension of time.
your vel is the way the ray travese in one time unit.
In this case the next position for let´s say the next frame, will be the last mypos calculated in the getAll collisions function multiplied by the object matrix.
The new vel will be, assuming we have a constant speed with no acceleration, the last reflect vector multiplied by the intensity we calculated at the beginning, as the speed doesn´t change.
Best wishes
Martin
On 29/01/2015 at 11:43, xxxxxxxx wrote:
in other words
def main() : sourceobj = doc.SearchObject("Null") pos = sourceobj.GetAbsPos() vel = c4d.Vector(0,0,800) #initial vel count = 0 bounceList = [] #store all collision points with their velocities print getAllCollisions(pos,vel,count,bounceList) targetobj = doc.SearchObject("Cube") matr = targetobj.GetMg() lastHitPos = bounceList[-1][0] lastVel = bounceList[-1][1] intensity = vel.GetLength() newVel = lastVel.GetNormalized()*intensity newPos = (lastHitPos + lastVel)*matr print newPos,newVel if __name__=='__main__': main()
On 30/01/2015 at 06:47, xxxxxxxx wrote:
Hi Martin
In my test scene I just have a null with a small object as its child - the null bounces around inside the cube at a constant velocity. And everything looks to be working perfectly. It's useful to know about multiplying the object matrix though. I'll probably need to do that in the future.
Thanks again,
Glenn.
On 01/02/2015 at 04:59, xxxxxxxx wrote:
Hi Glenn,
great!
I can almost imagine your small objects bouncing around(funny sentence while typing it but wasn´t meant to be offensive in any way
)
Referring to Andreas' feeling in his guts (nice article by the way) and for the sake of completeness:
1.There is a problem with the floating point precision while "sticking" at the surface, but this will be the case even if we have much more precision in computer technology.
2.The starting point needs to be within the object's space, too, if you move the object from world origin.
3.If you use multiple rays in your code but with only one static object, the ray init function must be called only once, as it seems just preparing the object for collisions.
This becomes obvious once your collision object has a looooot polygons.
Curious about what you´ll end up with!
Martin
On 02/02/2015 at 09:49, xxxxxxxx wrote:
Hi Martin,
My bouncy objects I'm using to create traced lines inside geometry to create interesting abstract forms. Below is a simple cube.
One little thing you might know about - The lines don't update in realtime inside the editor view when I play the timeline. The code is inside a generator and updates every frame. It's a bunch of growing loft objects basically. When I move the camera around I get a brief glimpse of what's happening, but that's all. Ive tried playing with the following..
c4d.EventAdd()
c4d.DrawViews( c4d.DRAWFLAGS_FORCEFULLREDRAW)
but no joy.. not the end of the world, I'm just glad the end result is working.
On 03/02/2015 at 01:12, xxxxxxxx wrote:
Hi Glenn,
nice your tracer kind of thing!
If you want to do some further development I´ll sent you a pm.
Best wishes
Martin
On 03/02/2015 at 04:52, xxxxxxxx wrote:
Thanks for the message Martin, will drop you a line soon! | https://plugincafe.maxon.net/topic/8470/11053_ray-reflection-inaccuracy-solved | CC-MAIN-2020-10 | refinedweb | 1,895 | 56.05 |
I have modified the example code in the tutorial and have written the following function to get data from the GPSd daemon and return it in a useful format, including offsetting the time to local instead of GMT:
- Code: Select all | TOGGLE FULL SIZE
#!/usr/bin/python
import gps
from string import find
from datetime import datetime, timedelta
# ===========================================================================
def get_gps(time_offset):
session = gps.gps("localhost", "2947") #start a new session with the GPS daemon
session.stream(gps.WATCH_ENABLE | gps.WATCH_NEWSTYLE)
report_received = 0
while report_received == 0:
report = session.next() # wait for the next status message from the GPS receiver
if report['class'] == 'TPV': # Wait for a 'TPV' report and display the current time
if hasattr(report, 'time'):
report_received = 1
s = report.time
s = s[:find(s, "T")] + " " + s[find(s, "T")+1:]
s = s[:find(s, ".")]
dt = datetime.strptime(s, '%Y-%m-%d %H:%M:%S')
dt = dt + timedelta(hours=time_offset) # apply an offset for the local time zone
gps_time = dt.strftime('%Y-%m-%d %H:%M:%S') #convert time string into a useful format
mode = report.mode # get status from the GPS receiver. either no lock, 2d or 3d
if mode == 1:
mode_string = "NO"
if mode == 2:
mode_string = "2D"
if mode == 3:
mode_string = "3D"
lat = report.lat
longatude = report.lon
speed = 2.236936*report.speed # convert meters per second to mph
alt = report.alt
return gps_time, lat, longatude, speed, alt, mode_string; #return data back from the receiver.
gps_data = get_gps(-4)
print gps_data
gps_data = get_gps(-4)
print gps_data
gps_data = get_gps(-4)
print gps_data
when I run this, I get the following output
- Code: Select all | TOGGLE FULL SIZE
('2013-03-18 16:48:03', 33.xxxxxxx, -84.xxxxxxxx, 0.219219728, 295.6, '3D')
('2013-03-18 16:48:04', 33.xxxxxxx, -84.xxxxxxxx, 0.14987471200000002, 295.6, '3D')
('2013-03-18 16:48:05', 33.xxxxxxx, -84.xxxxxxxx, 0.091714376, 295.6, '3D')
I have 3 issues with this code I hope someone can help me with.
1. Currently the GPS module and daemon seem to default to a 1hz operation (which is why there is 1 second between each time sample). The way the function is written, I am waiting for an updated packet to be sent after I enter the function. Shouldn't the daemon be handling this function? Why cant I just ask the daemon what the last packet was instead of waiting for a whole new message from the GPS receiver?
2. I found some documentation online that shows that the GPSd daemon can accept input from the client connecting to it. Since the GPS receiver is capable to operating at 10Hz, cant I send a packet to the Daemon so it can send the configuration string to the GPS receiver to configure the receiver to operate at 10Hz instead of 1Hz?
3. I have noticed that sometimes the GPS receiver deosnt send an update packet for some reason. Unfortunately, the session.next() function call will wait for the next session, no matter what. There apparently is no timeout and no way to set one as far as I can tell. Does anyone know how to configure this so that it will drop out of this function in case the GPS receiver gets hung for some reason?
I need this function to be sped up because it is limiting the overall speed of my application.
I appreciate any insight anyone can give as to how this is actually working.
Thanks | http://forums.adafruit.com/viewtopic.php?p=188313 | CC-MAIN-2015-14 | refinedweb | 573 | 63.49 |
register ESB hosted WS in jbpm-bpel console as Partner ServiTorsten Lange Jan 22, 2008 6:58 AM
I'm using two server installations, one JBoss ESB 4.2.1 GA and one JBoss AS 4.2.1 GA with a JBPM-BPEL 1.1.GA.
Registering a WS (that resides on JBoss ESB server installation) as Partner Service on the JBoss AS installation using the jbpm-bpel console works as expected.
I'm using the URL pointing to the WSDL document. The jbpm-bpel console lists the base location, the target namespace and the service in Partner Service Catalog. (A BPEL-process is now able to use the service).
If I provide an ESB configuration with an HTTP-Gateway for this WS (according to quickstarts sample webservice-producer) I'm able to call the service from a client using gateway URL (tested with soapUI and WS endpoint) but there is no WSDL and I can't register this gateway URL as Partner Service in jbpm-bpel console.
Is it possible to use the gateway 'endpoint' as WS endpoint? How do I have to configure the Partner Service for the BPEL process?
Thanks, Torsten
1. Re: register ESB hosted WS in jbpm-bpel console as Partner SMark Little Jan 22, 2008 8:46 AM (in response to Torsten Lange)
Just to let you know that for BPEL we are only supporting ActiveEndpoints at this stage.
2. Re: register ESB hosted WS in jbpm-bpel console as Partner SBurr Sutter Jan 22, 2008 8:51 AM (in response to Torsten Lange)
Have you tried the contract.war?
look for the service, click on the link and get the WSDL?
In any case, the WSDL through/mediated the ESB is virtually the same as the WSDL directly to the JBossWS endpoint aside from the port number.
Burr
3. Re: register ESB hosted WS in jbpm-bpel console as Partner STorsten Lange Jan 23, 2008 9:06 AM (in response to Torsten Lange)
Exploring the 'contract' web application I found the URL to register Partner Service under JBPM-BPEL but it is not the JBossWS endpoint with a different port number.
I've registered the service using
(without ...'?wsdl').
@Mark
Is this an undocumented/not supported feature? Subject to change?
Thanks, Torsten
4. Re: register ESB hosted WS in jbpm-bpel console as Partner SMark Little Jan 23, 2008 3:13 PM (in response to Torsten Lange)
What do you mean "undocumented"? Support for only ActiveEndpoints BPEL is well documented in the ESB.
5. Re: register ESB hosted WS in jbpm-bpel console as Partner SBurr Sutter Jan 23, 2008 3:20 PM (in response to Torsten Lange)
We have never tested the mediation of a jBPM-BPEL Endpoint via the ESB. Only regular JBossWS endpoints and integration with Active Endpoints BPEL have been tested.
Can you list the steps taken to verify that the WS endpoint (jBPM-BPEL I assume) is available?
You should see it originally under
If you can find it there then you can setup the jboss-esb.xml like you would in webservice_producer.
Do spend some time figuring out how the webservice_bpel works with AE (and the other WS examples work), then you might be able to extract the knowledge you need to be successful here.
6. Re: register ESB hosted WS in jbpm-bpel console as Partner STorsten Lange Jan 24, 2008 6:11 AM (in response to Torsten Lange)
First of all: Our test application is running!
To ensure that we have defined a legal scenario (without ActiveEndpoints) I would like to clarify our approach.
We have installed two server instances:
- one JBoss AS 4.2.1 GA with a JBPM-BPEL 1.1.GA. (server instance A)
- one JBoss ESB 4.2.1 GA (server instance B)
Then we have deployed a WS on B and provided a jboss-esb.xml configuration via *.esb deployment (based on webservice-producer example).
After that we have defined and registered a BPEL process on A that uses the 'plain' WS on B. (The WS was registered as Partner Service in jbpm-bpel console on A using '').
The BPEL process is running and calls the WS directly.
In the next step we tried to connect to the ESB mediated WS. (The WS was registered as Partner Service in jbpm-bpel console on A using '')
The BPEL process is running and calls the actions defined in jboss-esb.xml (print-before, JBossWSAdapter that calls TestWS and print-after).
Question:
Is the definition of the Partner Service in JBPM-BPEL using following base location ''
the recommended approach?
Torsten | https://developer.jboss.org/thread/143529 | CC-MAIN-2018-05 | refinedweb | 767 | 63.19 |
Shapiro delay
From Wikipedia, the free encyclopedia
The Shapiro time delay effect, or gravitational time delay effect, is one of the four classic solar system tests of general relativity. Radar signals passing near a massive object take slightly longer to travel to a target and longer to return (as measured by the observer) than it would if the mass of the object were not present.
[edit] History
The time delay effect was first noticed in 1964, by Irwin I. Shapiro. Shapiro proposed an observational test of his prediction: bounce radar beams off the surface of Venus and Mercury, and measure the round trip travel time. When the Earth, Sun, and Venus are most favorably aligned, Shapiro showed that the expected time delay, due to the presence of the Sun, of a radar signal traveling from the Earth to Venus and back, would be about 200 microseconds, well within the limitations of 1960s era technology.
The first test, using the MIT Haystack radar antenna, was successful, matching the predicted amount of time delay. The experiments have been repeated many times since, with increasing accuracy.
[edit] Calculating time delay
The speed of light in meters per given interval of "proper time" is a constant, however the travel time of any electromagnetic wave, or signal, moving at 299,792,458 meters per "second" is affected by the gravitational time dilation in regions of spacetime through which it travels. This is because the coordinate time and proper time diverge as the gravitational field strength increases.
[edit] Time delay due to light travelling around a single mass
For a signal going around a massive object, the time delay can be computed as the following:
Here
is the unit vector pointing from the observer to the source, and
is the unit vector pointing from the observer to the gravitating mass M.
See Dot product.
The above formula can be rearranged like this:
which is the extra distance the light has to travel, where Rs is the Schwarzchild radius.
This is the same as:
[edit] Special cases
[edit] Shapiro delay and interplanetary probes
Shapiro delay must be considered along with ranging data when trying to accurately determine the distance to interplanetary probes such as the Voyager and Pioneer spacecraft (see the Voyager program, the Pioneer program, and the Pioneer anomaly).
[edit] Quote by Einstein
)
[edit] Shapiro delay of neutrinos and gravitational waves
From the near-simultaneous observations of neutrinos and photons from SN 1987A, we know that the Shapiro delay for neutrinos is same as that for photons to within 10 %. Since gravitational waves have not been directly detected, we don't have any data on the Shapiro delay for gravitational waves. In general relativity and other metric theories of gravity, the Shapiro delay for gravitational waves is expected to be same as that for light (and neutrinos). However in theories such as Teves and other modified GR theories which reproduce Milgrom's law and avoid the need for dark matter, the Shapiro delay for gravitational waves is much smaller than that for neutrinos or photons.
[edit] See also
- Tests of general relativity
- Gravitational redshift and Blueshift
- Gravitational time dilation
- Proper time
[edit] References
- "Boost for General Relativity." Nature. 12 July 2001.
- Relativity : the Special and General Theory by Albert Einstein. at Project Gutenberg
- Irwin I. Shapiro (December 1964). "Fourth Test of General Relativity". Physical Review Letters 13: 789–791. doi:10.1103/PhysRevLett.13.789.
- Irwin I. Shapiro, Gordon H. Pettengill, Michael E. Ash, Melvin L. Stone, William B. Smith, Richard P. Ingalls, and Richard A. Brockelman (May 1968). "Fourth Test of General Relativity: Preliminary Results". Physical Review Letters 20: 1265–1269. doi:10.1103/PhysRevLett.20.1265.
- d'Inverno, Ray (1992). Introducing Einstein's Relativity. Oxford: Clarendon Press. ISBN 0-19-859686-3. See Section 15.6 for an excellent advanced undergraduate level introduction to the Shapiro effect.
- Will, Clifford M. (2001). "The Confrontation between General Relativity and Experiment". Living Rev. Rel. 4: 4–107. gr-qc/0103036 A graduate level survey of the solar system tests, and more.
- John C. Baez, Emory F. Bunn (2005). "The Meaning of Einstein's Equation". Amer. Jour. Phys. 73: 644–652. doi:10.1119/1.1852541. gr-qc/0103044
- Michael J. Longo, Physical Review Letters vol. 60, Jan. 18, 1988, p. 173-175
- Lawrence M. Krauss and Scott Tremaine, Physical Review Letters, vol. 60, Jan. 18, 1988, p.176, 177
- S.Desai, E. Kahya, and R.P. Woodard, Phys. Rev. D 77, 124041 (2008) | http://ornacle.com/wiki/Shapiro_delay | crawl-002 | refinedweb | 746 | 57.67 |
Categories: Python | S60 | How To | Code Examples
This page was last modified 22:46, 12 October 2007.
How to know cpu speed
From Forum Nokia Wiki
With a utility library called Miso, we can do a lot of C++ API only things with pys60 platform. The following snippet can be used for getting cpu speed of your S60 smartphone.
import miso print miso.get_hal_attr(11) # 104000 for my 6600
You could go further with this project to make back light always on, determine phone models, and many many cool stuff.
Enjoy!
External Link
And this is the official web site of Miso project. | http://wiki.forum.nokia.com/index.php/How_to_know_cpu_speed | crawl-001 | refinedweb | 103 | 79.9 |
Here is a small patchset I've been sitting on for awhile
to make signaling mostly subject to user namespaces. In
particular,
1. store user_namespace in user struct
2. introduce CAP_NS_OVERRIDE
3. require CAP_NS_OVERRIDE to signal another user namespace
The first step should have been done all along. Else wouldn't
a hash collision on (ns1, uid) and (ns2, uid), however unlikely,
give us wrong results at uid_hash_find()?
The main remaining signaling+userns issue is of course the
siginfo. Tacking a userns onto siginfo is a pain due to
lifetime mgmt issues. I haven't decided whether to just
catch all the callers and fake uid=0 if user namespaces
aren't the same, introduce some unique non-refcounted id to
represent (user,user_ns), or find some other way to deal with
it.
thanks,
-serge
-
To unsubscribe from this list: send the line "unsubscribe
linux-security-module" in
the body of a message to [email protected]
More majordomo info at | http://article.gmane.org/gmane.linux.kernel.lsm/5347 | CC-MAIN-2018-17 | refinedweb | 160 | 64.71 |
@Parameter and null-values
Splash › Forums › Rewrite Users › @Parameter and null-values
This topic contains 21 replies, has 3 voices, and was last updated by
reinhard hobler 2 years, 7 months ago.
- AuthorPosts
This morning I continued my evaluation on rewrite.
Consider the following scenario:
We have a bundle of web-frontends that are more or less designed as RIA-applications. Let’s say we have a main Customer Page where we show information related to customers.
Initially, the customer.xhtml page is rendered without a customer loaded. On the page the user then can search and open a certain customer (via a modal search-dialog). The customer is then loaded from database and the (initally empty) fields on the page are filled.
I now would like have this two ‘states’ of the page considered in the related urls.
With rewrite I kind of managed it to get
host:port/customerapplication/customer
for the ’empty’ customer-page and
host:port/customerapplication/customer/?customerId=4711
when customer 4711 is loaded.
It would be much nicer if the URL here would be
host:port/customerapplication/customer/4711
but if I change
@Join(path = "/customer", to = "/jsf/customer.xhtml")
to
@Join(path = "/customer/{customerId}", to = "/jsf/customer.xhtml")
I get a 404 when targeting host:port/customerapplication/customer.
I am now not sure whether this not possible at all or if I missed s.th. out.
Please find attached both the jsf-page and the corresponding Backing-bean.
- This topic was modified 2 years, 8 months ago by
reinhard hobler.
- This topic was modified 2 years, 8 months ago by
Lincoln Baxter III.
Attachments:
added customer.xhtml
Attachments:
If you want
host:port/customerapplication/customerto work, you need a rule for that 🙂 since
host:port/customerapplication/customer/Xhas an extra required segment according to your join rule.
You need both of these for what you want:
@Join(path = "/customer", to = "/jsf/customer.xhtml") @Join(path = "/customer/{customerId}", to = "/jsf/customer.xhtml")
I don’t believe we have an aggregate
@Joinsannotation,
Created issue: to track this functionality.
The solution with the aggregate @Joins annotation did not really work – I got a 404 for both variants. Here I will wait for the next release 🙂
However, I got it working by using a Rewrite configuration class with rules for the two joins:
import javax.servlet.ServletContext; import org.ocpsoft.rewrite.config.Configuration; import org.ocpsoft.rewrite.config.ConfigurationBuilder; import org.ocpsoft.rewrite.servlet.config.HttpConfigurationProvider; import org.ocpsoft.rewrite.servlet.config.rule.Join; public class RewriteConfig extends HttpConfigurationProvider { @Override public Configuration getConfiguration(ServletContext context) { return ConfigurationBuilder.begin() .addRule(Join.path("/customer/{customerId}").to("/faces/customer.xhtml")) .addRule(Join.path("/customer").to("/faces/customer.xhtml")); } @Override public int priority() { // TODO Auto-generated method stub return 10; } }
There are two points not so nice with that approach:
First I can’t use navigation via your Navigate anymore (see CustomerBean.java) as then I get an IllegalArgumentException:
Caused by: java.lang.IllegalArgumentException: Unable to find the resource path for: ... at org.ocpsoft.rewrite.faces.navigate.Navigate.to(Navigate.java:84)
So I had to change the method to s.th. like this:
public String openCustomer() { refreshCustomer(); return "/customer.xhtml?customerId=" + customerId + "&faces-redirect=true"; }
Second point is that now the order of the rules in the rewrite configuration is crucial. If I put the rule with the parameter last then the above actionMethod openCustomer() leds to the following url: host:port/customerapplication/customer/?customerId=4711
Yeah I think I know why
@Joinsdidn’t work, sorry about that.
Navigation is just a truth of the design.
But… the last part seems like it might be an improvement area for us. Do you think you could upload your app (or a small maven sample application) so that I could take a look at the code and the behavior?
Thanks!
Please find attached the sample project and the app.
Thanks for looking into the issue !
Attachments:
Christian KaltepothModerator
Hey Reinhard,
sorry for the late reply. I’ve a comment regarding one of your latest posts. You wrote that you cannot use
Navigateany more if you don’t use annotations for configuration. That’s not exactly true. Instead of passing the class you can also pass a string in. So something like this should work:
public Navigate openCustomer() { refreshCustomer(); return Navigate.to("/faces/customer.xhtml").with("customerId", customerId); }
Not so nice like passing in the class but it is simple compared to string concatenation. 🙂
Christian
Hi Christian,
yes this is working too and it looks much nicer than concatenating the url.
Thanks !
Reinhard
Unfortunately, with the new Release of rewrite (2.0.9) my rule
.addRule(Join.path("/customer/{customerId}").to("/faces/customer.xhtml"))does not work properly anymore.
If I update the parameter
customerIdvia the
h:inputTexton my xhtml-page and then call the action the url is rendered fine.
But when I call a specific url like
host:port/customerapplication/customer/Xdirectly the
Xis not transferred to the parameter anymore.
With 2.0.8 this was working fine 🙁
Hmm,
This is very strange. I don’t know what we would have changed that would affect this. Could you provide the backing bean, xhtml page, and rewrite rule code? Or even better, could you provide a small sample application including just these things? I’d like to debug and see what is happening.
Though maybe Christian has more immediate thoughts as to what might be going wrong here.
Thanks!
~Lincoln
Okay, great! I’ll try it out as soon as I get a few spare minutes.
Christian KaltepothModerator
Hey Reinhard,
thanks for providing the sample app. Which container do you deploy to? And could you please also post the exact steps to reproduce the issue? Thanks.
Christian
- AuthorPosts
You must be logged in to reply to this topic. | http://www.ocpsoft.org/support/topic/paramter-and-null-values/ | CC-MAIN-2016-50 | refinedweb | 966 | 50.73 |
I read the new "Beyond (COM) Add Reference: Has Anyone Seen the Bridge?" article yesterday and, was quite impressed by the detailed groundwork that was laid-out to explain the differences between COM and CLR and, how Interop provides a bridge for seamlessly calling in and out of both environments. As the author states in that article the real meat is still to come so, if you are reading this and you haven't already read that article scoot over now and give it a look - you won't be disappointed.
I'm really looking forward to having Interop explained to me, not so much because the "Add COM reference" behaviour in VS.NET doesn't work - it does! - but more because I know that someday I'll be involved in a project where Interop will go wrong and I want to have some idea of what I'm dealing with. What's more, having the classes in the System.Runtime.InteropServices namespace explained will add yet another tick to the namespaces that I've taken the time to learn about ;-)
After reading that article, I stumbled across this blog entry that would have meant very little to me had I not read the Interop article (which I suppose serves to validate the fact that my knowledge store has increased).
Bonus Msdn rating system rant...One thing that confounds me is the ratings system on Msdn. When you rate an article (as I did with this one) you are asked to leave a message indicating your thoughts about the article. I wish that Microsoft would make these comments visible as it would provide a better insight into the overall rating. For example, the guy who rated Sam's article a 1 out of 9 - it would be insightful (and add perspective) to see *why* he thought that it smelled *that* bad. Also, if you rate an item more than 5 points above or below the current average, it should be moderated (based on the comment that is left) as to whether it actually gets added, this would add integrity to the overall rank.
(Listening To: Clubbed to Death (Kurayamino Version) [Rob Dugan / Chillout Sessions Vol 4])
Badly need your help. It is curious that physical courage should be so common in the world and moral courage so rare. Help me! Can not find sites on the: Alavert vs claritin. I found only this - <a href="genericalavert.info/">alavert recall</a>. The other quarks for the discovery telescope work not being overwhelming to drink the surfers, alavert. Alavert, the most attended " minds were big, foundation and folks. Thanks :eek:. Yale from Bolivia. | http://weblogs.asp.net/dneimke/archive/2003/11/19/38333.aspx#38361 | crawl-003 | refinedweb | 441 | 67.99 |
Didn't really unserstand where "with using macro your macro must not know anything about environment" goes: If you currently work with switching template behavior then your template knows about environment (variables passed in). They ARE the environment :|
Advertising
With macros I slice my template logic in micro-pieces (much like java server facelets) that I can reuse anywhere. Functionality is limited compared with facelets, but here's how I'd simplify the differences between macro only and slots: * "each template accepts vars" equivalent:* echo do_site(array( 'banner1' => 'stuff', 'banner2' => 'stuff2', 'layout' => 'portrait')); echo do_email(array( 'main_image' => 'someimage', 'content' => 'blahblah')); * "slots" equivalent:* $stuff = new StuffTemplate(); $stuff2 = new Stuff2Template(); $portrait = new PortraitTemplate(); $site = new SiteTemplate(array( 'var1' => 'aaaa', 'var2' => 'bbbb')); $site->setSlot('banner1', $stuff); $site->setSlot('banner2', $stuff2); $site->setSlot('layout', $portrait); echo $site; $content = new ContentTemplate(); $email = new EmailTemplate(array( 'var1' => 'aaaa', 'var2' => 'bbbb')); $email->setSlot('main_image', 'someimage'); $email->setSlot('content', $content); echo $email; I prefer the second much more because it ALSO allows the usage of variables and encourages (imho) something that looks similar to a Decorator OOP pattern... Can't help with it much more, probably because of my capacity of explaining my idea or probably because of a language limit... Anyway, hope it was useful anyway :) So stopping with my delirium and letting others put their opinion here :) Marco Pivetta On 11 July 2011 11:15, Anton Andriyevskyy <x.meg...@gmail.com> wrote: > Ok, first at all you do have secondary templates in your approach - just to > make clear how I used terms: > > * your primary template is the one with slots > * your secondary template is the one which uses primary one and replaces > > *p.s. please do not argue on usage of terms, lets just assume what is > primary/secondary ones and in these terms* > *my thoughts in previous email applies.* > > Then, with approach you proposed - it seems like you cannot reuse your > secondary templates in different primary templates. > For example, what if you have main html layout (rendering your website > opened in browser tab), and then popup layout which > has simplified view (with less sections, and maybe with "close this popup" > button applied). Then you can display the same page > in the full normal view, or with minimal components in popup view. But if > you are hardcoding template inheritance, you are not able to do so. > > Here is another approach that is widely used (I think so): > > xhtml.xml - defines xhtml template with body, tags etc, expects layout and > page variables to be passed > layout-full.xml - defines html layout for the normal site view and calls > "page" macro in it; > layout-popup.xml - defines html layout for popups and calls "page" macro in > it, again. > > This way you can reuse the same bind the same page contents to different > html layouts, > and if you use slots for this approach - you will have to make your final > "page" templates to be aware about > what slots are declared in primary templates. > > As a conclusion, it looks like using slots is like mutable programming, > while using macro is more like immutable one > in terms of that with using macro your macro must not know anything about > environment from where it's used, > while with slots it must do - and that makes it less separated and > reusable. Eg, in order to use your secondary (final, or page) > template in primary template, you have to design your primary template as > expected by all secondary templates used with it, > which is not right. > > So my bid is still against slots. > > But I'm very (VERY!) interested to see an example where slots are better. > Just had no chance to find such usage yet. > > Regards, > > Anton Andriyevskyy > Business Automation & Web Development > > > > On Mon, Jul 11, 2011 at 11:41 AM, Marco Pivetta <ocram...@gmail.com>wrote: > >> The <head/> replacement in the template above is obviously an overkill as >> it is a required xhtml element, but I hope it renders the idea of being able >> to replace stuff at precise spots :) >> >> Marco Pivetta >> >> >> >> >> >> On 11 July 2011 10:37, Marco Pivetta <ocram...@gmail.com> wrote: >> >>> 1) I usually don't have secundary templates. Or at least, this happens >>> rarely, like when differentiating emails from website xhtml. I prefer having >>> small and clean templates that use the smallest possible number of >>> variables. Supposing I write a "xhtml wrapper" template that accepts some >>> content and handles basic stuff like placing required tags (<html/>, <head/> >>> and <body/>, DTD, namespace), that template should handle and be aware ONLY >>> of those vars: >>> >>> templates/xhtml.xml - xhtml wrapper, we'll inject body in here or use the >>> standard one: >>> <tal:block metal:<!DOCTYPE html></tal:block> <!-- >>> allows DTD replacement --> >>> <xhtml >>>>> xml:>>>> > >>> <tal:block metal: <!-- allows <head/> replacement >>> --> >>> <head> >>> <tal:block metal: <!-- allows >>> <head/> content replacement --> >>> <tal:block >>> metal: <!-- calling the default >>> <head/>, used when I don't need particular customization or replace pieces >>> only within the default <head/> --> >>> </tal:block> >>> </head> >>> </tal:block> >>> <tal:block metal: <!-- allows <body/> replacement >>> --> >>> <body> >>> <tal:block metal: <!-- allows >>> <body/> content replacement --> >>> <tal:block >>> metal: <!-- calling the default >>> <body/>, used when I don't need particular customization or replace pieces >>> only within the default <body/> --> >>> </tal:block> >>> </body> >>> </tal:block> >>> </xhtml> >>> >>> user-profile.xml - my view, calls template and does stuff in it - >>> replaces body completely: >>> <tal:block metal: >>> <tal:block metal:<!DOCTYPE html PUBLIC "-//W3C//DTD >>> XHTML+RDFa >>> 1.0//EN"""></tal:block> >>> <!-- need RDFA when displaying a user profile (example, not appying here) >>> --> >>> <tal:block metal: >>> <div id="article"> >>> <h1 tal: >>> <p tal: >>> <a href="mailto:${user/email}" tal: >>> <!-- etc... --> >>> </div> >>> </tal:block> >>> </tal:block> >>> >>> This is an example... I usually nest more (i18n ignored here): >>> >>> login.xml - my view, calls template and does stuff in it - replaces body >>> partially: >>> <tal:block metal: >>> <tal:block metal: >>> <tal:block metal: <!-- >>> this nesting could be omitted, but I prefer keeping it avoids troubles with >>> duplicate slot names --> >>> <tal:block metal: >>> <h1>Login:</h1> >>> </tal:block> >>> <tal:block metal: >>> <!-- I usually do this with form objects. Copying for >>> clearness >>> <form method="post" action="/login"> >>> <input type="text" name="login" >>> >>> <input type="password" name="password" >>> >>> <input type="submit" value="Login"/> >>> </form> >>> </tal:block> >>> </tal:block> >>> </tal:block> >>> </tal:block> >>> >>> This is how I usually work. Every template could be used singularly or >>> could use legacy default macro calls. >>> I could use my xhtml template in any project, won't be an issue :) >>> >>> 2) views are views, and the concept of "hardcoding" is quite different >>> from the one used in programming. A view is usually not part of the code >>> flow. If it is, then it probably isn't a view... I actually don't see any >>> hardcoding in the template above. >>> >>> >>> Marco Pivetta >>> >>> >>> >>> >>> >>> On 11 July 2011 10:07, Anton Andriyevskyy <x.meg...@gmail.com> wrote: >>> >>>> >> The big advantage I personally see in this way of developing is that >>>> your template >>>> >> doesn't need to be aware of every variable that could be injected in >>>> it. >>>> >>>> ... but as for me this adds 2 disadvantages: >>>> >>>> 1) every secondary template that uses that main template must be aware >>>> of its slots; >>>> taking into account that we always have more secondary templates then >>>> primary templates, >>>> it's better to make primary templates to be aware of something, then to >>>> have secondary ones to do this. >>>> >>>> 2) this way you hardcode which primary template must be used to render >>>> your secondary template; >>>> of course you can still use variable macro name in metal:use-macro, and >>>> then define fill-slot, >>>> but this way you are limiting your primary templates to always define >>>> the same slots. >>>> >>>> So I'm still convinced that using slots is just a way to limit >>>> scalability of templates, >>>> and I'm very interested to see useful examples where slots are better >>>> then macro. >>>> >>>> Thanks, >>>> >>>> Anton Andriyevskyy >>>> Business Automation & Web Development >>>> >>>> >>>> >>>> On Mon, Jul 11, 2011 at 10:51 AM, Marco Pivetta <ocram...@gmail.com>wrote: >>>> >>>>> Suppose that you wrote a complex template... >>>>> It has a header, footer, sidebars, h1, site logo... >>>>> >>>>> Let's say you wish to have just 1 javascript or css added to your >>>>> template when visiting any page that relates, let's say, the user profile. >>>>> >>>>> Supposingthat you're using some standard MVC stack you'd probably have >>>>> something like a site.xml template and a user.xml: >>>>> >>>>> user.xml: >>>>> <tal:block metal: >>>>> <tal:block metal: >>>>> <!-- add your JS here! --> >>>>> </tal:block> >>>>> <tal:block metal: >>>>> <!-- add your CSS here --> >>>>> </tal:block> >>>>> </tal:block> >>>>> >>>>> The big advantage I personally see in this way of developing is that >>>>> your template doesn't need to be aware of every variable that could be >>>>> injected in it. If you have specialized views, then those views should >>>>> handle variables and replace slots. >>>>> This makes your template independent from your app and also reusable, >>>>> and also less fragile and subject to bugs or VariableNotFound exceptions >>>>> :) >>>>> >>>>> I often define dozens of slots and macros... Also if I don't use them, >>>>> like: >>>>> <div id="aside"> >>>>> <!-- stuff --> >>>>> <tal:block metal: >>>>> </div> >>>>> This makes me life easier when I want to place a banner in that >>>>> position in future... I just have to generate the content somewhere else >>>>> and >>>>> then stuff it in there with metal:fill-slot. No logic needed in the >>>>> template. The final view can handle that :) >>>>> >>>>> >>>>> Marco Pivetta >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> On 11 July 2011 09:40, Anton Andriyevskyy <x.meg...@gmail.com> wrote: >>>>> >>>>>> Ok, Marco, so actually we are still continuing to use macro, but we >>>>>> make them more dynamic >>>>>> by defining slots, correct? >>>>>> >>>>>> Then still I have question how it's better then defining macro >>>>>> (instead of fill-slot) and call it >>>>>> with variable macro name inside template? >>>>>> >>>>>> Any thoughts? >>>>>> >>>>>> Anton Andriyevskyy >>>>>> Business Automation & Web Development >>>>>> >>>>>> >>>>>> >>>>>> On Mon, Jul 11, 2011 at 10:26 AM, Marco Pivetta >>>>>> <ocram...@gmail.com>wrote: >>>>>> >>>>>>> Marco >>>>>> >>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> | https://www.mail-archive.com/phptal@lists.motion-twin.com/msg01675.html | CC-MAIN-2018-13 | refinedweb | 1,634 | 60.04 |
On Thu, Oct 15, 2009 at 12:48 AM, Glenn Rempe <glenn@rempe.us> wrote:
> "The ext2 inode specification allows for over 100 trillion files to
> reside in a single directory, however because of the current
> linked-list directoryimplementation, only about 10-15 thousand files
> can realistically be stored in a single directory.
...
> Of course this will vary by filesystem in absolute terms, but I think
> the concept is the same for all current file systems. No?
Uhm, well, for the record, basically, no :-)
There's file systems that can use things like a tree instead of a
linked list for directories.
IOW more powerful file systems like ZFS or GPFS have different characteristics.
Things like running 'ls' probably do become more and more expensive
rather non-linearly across almost all filesystems, but you probably
don't _really_ have to run that 'ls' :)
All that said, put them /-es in your namespace name and you can
probably stick with EXT2!
ciao,
- Leo | http://mail-archives.apache.org/mod_mbox/incubator-couchdb-user/200910.mbox/%3C30b2aef60910141714p6d2b906cjb093f6d24c2879fa@mail.gmail.com%3E | CC-MAIN-2016-44 | refinedweb | 162 | 53.85 |
18 May 2011 13:19 [Source: ICIS news]
By Anna Jagger
COLOGNE (ICIS)--Global chemicals merger and acquisition (M&A) activity is rising to pre-crisis levels, with most of the deals driven by industry rather than finance, Tom Crotty, group director at Swiss-headquartered INEOS, said on Wednesday.
“M&A was a natural part of our lives until 2007,” he told delegates at the Global Petrochemicals annual meeting, organised by the World Refining Association (WRA). “It went away but it’s back.”
In the first four months of 2011, there were $50bn (€35bn) of announced deals in the sector, the equivalent to the pre-crisis deal rate of 2007, Crotty said.
“Companies that have generated a lot of cash are looking to spend it,” he added.
In addition, as producers emerge from the downturn, many are seeking to restructure their businesses to cut costs and prepare for the next set of unpredictable events, Crotty said.
While there have been some major deals announced by financial institutions, the largest of which is Berkshire Hathaway’s $9.7bn bid for US lubricants and specialty chemicals company Lubrizol, most of the deals are being driven by industry.
“The reason we are not seeing more from the financial sector is that some investors are twitchy about the downside risk of cyclical businesses,” Crotty told ICIS on the sidelines of the meeting.
The Lubrizol acquisition was perhaps less of a risk because that business sector has a lower degree of cyclicality, he suggested.
Recently-announced, industry-driven deals include Solvay’s $4.8bn agreement to buy Rhodia and Clariant’s $2.7bn bid for Sud-Chemie.
Divisional acquisitions are also dominated by industry players. Examples include AkzoNobel’s purchase of Dow Chemical’s powder coatings business and Arkema’s purchase of Total Petrochemical’s coating resins business.
M&A activity is also expected from Chinese players as they seek to broaden their geographical reach, Crotty said. One such deal is INEOS’ agreement to sell a 50% stake in its European refining operations to state-owned PetroChina.
“We will see a lot more of those deals going on. They want to be part of our industry, not just in ?xml:namespace>
INEOS, in the meantime, intends to focus on organic growth and explore joint venture deals - such as its recently announced phenol venture with Sinopec - that take the company into new geographies, Crotty said.
However, this does not preclude bolt-on acquisitions, he added.
INEOS signed a memorandum of understanding (MOU) with Sinopec in January to build a 400,000 tonne/year phenol plant in
($1 = €0.70) | http://www.icis.com/Articles/2011/05/18/9461132/global-chemicals-m.html | CC-MAIN-2014-52 | refinedweb | 433 | 52.8 |
If you are defining a schema that has elements or attribute of numeric types and require more restrictions on their value, try to avoid using pattern facets. If you do, you will get the warning:
Warning: Type (name of your type) is restricted by a facet 'pattern' that may impede full round-tripping of instances of this type.
You may end up doing this because you want to specify that the number start with the digit 1 and end with the digit 9. Of course, this isn't a common scenario and you are more likely to want a certain number of digits or a minimum or maximum value. In those case, use the minInclusive, minExclusive, maxInclusive and maxInclusive facets.
One interesting simple type that can be the cause of a number of static type issues is xs:anySimpleType. This type is the base type of all simple types. That includes list and union types. By default, attributes are typed xs:anySimpleType, so if you do not specify a type via the type attribute, any simple type value is valid for that attribute. This includes list type values. You can also have element content typed to xs:anySimpleType. In that case, you can optionally specify the specific simple type that a specific element instance contains.
Because xs:anySimpleType includes list types, you may end up with static typing errors if you do not specify a type for an attribute and are querying for the attribute in a typed xml column. The problem has to do with cardinality. The error message that you get can be confusing and the typical way to correct such a static typing error does not work in this case. Here is an example:
create xml schema collection att as N'
<xs:schema xmlns:
<xs:element
<xs:complexType>
<xs:sequence>
<xs:element
</xs:sequence>
<xs:attribute
</xs:complexType>
</xs:element>
</xs:schema>'
go
declare @x xml(att)
set @x = 'string'
select @x.query('/mult/elem cast as xs:string?')
go
declare @x xml(att)
set @x = 'string'
select @x.query('/mult/@att cast as xs:string?')
These two queries will result in the follow error messages:
Msg 2365, Level 16, State 1, Line 3
XQuery [query()]: Cannot explicitly convert from 'xs:string *' to 'xs:string ?'
Msg 2365, Level 16, State 1, Line 4
XQuery [query()]: Cannot explicitly convert from 'xdt:anyAtomicType *' to 'xs:string ?'
The first query is easy to fix. Because there can be more than one elem element under the mult element, you must specify which chlid element you really want. We change the query to be (/mult/elem)[1] cast as xs:string?. So why do we see the same error with the second query? There can only be one @att element under the mult element, so why is the type that is inferred xdt:anyAtomicType*? If we try to fix the second query using the same workaround as the first, we still get the same error message! Even though you don't see it, the attribute is being implicitly atomized because of the cast operator. Because xs:anySimpleType includes list types, the atomization results in potentially zero or more atomic values. Since the query compiler can not possible know up front what the type is for the atomic values, we infer xdt:anyAtomicType.
The workaround is to explicitly atomize the attribute and place a positional predicate or more simply, supply an atomic type for the attribute. To atomize the attribute you can change the query as such:
declare @x xml(att)
set @x = '<mult att="foo"><elem>string</elem></mult>'
select @x.query('data(/mult/@att)[1] cast as xs:string?')
Note that the work around is also applicable for elements and attributes that are list types.
Today, I want to a little about how content models are defined in complex types. These are important concepts in not only creating schemas and instances that are valid against the schemas, but will also help in understanding static typing and static typing errors within XQuery (this will be topic in a couple of posts).
The important thing to understand about complex types is that they define content models that contain elements and attributes. The structure and potentially the order of elements within a complex type is the content model. XSD allows you group your content that specifies if all the elements are required and should appear in order in a valid instance. These content groups and elements within these content groups can be specified as optional and may even repeat an arbitrary number of times.
A sequence group specifies that the content should all be present and in order. A choice group specifies that one item in the group should be present. An all group specifies that all the content should be present, but in any order. Sequences and choice groups can be nested within each other. An all content group can only be at the top of a complex content model.
Here is an example:
<
<
Notice that I can specify minOccurs and maxOccurs attributes on model groups and elements. For the complex type "foo", the sequence can be repeat an arbitrary number of times (maxOccurs="unbounded". And the element bar within this sequence does not have to appear at all within one instance of the sequence (minOccurs="0"). The same goes for the choice model group.
Last.
My fellow team members have all blogged on static typing and anyone reading these blogs would be correct to conjecture that it is pretty important. There is so much to say about it and I'd rather not duplicate what my team members have written. For an introduction, read Denis' entry here and Mike's entry here. After reading these posts, it should be apparent that the point of static typing is to aid the developer in writing correct queries. Static typing is often used in other languages such as C# which are strongly typed. XQuery is a strongly typed language and implementations have the option of providing static type checking at query compile time. The XQuery implementation in SQL Server 2005 does in fact perform static type checking.
Before going into static typing, it is important to understand types within XML: where they come from, how they are defined and what can they "look" like. I will spend the next few posts talking just about types.
The type system in XQuery is based on XML Schema (XSD). If you don't plan on using XSD validation in your XML, you might think there is no point in learning more about types. However, static typing is still in affect when quering untyped XML within XQuery. The difference between typed and untyped instances is that the former is validated against an XSD collection. I won't go into the details of XSD, but I suggest those who are not familiar with it read Part 0 of the XSD specification.
Part 2 of the XSD specification talks about primitive and builtin types. XQuery inherits these builtin types into its own type system. Along with simple and complex types from XSD, XQuery defines node types. XQuery also has the notion of a sequence of items. Items are either atomic values or nodes. (Don't worry, these will become clear later)
Atomic types within XQuery are the builtin primitive types (simple types) and the types derived from these primitives by restriction or union. XQuery defines a few extra simple types: xdt:untypedAtomic, xdt:anyAtomicType, xdt:yearMonthDuration and xdt:dayTimeDuration (SQL Server 2005 does not support the last two types). We will discuss these types in the future. Like XSD, the builtin types just exist and the user has the ability to introduce new types. In SQL Server 2005 we do this by creating an XSD schema collection. To create new atomic simple types, we have to restrict an existing atomic simple type. For example, if I wanted to create a type named foo that is an integer greater than 10, I would execute this DDL:
CREATE XML SCHEMA COLLECTION new_type_collection AS N'<xs:schema xmlns: <xs:simpleType <xs:restriction <xs:minExclusive </xs:restriction> </xs:simpleType> <xs:element</xs:schema>'
I've also defined an element name fooElement. Assuming I have an XML instance, I can now use this type within a query.
declare @x xml(new_type_collection)set @x = '<tn:fooElement xmlns:11</tn:fooElement>'select @x.query('declare namespace tn="urn:new_type"; tn:foo("12") > /tn:fooElement')
Notice that I created an instance of the type foo by using a constructor syntax. What I have done is created an instance with the numeric value of 12 and then compare it to the value stored within the instance I am querying. In this case, the result is true. I can also create instances of builtin types with the constructor syntax:
declare @x xml(new_type_collection)set @x = '<tn:fooElement xmlns:11</tn:fooElement>'select @x.query('declare namespace tn="urn:new_type"; xs:integer("0") > /tn:fooElement')
Here, I've created an instance of xs:integer with the value 0 and compared it to the stored instance.
Okay, so now you know what builtin types are, how to create new restricted types from them via an XML Schema and how to create instances of these simple types within a query. The builtin simple types consist of string, date/time, floating point, decimal, integer, binary and various other types. To learn more about them, their semantics, restrictions and valid value and lexical spaces, read Part 2 of the XSD Specification. If you prefer to read a book try Definitive XML Schema by Priscilla Walmsley. Here is a diagram of the builtin type hierarchy.
Next time, I will talk about union and list types and their properties within XQuery.
Welcome to my MSDN blog! My name is Galex Yen and I've been working within the XML datatype team in SQL Server for the past year. My team has begun to blog about our exciting new feature and it seems I'm one of the late comers. I've linked to my fellow team members' blogs under the category "Other MSDN XML Blogs." Our hope is to provide a one stop shop for dialogue and education on the native XML datatype.
I'm very enthused about how we've integrated XML into SQL Server 2005 and I hope that all of you will learn something from our posts. I encourage you to ask questions and provide feedback.
Trademarks |
Privacy Statement | http://blogs.msdn.com/galexy/default.aspx | crawl-002 | refinedweb | 1,744 | 62.58 |
React Native — Platform specific code
With React Native we are writing the code for both, iOS and Android, and it doesn't take long to notice that we need to differ one from another.
As we can see, our Header component, that has a simple task of displaying text, behaves differently on Android and iOS. Clearly, we need to have different styles for the two. So, how can we accomplish this?
Good people from the React Native team have provided a quite simple solution. They’ve offered us a module called Platform.
All we need to do is import Platform from react-native and we’re good to go. The Platform has OS property which tells us if we’re running our app on iOS (ios) or Android (android). Furthermore, Platform comes with a method select which given an object with a key of Platform.OS will return the value for the platform we are running our code on.
Enough talk. Let’s see this in action.
import React from 'react';
import { View, Text, StyleSheet, Platform } from 'react-native';
export const Header = () => (
<View style={styles.header}>
<Text style={styles.text}>I am Header</Text>
</View>
);
const styles = StyleSheet.create({
header: {
height: Platform.OS = 'android' ? 76 : 100,
marginTop: Platform.OS = 'ios' ? 0 : 24,
...Platform.select({
ios: { backgroundColor: '#f00', paddingTop: 24},
android: { backgroundColor: '#00f'}
}),
alignItems: 'center',
justifyContent: 'center'
},
text: {
color: '#fff',
fontSize: 24
}
});
The result:
Let’s break down our code!
height: Platform.OS = 'android' ? 76 : 100,
marginTop: Platform.OS = 'ios' ? 0 : 24,
Nothing fancy here. We’ve already mentioned that Platform.OS returns ios or android depending on the platform it’s running on. Combining that with the ternary operator gave us this nice code which helped set height/margin of our Header. This code is equivalent to
height: 76, marginTop: 24 on Android and
height:100, marginTop: 0 on iOS.
Moving along we have:
...Platform.select({
ios: { backgroundColor: '#f00', paddingTop: 24},
android: { backgroundColor: '#00f'}
}),
Platform.select will return the value given the key from Platform.OS., so in our case the code becomes
...{ backgroundColor: '#f00', paddingTop: 24} for iOS, and
...{ backgroundColor: '#00f'} for Android.
To sum it up, or styles are going to look like this:
Android:
const styles = StyleSheet.create({
header: {
height: 76,
marginTop: 24,
backgroundColor: '#00f',
alignItems: 'center',
justifyContent: 'center'
},
text: {
color: '#fff',
fontSize: 24
}
});
-----------------------------------
iOS:
const styles = StyleSheet.create({
header: {
height: 100,
marginTop: 0,
backgroundColor: '#f00',
paddingTop: 24,
alignItems: 'center',
justifyContent: 'center'
},
text: {
color: '#fff',
fontSize: 24
}
});
We haven’t come to an end with Platform.select. The cool thing about it is that it accepts any value, so you can use this to your advantage to return components for iOS/Android. In our case, we’ve created BodyAndroid.js, BodyIOS.js, and Body.js, and replaced default text in App.js with Body component. So, our App.js looks like this:
import React from 'react';
import { View} from 'react-native';
import {styles} from "./src/theme/Style";
import { Header } from './src/components/Header';
import { Body } from "./src/components/Body";
export default class App extends React.Component {
render() {
return (
<View style={styles.container}>
<Header />
<Body />
</View>
);
}
}
The rest of our code:
BodyAndroid.js
import React from 'react';
import { View, Text} from 'react-native';
import {styles} from "../theme/Style";
export const BodyAndroid = () => (
<View style={styles.body}>
<Text style={styles.h1}>This is Android App!</Text>
</View>
);
--------------------------------
BodyIOS.js
import React from 'react';
import { View, Text} from 'react-native';
import {styles} from "../theme/Style";
export const BodyIOS = () => (
<View style={styles.body}>
<Text style={styles.h1}>This is iOS App!</Text>
</View>
);
--------------------------------
Body.js
import { Platform } from 'react-native';
import { BodyAndroid } from './BodyAndroid';
import { BodyIOS } from './BodyIOS'
export const Body = Platform.select({
ios: BodyIOS,
android: BodyAndroid
});
And the result:
As good as this looks I don’t consider it the best solution. There is something called Platform-specific extension which I prefer. So in the case of iOS, we want to have
.ios. extension, while for Android we’ll have
.android.. This will help React Native determine which component to use for what platform.
Let’s illustrate this with an example.
The code for our Footer is very similar to our Header, therefore, I won’t be pasting it here. Important to notice is this simple line
import { Footer } from './src/components/Footer';. The components directory doesn’t contain Footer file, but righter Footer.ios and Footer.android. React Native is smart enough to determine which one to use, depending on what platform we’re building our app for.
We’ve seen how we can add our component using the Platform-specific extension and Platform.select method, but was that all Platform module can do? Well, no. There’s one more thing left and you might have guessed it. It is detecting the version of Android/iOS. So let’s modify our Body message by appending to it the version number.
Showing Platform version is as simple as calling Platform.Version.
Well… there is a catch. While Android returns the version as an integer, iOS isn’t so friendly and will give us the version in a form of a string. It shouldn’t be difficult to convert it to the integer if we need to compare it (which is the most likely scenario if we need a version number). If we just want to display it we’re safe to go with what we got.
To make everything more interesting, React Native comes with build in components and APIs, some of which are Android/iOS specific. To mention a few, for Android we have: DatePickerAndroid, ProgressBarAndroid, ViewPagerAndroid; and for iOS: AlertIOS, ImagePickerIOS, TabBarIOS. Furthermore, we can write Native modules for our Platform, but that is topic for itself.
To Platform or not to Platform, that is the difficult question. Usage of the platform-specific code is quite simple when it comes to React Native. We have a variety of choices. To create platform-specific component or make a modification in the component by determining OS is entirely up to us, and our case scenario.
The code used in this article can be found at : | http://brianyang.com/react-native-platform-specific-code/ | CC-MAIN-2018-22 | refinedweb | 1,014 | 69.07 |
Obsolete Technical Skills 603
Ponca City, We Love You writes "Robert Scoble had an interesting post on his blog a few days ago on obsolete technical skills — 'things we used to know that no longer are very useful to us.' Scoble's initial list included dialing a rotary phone, using carbon paper to make copies, and changing the gas mixture on your car's carburetor. The list has now been expanded into a wiki with a much larger list of these obsolete skills that includes resolving IRQ conflicts on a mother board, assembly language programming, and stacking a quarter on an arcade game to indicate you have next. We're invited to contribute more."
Assembly isn't obsolete! (Score:5, Insightful)
Re:Assembly isn't obsolete! (Score:5, Informative)
Re:Assembly isn't obsolete! (Score:4, Insightful)
Re:Assembly isn't obsolete! (Score:4, Insightful)
Re:Assembly isn't obsolete! (Score:5, Funny)
Re: (Score:3, Interesting)
Last I checked, his bootloader could load nearly any OS for x86. Doing all of that in a few KILOBYTES of otherwise unused space would be just about impossible with anything other that assembly.
LIST of obsolete things (Score:5, Interesting)
- what to do with a Commodore 64 when its cursor is blinking at you
-----(everyone I know in my circle of friends would go "duh")
-----(they have no clue how to navigate without icons or explorer)
- how to write a simple basic program for your C=64:
----- 10 print "hello"
----- 20 goto 10
----- RUN
- LOAD "$" to get directory off my cassette drive (yes we used cassettes)
- LOAD "*",8,1 to autoload & start most floppy disks
- how to crate 16-color pictures that look good
- how to program the SID to make music
- dir df0: to get a directory on a Commodore Amiga 500/2000
- the difference between Chip and Fast RAM
- why it's a bad idea to multitask 2 programs off the same floppy
-----(because the floppy will knock itself silly trying to read two tracks at the same time)
- ATDP 5601750 to dial on a rotary/pulse phone (ATDT for touchtone)
- +++ to get your modem's attention so you can issue commands like:
- ATH to hang up
- how to create pretty pictures using ANSI
- what is Zmodem, and why it's better to download files with Z rather than Xmodem
- how long will it take to download a 3.5 inch floppy over 2.4k modem
-----(long enough to eat supper and take a shower)
-----(or watch the latest episode of Star Trek The Next Generation)
- how many hours you can squeeze on a T-180 VHS tape (9)
- how many episodes of Quantum Leap if you remove the commercials (12)
- how to repair your copy of Star Wars after the tape tears in half (scotchtape)
Most of the things I just listed were items known by "everyone" back in the 1980s. If you wanted to use a computer, you had to know the various commands and understand how/why things work.
Today people don't need to know command-line text.
They can just point-and-click; it's become easy.
And a lot of the things we used to need to know?
It's essentially automatic now.
Re:LIST of obsolete things (Score:4, Interesting)
Re:LIST of obsolete things (Score:5, Informative)
Sorry, those became way obsolete with Dos 6.22s ability (iirc) to have multiple configurations to chose from.
Anyone remember countless runs of memmaker to squeeze the last byte of RAM out of a config ?.
Some skills just seem like they're obsolete or dying because the proportion of people within a field that have them is getting smaller -- but they're really stronger than ever when you look at the raw numbers.
I agree with the parent and fully suspect that there are more people who understand x86 assembler today than there were at the perceived 'height' of assembler, back in the early 90s. There are just that many more people in the IT field. Learning assembler, if you happen to be interested, is also a lot easier now than it was then. Today, computers are basically a mainstream subject, plus you have all the information available on the Internet. In 1990, finding a good book on assembler programming would probably have required a trip to a large university's library.
Obviously there are some skills that really are on their way out, or will be when the current crop of people who truly understand them either retire or die. But in many cases I think it's easy to confuse the S/N ratio in a particular sphere with the number of people who actually are familiar with a topic.
Re: (Score:3, Insightful)
At first we tried poking in the textual strings of BASIC programs into memory, not realizing that even BASIC programs were st
Re:Assembly isn't obsolete! (Score:5, Funny)
Well not reputable web programming anyway.
Re:Assembly isn't obsolete! (Score:5, Funny)
It's not obsolete, here's why: (Score:5, Insightful)
On the other hand, there are many times less people capable of making horse buggies than in the XIXth century; that's obsolete.
Population: Growing! (Score:3, Funny)
Re: (Score:3, Insightful)
Seriously though, I do a lot of PIC assembly programming. Something like Arduino is fun to play with, but for anything non-trivial in an embedded system, it has to be assembly.
Re:It's not obsolete, here's why: (Score:4, Insightful)
Because non-programmers don't program in ANYTHING? Duh?
I bet the number has fallen sharply. It used to be impossible to do many things without ASM. Now you can just throw processing power at problems and hope they go away. Ever notice how much less responsive your computer is when you're not even USING all the amazing new functionality, compared to say PC-GEOS? A lot of that is due to lazy programming. And part of that is not optimizing much, if at all; and part of that is not doing any assembler.
Most programs are never optimized (or at least never heavily optimized) because they can run on our computers of today. Think about it: right now I have barely more actual functionality than I did on my Sun 4/260, but in the name of eye candy and tooltips and shit I run Ubuntu and it's about as responsive on this Core Duo T2600/2GB DDR/80GB 7200rpm SATA as Solaris 1.x was on a SPARC at 16 MHz, with 24MB of FPM DRAM, and a 500MB 5400 RPM SCSI-II fast/narrow disk.
Re:It's not obsolete, here's why: (Score:5, Insightful)
Coding in higher-level languages frees programmers up to create actual cool stuff. It's great that some ur-geek wrote a bitchin' disk driver in ASM that fits in 7KB of code during one Jolt-and-meth-fueled month back in 1991 but jesus, who cares. Given the chance, I bet that engineer would have done it in 1/4 of the time in C and actually done something useful with the rest of his month. Or at least stayed away from the meth and Jolt.
It's the technological equivalent of carrying buckets of water three miles from the stream to your prarie frontier home every single morning. Like, it's cool and admirable that people once did that, but thank goodness we generally don't have to do that these days. Even if my tap water really doesn't have any new functionality compared to that stream water.
Re: (Score:3, Interesting)
Maybe less in terms of quantity, but more in terms of quality.
You think you'd be using a nice, modern web browser or game if they had to code the whole thing in assembly?
Quite possibly, yes. The assembly requirement would present quite a barrier of entry, but at least it would raise the overall quality of the software. People who manage to write bug-ridden crapfests in high level languages would have a hard t
Re:It's not obsolete, here's why: (Score:4, Insightful)
>Maybe less in terms of quantity, but more in terms of quality.
I disagree. The complexity of a software module does not grow linearly with size. It grows much faster than that. Something like Firefox (a piece of software most of us enjoy, though most of us agree it could be much more svelte) just couldn't be accomplished in any reasonable time frame in assembly because of the sheer complexity involved.
Assembly has its place (and always will) and I'll ALWAYS look to assembly programmers as the true heroes of the programming world. I just like to take issue (or rather, poke fun) at these people that pine for an imaginary world where everything is written in assembly.
Re: (Score:3, Interesting)
You're also overlooking something called "debugging". You think you'd be using a nice, modern web browser or game if nobody involved had any understanding of assembly language? When testers send crash dumps back to the developers of IE & Firefox, what do you think those developers are looking at? Same thing for games. The latest few months of any project a
Re:It's not obsolete, here's why: (Score:5, Insightful)
In the context of this discussion, a skill is obsolete when it is no longer needed to do something that is still being done today - For example, nobody needs to know how to load a program off tape on a C64 these days, because we don't have C64s anymore.
By this definition, assembly programming is obviously NOT obsolete. We still need assembly programmers: for device drivers, for kernel programming, for writing compilers, for reverse engineering old code that is no longer supported, for cracking dumb DRM schemes that take away our fair-use rights, etc etc etc. The fact that not many people know how to write assembly is irrelevant: does the fact that few people know how to build a human-rated space launch vehicule mean that it is obsolete?
Re:Assembly isn't obsolete! (Score:4, Insightful)
Niche ? JIT compilers depend on it - to nitpick, they propably product opcodes, but it's not like there's much difference. In fact all compilers which produce machine code depend on it. All systems programming depend on someone writing the assembler routines to actually manipulate the hardware.
Assembler is a niche skill to a programmer in the same way that knowing how to build foundations is a niche skill to a house builder: you can make do without, but only as long as you get someone else to do the groundwork for you.
Re: (Score:3, Informative)
However the most common use of lots of assembler is compilers. Not just traditional source->executable compilers, but JIT recompilers are in every emulator that wants a sensible amount of speed.
Re: (Score:3, Interesting)
Steve Gibson does it: [typepad.com]
Re:Assembly isn't obsolete! (Score:4, Funny)
Well, you just told me to get a floppy drive.
Re: (Score:3, Informative)
Re:Assembly isn't obsolete! (Score:5, Insightful)
Re:Assembly isn't obsolete! (Score:4, Interesting)
Two hundred million VB, PHP and Ruby programmers want to disagree with you. But you are right. Assembly is as much a part of the system as transistors and stack pointers. My first system had a 6502 with a BASIC interpreter in ROM. The back page of the instruction book had the 6502 instruction set printed on it (lucky it wasn't a Z80). That was much more interesting for a 13 year old than basic.
Re:Assembly isn't obsolete! (Score:4, Insightful)
Re:Assembly isn't obsolete! (Score:5, Informative)
Re: (Score:3, Informative)
I had a compiler on CP/M which generated assembly and sent the output to an assembler. I don't think GCC works that way. It probably generates machine code directly. Maybe it has a symbolic "assembly" layer inside.
Re: (Score:3, Informative)
Re:Assembly isn't obsolete! (Score:4, Informative)
In fact, the gcc or g++ commands are 'drivers' that first call a preprocessor, then a compiler, then an assembler and finally a linker (all of them separate executables).
websites in assembly ... (Score:3, Interesting)
Programming a website in assembly, on the other hand, would be pretty thickheaded.
My point is that a knowledge of assembly is indeed very usefull for any programmer. I only disagree with your gratitious bashing of script languages and their users.
Re:Assembly isn't obsolete! (Score:5, Insightful)
Re:Assembly isn't obsolete! (Score:4, Insightful)
For example, data structures such as lists and arrays are used interchangeably without any idea of the pros and cons of each, and the right place to use them. There are plenty more examples of this.
At the very least, the abstract notion that we should aspire to understand what lies beneath our current level of knowledge and how it affects the quality of code is fundamental to good practice.
Re: (Score:3, Informative)
and sometimes programmers make really horrible descisions like trying to delete elements from the middle of an array and move up everything after it. Sometimes programmers read large blocks of data into strings and try to use string manipulation on them etc. Theese bad descisions are imperc
Re:Assembly isn't obsolete! (Score:4, Interesting)
Cracking protected information. (Score:5, Insightful)
Re:Cracking protected information. (Score:5, Insightful)
Re:Assembly isn't obsolete! (Score:5, Insightful)
Sure 'smartphones' etc start getting programmable in high-level languages but OTOH simple microcontrollers enter more and more of daily appliances. You don't write firmware in assembly for a DVD player anymore, but you write it for a toaster or a bicycle lamp, devices that 5 years ago didn't have any firmware or programming capability. The frontier is and likely always will be assembly, and even though the frontier keeps moving and likely in 5 years the bicycle lamps will be programmable in Java, maybe ballpens will be programmable in assembly.
Re: (Score:3, Informative)
Here's [made-in-china.com] a programmable pen, couldn't find a bicycle lamp, so here's a NetBSD Toaster [embeddedarm.com] instead, for 4096 levels of burned bread and a web server.
Re:Assembly isn't obsolete! (Score:4, Informative) [wikipedia.org]
Running a shmoo curve on magnetic core memory is an obsolete skill. [ieee.org]
Re: (Score:3, Interesting)
But it goes beyond kernel debugging. Any Antivirus researcher worth his weight (or at least a fraction thereof) knows x86 assembler to the core. When the automatic analysis fails, you still toss the malware into a disassembler and you have to find out why the analyser failed. What system did they use this time to foil your analysis attempts?
Although you do notice that also on the "other side" (i.e. at the people writing those crit
All skills are of value (Score:5, Interesting)
Re: (Score:3, Interesting)
Re: (Score:3, Funny)
Assembly coding isn't obsolete... (Score:2, Informative)
Too many jokes and false entries (Score:4, Insightful)
The whole list is crap (Score:3, Interesting)
Using a Fountain Pen
Coins on the machine to reserve next go
Memory Management
There are many many useful and relevant skills on there.
Re: (Score:3, Interesting)
Re:One more for the list: (Score:5, Funny)
Re:One more for the list: (Score:4, Funny)
Stretching a bit to make the list (Score:2)
It's a crap list. (Score:2, Informative)
Navigating by compass is obsolete? (Score:5, Insightful)
Some things on that list are either silly or shortsighted.
Re:Navigating by compass is obsolete? (Score:5, Funny)
Another thing that's obsolete is like maths, because we always have calculators now.
Re:Navigating by compass is obsolete? (Score:5, Funny)
Re:Navigating by compass is obsolete? (Score:5, Funny)
You know, there is this one leg of my table that's a little short, so the log table comes in handy.
Assembly language is obsolete? (Score:3, Informative)
Re:Assembly language is obsolete? (Score:4, Insightful)
Re: (Score:3, Informative)
The ARM Risc is a joy to program. 15 general purpose registers that could be used with any instruction, conditional instructions, I could go on all night. This caters perfectly to the needs of assembly. The only thing that x86 caters for is the need for compatibility with the 8086.
I'll add one (Score:5, Funny)
Re:I'll add one (Score:5, Funny)
Using a rotary phone is a "technical skill"?? (Score:5, Interesting)
Anyway , here in the UK new and refurbished rotary phones are a niche fashion item. You can pick them up in a number of places for a reasonable amount.
Churn butter? (Score:5, Insightful)
Re:Churn butter? (Score:5, Funny)
The surprising part is how butter comes out in those brick shapes. Surprising for the cow, that is...
Obsolete skills (Score:5, Insightful)
Another one (Score:5, Funny)
Yeah yeah, Troll.
So, I'm obsolete, huh? (Score:5, Insightful)
Creative Destruction at Work (Score:5, Interesting)
I've noticed that we on Slashdot seem to struggle with this concept daily, be it the loss of jobs to outsourcing, development and adoption of new technology, reform of IP laws, the slow death of the MPAA/RIAA, and even the subject of this article (which is the perfect example). It is probably a little off-topic, but I think this common thread should in these subjects should be pointed out, because all of our discussions seem to hinge on this critical question: Is the creation worth the destruction?
I can think of a few (Score:5, Insightful)
The skill to determine a modem's connect speed from hearing the negotiation sounds.
'Notching' an old single-sided floppy to be able to make it a double-sided disc.
Cleaning and/or aligning the heads on your cassette player.
Terminating or crimping coax.
Knowing you need to type "DIR
Was 'winding your watch' in the list?
I'd love to see some speculation on what skills you'd expect to be obsoleted by 2029.
asm is NOT obsolete! (Score:5, Interesting)
Every serious programmer should have some experience of assembly language so they can grok what's really going on. Nothing tells you why buffer overruns are so bad than watching a program written in asm run over its own stack obliterating the return address. It doesn't need to be a fancy 32 bit or 64 bit desktop chip, an 8 bit ISA or one of the classics such as the Motorola 68K is enough to understand the principles of what happens at the chip level. If you want to see what happens when programmers simply don't grok the hardware, just check out The Daily WTF.
By the way, get off my lawn!
That's just great (Score:5, Funny)
Everything I learned as a kid is obselete now... (Score:5, Interesting)
He was the master at converting 3-cylinder Saab 96 (and 95) models to the newer V4 engine. He had it down to a science, and cars we converted ran all over the country.
A few of the more mundane skills I learned back then:
--Setting the dwell angle by adjusting the ignition points, then rotating the distributor to set the ignition timing.
--Disconnecting the ringer on Western Electric rotary-dial phones, so Ma Bell couldn't detect how many extentions you had (illegally) connected to your line.
--Dialing only the last 5 digits of a 7-digit phone number: within the same exchange, the mechanical switches at the local Bell office would make the connection.
--Scraping conducting material off the rotary dial in the cable box to enable HBO and Showtime.
Jumping off the bandwagon? (Score:5, Insightful)
I grew up with home computers. I learned BASIC when I was 11. That is obsolete skill now. Then I got my first PC in 1988 and learned DOS. That's obsolete. Then I learned Borland's Turbo Pascal. That's obsolete. Then I learned Microsoft C programming and started programming Windows 3.1 applications that used Windows menus etc. That's obsolete. I learned Gopher and Telnet in the 80s. That's obsolete. I learned Pine. That's obsolete. I learned to tweak Windows 95 registry. That's obsolete. I learned BEA Tuxedo at work. That's obsolete. Looking at it now - I've wasted countless of hours to something that is totally obsolete now! Had I invested that time into improving myself - learning who I am, how I behave, how to enjoy this life - I would be much happier now I guess.
Re:Jumping off the bandwagon? (Score:4, Insightful)
Re:Jumping off the bandwagon? (Score:5, Informative)
Basic:
Basic programming building blocks- variables, statements, control of execution flow with if/then/else and goto
DOS:
directory structures, command line navigation, computer architecture (and how bad design time decisions can lead to decades worth of headaches)
Turbo Pascal:
Not too familiar w/ Pascal anymore, but if IIRC, you should have learned how to use functions, namespaces, and the modular programming model.
Microsoft C Programming:
Event driven programming models, resource handles, GUI development issues- how to expose just enough complexity to make things useful without cluttering the screen, and the C aspect... you learned the syntax underpinning just about every other major language since and the basics of using structures, pointers, handling memory, the list could go on for pages.
Gopher/Telnet:
How plain text internet protocols generally work- and if anything you learned some cool tricks to do a raw telnet session on port 25 and spoof email from the boss.
Pine:
Windows 95 registry:
Eh probably the least portable skill here- you at least learned to be comfortable with digging into a blackbox OS and looking under its skirt. The registry is still in use in XP, not so sure about vista, so this is a skill you will get at least 15 years of use out of.
Bea Tuxedo:
not too familiar w/ this product, but if I remember correctly, its all about virtualization, which is now one of the hottest new technologies in the sysadmin/IT world.
Sounds like you learned a hell of a lot. Sure none of these are all that employable *today* but couple that background with a weekend spent with a Java book and I would employ you with a 6 figure salary in a second over some newly minted sun certified ITT Tech grad.
Re: (Score:3, Insightful)
C programming (not MS-specific) has been a useful skill for decades now, with no end in sight. I program in C every day.
telnet: it's been replaced by ssh, which basically works the same. Command-line UNIX doesn't seem to be going anywhere.
Pine: who cares? Email programs aren't hard to learn.
LILO?!!! (Score:3, Funny)
Starting a fire with sticks (Score:5, Funny)
Crushing a Mastadon with a bolder
Killing your enemies & impregnating their women
Being a Sun God
Syquest drives. (Score:3, Funny)
RS
Troubleshooting/repairing hardware... (Score:4, Interesting)
There are hundreds of obsolete skills. (Score:5, Interesting)
I don't have MCSE, CCNA or anything else because the sheer fact is that by the time you've passed the course and been using it for a year, its content is out of date. Not all of it, but quite a bit of it. Especially on those courses designed for particular bits of software. And they are nothing but memory tests. That's not learning.
I've done assembly, I've done BASIC and everything in between. My University tried to teach me Java until I stopped attending the lectures for that part and was instead "hired out" to other students as the person to ask about the Java coursework. I'd only ever dabbled in it but having programmed in a lot of other languages it was no more than a curiousity to flick through a Java book and pick up the syntax. I did the coursework myself at home, taught many others to pass the course, and passed myself (good grades for that course) with barely a sweat. I'd dabbled in Java before but it was merely a matter of flicking through a half-decent book on the subject, applying everything else you already know and making sure you have a list of function-method-procedure (call them whatever you like, OO is just a shortcut that saves you typing so much functional-programming code) name changes handy. KMP search algorithms are the same in any language, it's just a matter of learning or merely memorising (which is NOT learning) the differences between languages.
Similarly, my primary job is being hired by schools to manage their networks. First one was 98-standalones with Ethernet cables basically used for display.
Formal training in any of the above OS, network management, network management software or application software? Zilch. Number of networks exploded? Zilch. Number of networks more productive once I had finished with them? 100%. Number of schools chasing me for further employment to work on their next big network, next OS, next suite of applications? I lose count. And these are critical networks - they run everything from the canteen to the staff wages to the legally required paperwork to the student desktops to the fire and security systems. You have no idea how crippled a school is nowadays if its servers go down... lessons stop, systems go haywire and the students get sent home. And they literally fight over getting an imbecile like me in to manage their systems, or even just clean them up so that they can employ a "normal" technician next year.
If you can learn, you can run any OS, of any age, at any time, in any combination without a problem. If you can't then you're stuck memorising "Windows Vista for Dummies" until the next OS comes out a
Re: (Score:3, Informative)
Erm... You might have been technically correct fifty years ago when everybody still did Latin but not any longer. It's standard practice in every company I've ever worked, for the last 20-odd years and probably a lot longer than that. CV = personal details + list of qualifications + (summarised) work history + references + (possibly) brief statements about important project you've done in the past (unless you're under 18 when it seems you're taught to list "interests" like "watching TV
This is the list for morons. (Score:5, Funny)
Balancing a checkbook
Clicking on the up and down arrows of a vertical scrollbar
Commuting
Extracting square roots
Handwriting (How to fill out forms and sign stuff and write notes.)
Having Cash (and how to properly make change)
Long division?
Look for a job in the classifieds?
Looking up a business on the yellow pages
Local Grocery Store?
Paying for something with a check
Playing solitaire with playing cards
Reading a paper map
Searching a card catalog
Using a cell phone to make a call
Untangling the cord of a telephone
Using a card catalog
Using a fax machine
Using the Dewey Decimal System
Zipping your pants
If your new hire can't do any of those, you do you really want them?
Phone Books (Score:5, Interesting)
Back when I was a kid, I grew up in a modest town of about 50,000 people. Too big to be a small town, not big enough to get on most maps. Our phone book was about one inch thick. Small towns had phone books that were essentially glorified pamphlets, about 1/4" thick, and even then they shared it with all the neighboring towns. I knew people from small towns who thought phone numbers were four digits long, since the first three digits were always the same (and the then-optional area code was the same for probably a hundred miles).
When my family would go on trips we would visit "big cities" like Dallas, Houston, Orlando, Memphis, etc. (yes, I'm from the South) and in the hotel rooms I would notice that the phone books were always really thick. Like 4-5" thick. And sometimes, that was just the yellow pages, the white pages were an entirely different book, itself 3" at least. And they always had these awesome pictures on the front of the local skyline instead of the giant public domain "fingers do the walking" logo that would grace the phone book back home.
So consequently I made the connection early on in my mind that living in a huge city meant you were a success. And living in a huge city meant a huge phone book. Therefore, having a huge phone book in your home meant you were a success. A tenuous connection, but even then I had big dreams of moving to a "big city" later in life and one of these days I would have a big phone book in my house because hey, that's what big successful people living in big successful cities do.
Years and years pass. I grow up, go through High School, go to College, graduate, get married, and eventually my Wife and I move to the Dallas/Fort Worth Metroplex. We get good paying jobs and rent then eventually buy a house. Initially the phone books that would appear on our porch would be the same standard one-inch affairs I grew up with because we live in the suburbs and they only cover the suburbs, but then one day a bag with two phone books, a 3-inch white pages and a 5-inch yellow pages, shows up on our front porch. These phone books cover the entire Metroplex. They have amazing photos of the Dallas skyline, with Reunion Tower (the one with the ball on the end) on them (under a stuck-on ad for some ambulance chaser, but that peels off easily enough).
I'm elated. After all these years, I've finally made it! I'm finally in a good job making good money and living in a big city and hey, like all big successful people living in big cities, I have a pair of bigass phone books. I've arrived! Every time I look at these phone books I'll remember how I'm in a big city.
So I put these phone books next to the phone and the first thing my Wife says was "Just throw those things away. We have the Internet now."
I ignore the order and I keep the phone books under the phone cradle for a few years, exchanging them out when a new one comes in. I never tell my Wife the insanely silly "but I've always wanted a big phone book" fantasy because I'm not in the mood to get laughed at (though, apparently, I don't mind that people on Slashdot will laugh at me). I get to keep them in place with the razor thin "well what if we want to look up a phone number when the power's off or our Internet is down?" excuse.
But then one day I'm cleaning the house and I'm trying to reduce some clutter and it occurs to me that in two years I've never opened these things, ever, and they're just collecting dust and the odds of the power going out or the Internet going down at the same time as my cell phone battery dying and me having to have some obscure phone number are vanishingly small. Oh, and in the years since we moved out here we've switched to Vonage so we couldn't even use the phone in a power outage anyway. And I now have Internet access on my phone (hell my wife has a Treo) so if we needed to
Some weird choices there (Score:3, Informative)
How about: making wooden wheels, for cars or carts?
Drilling holes in stone with a hammer and a stardrill?
Repacking plumbing/steam gasket seals?
Installing/maintaining lead/oakum plumbing?
Relashing valve pushrods or regrinding valve seats with a file?
Filing threads?
Making nails with a hammer and a header?
Making wrought iron?
Making aluminum without electricity?
Forming lumber with a froe, an adze, and a two-man saw?
Tanning leather?
And some of the items, I just flat-out disagree with: making a fire by striking two pieces of flint together? That *doesn't work*. You strike a piece of steel against flint, which throws sparks because the steel is cut by the flint and showers off bits of hot steel. Flint doesn't burn.
Simplistic thinking in this list (Score:5, Insightful)
Even the summary contains a dubious suggestion, "Changing the gas mixture on your car's carburetor". Perhaps the author is unaware of the vast numbers of motorcycles and small engines sold each year that incorporate carburetors?
"Cast lead bullets"? Thousands, if not millions, of ammunition reloaders would disagree.
"Changing vacuum tubes"? Millions of musicians would disagree.
"Darkroom photography skills"? "Developing photographic film"? Obviously, this person is not a photographer!
That's as far as I can get without becoming even more disgusted with the state of humanity, or at least the supposedly tech-savvy people who probably are contributing to this list.
Using DEBUG to Start a Low-Level Format "g=c800:5" (Score:3, Interesting)
Cutting write enable notches in 5.25" floppies.
Drilling write enable holes in read only 3.5" floppies.
Replacing worn out switches in Amiga mice.
Building custom serial cables.
Re-ordering items in config.sys to optimize the amount of RAM free.
Monochrome VGA, with 704k free.
Watching terminal output to figure out serial speed, bits, parity, and stop bits.
Disabling screen I/O while using punter, to get that extra 5% of throughput.
Avoiding the zero subnet.
Working with non-CIDR subnet masks, or masks with zeros in them.
PC-NFS.
Deleting enough files on RSX, so that there was contiguous space to put system files on.
PIP on CP/M. Hiding files using a programmer number.
Generating Novell remote program loader files using diskettes.
EMS vs XMS debates. The Intel Above Board.
Locking up Hayes 1200B modems by hitting backspace.
Ripterm. Ymodem-G. QWK mailers. Whistling the modem tone to see if a modem was calling you.
Intentionally misspelling things on a BBS to avoid the profanity filter. (Warez, pron, fcuk, leet, a$$, sh1t, etc.)
Using high speed cassette copiers. Using Chrome tape.
Connecting daisychained peripherals. Connecting separate analog and control busses on hard drives.
Figuring out which drives were RLL capable.
GCM vs GCR.
Backing up data to VHS. Cofiguring multiport serial boards.
Fossil drivers.
The 5.25" hard disk.
Re:Shorthand is not redundant yet (Score:5, Funny)
Re:Shorthand is not redundant yet (Score:4, Funny)
Kinky!
Re:But what is going to be obsolete ? (Score:4, Informative)
Everything which is written in Java uses C.
Everything which is written in C uses Assembler.
Everything which is written in Assembler uses machine code.
And so on.
Re:But what is going to be obsolete ? (Score:5, Insightful)
In a nutshell, it doesn't matter what language you use, which language is the next big thing, or what language becomes obsolete tomorrow. You will probably not know all those fancy functions that do what you used to do by hand, but what matters is whether you know the math behind the code. I've seen so many people claiming to know Java, C# and whatnot, just to give me that incredibly blank stare when I ask them for hash tables. Yes, they know every function, every class in Java by heart, but they have no knowledge of what they should actually DO with it.
Now, it might not be a "necessity" tomorrow when there is a function that does it for you. But it is VERY easy to learn about a function (hell, look it up, it ain't like there's no online help file for it) while it is not so trivial to understand what it actually DOES.
So it does not matter what language will arise or what language becomes obsolete. What matters is that you know the theory behind the structures you're supposed to use. When you know that, you can understand what the functions and classes do. When you understand that, you can more efficiently and sensibly fill them. When you do that, your program will work with fewer bugs and fewer "why the fu.. doesn't that work now, it did last time" moments.
Don't learn languages. Learn theory!
Re: (Score:3, Insightful)
Re: (Score:3, Informative)
Have a good look around the car and you might notice the mono-motronic ecu, the catalytic converter, the fuel pump for the injection system. Take the air filter housing off and you'll spot the injector aswell...
Re: (Score:3, Funny)
Re: (Score:3, Informative) | http://slashdot.org/story/08/02/20/0429252/obsolete-technical-skills?sdsrc=nextbtmprev | CC-MAIN-2014-23 | refinedweb | 6,191 | 62.78 |
Log::Message::Structured::Stringify::Sprintf - Traditional style log lines
package MyLogEvent; use Moose; use namespace::autoclean; with 'Log::Message::Structured'; has [qw/ foo bar /] => ( is => 'ro', required => 1 ); # Note: you MUST compose these together and after defining your attributes! with 'Log::Message::Structured::Stringify::Sprintf' => { format_string => q{The value of foo is "%s" and the value of bar is "%s"}, attributes => [qw/ foo bar /], }, 'Log::Message::Structured'; ... elsewhere ... use aliased 'My::Log::Event'; $logger->log(Event->new( foo => "ONE MILLION", bar => "ONE BILLION" )); # Logs an object which will stringify to: The value of foo is "ONE MILLION" and the value of bar is "ONE BILLION".
Augments the
as_string method provided by Log::Message::Structured as a parameterised Moose role.
Array of attributes whos values will be interpolated into the format string.
This format string is fed to sprintf with the values from the attributes to produce the output.
Tomas Doran (t0m)
<bobtfish@bobtfish.net>. Damien Krotkine (dams)
<dams@cpan.org>.
Licensed under the same terms as perl itself. | https://metacpan.org/pod/Log::Message::Structured::Stringify::Sprintf | CC-MAIN-2014-23 | refinedweb | 168 | 63.8 |
I think its flash, not sure?
but the cold dead hand video: ... jim-carrey
How would you auto downjload via python?
I checked /tmp directory upon loading the video. But nothing is there?
youtube-dl is a small command-line program to download videos from YouTube.com and a few more sites. It requires the Python interpreter (2.6, 2.7, or 3.3+), and it is not platform specific. It should work in your Unix box, in Windows or in Mac OS X. It is released to the public domain, which means you can modify it, redistribute it or use it however you like.
import requests
r = requests.get("", stream=True)
with open('cold_dead_jim_carrey.mp4', 'wb') as handle:
for block in r.iter_content(1024):
if not block:
break
handle.write(block)
import requests
import re
def funny_id(url='url'):
'''Take video id from url'''
url_read = requests.get(url)
text = url_read.text
id_vid = re.search(r'''<source src="(.*)/v600.mp4" />''', text)
return id_vid.group(1)
def quality(choosen_quality, funny_id):
'''Choose quality and insert funny_id'''
vid_quality =\
{'low': '',
'med': '',
'high': ''}
adress = vid_quality[choosen_quality]
first = adress.partition('v/')[:2]
last = adress.partition('v/')[2:]
video_adress = '{}{}{}'.format(first[0]+first[1], funny_id, last[0])
return video_adress
def download(fin_url):
'''Download given url'''
req = requests.get(fin_url, stream=True)
with open('your_video.mp4', 'wb') as handle:
for block in req.iter_content(4096):
if not block:
break
handle.write(block)
if __name__ == '__main__':
# Paste in in url from funnyordie
url = ''
#Choose video quality you want(low, med, high)
video_quality = 'high'
#-----| Run it |-------
funny_id = funny_id(url)
fin_url = quality(video_quality, funny_id)
download(fin_url)
Return to General Coding Help
Users browsing this forum: No registered users and 3 guests | http://www.python-forum.org/viewtopic.php?p=2261 | CC-MAIN-2014-42 | refinedweb | 280 | 62.95 |
Hi, so this is part 2 of my security system/ chicken coop door monitor project. Right now I’m just focusing on the security system part. I’m having difficulty displaying the password as its being typed. I definitely think it has something to do with the int Position = 0. What I want to do is have the password displayed as ***** on the LCD. The way I think I can do this is by increasing the values of Position by 1 each time a button is pressed. I don’t think I implemented the Position part right (I probably messed up the password part too) and I’d really appreciate some help! If you have any questions about my code I’d be happy to clarify!
#include <Password.h> #include <LiquidCrystal.h> #include <Keypad.h> Password password = Password( "1234" ); const byte ROWS = 4; const byte COLS = 4; char keys[ROWS][COLS] = { {'1', '2', '3'}, {'4', '5', '6'}, {'7', '8', '9'}, {'*', '0', '#'} }; byte rowPins[ROWS] = {3, 5, 6, 7}; byte colPins[COLS] = {8, 9, 10}; Keypad myKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); LiquidCrystal lcd(A0, A1, A2, A3, A4, A5); void setup() { lcd.begin(16, 2); MainMenu(); Serial.begin(9600); } void loop() { char myKey = myKeypad.getKey(); Serial.print("Pressed: "); Serial.println(myKey); if (myKey == '#') { lcd.clear(); lcd.setCursor(0, 0); lcd.print(" Enter Password"); int Position = 0; if (myKey == '0' || myKey == '1' || myKey == '2' || myKey == '3' || myKey == '4' || myKey == '5' || myKey == '6' || myKey == '7' || myKey == '8' || myKey == '9' ) { lcd.setCursor(Position, 1); lcd.print('*'); ++Position; } if (Position == 5) { checkPassword(); password.append(myKey); } } } void checkPassword() { if (password.evaluate()) { Serial.println("Success"); } else { Serial.println("Wrong"); password.reset(); } } void MainMenu () { lcd.setCursor(0, 0); lcd.print("* for Coop"); lcd.setCursor(0, 1); lcd.print("# for Security"); } | https://forum.arduino.cc/t/password-library-and-creating-a-variable-integer/522385 | CC-MAIN-2021-25 | refinedweb | 295 | 61.33 |
You can subscribe to this list here.
Showing
4
results of 4
On Fri, Apr 21, 2006 at 11:17:58PM +0400, Oleg Broytmann wrote:
> DB PAI driver
DB API
Oleg.
--
Oleg Broytmann phd@...
Programmers don't die, they just GOSUB without RETURN.
On Fri, Apr 21, 2006 at 11:34:57AM -0600, Gabe Rudy wrote:
> from sqlobject.sqlbuilder import *
> Contact._connection.sqlrepr(
> Select( StrCat(Contact.q.lastName, ",", Contact.q.firstName) ) )
>
> Does this sound like a reasonable feature request?
It does. The name could be CONCAT() or CONCATENATION(). Please don't
forget about tests and documentation.
> A reasonable concern would be if the majority of suppored
> databases have some syntax to deal with this
Postgres and SQLite have || operator, MySQL has CONCAT() function (||
operator in MySQL means boolean OR).
> what would happen if they
> didn't (exception raised? do it in python?).
A backend reports an error, DB PAI driver rasies an exception, and you
can ignore this for now.
Oleg.
--
Oleg Broytmann phd@...
Programmers don't die, they just GOSUB without RETURN.
Hey guys,
SQLBuilder is working great for my optimized queries and table displays, one
thing I think would be cool is if it could also provide some simple string
operators for queries.
I think that concatenation would be particularly usefull, but it may not be
standardized in the SQL specs, at least it appears to be implemented
differently in different databases, but that's what SQLBuilder is for eh? I
know at least postgres and sqlite use || for the operator.
I would like to generate a query such as
"select last_name || ', ' || first_name from contact"
(I actually care about doing more complex queries involving data from multiple
tables, but for simplicity this is the idea)
One possible syntax could be:
from sqlobject.sqlbuilder import *
Contact._connection.sqlrepr(
Select( StrCat(Contact.q.lastName, ",", Contact.q.firstName) ) )
Does this sound like a reasonable feature request? I'd help with the coding if
it was cleared. A reasonable concern would be if the majority of suppored
databases have some syntax to deal with this and what would happen if they
didn't (exception raised? do it in python?).
Cheers,
--gabe
Greetings,
I'm looking into building a tree structure using SQLObject. Prior to
using SQLObject, I was using a modified preorder tree structure. I'd
like to continue this approach, and have found several posts from
others on this list who took that path as well. One approach appears
to be wrapped into the Alinea project
().
Another approach was proposed by Ben Bangert
().
I'm trying to compare the two approaches (in an attempt to not
reinvent the wheel). However, pastebin seems to have long since
dropped any references to 372150 and I can't find it cached anywhere.
Does anyone have a pointer to that sample code?
Many thanks,
James
> On Sep 23, 2005, at 11:14 AM, Philippe Normand wrote:
>
> > I also read the link you gave above (sitepoint), and cooked up a class
> > to implement a Modified Preorder tree structure, see:
> >
> >
> >
> >
> > Actually the code is not (that) specific to Alinea and could be reused
> > by others ...
> >
> > Please close your eyes and don't read the code of "moveTo" method,
> > it's
> > really ugly ;( In fact moving nodes in such a tree structure is not
> > trivial, if you have a smart solution let me see :)
>
> I'm still putting together unit tests to ensure it works, but I do
> have a appendChild (move) function that does significantly less
> queries than your version to move a node that contains children to
> have a new parent node. I have no idea how long pastebin.com history
> lasts, so better look sooner than later:
>
>
>
> Thats my code to deal with the Modified Preorder tree. In my limited
> interactive testing, it is moving and closing gaps properly in the
> few dozen cases I've manually tested.
>
> As there's no quick way to reliably remove the cache for all objects
> in the class (is there?), the table inheriting from it should have
> cacheValues set to False. Enhancements to that code are very
> appreciated. :)
> | http://sourceforge.net/p/sqlobject/mailman/sqlobject-discuss/?viewmonth=200604&style=flat&viewday=21 | CC-MAIN-2016-07 | refinedweb | 680 | 64.41 |
sqmpy v1.0.0-alpha.3
Simple Queue Manager, also sqmpy, is a web interface for submitting jobs to HPC resources.
sqmpy stands for simple queue manager written in python and is a web application which is based on Flask miroframework and SAGA-Python distributed computing access layer. Sqmpy lets user to submit simple python or shell scripts on remote machines. Then user can monitor the running job in job detail page. The notification system will send emails after status changes to the user. Moreover sqmpy lets user to have a history of previous jobs and all files related to those jobs.
Dependencies
Sqmpy has a few dependencies which will be installed while installing with python setup or pip:
- SAGA-python
- Flask
- Flask-SQLAlchemy
- Flask-Login
- Flask-WTF
- Flask-Admin
- Flask-CSRF
- enum34
- py-bcrypt
Installation
I suggest to install a virtaul environment to try sqmpy or if you want to run it on your local machine. If you have virtual-env installed then:
$ virtual-env --no-site-packages sqmpy-env $ . sqmpy-env/bin/activate
If you don’t have virutal-env on your machine then try to download it. Please be aware that this is outdated since new versions of virtualenv do not download and install pip and setuptools for security reasons:
$ wget $ python virtualenv.py --no-site-packages sqmpy-env $ . sqmpy-env/bin/activate
To install sqmpy from pypi:
$ pip install sqmpy
To install from git:
$ git clone git://github.com/mehdix/simple-queue-manager.git $ cd simple-queue-manager $ python setup install
Configuration
There are a few settings which sqmpy can read from a configuration file. There is a default_config python module in sqmpy package that contains default configuration values. The same configurations can be read from a user defined config file via SQMPY_CONFIG environment variable:
$ export SQMPY_CONFIG = /path/to/config/file/config.py $ python run.py
Run With No Configuration
In this case sqmpy will user in-memory sqlite db, logging to stdout, and a temp folder for staging files. State will lost after restarting the application.
Using Sqmpy
Sqmpy is a flask web application therefor it runs like any other flask applications. Put the following code in apython file called run.py and run it:
from sqmpy import app app.run('0.0.0.0', port=5001, debug=True)
About Files and Folders, Local or Remote
Sqmpy will create a sqmpy.log and sqmpy.db and a staging folder called staging. The path to these files are being read from config values: LOG_FILE, SQLALCHEMY_DATABASE_URI and STAGING_FOLDER. Staginf folder will contain uploaded files and script files created by sqmpy. Moreover on remote machiens Sqmpy will create another folder called sqmpy in user home directory and will upload files there before running tasks. For each job one folder will be created and will be set as job working directory. This folder will contain input and output files as well as script file and any other files being produced or consumed by the remote job.
- Downloads (All Versions):
- 6 downloads in the last day
- 17 downloads in the last week
- 18 downloads in the last month
- Author: Mehdi Sadeghi
- License: BSD
- Categories
- Package Index Owner: mehdix
- DOAP record: sqmpy-v1.0.0-alpha.3.xml | https://pypi.python.org/pypi/sqmpy/v1.0.0-alpha.3 | CC-MAIN-2015-11 | refinedweb | 537 | 55.34 |
Phil,
I'll get around to looking at this in a few hours time.
Thanks for the input,
-John K
On Thu, 2002-10-17 at 17:44, Phil Surette wrote:
> Thanks everyone for getting the nightly build going
> for cli. Talk about responsive!
>
> I'm trying the package out right now, very nice
> (though it requires a bit of play to figure out
> how to do things).
>
> I ran into a bug when trying to use the HelpFormatter
> which excercises Option.hasArgName. Here's my patch
> for it.
>
> /org/apache/commons/cli/Option.java
> ***************
> *** 395,401 ****
> * set.
> */
> public boolean hasArgName() {
> ! return (this.argName != null || this.argName.length() > 0 );
> }
>
> /**
> --- 395,407 ----
> * set.
> */
> public boolean hasArgName() {
> ! if (argName == null) {
> ! return false;
> ! }
> ! else {
> ! return argName.length() > 0;
> ! }
> ! //return (this.argName != null || this.argName.length() > 0 );
> }
>
> /**
--
John Keyes <jbjk@mac.com>
--
To unsubscribe, e-mail: <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org> | http://mail-archives.apache.org/mod_mbox/commons-dev/200210.mbox/%3C1034874260.1343.27.camel@oasis.capeclear.ie%3E | CC-MAIN-2014-52 | refinedweb | 161 | 62.44 |
Deploying Gatsby
Tutorials for deploying on different static site hostsTutorials for deploying on different static site hosts
NetlifyNetlify
Netlify is an excellent option for deploying Gatsby sites. Netlify is a unified platform that automates your code to create high.
Deploying to NetlifyDeploying to Netlify
To deploy your Gatsby site to Netlify, go to the create a new site page, select your project repo from GitHub, GitLab, or Bitbucket, and follow the prompts.
Amazon S3 and CloudfrontAmazon S3 and Cloudfront
If you decide to host your Gatsby site on S3 with Cloudfront as CDN, you should change the “Origin Domain Name” on the Cloudfront panel with the real URL of your S3 bucket: examplewebsite.com.s3-website-eu-west-1.amazonaws.com replacing the default URL suggested by Amazon examplewebsite.com.s3.amazonaws.com.
Without this change, S3 doesn’t look for index.html files when serving “clean urls”.
GitHub PagesGitHub Pages
Deploying a project pageDeploying a project page
You can deploy sites on GitHub Pages with or without a custom domain. If you choose to use the default setup (without a custom domain), or if you create a project site, you will need to setup your site with path prefixing.
On Github, you get one site per GitHub account and organization, and unlimited project sites. So it is most likely you will be creating a project site. If you do not have an existing repository on Github that you plan to use, take the time now to create a new repository on Github.
Use the NPM package
gh-pages for deploying
First add gh-pages as a
devDependency of your site and create an npm
script to deploy your project by running
npm install gh-pages --save-dev
or
yarn add gh-pages --dev (if you have yarn installed).
Then add a
deploy script in your
package.json file.
"scripts": { "deploy": "gatsby build --prefix-paths && gh-pages -d public", }
In the
gatsby-config.js, set the
pathPrefix to be added to your site’s link
paths. The
pathPrefix should be the project name in your repository. (ex. - your
pathPrefix should be
/project-name). See
the docs page on path prefixing for more.
module.exports = { pathPrefix: `/project-name`, }
If you have not yet initialized a git repository in your working gatsby site
repo, set up git in your project with
git init. Then tell Gatsby where to
deploy your site by adding the git remote address with https or ssh. Here is how
to do it with https:
git remote add origin git@github.com:username/project-name.git.
Now run
yarn deploy or
npm run deploy. Preview changes in your GitHub page. You can also find the link to your
site on GitHub under
Settings >
GitHub Pages.
Deploying a user/organization siteDeploying a user/organization site
Unlike project pages, user/organization sites on GitHub live in a special
repository dedicated to files for the site. The sites must be published from the
master branch of the repository which means the site source files should be
kept in a branch named
source or something similar. We also don’t need to
prefix links like we do with project sites.
The repository for these sites requires a special name. See for documentation on naming your site’s repository.
If you wish to link your custom domain with your
user.github.io repo, you will need
a
CNAME file inside the
static folder at the root directory level with the your
custom domain url inside, like so:
your-custom-domain.com
Gitlab PagesGitlab Pages
Gitlab Pages are similar to GitHub pages, perhaps even easier to setup. It also supports custom domain names and SSL certificates. The process of setting GitLab pages up is made a lot easier with GitLab’s included continuous integration platform.
Create a new GitLab repository, initialize your Gatsby project folder if you haven’t already, and add the GitLab remote.
git init git remote add origin git@gitlab.com:examplerepository git add . git push -u origin master.
Path PrefixPath Prefix.
module.exports = { pathPrefix: `/examplerepository`, }
Build and deploy with Gitlab CIBuild and deploy with Gitlab CI
To use GitLab’s continuous integration (CI), you need to add a
.gitlab-ci.yml
configuration file. This can be added into your project folder, or once you have
pushed the repository, you can add it with GitLab’s website. The file needs to
contain a few required fields:
image: node:latest # This folder is cached between builds # cache: paths: - node_modules/ pages: script: - yarn install - ./node_modules/.bin/gatsby build --prefix-paths artifacts: paths: - public only: - master
The CI platform uses Docker images/containers, so
image: node:latest tells the
CI to use the latest node image.
cache: caches the
node_modules folder
in between builds, so subsequent builds should be a lot faster as it doesn’t have
to reinstall all the dependancies. We have used the
yarn install and
./node_modules/.bin/gatsby build --prefix-paths which will install all dependancies, and
start the static site build, respectively.
We have used
./node_modules/.bin/gatsby build --prefix-paths because we then don’t have to install
gatsby-cli to build the image, as it has already been included and installed
with
yarn install. We have included
--prefix-paths as when running the command have a repository under your namespace, the url will be yourname.gitlab.io/examplerepository.
Visit the GitLab Pages to learn how to setup custom domains and find out about advanced configurations.
HerokuHeroku
You can use the heroku buildpack static to handle the static files of your site.
Set the
heroku/node.js and
heroku-buildpack-static buildpacks on your application creating an
app.json file on the root of your project.
{ "buildpacks": [ { "url": "heroku/nodejs" }, { "url": "" } ] }
Sometimes specifying buildpacks via the
app.json file doesn’t work. If this is your case try to add them in the Heroku dashboard or via the CLI.
Add a
heroku-postbuild script in your
package.json:
{ // ... "scripts": { // ... "heroku-postbuild": "gatsby build" // ... } // ... }
Finally, add a
static.json file in the root of your project to define the directory where your static assets will be. You can check all the options for this file in the heroku-buildpack-static configuration.
{ "root": "public/" }
Debugging tipsDebugging tips
Don’t minify HTMLDon’t minify HTML
If you see the following error:
Unable to find element with ID ##
or alternatively
Uncaught Error: Minified React error #32; visit[]=## for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
This is a new problem when dealing with static sites built with React. This is not caused by Gatsby. React uses HTML comments to help identify locations of components that do not render anything. If you are using a CDN that minifies your HTML, it will eliminate the HTML comments used by React to take control of the page on the client. Cloudflare is a CDN that minifies HTML by default. | https://www.gatsbyjs.org/docs/deploy-gatsby/ | CC-MAIN-2018-05 | refinedweb | 1,154 | 56.05 |
A proposed hardware-based method for stopping known memory corruption exploitation techniques. #nsacyber
This project captures research to effectively fix the lack of underlying control flow enforcement that would prevent memory corruption exploitation. This mechanism does not exist today but could be implemented in the future by the IT industry.
This paper is a brief introduction to the problem of memory corruption and a description of one way to prevent control flow hijacking. It also includes a discussion on the issues that may be encountered in the IT ecosystem when an architectural change like this is introduced.
Additionally, Intel recently disclosed an x86 instruction specification called Control-flow Enforcement Technology (CET) that closely resembles Landhere.
Questions or comments can be sent to [email protected] or submitted to our GitHub issue tracker.
The code folder has examples of software that would leverage the hardware described in the paper. It is hoped that researchers can learn more about the effect and strength of the proposal by reverse engineering and performing static analysis on them. Perhaps demonstrate a way to bypass the mitigation and report via mechanisms described above. The files are:
These simple examples should allow one to explore the impact of the CFI countermeasure in a process address space. The binaries should run on any x86 Linux machine. The opcodes will work as NOP's. The landing point opcodes are as follows:
The binaries contain no fine grained label checks. They only have a corresponding Landing Point instruction to any indirect branch as a label, which is coarse grained. If other binaries are desired, we can produce them, if source is provided.
One can extract the gadgets (as defined on line 271/2 in the paper) from the binaries and attempt to chain them together. Note: RLP gadgets are of no semantic use due to the (imaginary) shadow stack. So gadget chains can only contain CLP and JLP based gadgets. To test validity of a claim, one can use gdb to "run" a gadget chain. First one can manually change the memory as an exploit might do by setting a breakpoint at the appropriate place and performing the overwrite(s). Then continue using single stepping. As a substitute for the HW enforcement, whenever an indirect branch occurs one can visually validate it lands on a landing point. If it reaches the goal (e.g. exec("Your string")) without crashing the application, you win and this form of CFI loses. There is no secret right answer.
We believe it's not possible or extremely unreliable to bypass the minimal CFI design (line 116 in the paper) with these code samples (and others like them). Unfortunately, this is the best dynamic tool we can offer for now to allow independent validation.
Galois has taken the time and effort to implement a full Linux build of Landhere+ShadowStack concept. This includes instrumented binaries and a VM to create Landhere binaries on one's own. See for more information. Also at the Galois site is a fully instrumented landing point Linux file system that we have used as an exemplar for gadget analysis.
As a convenience, we have extracted all gadgets from the Galois file system and made them available as an attachment to a release. The resulting gadgets are 50 instructions or less and contain 5 or less pre-conditions (e.g. conditional branches).
A gadget is effectively a trace as it would happen if certain conditions were true. Each gadget is represented as a textual assembly listing. There can be multiple traces from a single landing point. If there's a gadget with an indirect function in the middle, that branch is treated as a stub and the trace falls through to the subsequent instruction, an RLP. Gadgets can have nested function calls/flows.
The tarball contains two main subdirectories, exes and libs which reflect the executables and libraries from the Galois set. Each executable is further broken down into raw and filtered. The files in the raw folder contain all possible gadgets. The files in the filtered folder are de-duped (logical and binary) and are labeled for their chaining purpose (return, link, prestitch, poststitch, dispatch loop, atomic).
Return is a gadget that "returns", typically it's a real function. It's intended to be used with the dispatch loop but can also be substituted for a call*.
Dispatch loop is a quasi gadget that is used to chain multiple return gadgets (i.e. "functions").
Link is a forward flowing gadget that does not return (gadget block exit is either a call* or jmp*).
Pre and post stitch gadgets are a sub-genre of link gadgets that can be combined if the stack pointer change is neutral to the shadow stack.
Atomic is the minimal size gadget for a particular free branch. Namely it is the flow from closest preceding landing point. There may be several Atomic gadgets that flow to the same free branch given any pre-conditions. However, because the maximum size is up to 50 instructions, a gadget might also flow through multiple landing points before encountering a free branch. These nested gadgets are included (but aren’t labeled as atomic) to illustrate side effects that might, or might not, be useful since one is not restricted to branching to the nearest landing point from a free branch. Atomic serves to bound the smallest theoretical flows.
See DISCLAIMER. | https://xscode.com/nsacyber/Control-Flow-Integrity | CC-MAIN-2021-10 | refinedweb | 899 | 54.93 |
Uncyclopedia:Votes for deletion/archive14
From Uncyclopedia, the content-free encyclopedia
Pledges
Delete I just can't see anyone ever laughing at this. It's just not funny.--Kafeithekeaton 17:25, 22 Oct 2005 (UTC)
- Yeah, neither can I, cause it's hard to laugh at an article that doesn't exist, OMGWTFPWNEDROTFLMAO!!!!11oneone --Spintherism 17:36, 22 Oct 2005 (UTC)
- This sort of stuff can go to QVFD, by the way. --Spintherism 17:39, 22 Oct 2005 (UTC)
Boig jerk and Adam Taylor
It is just vanity. Looks like the author is trying to insult a friend. Mosquitopsu 17:22, 22 Oct 2005 (UTC)
- Deleted. --Spintherism 17:27, 22 Oct 2005 (UTC)
Dump truck mode
Delete Seems the author just tried to link to an outside picture, then ignored it.--Kafeithekeaton 17:20, 22 Oct 2005 (UTC)
Making up Bob Dole quotes
Delete Hey hey, ho ho, Making up Bob Dole quotes has got to go! It's boring, unfunny, overly political, and whoever wrote it doesn't know anything about formatting. And it's not as if I'm being political by calilng for it's deletion. It's just a crappy page. Also, FYI: I'm a big fan of making up quotes in general. (I'm trying to popularize HowTo:Make up quotes - check it out!) It's just that this particular page sucks. This is the first time I've ever submitted a page for deletion in any wiki ever ... wow ... If anybody wants to reformat it and try to think of something really really funny to say and save it, fine by me. Go for it! I'd prefer that happen. But otherwise, it's NUKE TIME! Nerd42 23:46, 21 Oct 2005 (UTC)
- Already been deleted 3 times. The stupid thing just keeps growing back!
» Brig Sir Dawg | t | v | c » 00:00, 22 Oct 2005 (UTC)
- Would you prefer I did not link to it from HowTo:Make up quotes? I was just doing it sort of in the interests of fairness ... even though I wanted the page deleted ... isn't there some kinda tag you admins can add that locks the page down so people can't edit it? I've seen that done on wikipedia ... Nerd42 00:07, 22 Oct 2005 (UTC)
Vista
Biased, mostly unfunny. Copied the only redeemable paragraph to Windows Vista. - Guest 13:24, 21 Oct 2005 (UTC)
Dog City
Yes, I'm obnoxious, I know, but if there was a point to this article, or humour involved, then it went right over my head. Also, everything else edited by the same guy seems to be one-line unfunny stuff. --Malleus 09:10, 21 Oct 2005 (UTC)
I found these while looking through the uncategorised articles section, and couldn't find any redeeming features. Am I the only one who thinks articles like these should be shot repeatedly? If they had physical bodies, anyway. --Malleus 03:25, 21 Oct 2005 (UTC)
Money saving tips
Copied from [1] as listed on article. 205.188.117.69 02:11, 21 Oct 2005 (UTC)
Hendrix and Jimmmi Hendrikz
The first one seemed pointless and generally not funny, while the second one had no redeeming features that I could find. Oh yeah, I have no idea what the first one has to do with planets... --Malleus 23:22, 20 Oct 2005 (UTC)
Kellogg, Brown, & Root
This seemed to me to be completely pointless. The reference to Neocon doesn't seem to have any actual meaning, and I couldn't really make any connection between this and the reference to it in the article for Dick "Robot" Cheney. --Malleus 09:56, 20 Oct 2005 (UTC)
Johann Gutenberg
Yeah, it's me again. This one isn't funny in any way, is random, and as far as I can tell screws around with continuity. --Malleus 01:55, 20 Oct 2005 (UTC)
Vibhu
This is complete and utter spam. It's not funny at all. Delete please. --71.137.21.38 18:35, 19 Oct 2005 (PST)
Rigondas Gang
I'm still new, but I saw this and thought that it should be put here. It's pointless, not funny, and neither are the others that are linked to it. It also had a badly written sentence referring to it in the Latvia entry. If I'm wrong about this, please point it out. --Malleus 00:53, 20 Oct 2005 (UTC)
- You know what? I don't like it either. Consider it burninated. --
» Brig Sir Dawg | t | v | c » 01:19, 20 Oct 2005 (UTC)
Rasputin
This article is pointless randomness. And the P section (added Aug 29) is really stupid. --Ogopogo 23:04, 19 Oct 2005 (UTC)
- The admins (actually, an admin, but we seem more godlike the other way) took pity on this article and made it better. Tell us what you think. --
» Brig Sir Dawg | t | v | c » 00:04, 20 Oct 2005 (UTC)
- Not really very much better though.
- I'll stub it.
I must say that the re-write is a lot better than before (and is already a lot better than many articles on uncyclopedia), though needs work of course. This re-write will give others a chance to work from that. Thanks. By the way, I just finished doing a Lorena Bobbit type of edit to free a certain part of the old article from its misery. --Ogopogo 01:45, 20 Oct 2005 (UTC)
I actually sort of liked the whole "His Story, His Death, His Penis" thing that was going on with the headings. --Spintherism 04:59, 20 Oct 2005 (UTC)
MorphOS
Another copyvio directly from the MorphOS Home Page at [2] 70.88.222.85 22:00, 19 Oct 2005 (UTC)
Sophie Mohammad Augusta Ali Frederickqxa
Please delete this too. It's a pointless redirection to the now-huffed Catherine the Great article. Thanks. --Ogopogo 06:50, 19 Oct 2005 (UTC)
Undictionary:Catherine the Great
I also recommend Undictionary:Catherine the Great, another pointless random-humour ditty, for removal. --Ogopogo 04:49, 19 Oct 2005 (UTC)
- DELETE - Between the fact it's nearly impossible to read and may contain outright facts, it should eat it. I'm tired of the random junk, too. -- --
» Brig Sir Dawg | t | v | c » 06:35, 19 Oct 2005 (UTC)
Pierre Eliot Trudeau [sic]
I recommend Pierre Eliot Trudeau, a pointless random-humour ditty, for removal.
(Note it's not to be confused with the Pierre Trudeau article on the famous Canadian politican who died a few years ago in his 80s or the Pierre Elliott Trudeau redirect, both of which should be kept, of course.) --Ogopogo 04:49, 19 Oct 2005 (UTC)
- Mercilessly Huffed under Forest Fire Week rules. Wasn't even UD worthy. -- --
» Brig Sir Dawg | t | v | c » 06:38, 19 Oct 2005 (UTC)
Max Headroom
Bad. --Spintherism 05:32, 18 Oct 2005 (UTC)
Bad meaning Good, like Michael Jackson. Hell Yeah. --11011 05:45, 18 Oct 2005 (UTC)
- Against Deletion - May ramble, but it could certainly go somewhere. ----
» Brig Sir Dawg | t | v | c » 07:21, 18 Oct 2005 (UTC)
- Actually, now that I look at it again, there's definitely some potential. --Spintherism 18:28, 18 Oct 2005 (UTC)
Rewrite There's a few good lines, but I think it needs to be better. --Sir AlexMW KUN PS FIYC 22:59, 18 Oct 2005 (UTC)
Conquer online
Also bad. --Spintherism 05:34, 18 Oct 2005 (UTC)
Tanner Hux
Non-notable person, just looks like slandanity, vanity, or harassment. Woulda QVFDed except it is a registered user, so giving benifit of the doubt. --Splaka 01:29, 18 Oct 2005 (UTC)
- Heh, already deleted, but you forgot Image:Tanner.jpg --Splaka 03:51, 18 Oct 2005 (UTC)
Disprocess
Advertisement for some silly washed-up band. --
» Brig Sir Dawg | t | v | c » 10:29, 17 Oct 2005 (UTC)
Antiwikipedia
external link page, stubby, little potential for a good article --Paulgb Talk 18:17, 16 Oct 2005 (UTC)
- i don't know what that page used to say ... but I've made a better related page: Aidepolcycnu its much better ... but could be longer and funnier i'm sure. edits please! Nerd42 23:50, 21 Oct 2005 (UTC)
Somethingawful.com
Unfunny history of SA.com, wtf is it doing here? --Caiman 15:26, 16 Oct 2005 (UTC)
Deleted - wikipedia cut and paste --Paulgb Talk 18:22, 16 Oct 2005 (UTC)
iliveinyourbathroom
Pointless and unfunny.Needs a delete or a total overhaul. It even says in the article "Im wasting valuble, payed for space on a server! Im also wasting the time of whoever is reading this! Yes! You! Right now, as you read this, you're older than youve ever been. And now you're even older. And now you're even older. And now you're older still".(Foo21 03:02, 16 Oct 2005 (UTC))
- HEY, They said it would be left alone aslong as I put a "work in progress" note up. Its there. Lemme alone. Jack Cain 03:29, 16 Oct 2005 (UTC)
- If you really think you will keep working on it, Move it to User:Jack Cain/iliveinyourbathroom if it really is your "personal" experiment. Wikis are for everyone to edit it, personal stuff goes in user namespaces.(Foo21 18:57, 16 Oct 2005 (UTC))
DeltacoDa cheated. This type of crap should be put on QVFD. Exterminate without mercy. - Guest 07:17, 16 Oct 2005 (UTC)
The X-rated journals of Private Seth Parts of the 69th sperm airborne, and Major Edna Melons the undercover egg, depicting the bloody, gory, and intensely violent war against the Gonorrhean army led by some infamous French guy named General Genitalia
Great Scott!!! - Guest 16:56, 14 Oct 2005 (UTC)
- Keep Utter insanity --The Right Honourable Maj Sir Elvis UmP KUN FIC MDA VFH Bur. CM and bars UGM F@H (Petition) 07:45, 16 Oct 2005 (UTC)
- Keep Although someone needs to edit it, I want funny stuff, not walls of text! -- Nintendorulez 19:01, 16 Oct 2005 (UTC)
- Lick It could use some polish, but it's better than the average MTU/QVFD fodder. ----
» Brig Sir Dawg | t | v | c » 07:22, 18 Oct 2005 (UTC)
Keep--Spintherism 18:30, 18 Oct 2005 (UTC)
Keep and Expand the title --Nytrospawn 22:54, 18 Oct 2005 (UTC)
Change my vote to that The title's not long enough! --Nintendorulez 10:57, 21 Oct 2005 (UTC)
Not Smarts
This article is... not smart. And pretty fricking lame. --MonkeyGem 21:22, 13 Oct 2005 (UTC)
Del-eat --Splaka 21:44, 13 Oct 2005 (UTC)
Not Keep --Spintherism 05:49, 14 Oct 2005 (UTC)
It should be titled Not Funnies --Josie v. 3.1
Door C - Howard Nosliw - The Underlying False Facts of Existance - Mr. M. Thew
See user's contributions for (possibly) more pages worthy of closer scrutiny. Drivel, all of it. And this person likes to make news and anniversaries out of this Door C crap. The above four seem to be the biggies. --Bouahat 17:04, 11 Oct 2005 (UTC)
I vaguely went "huh, shaped a bit like a joke." Shove it all in Door C and redirect the rest to discourage recreation - David Gerard 23:39, 11 Oct 2005 (UTC)
Come on... haven't you ever wanted a pet to play with... such is the case with Door C. You just can't comprehend the joke in it's entirety. If you actually read it, then you might understand.
- I read it... it's just not funny at all. Funny material has at least something to do with the real world. Funny material takes reality and gives it a verbal wedgie. Door C is just random sentences. Maybe you could explain the brilliant social commentary or literary technique behind it. I'm not holding my breath. --Bouahat 05:56, 14 Oct 2005 (UTC)
I don't really see any reason to delete this. It's pretty funny when you think about it all. And I just love the stuff on those two guys. EH, I say keep Door C! --Kfc21
Delete Considering the ephemeral nature of the alleged Door C, it's fitting that the article on it be equally short-lived. --Spintherism 04:38, 13 Oct 2005 (UTC)
Not fair what has Door C ever done to you?
May as well keep it's existance is certainly not stopping the creation of the much funnier Door C article.--The Right Honourable Maj Sir Elvis UmP KUN FIC MDA VFH Bur. CM and bars UGM F@H (Petition) 12:08, 14 Oct 2005 (UTC)
Sequel to Truth & Simon Cowell
Delete both. Probably QVFD material, but methinks the submitter should be publicly flogged for this tripe. --DWIII 16:09, 11 Oct 2005 (UTC)
what the fuck is QVFD? i'll vote for my own fucking deletions. fucking fucktards. I agree that it was stupid, but i still hate you. --gostbait 23:15, 11 Oct 2005
- Is that a "Keep," then? --—rc (t) 05:28, 12 Oct 2005 (UTC)
- Folks, we have a winna for a Darwin Award for worst deleted articles and snotty attitude of the writer, I think the articles sort of deleted themselves, know what I mean? --Orion Blastar 00:45, 14 Oct 2005 (UTC)
uh-uh. kill it. --- User:Gostybaity
Your wish is my command. --Spintherism 04:59, 13 Oct 2005 (UTC)
Spearman melton
Non-notable, seems to be slander. --
Sir Famine, Gun ♣ Petition » 19:41, 9 Oct 2005 (UTC)
- delete -- ComaVN 07:43, 13 Oct 2005 (UTC)
- Keep No worse (and in fact slightly better than) most of the others in Category:Teachers who let their students visit Uncyclopedia during class--The Right Honourable Maj Sir Elvis UmP KUN FIC MDA VFH Bur. CM and bars UGM F@H (Petition) 12:11, 14 Oct 2005 (UTC)
Phill11
Non-notable, seems to be slander. --
Sir Famine, Gun ♣ Petition » 19:41, 9 Oct 2005 (UTC)
Delete--Spintherism 05:02, 13 Oct 2005 (UTC)
Delete--ComaVN 07:43, 13 Oct 2005 (UTC)
Jack Van Impe.
retarded redirect includes period. I'm new, so I wasn't sure if this is the place to list redirects. if not, lemme know. thankz, Poopface Mcwilliamstein 19:00, 8 Oct 2005 (UTC)
Fadoogle
Short page, seems to be vanity. --
Sir Famine, Gun ♣ Petition » 17:08, 8 Oct 2005 (UTC)
Micah Carlson
Pure vanity as far as I can tell. Seems to be one editor, although split between logged in and anon-IP. Non-notable. --
Sir Famine, Gun ♣ Petition » 16:37, 8 Oct 2005 (UTC)
Delete Whatever happened to the good old days of voting to keep things? Have the articles gotten worse, or am I just more of an asshole? --Spintherism 05:10, 13 Oct 2005 (UTC)
Bushhole
It's funny because it kind of sounds like the word "asshole", but instead it has the name of President George W. Bush where "ass" should be. Delete --EvilZak 05:54, 8 Oct 2005 (UTC)
Deletezor, these pathetic anti-bush jokes are given us real lefties a bad name. --User:Jordon:Jordon Sometime in October 2005
Delete Yeah, well I gave your mom a bad name last night. --Spintherism 05:03, 13 Oct 2005 (UTC)
More bushbashing please till it registers with the brainwashed voters...Wolf
Delete because we cannot let those Liberal Terrorists win. --Orion Blastar 00:47, 14 Oct 2005 (UTC)
James Allemann
Part of a set of other shitty articles that I deleted. This one seems to be the ring leader it has more mass. --Spintherism 01:14, 8 Oct 2005 (UTC)
Gwillinbury
This article, along with eets leetle friinds below, appears to be a whole set of vanity articles about the local water polo (!) team. I originally submitted them to QVFD because I'm a heartless killing machine, but my gun jammed so I'll submit them for
execution discussion here.
- Oops. In my haste to put out the hit, I neglected the obligatory horse-head-in-the-bed. I've now added {{vfd}} tags. Sorry. --
SirBobBobBob ! S? [rox!|sux!]
17:25, 7 Oct 2005 (UTC)
- Gwillinbury
- East Gwillinbury
- Gwillinbury Body of Water of Which is Just Large Enough to be Significant
- Wilmington Community Center
- The War That Nobody Decided to Hire a Title Selector for
- They also created/modified Two Day War, but it may be good for a small laugh
- TWWPCootU redirect to Water polo, but useless if the rest are huffed
“Kill them all, I say, and let God sort them out.”--
"Kill the foo' !" - Mr. T on Gwillinbury
- Keep Looks like someone trying to make up a history along the lines of Disney, etal (although obviousely it's a bit small ATM--The Right Honourable Maj Sir Elvis UmP KUN FIC MDA VFH Bur. CM and bars UGM F@H (Petition) 22:29, 5 Oct 2005 (UTC)
Balto
It says "Please finish this article." I'm tempted to do so, but the author and I probably have a different sense of the word "finish" in mind.--Spintherism 05:36, 5 Oct 2005 (UTC)
- Finish or Delete--The Right Honourable Maj Sir Elvis UmP KUN FIC MDA VFH Bur. CM and bars UGM F@H (Petition) 22:37, 5 Oct 2005 (UTC)
- I think this quote from the author's user page may shed some light on the subject: "alo ljudi sta vi tu pisete ja nista ne razumem." Ok, maybe not. But just in case his affair with Sophia was more than a two-night stand, I've left him a note on his talk page. I like the idea so far. Keep if he responds, Huff otherwise. --
SirBobBobBob ! S? [rox!|sux!]
17:39, 7 Oct 2005 (UTC)
- I probably should have made it a "stub". my bad. feel free to change it or rewrite all of it if you want, I didn't really have a solid idea in the first place. Sorry :( --His Drippiness Meltingwax MUN MOOU (Stamp&Seal) 11:50 9 Oct 2005 (EST)
Brian Peppers (look out, disturbing images)
Remove images I'm not sure those pictures could be funny under any circumstances. I don't care if the article is kept, but I think either the opposite strategy should be taken (i.e. replace with a picture of an exceedingly handsome guy - the people who know about Brian Peppers from Snopes or elsewhere will get it), or there should be an original image. Like a really bad hand-drawn mugshot or something. --—rc (t) 06:24, 3 Oct 2005 (UTC)
- delete. Google the guy and you'll get a bunch of crazy hits. He's been mocked enough. --Steve Johnsenson 02:30, 6 Oct 2005 (UTC)
Rewrite&Reimage About 15 pages now link there. Either unlink all and delete page+pictures, or replace pictures with non-factual ones. --
Sir Famine, Gun ♣ Petition » 17:13, 8 Oct 2005 (UTC)
This "let's make fun of an ugly sex offender lol!" fad on the net wasnt even funny back in early 2005 when it started. --Maj Sir Insertwackynamehere
CUN VFH VFP Bur. CMInsertwackynamehere | Talk 02:18, 17 Oct 2005 (UTC)
Starship Troopers
Delete or at least total rewrite It's a straight synopsis of the movie. --the drizzle 00:35, 3 Oct 2005 (UTC)
- Nytrospawn says it's a work in progress--The Right Honourable Maj Sir Elvis UmP KUN FIC MDA VFH Bur. CM and bars UGM F@H (Petition) 22:40, 5 Oct 2005 (UTC)
- Rewrite it if you wish, but the movie was funny as hell the way it was made. --Nytrospawn 03:04, 6 Oct 2005 (UTC)
Great Burnination
Delete Unfunny. --Algorithm 04:30, 2 Oct 2005 (UTC)
- The vandals are using our own terminology against us! Kill them before they take over! Or just delete the article. --
SirBobBobBob ! S? [rox!|sux!]
19:23, 4 Oct 2005 (UTC)
- 'Abstain May be funny to some. --The Right Honourable Maj Sir Elvis UmP KUN FIC MDA VFH Bur. CM and bars UGM F@H (Petition) 22:41, 5 Oct 2005 (UTC)
put this out of it's misery
Kanye West's Interview with Justice John Roberts
It's hilarious guys! Really!! It bears no resemblance to beating a dead horse. Seriously. Ok, this might have some humor value, but I'm humorally deficiant today. --
Sir Famine, Gun ♣ Petition » 16:32, 25 Sep 2005 (UTC)
- Since nobody has replied either way, I figured I'd take a look. Now I know why nobody has replied. They fell asleep. It's boring, but in a potentially humo(u)rous way. Weak keep in hopes that it goes somewhere, someday, and in the meantime I'll bookmark it for use when I have insomnia. --
SirBobBobBob ! S? [rox!|sux!]
17:35, 5 Oct 2005 (UTC)
Delete just strong enough to cancel out the weak keep and bring the score to a nice negative one. I really don't see it going anywhere. Ever. --Spintherism 05:20, 13 Oct 2005 (UTC)
Template:Kanye
Funny once or twice, unfunny when uncreative morons splash it across every single god damn page on this site. --
Sir Famine, Gun ♣ Petition » 22:09, 23 Sep 2005 (UTC)
- I dont think we can delete it seeing as how articles use it, but maybe we should find a way to discourage its use --Maj Sir Insertwackynamehere
CUN VFH VFP Bur. CMInsertwackynamehere | Talk 03:31, 24 Sep 2005 (UTC)
Just like the Ballmer template, some people seem to find that it gets funnier the more you overuse it. I say keep it, it's not very annoying. --Carlos the Mean 17:32, 24 Sep 2005 (UTC)
- You do have a point. Because I still find the Balmer one pretty funny. I was just venting my frustration at having to delete bunches of this template from a number of pages where it was just plain stupid. "George Bush doesn't care about people for whom quotes are made up." "George Bush doesn't care about 2b or not 2b." "George Bush doesn't care about User:OneTopJob6." With no connection to the articles, I guess it's on the same level as dumping "Bush is ghey!!!" on the same pages. While I don't seriously expect this to be deleted, I'm using this as a soap box to say:
Please tie this template into the content of the page. If you don't, I will have to kill you. Thanks.
- And now I will waste 2 hrs deleting it from 75% of the pages it is on. Feel free to help. --
Sir Famine, Gun ♣ Petition » 15:09, 25 Sep 2005 (UTC)
Keep. The template is not guilty that it's overused. Strip it from articles it doesn't belong to. - Guest 17:40, 24 Sep 2005 (UTC)
Keep with restrictions. There are some articles which fit in well with the context of the article. Just like the Ballmer quote, it should only be added if it somehow relates to the article it's posted on, and not just at random. --sColdWhat 10:42, 19 Oct 2005 (UTC)
- And therein lies the problem. 98.3% of the usage is not in context (or only vaguely-so) when the template is so easy to use. If it's worthy, just put it directly in the article. --
» Brig Sir Dawg | t | v | c » 15:29, 19 Oct 2005 (UTC)
- Why delete a template because it's so easy to use? If we are to write the quote right into the article, I think we should keep the template so we can {{subst:}} it. But I'm starting to forget the purpose of this template. --sColdWhat 22:18, 19 Oct 2005 (UTC).
- It's better to use the Randomquote template. If it's totally canned and has no variation, it probably has only a handful of suitable uses on the entire site, which means you might as well go to the effort to place the entire thing in the page, rather than just the template. Random quotes of the canned variety may sometimes add to a page, and they're easier to change/rotate. Since "Ballmer" and "Kayne" are canned and cannot really be used for quotes from anyone else, they are dead-ends and only temporally entertaining (Bush's lease expires in 2009, for instance). --
» Brig Sir Dawg | t | v | c » 22:52, 19 Oct 2005 (UTC)
Merge. Unify all of the templates so that one of them is used at random. Each time the article is displayed, a different type of quote appears. For a similar type of template, see Template:Really random sighting. --KP CUN 03:06, 28 Sep 2005 (UTC)
- Do you mean like this? Template:Randomquote (view the source). Minimalistic, and quote forms can be added or removed later as they become/unbecome popular. The originating quote templates can be deleted and the forms moved to this quotepage too. Also, with proper weighting, it will rarely show. --Splaka 03:17, 28 Sep 2005 (UTC)
CUN 03:28, 28 Sep 2005 (UTC)
- A second thought occurs too. All the occurances of Template:Really random sighting could be deleted and replaced with this, and the template Template:Really random sighting added to the list. Maybe bring this up in the VD. --Splaka 03:34, 28 Sep 2005 (UTC)
- I think that they should be kept separate. The really random sightings involve Elvis, the Loch Ness Monster, UFOs, and Big Foot. These should appear only sporadically. The random quotes should appear more often. Some articles may want to have a random quote appear every time. --KP CUN 04:05, 28 Sep 2005 (UTC)
- Ok, that makes more sense. A way to vary the amount of randomness would be to have a parameter (ie: {{randomquote|50}}) that went directly into <option weight="{{{1}}}"></option>. Higher number = more odds of being blank *shrug*. It might be, if there were enough one-line quotes (Kanye/Ballmer style), that we might not even want a blank option. --Splaka 04:10, 28 Sep 2005 (UTC)
Personally, I'd vote to keep the ReallyRandomSighting template. It has a separate purpose from this template. I've also recommended in the talk page that we move RandomQuote to HateQuote or something, to make it obvious for new users what it is. That way if we need a random, non-hateful quote we can set one up. But overall, nice work. --
Sir Famine, Gun ♣ Petition » 13:53, 1 Oct 2005 (UTC)
Lord Mud Loach
Slandanity? --Splaka 10:59, 19 Sep 2005 (UTC)
Template:Kratos
Unlike the {{Oscar}}, {{Ballmer}}, and {{Kanye}} templates, which can be used for a wide variety of subjects, this template seems like it would only be funny to fans of whatever game this is from. If it's nearly unusable outside of the articles on the game's other characters, then should this be moved inline with the articles it's in? --EvilZak 01:21, 19 Sep 2005 (UTC)
Delete As much as I love Tales of Symphonia, I don't find it particularly funny. --AlexMW 01:09, 20 Sep 2005 (EDT)
Comment Perhaps it could be converted to a template concerning slandanity or non-notible fictional characters ? 70.88.218.145 17:06, 20 Sep 2005 (EDT) Overhaul to make it funny to anyone. Re-written from scratch I've changed it up a little to be something different. Does this work?--Kafeithekeaton 01:45, 22 Sep 2005 (UTC)
Hmmm. Needs to be a bit wittier, but I say keep. --Hobelhouse 00:25, 6 Oct 2005 (UTC)
Mariusz Gaworczyk
First: in Polish. Second: no censorship. Third: short, stupid and pointless (I know, beacuse I'm Polish, like many people here). So please: delete this crap.
Portal of evil
Defeated --—rc (t) 16:44, 6 Oct 2005 (UTC)
'kin hell! What is going on on this page! --User:IMBJR/sig 22:27, 5 Oct 2005 (UTC)
- Delete looks like a newb test.--The Right Honourable Maj Sir Elvis UmP KUN FIC MDA VFH Bur. CM and bars UGM F@H (Petition) 22:33, 5 Oct 2005 (UTC)
- Delete, good title, bad article --Steve Johnsenson 02:07, 6 Oct 2005 (UTC)
- Delete It isn't even an article it is just crap. --LaughingManic 17:37, 6 Oct 2005 (UTC)
Daikenkai
I decided to give this one a fair trial. Ordinarily, it probably wouldn't be worth it, but compared to the shit I just deleted, this is quite impressively coherent. --Spintherism 05:28, 5 Oct 2005 (UTC)
- Delete--The Right Honourable Maj Sir Elvis UmP KUN FIC MDA VFH Bur. CM and bars UGM F@H (Petition) 22:32, 5 Oct 2005 (UTC)
- Expand or Delete The lyrics have some potential, maybe an article on Japanese Linkin Park songs? either way, this ones too small, and doesn't fit in the undic -- Jordon Sometime Around Noon, 6 Oct 2005
Taldo
Again, probably not worth voting on.--Spintherism 05:30, 5 Oct 2005 (UTC)
Just delete it--Monkeysfighting 09:58, 9 Oct 2005 (UTC)
Axel F
I should just be deleting this stuff. --Spintherism 05:32, 5 Oct 2005 (UTC)
- Delete--The Right Honourable Maj Sir Elvis UmP KUN FIC MDA VFH Bur. CM and bars UGM F@H (Petition) 22:36, 5 Oct 2005 (UTC)
- Delete/Rewrite looks like vanity to me, and the picture is very obviously a grue, which is plagarism; however it has some potential in its randomness -- Jordon Sometime Around Noon, 6 Oct 2005
- Delete. It looks too much like vanity for me.--Josie v. 3.1 20:53, 6 Oct 2005 (UTC)Josie v. 3.0
- I get it! Axel F, as opposed to "High F" or "F above Middle C". It's a musical reference, and the "2XX0" is supposed to be like "a year ending in 0 sometime between 2000 and 2990". Kill it -- if you have to explain the joke... -- <s>Sir BobBobBob !
S? [rox!|sux!]
17:43, 7 Oct 2005 (UTC)
</s> Deleted --Spintherism 02:54, 8 Oct 2005 (UTC)
Bindlebeep
Is this based on some cultural phenomenon that I've never heard of? --Spintherism 04:57, 30 Sep 2005 (UTC)
- Yeah, I think it's the last name of some people on a crappy show on Disney, or whatever. Just Kill it to death. --Cheeseboi 13:33, 1 Oct 2005 (UTC)
- Dull Delete --The Right Honourable Maj Sir Elvis UmP KUN FIC MDA VFH Bur. CM and bars UGM F@H (Petition) 22:42, 5 Oct 2005 (UTC)
Mc Donalds and Cronic Instant Death Syndrome
Hurt my brain :( --Splaka 22:55, 27 Sep 2005 (UTC)
Delete Mc Donalds, and if I get my hands on some inspiration (drugs are bad, kids) might try to rewrite Chronic Instant Death Syndrome. --Spintherism 04:34, 30 Sep 2005 (UTC)
Satisfy my otherwise insatiable hunger by deleteing Cronic Instant Death Syndrome. I've actually been living with the real chronic instant death syndrome my entire life. It runs in my family so deep that I find this phony version to be racist. --Magotchi 07:43, 30 Sep 2005 (UTC)
Maybe it can be merged to McDonalds after a rewrite ? 70.88.222.85 23:34, 4 Oct 2005 (UTC)
Unless someone rewrites them Delete both --The Right Honourable Maj Sir Elvis UmP KUN FIC MDA VFH Bur. CM and bars UGM F@H (Petition) 22:43, 5 Oct 2005 (UTC)
- Kill it dead. --Hobelhouse 00:22, 6 Oct 2005 (UTC)
Random Insanity Redux
The article has been recreated. The humor content is still 0. --KP CUN 17:48, 2 Oct 2005 (UTC)
- Dropped a note on the recreator's page about recreating it. Suggested that information about the article be written up ala Steam Forums, and if that page's contents must be around, that they be a sub-page of that article, rather than the main text. Bare minimum, there has to be some body of information which explains what all that worthless crap is. Even if it's made up. --
Sir Famine, Gun ♣ Petition » 18:10, 2 Oct 2005 (UTC)
- Keep new version --The Right Honourable Maj Sir Elvis UmP KUN FIC MDA VFH Bur. CM and bars UGM F@H (Petition) 22:45, 5 Oct 2005 (UTC)
Julie Pitta
Vanity? --Carlb 04:15, 27 Sep 2005 (UTC)
Smells like vanity, and is an orphan with one anon-ip editor. I'm taking it home and calling it deleted. --
Sir Famine, Gun ♣ Petition » 23:31, 28 Sep 2005 (UTC)
Mr. Pike
If he was a fish, I'd say let him swim in the cesspool of Uncyclopedia. Unfortunately, he's not. --
Sir Famine, Gun ♣ Petition » 16:22, 25 Sep 2005 (UTC)
Keep Becuase I stole their article and filled it full of rubbish that only those who have knowledge of British TV would get. --The Right Honourable Maj Sir Elvis UmP KUN FIC MDA VFH Bur. CM and bars UGM F@H (Petition) 14:25, 27 Sep 2005 (UTC)
KEEP because there is little to be gained from deleting this article, other than a group of angry high-school students who will terrorize the site. But, if not, they will be happy smiley children.
Oscar Wilde: Keep this article, or I'll blow steaming hot jizz all over some five-year-old's face. Again.
- You just got banned. No vote for you. -F
Mr. Pike is now nearing completion, with non-Brittish TV edits to fill out the end. Can we get the same sort of polish on Mr. Kachi? --
Sir Famine, Gun ♣ Petition » 01:17, 29 Sep 2005 (UTC)
Category:Boksters & Category:Witchcraft
We really don't need "Witchcraft" cause we already have Category Magic, Magick, Magicians etc. There's really no need. Boksters is also completely retarded. Wth? Yeah, so watch out for Wayland's contributions. --MonkeyGem 12:16, 25 Sep 2005 (UTC)
Delete. For the same reasons that MonkeyGem listed. Luffy 00:47, 27 Sep 2005 (UTC)
Pointed Stick
Go-o-o-one... Not only is it a straight rip from Monty Python's Fresh Fruit Self-Defence sketch, but there already is a pointed stick article. --theRewittenSheep 16:52, 22 Sep 2005 (UTC)
Merge --The Right Honourable Maj Sir Elvis UmP KUN FIC MDA VFH Bur. CM and bars UGM F@H (Petition) 12:34, 25 Sep 2005 (UTC)
Lemons
Looks like two kids fighting, but not sexy like if it was the Olsen Twins (speaking of which, what happened to their article?). Plus, it's plural. I hate that. --
Sir BobBobBob ! S ? [rox!|sux!]
15:24, 22 Sep 2005 (UTC)
- Keep Nothing wrong with the origal article surely? It needs expanding etc but damn I thought it was amusing :) --TheRappingShoe 18:14, 22 Sep 2005 (UTC)
- Actually, it's gotten a lot better now that its existence has been threatened, kinda like a rat on the Titanic learning to swim. I'm going to ambiguate Lemon, Lemons, Jack Lemmon, and maybe even John Lennon (whose name is close enough for me). --
SirBobBobBob ! S? [rox!|sux!]
18:19, 28 Sep 2005 (UTC)
Tourette's Syndrome. --Splaka 11:00, 30 Sep 2005 (UTC)
I am re-writing it at the moment. should be finished in a few days!
Rewrite it has potential (with some tweaking), and if anyone is offended by it, I don't care. -- Jordon Sometime Around Noon, Oct 6, 2005
Tim
Vanity page with too many edits for QVFD. Splaka, why do you think it's worth saving? --
Sir BobBobBob ! S ? [rox!|sux!]
15:24, 22 Sep 2005 (UTC)
- Comment Perhaps a rewrite is in order ? this article certainly has the potential for an article such as Bob for example and certianly any line from Monty Python deserves a fair chance in my opinion. 134.241.43.254 22:22, 22 Sep 2005 (UTC)
- An MTU is not necessarily a vote to keep. When a rather short page is a bit better than a QVFD, I put it on MTU, to give it 7 days to shape up, before a VFA/QVFA/Move. The MTU entries (I hope) will be judged by an admin sometime down the line. Feel free of course to put any bad ones on VFD/QVFD you think appropriate. (This is not a vote, just a comment) --Splaka 20:47, 23 Sep 2005 (UTC)
Delete If somebody wants to write a tim article, they can start over from scratch. There's nothing here worth saving. --Spintherism 17:33, 2 Oct 2005 (UTC)
Mythology
There's already a category for that. It's useless. --MonkeyGem 13:02, 22 Sep 2005 (UTC)
- Content Moved to Category:Mythology --The Right Honourable Maj Sir Elvis UmP KUN FIC MDA VFH Bur. CM and bars UGM F@H (Petition) 12:38, 25 Sep 2005 (UTC)
Simon Wai's Sonic 2 Beta
Injoke? --Splaka 10:59, 19 Sep 2005 (UTC)
Actually, SWS2B is a website found at [[3]] pertaining to Sonic 2, or, more specifically, a prototype of it. Simon Wai is the discoverer of the beta, though I guess it can be considered an injoke, though if you read the Sonic and Hedgehog religion article that should be more than enough to get it. ----Guess Who 05:07, 22)
highlight on front page It is supposed to be a reference to Calvin and Hobbes and I'd support moving it to the tiger article. Seems to make sense. --Spooner 01:24, 10 Sep 2005 (UTC)
No highlight You have to check the quality of the highlighted pages and compare them to this --Nytrospawn 19:41, 11 Sep 2005 (UTC)
Consider Moving to 'Tiger' or other appropriate article. COuld be used to expand either a mediocre article or act as a springboard for a new one.--Sir Flammable KUN 15:52, 12 Sep 2005 (UTC)
Keep but categorise it in Tired Pop Culture References and label it as sporked. --Carlos the Mean 12:30, 14 Sep 2005 (UTC))
- Just wanted to point out that in Texas you can find a town named just about anything (from London to Paris). --D3matt 18:45, 6 Sep 2005 (UTC)
Keep It's kinda sorta funny, possibly unintentionally. I was a bit perplexed when I saw my Shelbyville article added to Texas but I'll admit to snorting when I saw Ringgold, GA on the list of Texas cities. --Bouahat 22:44, 11 Sep 2005 (UTC)
Keep, and consider turning Category:Cities into a redirect to Category:Texas Cities. Well, maybe not go that far, but it's funny, especially now that there is a Category:Definitely not fucking Texas Cities Mandiatory disclaimer: I'm from Texas.--BobBobBob 22:25, 15 Sep 2005 (UTC)
“Never ask a man if he's from Texas. If he is, he'll tell you. If he's not, don't embarrass him.”
'Keep Harmless in itself, too much effort to revert. I'm also no sure why some cities AREN'T in texas. --Chronarion 18:37, 5 Oct 2005 (UTC)
End of the world
Not quite funny. A couple of good lines, but comes off as an instrument of torture from a poetry open mike night. --Marcos_Malo OUN S7fc BOotS Bur. | Talk 08:12, 1 Sep 2005 (UTC)
- I tried to brush it up a bit. Flyingbird 18:09, 10)
- Burn Ok, this isn't everything2... --Chronarion 18:35, 5 Oct)
- I agree, Keep but maybe a few funny additions should be made, although I did enjoy the picture of the quicksilver test subject posing with a cow. Jordon -unknown date, sometime in september-
)
No judgemnet - I have been doing a few rewrites around the place and thought I could ressurect this one... Thoughts? --theRewittenSheep 18:57, 16)
Baleet Long and boring, as well as stolen. --Poofers 05:37, 19 Sep 2005 (UTC)
Yes Zorro's Ass pun, as well as a play on the deity Ahura Mazda?--slack 15:22, 5 Oct <small>Bur.</small> | Petition 09:00, 31 Aug 2005 (UTC)
- I thought I'd posted a reply to this earlier, but apparently not. I think I said something like: 'Yeah, elvis is right.'--Spintherism 04:23, 2)
REWRITE: I was going to write one, but after doing The Sun I simply couldn't be arsed to write another newspaper entry. The Grauniad should be a great target, so long as it's not a summary of all the Private Eye pisstakes. It's easy (and fun) to mock the right wing rags, and as a filthy, beardie, sandal-knitting leftie I know there's a good article ready to be written. --86.133.156.32 20:52, 7 Sep 2005 (UTC) | http://uncyclopedia.wikia.com/wiki/Uncyclopedia:Votes_for_deletion/archive14?oldid=5084906 | CC-MAIN-2016-07 | refinedweb | 6,748 | 81.12 |
How to change ticks labels attributes for the 2D plot?
Is there a way to access ticks labels to rotate them? I've tried
Graphics.matplotlib() and
set_rotation(), but this doesn't seem to produce changes. Am I doing wrong things?
In the example below the formatter and locator are working correctly, but the problem is all labels are oriented horizontally, messing all together. Need to rotate them.
import csv from datetime import datetime from matplotlib import ticker from matplotlib import dates data = [ ( '04/22/20', '04/23/20', '04/24/20','04/25/20','04/26/20', '04/27/20' ), (20, 40, 80, 160, 320, 640) ] labels = data[0] labels = map(lambda x: dates.date2num(datetime.strptime(x, '%m/%d/%y')), labels) labels = list(labels) values = data[1] values = map(lambda x: int(x), values) # Z is a list of [(x1,y1),(x2,y2)...] # x1, x2, ... are dates # y1, y2, ... are values Z = zip(labels, values) Z = list(Z) p = list_plot( Z, ticks=[1, None], tick_formatter=[dates.DateFormatter('%d.%m.%Y'), None], axes_labels=[ 'Days', '$\\log \\;{N}$' ], plotjoined=true, thickness=2, figsize=4, scale='semilogy' ) G = p.matplotlib() labels = G.axes[0].xaxis.get_ticklabels() labels = list(labels) for label in labels: label.set_rotation(45) p
This outputs the plot with an ugly x-axis on which all the dates are messed up. How to fix that?
A minimal example that can by copy-pasted in a fresh Sage session helps others get started on an answering a question, therefore increasing the chances of getting an answer. In this case,
dates.DateFormatterwill work
Z(with just enough dates to illustrate the problem)
Hello, thank you for your response. I've added the information needed to comply.
Following what is explained in this link, it seems the following should work:
but the last line returns an error because
figure.canvasis None
Yes, thanks for this answer. I've already tried that with the same result. But this example is for pure matplotlib, not the sage
Graphicsobject. I would like to know, what does that
matplotlib()exactly do? I even tried:
to draw the plot on the new figure provided, but this doesn't work for me. So, the question is, is this
matplotlib()function supposed to give the access to
pattributes, which were previosly set when the plot was created, and should the changes made on the figure effect onto the plot? And is the plot is supposed to be redrawn on the new figure when the plot is passed as an argument to matplotlib()?
Suggestion: format dates following the international standard ISO 8601. | https://ask.sagemath.org/question/51080/how-to-change-ticks-labels-attributes-for-the-2d-plot/ | CC-MAIN-2021-17 | refinedweb | 432 | 66.94 |
DBMI Library (client) - copy table. More...
#include <stdlib.h>
#include <string.h>
#include <grass/dbmi.h>
#include <grass/glocale.h>
#include "macros.h"
Go to the source code of this file.
DBMI Library (client) - copy table.
(C) 1999-2008 by the GRASS Development Team
This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
Definition in file copy_tab.c.
Copy a table.
Definition at line 446 of file copy_tab.c.
Referenced by V1_close_nat(), and Vect_rename().
Copy a table (by keys)
Definition at line 519 of file copy_tab.c.
Referenced by Vect_copy_table_by_cats().
Copy a table (by select statement)
Definition at line 493 of file copy_tab.c.
Copy a table (by where statement)
Definition at line 469 of file copy_tab.c. | http://grass.osgeo.org/programming7/copy__tab_8c.html | CC-MAIN-2018-17 | refinedweb | 131 | 64.47 |
Chapter 1.
Introduction
As. Such tools provide a visual programming model that allows you to include software components rapidly in your applications.
The JavaBeans architecture brings the component development model to Java, and that's the subject of this book. But before we get started, I want to spend a little time describing the component model, and follow that with a general overview of JavaBeans. If you already have an understanding of these subjects, or you just want to get right into it, you can go directly to Chapter 2, Events. Otherwise, you'll probably find that the information in this chapter sets the stage for the rest of the book.
The Component Model
Components are self-contained elements of software that can be controlled dynamically and assembled to form applications. But that's not the end of it. These components must also interoperate according to a set of rules and guidelines. They must behave in ways that are expected. It's like a society of software citizens. The citizens (components) bring functionality, while the society (environment) brings structure and order.
JavaBeans is Java's component model. It allows users to construct applications by piecing components together either programmatically or visually (or both). Support of visual programming is paramount to the component model; it's what makes component-based software development truly powerful.
The model is made up of an architecture and an API (Application Programming Interface). Together, these elements provide a structure whereby components can be combined to create an application. This environment provides services and rules, the framework that allows components to participate properly. This means that components are provided with the tools necessary to work in the environment, and they exhibit certain behaviors that identify them as such. One very important aspect of this structure is containment. A container provides a context in which components can interact. A common example would be a panel that provides layout management or mediation of interactions for visual components. Of course, containers themselves can be components.
As mentioned previously, components are expected to exhibit certain behaviors and characteristics in order to participate in the component structure and to interact with the environment, as well as with other components. In other words, there are a number of elements that, when combined, define the component model. These are described in more detail in the following sections.
Discovery and Registration
Class and interface discovery is the mechanism used to locate a component at run-time and to determine its supported interfaces so that these interfaces can be used by others. The component model must also provide a registration process for a component to make itself and its interfaces known. The component, along with its supported interfaces, can then be discovered at run-time. Dynamic (or late) binding allows components and applications to be developed independently. The dependency is limited to the "contract" between each component and the applications that use it; this contract is defined by interfaces that the component supports. An application does not have to include a component during the development process in order to use it at run-time; it only needs to know what the component is capable of doing. Dynamic discovery also allows developers to update components without having to rebuild the applications that use them.
This discovery process can also be used in a design-time environment. In this case, a development tool may be able to locate a component and make it available for use by the designer. This is important for visual programming environments, which are discussed later.
Raising and Handling of Events
An event is something of importance that happens at a specific point in time. An event can take place due to a user action such as a mouse clickwhen the user clicks a mouse button, an event takes place. Events can also be initiated by other means. Imagine the heating system in your house. It contains a thermostat that sets the desired comfort temperature, keeps track of the current ambient temperature, and notifies the boiler when its services are required. If the thermostat is set to keep the room at 70 degrees Fahrenheit, it will notify the boiler to start producing heat if the temperature dips below that threshold. Components will send notifications to other objects when an event takes place in which those objects have expressed an interest.
Persistence
Generally, all components have state. The thermostat component has state that represents the comfort temperature. If the thermostat were a software component of a computer-based heating control system, we would want the value of the comfort temperature to be stored on a non-volatile storage medium (such as the hard disk). This way if we shut down the application and brought it back up again, the thermostat control would still be set to 70 degrees. The visual representation and position of the thermostat relative to other components in the application would be restored as well.
Components must be able to participate in their container's persistence mechanism so that all components in the application can provide application-wide persistence in a uniform way. If every component were to implement its own method of persistence, it would be impossible for an application container to use components in a general way. This wouldn't be an issue if reuse weren't the goal. If we were building a monolithic temperature control system we might create an application-specific mechanism for storing state. But we want to build the thermostat component so that it can be used again in another application, so we have to use a standard mechanism for persistence.
Visual Presentation
The component environment allows the individual components to control most of the aspects of their visual presentation. For example, imagine that our thermostat component includes a display of the current ambient temperature. We might want to display the temperature in different fonts or colors depending on whether we are above, below, or at the comfort temperature. The component is free to choose the characteristics of its own visual presentation. Many of these characteristics will be properties of the component (a topic that will be discussed later). Some of these visual properties will be persistent, meaning that they represent some state of the control that will be saved to, and restored from, persistent storage.
Layout is another important aspect of visual presentation. This concerns the way in which components are arranged on the screen, how they relate to one another, and the behavior they exhibit when the user interacts with them. The container object that holds an assembly of components usually provides some set of services related to the layout of the component. Let's consider the thermostat and heating control application again. This time, the user decides to change the size of the application window. The container will interact with the components in response to this action, possibly changing the size of some of the components. In turn, changing the size of the thermostat component may cause it to alter its font size.
As you can see, the container and the component work together to provide a single application that presents itself in a uniform fashion. The application appears to be working as one unit, even though with the component development model, the container and the components probably have been created separately by different developers.
Support of Visual Programming
Visual programming is a key part of the component model. Components are represented in toolboxes or palettes. The user can select a component from the toolbox and place it into a container, choosing its size and position. The properties of the component can then be edited in order to create the desired behavior. Our thermostat control might present some type of user interface to the application developer to set the initial comfort temperature. Likewise, the choice of font and color will be selectable in a similar way. None of these manipulations require a single line of code to be written by the application developer. In fact, the application development tool is probably writing the code for you. This is accomplished through a set of standard interfaces provided by the component environment that allow the components to publish, or expose, their properties. The development tool can also provide a means for the developer to manipulate the size and position of components in relation to each other. The container itself may be a component and allow its properties to be edited in order to alter its behavior.
The JavaBeans Architecture.
Creating a Bean doesn't require any advanced concepts. So before I go any further, here is some code that implements a simple Bean:
public class MyBean implements java.io.Serializable
{
protected int theValue;
public MyBean()
{
}
public void setMyValue(int newValue)
{
theValue = newValue;
}
public int getMyValue()
{
return theValue;
}
}
This is a real Bean named MyBean that has state (the variable theValue) that will automatically be saved and restored by the JavaBeans persistence mechanism, and it has a property named MyValue that is usable by a visual programming environment. This Bean doesn't have any visual representation, but that isn't a requirement for a JavaBean component.
JavaSoft is using the slogan "Write once, use everywhere." Of course "everywhere" means everywhere the Java run-time environment is available. But this is very important. What it means is that the entire run-time environment required by JavaBeans is part of the Java platform. No special libraries or classes have to be distributed with your components. The JavaBeans class libraries provide a rich set of default behaviors for simple components (such as the one shown earlier). This means that you don't have to spend your time building a lot of support for the Beans environment into your code.
The design goals of JavaBeans are discussed in Sun's white paper, "Java Beans: A Component Architecture for Java." This paper can be found on the JavaSoft web site at. It might be interesting to review these goals before we move on to the technology itself, to provide a little insight into why certain aspects of JavaBeans are the way they are.
Compact and Easy
JavaBeans components are simple to create and easy to use. This is an important goal of the JavaBeans architecture. It doesn't take very much to write a simple Bean, and such a Bean is lightweight. (The previous example shows just how simple a Bean can be.)
Portable
Since JavaBeans components are built purely in Java, they are fully portable to any platform that supports the Java run-time environment. All platform specifics, as well as support for JavaBeans, are implemented by the Java virtual machine. You can be sure that when you develop a component using JavaBeans it will be usable on all of the platforms that support Java (version 1.1 and beyond). These range from workstation applications and web browsers to servers, and even to devices such as PDAs and set-top boxes.
Leverages the Strengths of the Java Platform
JavaBeans uses the existing Java class discovery mechanism. This means that there isn't some new complicated mechanism for registering components with the run-time system.
As shown in the earlier code example, Beans are lightweight components that are easy to understand. Building a Bean doesn't require the use of complex extensions to the environment. Many of the Java supporting classes are Beans, such as the windowing components found in java.awt.
The Java class libraries provide a rich set of default behaviors for components. Use of Java Object Serialization is one examplea component can support the persistence model by implementing the java.io.Serializable interface. By conforming to a simple set of design patterns (discussed later in this chapter), you can expose properties without doing anything more than coding them in a particular style.
Flexible Build-Time Component Editors
Developers are free to create their own custom property sheets and editors for use with their components if the defaults aren't appropriate for a particular component. It's possible to create elaborate property editors for changing the value of specific properties, as well as create sophisticated property sheets to house those editors.
Imagine that you have created a Sound class that is capable of playing various sound format files. You could create a custom property editor for this class that listed all of the known system sounds in a list. If you have created a specialized color type called PrimaryColor, you could create a color picker class to be used as the property editor for PrimaryColor that presented only primary colors as choices.
The JavaBeans architecture also allows you to associate a custom editor with your component. If the task of setting the property values and behaviors of your component is complicated, it may be useful to create a component wizard that guides the user through the steps. The size and complexity of your component editor is entirely up to you.
JavaBeans Overview
The JavaBeans white paper defines a Bean as follows:A Java Bean is a reusable software component that can be manipulated visually in a builder tool.
Well, if you have to sum it up in one sentence, this is as good as any. But it's pretty difficult to sum up an entire component architecture in one sentence. Beans will range greatly in their features and capabilities. Some will be very simple and others complex; some will have a visual aspect and others won't. Therefore, it isn't easy to put all Beans into a single category. Let's take a look at some of the most important features and issues surrounding Beans. This should set the stage for the rest of the book, where we will examine the JavaBeans technology in depth.
Properties, Methods, and Events
Properties are attributes of a Bean that are referenced by name. These properties are usually read and written by calling methods on the Bean specifically created for that purpose. A property of the thermostat component mentioned earlier in the chapter could be the comfort temperature. A programmer would set or get the value of this property through method calls, while an application developer using a visual development tool would manipulate the value of this property using a visual property editor.
The methods of a Bean are just the Java methods exposed by the class that implements the Bean. These methods represent the interface used to access and manipulate the component. Usually, the set of public methods defined by the class will map directly to the supported methods for the Bean, although the Bean developer can choose to expose only a subset of the public methods.
Events are the mechanism used by one component to send notifications to another. One component can register its interest in the events generated by another. Whenever the event occurs, the interested component will be notified by having one of its methods invoked. The process of registering interest in an event is carried out simply by calling the appropriate method on the component that is the source of the event. In turn, when an event occurs a method will be invoked on the component that registered its interest. In most cases, more than one component can register for event notifications from a single source. The component that is interested in event notifications is said to be listening for the event.
Introspection
Introspection is the process of exposing the properties, methods, and events that a JavaBean component supports. This process is used at run-time, as well as by a visual development tool at design-time. The default behavior of this process allows for the automatic introspection of any Bean. A low-level reflection mechanism is used to analyze the Bean's class to determine its methods. Next it applies some simple design patterns to determine the properties and events that are supported. To take advantage of reflection, you only need to follow a coding style that matches the design pattern. This is an important feature of JavaBeans. It means that you don't have to do anything more than code your methods using a simple convention. If you do, your Beans will automatically support introspection without you having to write any extra code. Design patterns are explained in more detail later in the chapter.
This technique may not be sufficient or suitable for every Bean. Instead, you can choose to implement a BeanInfo class which provides descriptive information about its associated Bean explicitly. This is obviously more work than using the default behavior, but it might be necessary to describe a complex Bean properly. It is important to note that the BeanInfo class is separate from the Bean that it is describing. This is done so that it is not necessary to carry the baggage of the BeanInfo within the Bean itself.
If you're writing a development tool, an Introspector class is provided as part of the Beans class library. You don't have to write the code to accomplish the analysis, and every tool vendor uses the same technique to analyze a Bean. This is important to us as programmers because we want to be able to choose our development tools and know that the properties, methods, and events that are exposed for a given component will always be the same.
Customization
When you are using a visual development tool to assemble components into applications, you will be presented with some sort of user interface for customizing Bean attributes. These attributes may affect the way the Bean operates or the way it looks on the screen. The application tool you use will be able to determine the properties that a Bean supports and build a property sheet dynamically. This property sheet will contain editors for each of the properties supported by the Bean, which you can use to customize the Bean to your liking. The Beans class library comes with a number of property editors for common types such as float, boolean, and String. If you are using custom classes for properties, you will have to create custom property editors to associate with them.
In some cases the default property sheet that is created by the development tool will not be good enough. You may be working with a Bean that is just too complex to customize easily using the default sheet. Beans developers have the option of creating a customizer that can help the user to customize an instance of their Bean. You can even create smart wizards that guide the user through the customization process.
Customizers are also kept separate from the Bean class so that it is not a burden to the Bean when it is not being customized. This idea of separation is a common theme in the JavaBeans architecture. A Bean class only has to implement the functionality it was designed for; all other supporting features are implemented separately.
Persistence
It is necessary that Beans support a large variety of storage mechanisms. This way, Beans can participate in the largest number of applications. The simplest way to support persistence is to take advantage of Java Object Serialization. This is an automatic mechanism for saving and restoring the state of an object. Java Object Serialization is the best way to make sure that your Beans are fully portable, because you take advantage of a standard feature supported by the core Java platform. This, however, is not always desirable. There may be cases where you want your Bean to use other file formats or mechanisms to save and restore state. In the future, JavaBeans will support an alternative externalization mechanism that will allow the Bean to have complete control of its persistence mechanism.
Design-Time vs. Run-Time
JavaBeans components must be able to operate properly in a running application as well as inside an application development environment. At design-time the component must provide the design information necessary to edit its properties and customize its behavior. It also has to expose its methods and events so that the design tool can write code that interacts with the Bean at run-time. And, of course, the Bean must support the run-time environment.
Visibility
There is no requirement that a Bean be visible at run-time. It is perfectly reasonable for a Bean to perform some function that does not require it to present an interface to the user; the Bean may be controlling access to a specific device or data feed. However, it is still necessary for this type of component to support the visual application builder. The component can have properties, methods, and events, have persistent state, and interact with other Beans in a larger application. An "invisible" run-time Bean may be shown visually in the application development tool, and may provide custom property editors and customizers.
Multithreading
The issue of multithreading is no different in JavaBeans than it is in conventional Java programming. The JavaBeans architecture doesn't introduce any new language constructs or classes to deal with threading. You have to assume that your code will be used in a multithreaded application. It is your responsibility to make sure your Beans are thread-safe. Java makes this easier than in most languages, but it still requires some careful planning to get it right. Remember, thread-safe means that your Bean has anticipated its use by more than one thread at a time and has handled the situation properly.
Security
Beans are subjected to the same security model as standard Java programs. You should assume that your Bean is running in an untrusted applet. You shouldn't make any design decisions that require your Bean to be run in a trusted environment. Your Bean may be downloaded from the World Wide Web into your browser as part of someone else's applet. All of the security restrictions apply to Beans, such as denying access to the local file system, and limiting socket connections to the host system from which the applet was downloaded.
If your Bean is intended to run only in a Java application on a single computer, the Java security constraints do not apply. In this case you might allow your Bean to behave differently. Be careful, because the assumptions you make about security could render your Bean useless in a networked environment.
Using Design Patterns
The JavaBeans architecture makes use of patterns that represent standard conventions for names, and type signatures for collections of methods and interfaces. Using coding standards is always a good idea because it makes your code easier to understand, and therefore easier to maintain. It also makes it easier for another programmer to understand the purpose of the methods and interfaces used by your component. In the JavaBeans architecture, these patterns have even more significance. A set of simple patterns are used by the default introspection mechanism to analyze your Bean and determine the properties, methods, and events that are supported. These patterns allow the visual development tools to analyze your Bean and use it in the application being created. The following code fragment shows one such pattern:
public void setTemperatureColor(Color newColor)
{
. . .
}
public Color getTemperatureColor()
{
. . .
}
These two methods together use a pattern that signifies that the Bean contains a property named TemperatureColor of type Color. No extra development is required to expose the property. The various patterns that apply to Beans development will be pointed out and discussed throughout this book. I'll identify each pattern where the associated topic is being discussed.
NOTE: The use of the term "design pattern" here may be confusing to some readers. This term is commonly used to describe the practice of documenting a reusable design in object-oriented software. This is not entirely different than the application of patterns here. In this case, the design of the component adheres to a particular convention, and this convention is reused to solve a particular problem.
As mentioned earlier, this convention is not a requirement. You can implement a specific BeanInfo class that fully describes the properties, methods, and events supported by your Bean. In this case, you can name your methods anything you please.
JavaBeans vs. ActiveX
JavaBeans is certainly not the first component architecture to come along. Microsoft's ActiveX technology is based upon COM, their component object model. ActiveX offers an alternative component architecture for software targeted at the various Windows platforms. So how do you choose one of these technologies over the other? Organizational, cultural, and technical issues all come into play when making this decision. ActiveX and JavaBeans are not mutually exclusive of each otherMicrosoft has embraced Java technology with products like Internet Explorer and Visual J++, and Sun seems to have recognized that the desktop is dominated by Windows and has targeted Win32 as a strategic platform for Java. It is not in anyone's best interest to choose one technology to the exclusion of another. Both are powerful component technologies. I think we should choose a technology because it supports the work we are doing, and does so in a way that meets the needs of the customer.
The most important question is how Beans will be used by containers that are designed specifically to contain ActiveX controls. Certainly, all Beans will not also be ActiveX controls by default. To address the need to integrate Beans into the world of ActiveX, an ActiveX Bridge is available that maps the properties, methods, and events exposed by the Bean into the corresponding mechanisms in COM. This topic is covered in detail in Chapter 11, ActiveX.
Getting Started
If you plan to play along, you should make sure that you have installed the latest versions of the Java Development Kit (JDK) and the Beans Development Kit (BDK). Both of these can be downloaded from the JavaSoft web site at.[1]
Remember that if you don't have a browser that supports JDK1.1, you will have to run your applets in the appletviewer program that is provided in the JDK. At the time of this writing, the only browser that supports JDK1.1 is HotJava.
The chapters in this book are arranged so that they build on concepts presented in preceding chapters. I suggest that you try to follow along in order. Of course, this is entirely up to you. If you are comfortable with the technology, you may find that you can jump around a bit.
1. Beans development requires JDK1.1; however, JDK1.1.1 is now available.
Back to: Developing Java Beans
© 2001, O'Reilly & Associates, Inc.
webmaster@oreilly.com | http://oreilly.com/catalog/javabeans/chapter/ch01.html | crawl-002 | refinedweb | 4,414 | 53.71 |
VR has grown over the past few years as the number of compatible devices increase. There are a ton of uses for it, both practical and for entertainment. If you know JavaScript, you can even start making your own VR apps right in the browser.
In this tutorial, we're going to make a quick search and find game. There will be a few objects hidden around the world and the player will have to find them all to win. We'll be using Redwood and A-frame to handle all of our VR and user experience needs.
Building the VR world
We'll start by making a new Redwood app. In a terminal, run the following command.
yarn create redwood-app vr-in-redwood
This bootstraps a new Redwood app with a lot of folders and files that have been auto-generated. We're going to start on the front-end so that we jump into the VR part. All of our front-end code is in the
web directory.
We're going to a new page called
World and it will point to the root of the app. To create this page, we'll run this command.
Setting up the world
yarn rw g page world /
After this finishes, go to the
web > src > pages directory and you'll see a
WorldPage folder. It has the code for the home page and it has a few other files to help with testing. If you take a look at
Routes.js, you'll also notice the new routes have automatically added.
We need to add Aframe to the project because this is the library we're going to use to make our VR world. Import this library in the
index.html file with the following line at the end of the
<head> element.
<script src=""></script>
Updating the component
Using this import, we have access to the different Aframe components available in the library. We can start building our new world in the
WorldPage component. Open that file and add the follwing code.
You can delete the import and the current contents of the return statement inside of the
WorldPage component. We won't be using any of the template code.
const WorldPage = () => { return ( <a-scene> <a-assets> <img id="room" crossorigin="anonymous" src="" /> </a-assets> <a-sky</a-sky> <a-camera look-controls-enabled={true}></a-camera> </a-scene> ) } export default WorldPage
This is what your
WorldPage component should look like now. We're using a few of the Aframe components.
<a-scene>creates the entire world for the VR app.
<a-assets>is how we import external resources, like images and audio files, into the world.
<a-sky>uses a picture to create the background for the world. This is how you can create a static environment for your world if you don't need the user to move around much.
<a-camera>is how we add a camera to the world so that a user can look around the world.
You can learn more about how the Aframe library and components work by checking out their docs.
Pulling views from Cloudinary
Right now there's a placeholder image that drops users into a nice room, but you'll probably want something different for your app. We'll use Cloudinary to host the images because that'll decrease our load time and we won't have to deal with a lot of large files.
So you can go to the Cloudinary site and sign up for a free account and upload any panoramic images you want to use. Then you can update the
src for the image in the
<a-assets> element.
You'll need to update
milecia in the asset URL to match the cloud name for your Cloudinary account so that you can use your images.
Adding customization
Since we have the option to upload as many images as we want, users might like it if they can switch between images and have their own worlds load when they come to the app.
We can add this by creating a new variable that will come from the back-end we'll be making in a bit. We'll start by adding a few GraphQL methods. Import a method from Redwood at the top of the
WorldPage component file.
import { useQuery } from '@redwoodjs/web'
Then we'll add a call to that method inside of the component.
const { loading, data } = useQuery(WORLDS)
Now we need to add the GraphQL definition for the query. So at the bottom of the component, above the export statement, add the following code.
const WORLDS = gql` query Worlds { worlds { id imageName } } `
With our GraphQL request defined, let's update the component to use our new data. First we'll add a loading state so that we don't have issues while data is being fetch. Below the
useQuery line, add the following lines.
if (loading) { return <div>Loading...</div> }
Below this, we'll add a new variable that will contain the URL users have recently uploaded for the world. It'll default to an image if there isn't a user selected one to load.
const worldUrl = data?.worlds[data.worlds.length - 1].imageName || 'room-360_nag5ns.jpg'
Then we'll make the URL dynamic by updating the URL in the assets.
<img id="room" crossorigin="anonymous" src={`{worldUrl}`} />
With all of this in place, you can finally run the app with this command.
yarn rw dev
You should see something similar to this.
Now we'll add the back-end and database setup to support the front-end we just created.
Setting up the back-end
Go to the
api > db directory and open
schema.prisma. This is where we'll add the schema to save the URL that the user wants for their world. We're going to update the provider to use a Postgres database.
provider = "postgresql"
Then we'll update the existing placeholder schema with our real schema. You can replace the
UserExample schema with the following.
model World { id Int @id @default(autoincrement()) imageName String }
Running the migration
Before we run the migration, we'll need to update the
.env file to use the database instance you want. You can set up Postgres locally. Update your
DATABASE_URL with your credentials. It might look similar to this.
DATABASE_URL=postgres://postgres:admin@localhost:5432/vr_worlds
With the schema in place, we'll be able to do our first migration.
yarn rw prisma migrate dev
This will make Prisma set up our new database. You'll be prompted to name your migration and then it will run. If you check the your Postgres instance now, you should see the new table there.
Set up the GraphQL server
All that's left is to create the GraphQL types and resolvers. The great thing about Redwood is that it has a command to generate these things for us.
yarn rw g sdl world
Now if you go to
api > src > graphql, you'll see
worlds.sdl.js with all of the types you need for GraphQL. Then if you go to
api > src > services, you'll see a new
worlds folder with a few files. The
worlds.js file has the one resolver that we need to fetch the data on the front-end.
That's all! Now you have a full-stack VR app that works.
Finished code
You can check out the finished code in this Code Sandbox or in this GitHub repo in the 'vr-in-redwood` folder.
Conclusion
Hopefully you can see how quickly you can create new VR app in the JavaScript ecosystem. One thing that could be added to this app is the actual ability for users to push their preferred world in. This is a little tricky, but not terribly hard. You can definitely add that functionality as a challenge if you want to get more into VR.
Discussion (0) | https://practicaldev-herokuapp-com.global.ssl.fastly.net/flippedcoding/creating-a-vr-app-with-redwood-1852 | CC-MAIN-2021-39 | refinedweb | 1,325 | 73.27 |
.
10 thoughts on “Installing Cryptography via Pip with MacPorts or Homebrew”
I owe you a beer.
Glad I could help.
THANK YOU!!! I was going crazy before to read your post and I finally solved 🙂
thanks man!
Thanks. It saved my day 😉
Reblogged this on wilane and commented:
Just to make sure this isn’t lost somewhere in cyberspace, thanks.
This post saved yet more lives today. Thanks!
Thanks alot! Just tried it on OS X El Capitan with homebrew and it works like a charm
Good day !
I will be very happy, if you told me: that i doing wrong ?
File “C:\Python27\lib\cryptography\hazmat\bindings\openssl\binding.py”, line 1
3, in
from cryptography.hazmat.bindings._openssl import ffi, lib
ImportError: No module named _openssl
P.S. I think. that file: _openssl.py is absent on my HDD
With best regrets!
You need to install OpenSSL: | https://chriskief.com/2014/03/25/installing-cryptography-via-pip-with-macports-or-homebrew/?shared=email&msg=fail | CC-MAIN-2019-04 | refinedweb | 149 | 85.39 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.