qid
int64
1
74.7M
question
stringlengths
0
58.3k
date
stringlengths
10
10
metadata
sequence
response_j
stringlengths
2
48.3k
response_k
stringlengths
2
40.5k
9,468
Can anyone identify these bricks, which I suspect are LEGO clones. They may be more than 30 years old. I bought them on ebay as Betta Bilda from LEGO/Duplo dealer. Some BB was included, but these are unknown to me, with an extensive BB collection. [![Mystery bricks 1](https://i.stack.imgur.com/1xSNi.jpg)](https://i.stack.imgur.com/1xSNi.jpg) [![Mystery bricks 4](https://i.stack.imgur.com/9pO9E.jpg)](https://i.stack.imgur.com/9pO9E.jpg) The underside of the bricks is hollow and with apparently random numbers - they aren't part numbers because they are different for the same part and sometimes the same for different parts. Window frames have no top studs. [![Mystery bricks 7](https://i.stack.imgur.com/MLvsa.jpg)](https://i.stack.imgur.com/MLvsa.jpg) [![Mystery bricks 8](https://i.stack.imgur.com/QmrFC.jpg)](https://i.stack.imgur.com/QmrFC.jpg) [![Mystery bricks 13](https://i.stack.imgur.com/tceIf.jpg)](https://i.stack.imgur.com/tceIf.jpg) I took a good look through many posts with similar questions, but found nothing that matched. Many Google reverse images searches kept pointing at real LEGO/Duplo, before I noticed this place. Usually I can identify unknowns like this, but these are a real challenge. Edit (Nov 29, 2019) =================== Some comments have asked for clarity on size of these bricks. The majority are close to if not identical to 8 stud LEGO, although there are also 2 and 4 stud bricks too. They clip to Betta Bilda pieces, in a similar way to authentic LEGO. The window frames appear to be confirmed by two comments as 1950-60 LEGO, but additional insight would still be appreciated.
2017/12/05
[ "https://bricks.stackexchange.com/questions/9468", "https://bricks.stackexchange.com", "https://bricks.stackexchange.com/users/9622/" ]
From the LEGO Wikipedia Page "1961 and 1962 saw the introduction of the first Lego wheels, an addition that expanded the potential for building cars, trucks, buses and other vehicles from Lego bricks. Also during this time, the Lego Group introduced toys specifically targeted towards the pre-school market." here is a picture of these first-ever Duplo bricks from the 60's[![enter image description here](https://i.stack.imgur.com/d44N4.jpg)](https://i.stack.imgur.com/d44N4.jpg) look similar?
I don't think they are LEGO due to the holes in the middle of the studs. LEGO pieces also say "LEGO" somewhere on them, so I bet that they are a 3rd party brand.
9,468
Can anyone identify these bricks, which I suspect are LEGO clones. They may be more than 30 years old. I bought them on ebay as Betta Bilda from LEGO/Duplo dealer. Some BB was included, but these are unknown to me, with an extensive BB collection. [![Mystery bricks 1](https://i.stack.imgur.com/1xSNi.jpg)](https://i.stack.imgur.com/1xSNi.jpg) [![Mystery bricks 4](https://i.stack.imgur.com/9pO9E.jpg)](https://i.stack.imgur.com/9pO9E.jpg) The underside of the bricks is hollow and with apparently random numbers - they aren't part numbers because they are different for the same part and sometimes the same for different parts. Window frames have no top studs. [![Mystery bricks 7](https://i.stack.imgur.com/MLvsa.jpg)](https://i.stack.imgur.com/MLvsa.jpg) [![Mystery bricks 8](https://i.stack.imgur.com/QmrFC.jpg)](https://i.stack.imgur.com/QmrFC.jpg) [![Mystery bricks 13](https://i.stack.imgur.com/tceIf.jpg)](https://i.stack.imgur.com/tceIf.jpg) I took a good look through many posts with similar questions, but found nothing that matched. Many Google reverse images searches kept pointing at real LEGO/Duplo, before I noticed this place. Usually I can identify unknowns like this, but these are a real challenge. Edit (Nov 29, 2019) =================== Some comments have asked for clarity on size of these bricks. The majority are close to if not identical to 8 stud LEGO, although there are also 2 and 4 stud bricks too. They clip to Betta Bilda pieces, in a similar way to authentic LEGO. The window frames appear to be confirmed by two comments as 1950-60 LEGO, but additional insight would still be appreciated.
2017/12/05
[ "https://bricks.stackexchange.com/questions/9468", "https://bricks.stackexchange.com", "https://bricks.stackexchange.com/users/9622/" ]
As suggested by @mindstormsboi I contacted LEGO customer services and sent them a link to this question as well as many additional photos. The information was passed to their expert team and the answer that came back was "they believe that these are not LEGO® parts". They were not able to identify them as a known clone type. I feel obliged to accept that as a definite answer, although it leaves unknown who actually manufactured the bricks I have. I will continue research into that question, but elsewhere. The customer service team member also gave me two interesting links to a fan created website with some of the history of LEGO parts, as well as section covering many of the clones and similar brick building sets. I include the two links below, as they may be of interest to some who find this question and answer. <https://www.inverso.pt/legos/> <https://www.inverso.pt/legos/clones/texts/mobitec.htm> Thank you to all who contributed their knowledge, experience or point of view.
From the LEGO Wikipedia Page "1961 and 1962 saw the introduction of the first Lego wheels, an addition that expanded the potential for building cars, trucks, buses and other vehicles from Lego bricks. Also during this time, the Lego Group introduced toys specifically targeted towards the pre-school market." here is a picture of these first-ever Duplo bricks from the 60's[![enter image description here](https://i.stack.imgur.com/d44N4.jpg)](https://i.stack.imgur.com/d44N4.jpg) look similar?
9,468
Can anyone identify these bricks, which I suspect are LEGO clones. They may be more than 30 years old. I bought them on ebay as Betta Bilda from LEGO/Duplo dealer. Some BB was included, but these are unknown to me, with an extensive BB collection. [![Mystery bricks 1](https://i.stack.imgur.com/1xSNi.jpg)](https://i.stack.imgur.com/1xSNi.jpg) [![Mystery bricks 4](https://i.stack.imgur.com/9pO9E.jpg)](https://i.stack.imgur.com/9pO9E.jpg) The underside of the bricks is hollow and with apparently random numbers - they aren't part numbers because they are different for the same part and sometimes the same for different parts. Window frames have no top studs. [![Mystery bricks 7](https://i.stack.imgur.com/MLvsa.jpg)](https://i.stack.imgur.com/MLvsa.jpg) [![Mystery bricks 8](https://i.stack.imgur.com/QmrFC.jpg)](https://i.stack.imgur.com/QmrFC.jpg) [![Mystery bricks 13](https://i.stack.imgur.com/tceIf.jpg)](https://i.stack.imgur.com/tceIf.jpg) I took a good look through many posts with similar questions, but found nothing that matched. Many Google reverse images searches kept pointing at real LEGO/Duplo, before I noticed this place. Usually I can identify unknowns like this, but these are a real challenge. Edit (Nov 29, 2019) =================== Some comments have asked for clarity on size of these bricks. The majority are close to if not identical to 8 stud LEGO, although there are also 2 and 4 stud bricks too. They clip to Betta Bilda pieces, in a similar way to authentic LEGO. The window frames appear to be confirmed by two comments as 1950-60 LEGO, but additional insight would still be appreciated.
2017/12/05
[ "https://bricks.stackexchange.com/questions/9468", "https://bricks.stackexchange.com", "https://bricks.stackexchange.com/users/9622/" ]
As suggested by @mindstormsboi I contacted LEGO customer services and sent them a link to this question as well as many additional photos. The information was passed to their expert team and the answer that came back was "they believe that these are not LEGO® parts". They were not able to identify them as a known clone type. I feel obliged to accept that as a definite answer, although it leaves unknown who actually manufactured the bricks I have. I will continue research into that question, but elsewhere. The customer service team member also gave me two interesting links to a fan created website with some of the history of LEGO parts, as well as section covering many of the clones and similar brick building sets. I include the two links below, as they may be of interest to some who find this question and answer. <https://www.inverso.pt/legos/> <https://www.inverso.pt/legos/clones/texts/mobitec.htm> Thank you to all who contributed their knowledge, experience or point of view.
I don’t exactly know if it is LEGO, But it may be an old version of LEGO. The numbers also could be the date the were made or a factory code.
9,468
Can anyone identify these bricks, which I suspect are LEGO clones. They may be more than 30 years old. I bought them on ebay as Betta Bilda from LEGO/Duplo dealer. Some BB was included, but these are unknown to me, with an extensive BB collection. [![Mystery bricks 1](https://i.stack.imgur.com/1xSNi.jpg)](https://i.stack.imgur.com/1xSNi.jpg) [![Mystery bricks 4](https://i.stack.imgur.com/9pO9E.jpg)](https://i.stack.imgur.com/9pO9E.jpg) The underside of the bricks is hollow and with apparently random numbers - they aren't part numbers because they are different for the same part and sometimes the same for different parts. Window frames have no top studs. [![Mystery bricks 7](https://i.stack.imgur.com/MLvsa.jpg)](https://i.stack.imgur.com/MLvsa.jpg) [![Mystery bricks 8](https://i.stack.imgur.com/QmrFC.jpg)](https://i.stack.imgur.com/QmrFC.jpg) [![Mystery bricks 13](https://i.stack.imgur.com/tceIf.jpg)](https://i.stack.imgur.com/tceIf.jpg) I took a good look through many posts with similar questions, but found nothing that matched. Many Google reverse images searches kept pointing at real LEGO/Duplo, before I noticed this place. Usually I can identify unknowns like this, but these are a real challenge. Edit (Nov 29, 2019) =================== Some comments have asked for clarity on size of these bricks. The majority are close to if not identical to 8 stud LEGO, although there are also 2 and 4 stud bricks too. They clip to Betta Bilda pieces, in a similar way to authentic LEGO. The window frames appear to be confirmed by two comments as 1950-60 LEGO, but additional insight would still be appreciated.
2017/12/05
[ "https://bricks.stackexchange.com/questions/9468", "https://bricks.stackexchange.com", "https://bricks.stackexchange.com/users/9622/" ]
As suggested by @mindstormsboi I contacted LEGO customer services and sent them a link to this question as well as many additional photos. The information was passed to their expert team and the answer that came back was "they believe that these are not LEGO® parts". They were not able to identify them as a known clone type. I feel obliged to accept that as a definite answer, although it leaves unknown who actually manufactured the bricks I have. I will continue research into that question, but elsewhere. The customer service team member also gave me two interesting links to a fan created website with some of the history of LEGO parts, as well as section covering many of the clones and similar brick building sets. I include the two links below, as they may be of interest to some who find this question and answer. <https://www.inverso.pt/legos/> <https://www.inverso.pt/legos/clones/texts/mobitec.htm> Thank you to all who contributed their knowledge, experience or point of view.
I don't think they are LEGO due to the holes in the middle of the studs. LEGO pieces also say "LEGO" somewhere on them, so I bet that they are a 3rd party brand.
54,813,381
I would like to remove all non-alphanumeric characters except brackets and what's between them in python. For example : ``` My son's birthday [[David | David Smith]] $$ (is) "today" 2019 ][ ``` become ``` My son s birthday [[David | David Smith]] is today 2019 ``` Here's my function for now : ``` def clean(texte): return re.sub(r"[^0-9a-zA-Z]+", " ", texte).lower() ``` It replace all non-alphanumeric like I want but it replace the square brackets and the pipe inside. I don't know how to add new regex in the sub method and adding a new condition.
2019/02/21
[ "https://Stackoverflow.com/questions/54813381", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7402246/" ]
Instead of replacing you might select what you want to keep using an [alternation](https://www.regular-expressions.info/alternation.html) to either match from `[[` till `]]` or `|` match 1+ times a word character `\w+` and then join the parts back to a string. ``` \[\[[^]]+\]\]|\w+ ``` That will match * `\[\[[^]]+\]\]` match from `[[` till `]]` using a negated character class * `|` Or * `\w+` Match 1+ times a word character [Regex demo](https://regex101.com/r/UeJh7n/1) | [Python demo](https://ideone.com/FykbLA) For example: ``` import re regex = r"\[\[[^]]+\]\]|\w+" test_str = "My son's birthday [[David | David Smith]] $$ (is) \"today\" 2019 ][" res = re.findall(regex, test_str) print(' '.join(res)) # My son s birthday [[David | David Smith]] is today 2019 ```
``` import re x = "My son's birthday [[David | David Smith]] $$ (is) \"today\" 2019 ][" def clean(texte): return re.sub(r"[^\[\[[^\]\]+\]\]|\w]+", " ", texte).lower() print(clean(x)) >>> 'my son s birthday [[david | david smith]] is today 2019 ][' ``` Then you could do a split of "]" and keep the first index.
61,451,684
I am working on a slider carousel with bootstrap. My 'active' image loads, but the controls and the slide don't work. As I am following a tutorial, I thought this would be an easy exercise for practice, but I've hit a snag. For anyone concerned about the boostrap.css link I posted the entire html doc ... but its functionality is working well otherwise, so I don't believe that is the issue here. ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" name="" content="Trey's Personal Website."> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Trey Coggins | Personal Website</title> <script type="text/javascript" src="script/index.js"></script> <link rel="stylesheet" type="text/css" href="styles/bootstrap/css/bootstrap.min.css"> <link rel="stylesheet" type="text/css" href="styles/index-style.css"> </head> <body> <header> <nav class="navbar navbar-expand-md navbar-dark bg-dark"> <a class="navbar-brand" href="">Trey Coggins</a> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse"> <span class="navbar-toggler-icon"></span></button> <div class="collapse navbar-collapse" id="navbarCollapse"> <ul class="navbar-nav"> <li class="nav-item"> <a class="nav-link" href="">Home</a> </li> <li class="nav-item"> <a class="nav-link" href="">About</a> </li> <li class="nav-item"> <a class="nav-link" href="">Contact</a> </li> </ul> </div> </nav> <div id="carouselControls" class="carousel slide" data-ride="carousel"> <div class="carousel-inner"> <div class="carousel-item active"> <img class="d-block w-100" src="img/bricks.jpg" alt=""> <div class="carousel-caption"> <h2>Let's build something together!</h2> </div> </div> <div class="carousel-item"> <img class="d-block w-100" src="img/woods.jpg" alt=""> <div class="carousel-caption"> <h2>Take a walk in the woods</h2> </div> </div> <div class="carousel-item"> <img class="d-block w-100" src="img/stone.jpg" alt=""> <div class="carousel-caption"> <h2>Elevate yourself to the next level</h2> </div> </div> </div> <a class="carousel-control-prev" href="#carouselControls" role="button" data-slide="prev"> <span class="carousel-control-prev-icon" aria-hidden="true"></span> <span class="sr-only">Previous</span> </a> <a class="carousel-control-next" href="#carouselControls" role="button" data-slide="next"> <span class="carousel-control-next-icon" aria-hidden="true"></span> <span class="sr-only">Next</span> </a> </div> </header> <div class="container text-center"> <div class="row"> <div class="col-md-4"> <img class="rounded-circle" src="img/trey-court-headshot.jpg" alt="Trey & Courtney"> <h2>Trey & Courtney</h2> <p>She's the love of my life!</p> <p><a class="btn btn-secondary" href="#" role="button">See more &raquo;</a></p> </div> <div class="col-md-4"> <img class="rounded-circle" src="img/tootsie-smile.jpg" alt="Mama Tootsie"> <h2>Bodhi & Tootsie</h2> <p>These two keep us young!</p> <p><a class="btn btn-secondary" href="#" role="button">See more &raquo;</a></p> </div> <div class="col-md-4"> <img class="rounded-circle" src="img/royal-hearts.jpg" alt="Royal Flush"> <h2>Poker</h2> <p>Join the action!</p> <p><a class="btn btn-secondary" href="#" role="button">See more &raquo;</a></p> </div> </div> </div> </body> </html> ```
2020/04/27
[ "https://Stackoverflow.com/questions/61451684", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
You have to return the map of logos which is not happening in your current code. Hence you are getting only one Logos component. ``` import React from 'react'; import { home } from '../homeObj'; const Logos = ({ title, img, img2, img3, key }) => { return ( <> <div className={styles.anaShif} key={key}> <h2 className={styles.h2}> {title} </h2> <div className={styles.logos}> <img id={img.id} src={img} alt={img.alt} className={styles.img} srcSet={`${img2} 2x, ${img3} 3x`} /> </div> </div> </> ); }; function Trusted() { const logosIndex = home.findIndex((obj) => obj.id === 'logos'); const logos = home[logosIndex].logos.map(({ id, alt, src }) => { return <Logos key={id} id={id} title={home[logosIndex].title} img={src} />; }); return logos; } export default Trusted; ```
You not only need to map over `home` but also the `logos` array with-in each `home` object. Also in your case, you don't need the third arg which is the entire array. **Simplify your code like this:** ```js home.map((_objects, i) => { if (_objects.id === "logos") { return ( <> { _objects.logos.map(logo => ( <Logos key={logo.id} id={logo.id} title={logo.title} img={logo.src} /> )) } </> ); }else { return null } } ```
61,451,684
I am working on a slider carousel with bootstrap. My 'active' image loads, but the controls and the slide don't work. As I am following a tutorial, I thought this would be an easy exercise for practice, but I've hit a snag. For anyone concerned about the boostrap.css link I posted the entire html doc ... but its functionality is working well otherwise, so I don't believe that is the issue here. ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" name="" content="Trey's Personal Website."> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Trey Coggins | Personal Website</title> <script type="text/javascript" src="script/index.js"></script> <link rel="stylesheet" type="text/css" href="styles/bootstrap/css/bootstrap.min.css"> <link rel="stylesheet" type="text/css" href="styles/index-style.css"> </head> <body> <header> <nav class="navbar navbar-expand-md navbar-dark bg-dark"> <a class="navbar-brand" href="">Trey Coggins</a> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse"> <span class="navbar-toggler-icon"></span></button> <div class="collapse navbar-collapse" id="navbarCollapse"> <ul class="navbar-nav"> <li class="nav-item"> <a class="nav-link" href="">Home</a> </li> <li class="nav-item"> <a class="nav-link" href="">About</a> </li> <li class="nav-item"> <a class="nav-link" href="">Contact</a> </li> </ul> </div> </nav> <div id="carouselControls" class="carousel slide" data-ride="carousel"> <div class="carousel-inner"> <div class="carousel-item active"> <img class="d-block w-100" src="img/bricks.jpg" alt=""> <div class="carousel-caption"> <h2>Let's build something together!</h2> </div> </div> <div class="carousel-item"> <img class="d-block w-100" src="img/woods.jpg" alt=""> <div class="carousel-caption"> <h2>Take a walk in the woods</h2> </div> </div> <div class="carousel-item"> <img class="d-block w-100" src="img/stone.jpg" alt=""> <div class="carousel-caption"> <h2>Elevate yourself to the next level</h2> </div> </div> </div> <a class="carousel-control-prev" href="#carouselControls" role="button" data-slide="prev"> <span class="carousel-control-prev-icon" aria-hidden="true"></span> <span class="sr-only">Previous</span> </a> <a class="carousel-control-next" href="#carouselControls" role="button" data-slide="next"> <span class="carousel-control-next-icon" aria-hidden="true"></span> <span class="sr-only">Next</span> </a> </div> </header> <div class="container text-center"> <div class="row"> <div class="col-md-4"> <img class="rounded-circle" src="img/trey-court-headshot.jpg" alt="Trey & Courtney"> <h2>Trey & Courtney</h2> <p>She's the love of my life!</p> <p><a class="btn btn-secondary" href="#" role="button">See more &raquo;</a></p> </div> <div class="col-md-4"> <img class="rounded-circle" src="img/tootsie-smile.jpg" alt="Mama Tootsie"> <h2>Bodhi & Tootsie</h2> <p>These two keep us young!</p> <p><a class="btn btn-secondary" href="#" role="button">See more &raquo;</a></p> </div> <div class="col-md-4"> <img class="rounded-circle" src="img/royal-hearts.jpg" alt="Royal Flush"> <h2>Poker</h2> <p>Join the action!</p> <p><a class="btn btn-secondary" href="#" role="button">See more &raquo;</a></p> </div> </div> </div> </body> </html> ```
2020/04/27
[ "https://Stackoverflow.com/questions/61451684", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
You have to return the map of logos which is not happening in your current code. Hence you are getting only one Logos component. ``` import React from 'react'; import { home } from '../homeObj'; const Logos = ({ title, img, img2, img3, key }) => { return ( <> <div className={styles.anaShif} key={key}> <h2 className={styles.h2}> {title} </h2> <div className={styles.logos}> <img id={img.id} src={img} alt={img.alt} className={styles.img} srcSet={`${img2} 2x, ${img3} 3x`} /> </div> </div> </> ); }; function Trusted() { const logosIndex = home.findIndex((obj) => obj.id === 'logos'); const logos = home[logosIndex].logos.map(({ id, alt, src }) => { return <Logos key={id} id={id} title={home[logosIndex].title} img={src} />; }); return logos; } export default Trusted; ```
Without much if else, you can also write like this. ```js home.filter((_objects, i) => _objects.id === 'logos') .map(({logos})=>logos.map(logo=> <Logos key={logo.id} {...logo} />)) ```
381,875
WordPress end points default rules, ``` GET ----> PUBLIC POST, PUT, DELETE ----> AUTH ``` How can I force authentication the WordPress REST API `GET` method requests?
2021/01/21
[ "https://wordpress.stackexchange.com/questions/381875", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/198965/" ]
You can't really apply authentication based directly on whether the request is GET or otherwise, but can forcefully apply authentication requirements globally in that manner, if you like. I've been quite verbose with the code to illustrate what's happening: ```php add_filter( 'rest_authentication_errors', function ( $error ) { /** * If it's a WP_Error, leave it as is. Authentication failed anyway * * If it's true, then authentication has already succeeded. Leave it as-is. */ if ( strtolower( $_SERVER[ 'REQUEST_METHOD' ] ) === 'get' && !is_wp_error( $error ) && $error !== true ) { if ( !is_user_logged_in() ) { $error = new \WP_Error( 'User not logged-in' ); } } return $error; }, 11 ); ``` Assumptions: * PHP is at least version 5.3 * We're only testing `GET` requests * If an authentication error has been met before this filter is executed, then we leave the error as-is. * If there is no error, and in-fact it's set to `true`, then this means authentication has already succeeded and there's not need to block anything. * We're only testing whether or not the user making the request is logged-in i.e. is authenticated with WordPress.
Good Question and not that easy to do propperly (took me 1 week to figure that out). Then I found 2 good summaries in WordPress docs: [Home / REST API Handbook / Extending the REST API / Routes and Endpoints](https://developer.wordpress.org/rest-api/extending-the-rest-api/routes-and-endpoints/) [Home / REST API Handbook / Extending the REST API / Adding Custom Endpoints](https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/) There I found out how to use **namespaces**, **routes** and **permission\_callback** correctly. Critical part was to add the **Permission Callback** into the `function.php` of your theme. ```php /** * This is our callback function to return (GET) our data. * * @param WP_REST_Request $request This function accepts a rest request to process data. */ function get_your_data($request) { global $wpdb; $yourdata = $wpdb->get_results("SELECT * FROM your_custom_table"); return rest_ensure_response( $yourdata ); }; /** * This is our callback function to insert (POST) new data record. * * @param WP_REST_Request $request This function accepts a rest request to process data. */ function insert_your_data($request) { global $wpdb; $contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : ''; if ($contentType === "application/json") { $content = trim(file_get_contents("php://input")); $decoded = json_decode($content, true); $newrecord = $wpdb->insert( 'your_custom_table', array( 'column_1' => $decoded['column_1'], 'column_2' => $decoded['column_2'])); }; if($newrecord){ return rest_ensure_response($newrecord); }else{ //something gone wrong return rest_ensure_response('failed'); }; header("Content-Type: application/json; charset=UTF-8"); }; /** * This is our callback function to update (PUT) a data record. * * @param WP_REST_Request $request This function accepts a rest request to process data. */ function update_your_data($request) { global $wpdb; $contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : ''; if ($contentType === "application/json") { $content = trim(file_get_contents("php://input")); $decoded = json_decode($content, true); $updatedrecord = $wpdb->update( 'your_custom_table', array( 'column_1' => $decoded['column_1'], 'column_2' => $decoded['column_2']), array('id' => $decoded['id']), array( '%s' )); }; if($updatedrecord){ return rest_ensure_response($updatedrecord); }else{ //something gone wrong return rest_ensure_response('failed'); }; header("Content-Type: application/json; charset=UTF-8"); }; // Permission Callback // 'ypp' is the Prefix I chose (ypp = Your Private Page) function ypp_get_private_data_permissions_check() { // Restrict endpoint to browsers that have the wp-postpass_ cookie. if ( !isset($_COOKIE['wp-postpass_'. COOKIEHASH] )) { return new WP_Error( 'rest_forbidden', esc_html__( 'OMG you can not create or edit private data.', 'my-text-domain' ), array( 'status' => 401 ) ); }; // This is a black-listing approach. You could alternatively do this via white-listing, by returning false here and changing the permissions check. return true; }; // And then add the permission_callback to your POST and PUT routes: add_action('rest_api_init', function() { /** * Register here your custom routes for your CRUD functions */ register_rest_route( 'your_private_page/v1', '/data', array( array( 'methods' => WP_REST_Server::READABLE, 'callback' => 'get_your_data', // Always allow. 'permission_callback' => '__return_true' // <-- you can protect GET as well if your like ), array( 'methods' => WP_REST_Server::CREATABLE, 'callback' => 'insert_your_data', // Here we register our permissions callback. The callback is fired before the main callback to check if the current user can access the endpoint. 'permission_callback' => 'ypp_get_private_data_permissions_check', // <-- that was the missing part ), array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'update_your_data', // Here we register our permissions callback. The callback is fired before the main callback to check if the current user can access the endpoint. 'permission_callback' => 'ypp_get_private_data_permissions_check', // <-- that was the missing part ), )); }); ``` If you like, I posted a Question (similar issue to yours, but for custom routes) and then my findings in the answer. **Full story** with complete code at: [How to force Authentication on REST API for Password protected page using custom table and fetch() without Plugin](https://wordpress.stackexchange.com/questions/391515/how-to-force-authentication-on-rest-api-for-password-protected-page-using-custom/391516#391516) Hope this helps a little.
38,401
Towards the end, when Ripley finally ... > > blows it out of the damned airlock! > > > She mutters a little song that seems to go ``` .... you .... are ... (my) ... lucky ..... star .... .... lucky-lucky-lucky .... ``` or something. What is that song?
2013/07/22
[ "https://scifi.stackexchange.com/questions/38401", "https://scifi.stackexchange.com", "https://scifi.stackexchange.com/users/3007/" ]
I think this is it: *You are my lucky star* from Broadway Melody, 1936. Easier to follow the lyrics in this earlier recording: And this version actually has the oft-omitted "Verse":
Debbie Reynolds - You Are My Lucky Star. I very much believe it's from the film "Singing in the Rain", Hollywood, from just after WW2. Ripley repeats it, as one would do, to concentrate on the job at hand rather than have her mind freeze or frazzle from the terror implicit in her situation. Lovely refrain and obviously someone believes it'll stand the test of time.
72,351,446
I can not figure out my mistake. Can someone help me? We are supposed to create the lists outside of the function. then create an empty list inside a function. We should return 9 different names. ``` first_names = ["Gabriel", "Reinhard", "Siebren"] last_names = ["Colomar", "Chase", "Vaswani"] def name_generator(first_names, last_names): full_name= () import random for _ in range(9): full_name=random.choice(first_names)+" "+random.choice(last_names) full_name.append(full_name) group_string = ", ".join(full_name) ```
2022/05/23
[ "https://Stackoverflow.com/questions/72351446", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19114904/" ]
The problem is that you're using a variable `full_name` twice: once as a string to store a new name in, and once as the list. This is closer to what you want: ``` import random first_names = ["Gabriel", "Reinhard", "Siebren"] last_names = ["Colomar", "Chase", "Vaswani"] full_names = [] for _ in range(9): new_name=random.choice(first_names)+" "+random.choice(last_names) full_names.append(new_name) group_string = ", ".join(full_names) ``` I'll note that I'd probably use `full_names` as plural version of the variable name too since it's a list of multiple things.
This makes a list of all possible full names and then picks from what hasn't been taken yet one by one. ``` remaining = [(a,b) for a in range(len(first_names)) for b in range(len(last_names))] full_name = [] while len(remaining)>0: (a,b) = random.choice(remaining) full_name.append(first_names[a] + " " + last_names[b]) remaining.remove((a,b)) ```
70,676,777
This useEffect is rendering one time if dependency array is empty but multiple times if i put folderRef in dependency array. I want to render the component only when I add or delete some folder. Please Help ``` import React, { useState, useEffect , useRef } from "react"; import { db } from "../firebase"; import { collection, getDocs } from "firebase/firestore"; import FolderData from "./FolderData"; function ShowFolder(props) { const [folders, setFolders] = useState([]); const folderRef = useRef(collection(db, "folders")); useEffect(() => { const getData = async () => { const data = await getDocs(folderRef.current); const folderData = data.docs.map((doc) => { return { id: doc.id, data: doc.data() }; }); console.log(folderData); setFolders(folderData); }; getData(); }, [folderRef]); return ( <div className="container md:px-4 mx-auto py-10"> <div className="md:grid lg:grid-cols-6 md:grid-cols-3 mlg:grid-cols-3 md:gap-10 space-y-6 md:space-y-0 px-1 md:px-0 mx-auto"> {folders.map((folder) => { return ( <div key={folder.id}> {folder.data.userId === props.userId && ( <div> <FolderData key={folder.id} folder={folder} /> </div> )} </div> ); })} </div> </div> ); } export default ShowFolder; ```
2022/01/12
[ "https://Stackoverflow.com/questions/70676777", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17878146/" ]
You redeclare `folderRef` each render cycle, so if you include it in the `useEffect` hook's dependency array it will trigger render looping. If you don't refer to `folderRef` anywhere else in the component then move it *into* the `useEffect` hook callback to remove it as an external dependnecy. ``` const [folders, setFolders] = useState([]); useEffect(() => { const folderRef = collection(db, "folders"); const getData = async () => { const data = await getDocs(folderRef); const folderData = data.docs.map((doc) => { return { id: doc.id, data: doc.data() }; }); console.log(folderData); setFolders(folderData); }; getData(); }, []); ``` Or store it in a React ref so it can be safely referred to as a stable reference. ``` const [folders, setFolders] = useState([]); const folderRef = useRef(collection(db, "folders")); useEffect(() => { const getData = async () => { const data = await getDocs(folderRef.current); const folderData = data.docs.map((doc) => { return { id: doc.id, data: doc.data() }; }); console.log(folderData); setFolders(folderData); }; getData(); }, [folderRef]); ``` ### Update I've gathered that you are updating the `folders` collection elsewhere in your app and want this component to "listen" for these changes. For this you can implement an `onSnapshot` listener. It may look similar to the following: ``` const [folders, setFolders] = useState([]); useEffect(() => { const unsubscribe = onSnapshot( collection(db, "folders"), (snapshot) => { const folderData = []; snapshot.forEach((doc) => { folderData.push({ id: doc.id, data: doc.data(), }); }); setFolders(folderData); }, ); // Return cleanup function to stop listening to changes // on component unmount return unsubscribe; }, []); ```
I think most Probably your useState function is like ``` const[folderRef , setFolders]=useState(Your Initial Value); ``` if this is the case then when ever you perform ``` useEffect(() => { setFolder(Setting Anything Here) .... },[folderRef]) ``` React starts an infinity loop coz every time you use setFolder the FolderRef gets updated and the useEffect is forced to run again and it won't Stop . use something like ``` const[folderRef , setFolders]=useState(Your Initial Value); const[isLoading, setIsLoading]=useState(true); useEffect(() => { setFolder(Setting Anything Here) setIsLoading(false) .... },[]) ... return ( { isLoading ? "Run the code you wanna run " : null } ) ```
62,747,664
Good day, I'm currently experiencing a weird phenomena, this morning as I open the dbgview application an error message popped out(kernel related), couldn't remember much about the details. Although the dbgview was showing at the task bar but as I clicked on it, it will jump out to no where. It was as if I have 2nd monitor and it jump out to other screen. * I checked with 2nd monitor and it was not there.. I tried to install the latest version. System recovery back to few days before which was still in working condition. But it doesn't help. Hope someone here could show me some clue. 07/07/2020 I discovered it might not related to debugview this app. As I opened up task bar and select the debugview application and maximize the window size it is showing up. However as long as I click restore button at the right top corner of the app it flew out to the universe again.... Thank you
2020/07/06
[ "https://Stackoverflow.com/questions/62747664", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4608323/" ]
DbgView remembers its last position, so what likely happened is that you disconnected a monitor while DbgView was running on it, or maybe you accidentally dragged DbgView offscreen, and now it opens in a position that's no longer visible. Try either of the following. * With DbgView running, `Alt-TAB` to it then press `Alt-Space`, `M` (which opens the system menu and selects Move). While the "move" cursor is showing, use the arrow keys to bring the window back onto the active screen. * With DbgView closed, run `regedit`, navigate to `HKCU\Software\Sysinternals\DbgView` and delete (or rename) the `Settings` value, then run DbgView again. Since it no longer finds the old saved position in the registry, it will now open in the default position on the active monitor.
Try this: * start dbgview * hold the left 'Windows key' * while still holding the windo
57,155,638
I have a line chart displayed on a webpage with chart.js but my time data is in UTC. I would like to convert it to the Denver timezone for display on the graph. Chart.js has a [luxon adapter](https://github.com/chartjs/chartjs-adapter-luxon) but I have no idea how to use it. I have included the following scripts: ``` <script src="./chart.js/dist/Chart.bundle.js"></script> <script src="https://cdn.jsdelivr.net/npm/luxon@1.15.0"></script> <script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-luxon@0.2.0"></script> ``` My time data formatted as a json string: ``` var data = [{"x":"2019-07-23 01:16:11","y":83.97},{"x":"2019-07-23 01:07:13","y":82.74},{"x":"2019-07-23 00:58:21","y":83.86}, ... ``` And here are my chart "Options": ```js options: { scales: { xAxes: [{ type: 'time', distribution: 'series', }] } } ``` So where and how do I implement a timezone definition? I have also looked through the [Luxon timezone documentation.](https://moment.github.io/luxon/docs/manual/tour.html#time-zones)
2019/07/23
[ "https://Stackoverflow.com/questions/57155638", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11821892/" ]
You can simply generate the divisor and quotient randomly and then compute the dividend. Note that the divisor must be nonzero (thanks to @o11c's remind).
I think that @Vira has the right idea. If you want to generate `a` and `b` such that `a = b * q + r` with `r=0`, the good way to do it is : 1. Generate `b` randomly 2. Generate `q` randomly 3. Compute `a = b * q` 4. Ask to compute the division : `a` divided by `b`. The answer is `q`.
57,155,638
I have a line chart displayed on a webpage with chart.js but my time data is in UTC. I would like to convert it to the Denver timezone for display on the graph. Chart.js has a [luxon adapter](https://github.com/chartjs/chartjs-adapter-luxon) but I have no idea how to use it. I have included the following scripts: ``` <script src="./chart.js/dist/Chart.bundle.js"></script> <script src="https://cdn.jsdelivr.net/npm/luxon@1.15.0"></script> <script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-luxon@0.2.0"></script> ``` My time data formatted as a json string: ``` var data = [{"x":"2019-07-23 01:16:11","y":83.97},{"x":"2019-07-23 01:07:13","y":82.74},{"x":"2019-07-23 00:58:21","y":83.86}, ... ``` And here are my chart "Options": ```js options: { scales: { xAxes: [{ type: 'time', distribution: 'series', }] } } ``` So where and how do I implement a timezone definition? I have also looked through the [Luxon timezone documentation.](https://moment.github.io/luxon/docs/manual/tour.html#time-zones)
2019/07/23
[ "https://Stackoverflow.com/questions/57155638", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11821892/" ]
1) Take any non-zero randomized Divisor (x). // say 5 2) Take any randomized temporary Dividend (D). // say 24 3) Calculate R = D % x; // => 4 4) return Dividend as (D -x ) // return 20 Now, your dividend will always be perfectly divisible by the divisor.
I think that @Vira has the right idea. If you want to generate `a` and `b` such that `a = b * q + r` with `r=0`, the good way to do it is : 1. Generate `b` randomly 2. Generate `q` randomly 3. Compute `a = b * q` 4. Ask to compute the division : `a` divided by `b`. The answer is `q`.
57,155,638
I have a line chart displayed on a webpage with chart.js but my time data is in UTC. I would like to convert it to the Denver timezone for display on the graph. Chart.js has a [luxon adapter](https://github.com/chartjs/chartjs-adapter-luxon) but I have no idea how to use it. I have included the following scripts: ``` <script src="./chart.js/dist/Chart.bundle.js"></script> <script src="https://cdn.jsdelivr.net/npm/luxon@1.15.0"></script> <script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-luxon@0.2.0"></script> ``` My time data formatted as a json string: ``` var data = [{"x":"2019-07-23 01:16:11","y":83.97},{"x":"2019-07-23 01:07:13","y":82.74},{"x":"2019-07-23 00:58:21","y":83.86}, ... ``` And here are my chart "Options": ```js options: { scales: { xAxes: [{ type: 'time', distribution: 'series', }] } } ``` So where and how do I implement a timezone definition? I have also looked through the [Luxon timezone documentation.](https://moment.github.io/luxon/docs/manual/tour.html#time-zones)
2019/07/23
[ "https://Stackoverflow.com/questions/57155638", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11821892/" ]
I think that @Vira has the right idea. If you want to generate `a` and `b` such that `a = b * q + r` with `r=0`, the good way to do it is : 1. Generate `b` randomly 2. Generate `q` randomly 3. Compute `a = b * q` 4. Ask to compute the division : `a` divided by `b`. The answer is `q`.
you can generate a number to be divided as [random number1]x[random number2] . The problem will then be [random number1]x[random number2] divide by [random number1]
57,155,638
I have a line chart displayed on a webpage with chart.js but my time data is in UTC. I would like to convert it to the Denver timezone for display on the graph. Chart.js has a [luxon adapter](https://github.com/chartjs/chartjs-adapter-luxon) but I have no idea how to use it. I have included the following scripts: ``` <script src="./chart.js/dist/Chart.bundle.js"></script> <script src="https://cdn.jsdelivr.net/npm/luxon@1.15.0"></script> <script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-luxon@0.2.0"></script> ``` My time data formatted as a json string: ``` var data = [{"x":"2019-07-23 01:16:11","y":83.97},{"x":"2019-07-23 01:07:13","y":82.74},{"x":"2019-07-23 00:58:21","y":83.86}, ... ``` And here are my chart "Options": ```js options: { scales: { xAxes: [{ type: 'time', distribution: 'series', }] } } ``` So where and how do I implement a timezone definition? I have also looked through the [Luxon timezone documentation.](https://moment.github.io/luxon/docs/manual/tour.html#time-zones)
2019/07/23
[ "https://Stackoverflow.com/questions/57155638", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11821892/" ]
x/y = z y\*z = x Generate y and z as integers, then calculate x.
you can generate a number to be divided as [random number1]x[random number2] . The problem will then be [random number1]x[random number2] divide by [random number1]
57,155,638
I have a line chart displayed on a webpage with chart.js but my time data is in UTC. I would like to convert it to the Denver timezone for display on the graph. Chart.js has a [luxon adapter](https://github.com/chartjs/chartjs-adapter-luxon) but I have no idea how to use it. I have included the following scripts: ``` <script src="./chart.js/dist/Chart.bundle.js"></script> <script src="https://cdn.jsdelivr.net/npm/luxon@1.15.0"></script> <script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-luxon@0.2.0"></script> ``` My time data formatted as a json string: ``` var data = [{"x":"2019-07-23 01:16:11","y":83.97},{"x":"2019-07-23 01:07:13","y":82.74},{"x":"2019-07-23 00:58:21","y":83.86}, ... ``` And here are my chart "Options": ```js options: { scales: { xAxes: [{ type: 'time', distribution: 'series', }] } } ``` So where and how do I implement a timezone definition? I have also looked through the [Luxon timezone documentation.](https://moment.github.io/luxon/docs/manual/tour.html#time-zones)
2019/07/23
[ "https://Stackoverflow.com/questions/57155638", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11821892/" ]
I think that @Vira has the right idea. If you want to generate `a` and `b` such that `a = b * q + r` with `r=0`, the good way to do it is : 1. Generate `b` randomly 2. Generate `q` randomly 3. Compute `a = b * q` 4. Ask to compute the division : `a` divided by `b`. The answer is `q`.
GZ0 has offered a great solution, one that is likely the most elegant. As an alternative, you could use the modulo operator, %. ``` if num1 % num2 == 0: return num1, num2 ``` You can use that to generate a list of a hundred or a thousand pairs to use in your program.
57,155,638
I have a line chart displayed on a webpage with chart.js but my time data is in UTC. I would like to convert it to the Denver timezone for display on the graph. Chart.js has a [luxon adapter](https://github.com/chartjs/chartjs-adapter-luxon) but I have no idea how to use it. I have included the following scripts: ``` <script src="./chart.js/dist/Chart.bundle.js"></script> <script src="https://cdn.jsdelivr.net/npm/luxon@1.15.0"></script> <script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-luxon@0.2.0"></script> ``` My time data formatted as a json string: ``` var data = [{"x":"2019-07-23 01:16:11","y":83.97},{"x":"2019-07-23 01:07:13","y":82.74},{"x":"2019-07-23 00:58:21","y":83.86}, ... ``` And here are my chart "Options": ```js options: { scales: { xAxes: [{ type: 'time', distribution: 'series', }] } } ``` So where and how do I implement a timezone definition? I have also looked through the [Luxon timezone documentation.](https://moment.github.io/luxon/docs/manual/tour.html#time-zones)
2019/07/23
[ "https://Stackoverflow.com/questions/57155638", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11821892/" ]
x/y = z y\*z = x Generate y and z as integers, then calculate x.
1) Take any non-zero randomized Divisor (x). // say 5 2) Take any randomized temporary Dividend (D). // say 24 3) Calculate R = D % x; // => 4 4) return Dividend as (D -x ) // return 20 Now, your dividend will always be perfectly divisible by the divisor.
57,155,638
I have a line chart displayed on a webpage with chart.js but my time data is in UTC. I would like to convert it to the Denver timezone for display on the graph. Chart.js has a [luxon adapter](https://github.com/chartjs/chartjs-adapter-luxon) but I have no idea how to use it. I have included the following scripts: ``` <script src="./chart.js/dist/Chart.bundle.js"></script> <script src="https://cdn.jsdelivr.net/npm/luxon@1.15.0"></script> <script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-luxon@0.2.0"></script> ``` My time data formatted as a json string: ``` var data = [{"x":"2019-07-23 01:16:11","y":83.97},{"x":"2019-07-23 01:07:13","y":82.74},{"x":"2019-07-23 00:58:21","y":83.86}, ... ``` And here are my chart "Options": ```js options: { scales: { xAxes: [{ type: 'time', distribution: 'series', }] } } ``` So where and how do I implement a timezone definition? I have also looked through the [Luxon timezone documentation.](https://moment.github.io/luxon/docs/manual/tour.html#time-zones)
2019/07/23
[ "https://Stackoverflow.com/questions/57155638", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11821892/" ]
x/y = z y\*z = x Generate y and z as integers, then calculate x.
I think that @Vira has the right idea. If you want to generate `a` and `b` such that `a = b * q + r` with `r=0`, the good way to do it is : 1. Generate `b` randomly 2. Generate `q` randomly 3. Compute `a = b * q` 4. Ask to compute the division : `a` divided by `b`. The answer is `q`.
57,155,638
I have a line chart displayed on a webpage with chart.js but my time data is in UTC. I would like to convert it to the Denver timezone for display on the graph. Chart.js has a [luxon adapter](https://github.com/chartjs/chartjs-adapter-luxon) but I have no idea how to use it. I have included the following scripts: ``` <script src="./chart.js/dist/Chart.bundle.js"></script> <script src="https://cdn.jsdelivr.net/npm/luxon@1.15.0"></script> <script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-luxon@0.2.0"></script> ``` My time data formatted as a json string: ``` var data = [{"x":"2019-07-23 01:16:11","y":83.97},{"x":"2019-07-23 01:07:13","y":82.74},{"x":"2019-07-23 00:58:21","y":83.86}, ... ``` And here are my chart "Options": ```js options: { scales: { xAxes: [{ type: 'time', distribution: 'series', }] } } ``` So where and how do I implement a timezone definition? I have also looked through the [Luxon timezone documentation.](https://moment.github.io/luxon/docs/manual/tour.html#time-zones)
2019/07/23
[ "https://Stackoverflow.com/questions/57155638", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11821892/" ]
1) Take any non-zero randomized Divisor (x). // say 5 2) Take any randomized temporary Dividend (D). // say 24 3) Calculate R = D % x; // => 4 4) return Dividend as (D -x ) // return 20 Now, your dividend will always be perfectly divisible by the divisor.
You can simply generate the divisor and quotient randomly and then compute the dividend. Note that the divisor must be nonzero (thanks to @o11c's remind).
57,155,638
I have a line chart displayed on a webpage with chart.js but my time data is in UTC. I would like to convert it to the Denver timezone for display on the graph. Chart.js has a [luxon adapter](https://github.com/chartjs/chartjs-adapter-luxon) but I have no idea how to use it. I have included the following scripts: ``` <script src="./chart.js/dist/Chart.bundle.js"></script> <script src="https://cdn.jsdelivr.net/npm/luxon@1.15.0"></script> <script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-luxon@0.2.0"></script> ``` My time data formatted as a json string: ``` var data = [{"x":"2019-07-23 01:16:11","y":83.97},{"x":"2019-07-23 01:07:13","y":82.74},{"x":"2019-07-23 00:58:21","y":83.86}, ... ``` And here are my chart "Options": ```js options: { scales: { xAxes: [{ type: 'time', distribution: 'series', }] } } ``` So where and how do I implement a timezone definition? I have also looked through the [Luxon timezone documentation.](https://moment.github.io/luxon/docs/manual/tour.html#time-zones)
2019/07/23
[ "https://Stackoverflow.com/questions/57155638", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11821892/" ]
1) Take any non-zero randomized Divisor (x). // say 5 2) Take any randomized temporary Dividend (D). // say 24 3) Calculate R = D % x; // => 4 4) return Dividend as (D -x ) // return 20 Now, your dividend will always be perfectly divisible by the divisor.
GZ0 has offered a great solution, one that is likely the most elegant. As an alternative, you could use the modulo operator, %. ``` if num1 % num2 == 0: return num1, num2 ``` You can use that to generate a list of a hundred or a thousand pairs to use in your program.
57,155,638
I have a line chart displayed on a webpage with chart.js but my time data is in UTC. I would like to convert it to the Denver timezone for display on the graph. Chart.js has a [luxon adapter](https://github.com/chartjs/chartjs-adapter-luxon) but I have no idea how to use it. I have included the following scripts: ``` <script src="./chart.js/dist/Chart.bundle.js"></script> <script src="https://cdn.jsdelivr.net/npm/luxon@1.15.0"></script> <script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-luxon@0.2.0"></script> ``` My time data formatted as a json string: ``` var data = [{"x":"2019-07-23 01:16:11","y":83.97},{"x":"2019-07-23 01:07:13","y":82.74},{"x":"2019-07-23 00:58:21","y":83.86}, ... ``` And here are my chart "Options": ```js options: { scales: { xAxes: [{ type: 'time', distribution: 'series', }] } } ``` So where and how do I implement a timezone definition? I have also looked through the [Luxon timezone documentation.](https://moment.github.io/luxon/docs/manual/tour.html#time-zones)
2019/07/23
[ "https://Stackoverflow.com/questions/57155638", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11821892/" ]
You can simply generate the divisor and quotient randomly and then compute the dividend. Note that the divisor must be nonzero (thanks to @o11c's remind).
GZ0 has offered a great solution, one that is likely the most elegant. As an alternative, you could use the modulo operator, %. ``` if num1 % num2 == 0: return num1, num2 ``` You can use that to generate a list of a hundred or a thousand pairs to use in your program.
35,760,833
I have a question that's somewhat similar to the one asked here. [Creating Formula (Effective-Discontinue) Dates while using vlookup](https://stackoverflow.com/questions/28097250/creating-formula-effective-discontinue-dates-while-using-vlookup) Basically, I have two tables: 1. Historical sales data per item (with sales dates) 2. Items eligible for commission along with effective/discontinued dates What I need is some way to calculate commission per item into my first table based on the eligible commission items in the second table. The part of my question that differs from the link I provided is that any one of my sales items might have multiple effective/discontinued dates, meaning that item 12345 might be effective 1/1/2015-3/31/2015 and also 4/15/2015-current, so a sale of the item on 4/1/2015 would be ineligible for a commission, but sales on 3/1/2015 and 5/1/2015 would be eligible. Does anyone have suggestions on formulas I can use and ways to organize my data in table 2 to best facilitate what I'm trying to do? Thanks. Edit: Here are some tables with sample data. Table 1 (sales data): ``` InvoiceDate ItemCode QuantityShipped 1/1/2015 123456 100 2/1/2015 789456 100 3/1/2015 789456 300 4/1/2015 123456 200 5/1/2015 123456 300 ``` Table 2 (item eligibility data): ``` Item Code Effective Date Discontinued Date Commission Rate 123456 1/1/2015 3/1/2015 0.02 123456 4/15/2015 0.03 789456 3/1/2015 0.02 ```
2016/03/03
[ "https://Stackoverflow.com/questions/35760833", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6010576/" ]
Entered in E3 as an array formula (using Ctrl+Shift+Enter) I'm not great at this part of excel so I'm sure there are better approaches. [![enter image description here](https://i.stack.imgur.com/mvLa8.png)](https://i.stack.imgur.com/mvLa8.png) [![enter image description here](https://i.stack.imgur.com/S0pbz.png)](https://i.stack.imgur.com/S0pbz.png)
Try this index/match: ``` =IFERROR(INDEX($I$2:$I$4,MATCH(1,IF(($G$2:$G$4<=A2)*(IF($H$2:$H$4<>"",$H$2:$H$4,TODAY())>=A2)*($F$2:$F$4=B2),1,0),0)),0) ``` It is an array, so Confirm with Ctrl-Shift-Enter. [![enter image description here](https://i.stack.imgur.com/Y4Q1y.png)](https://i.stack.imgur.com/Y4Q1y.png) For table references: ``` =IFERROR(INDEX(Table1[Commission Rate],MATCH(1,IF((Table1[Effective Date]<=[@InvoiceDate])*(IF(Table1[Discontinued Date]<>"",Table1[Discontinued Date],TODAY())>=[@InvoiceDate])*(Table1[Item Code]=[@ItemCode]),1,0),0)),0) ``` Still an array formula so ***you must use Ctrl-Shift-Enter*** to confirm the formula instead of Enter when exiting edit mode. After pasting the formula in the formula bar and making the needed changes hit Ctrl-Shift-Enter. If done properly Excel will put `{}` around the formula. [![enter image description here](https://i.stack.imgur.com/qsoBM.png)](https://i.stack.imgur.com/qsoBM.png)
13,334,965
Is it possible to have an app running at aws EC2 and have it's database running at heroku's postgres? In case it is, what are the downsides I should consider? Since heroku is hosted at AWS, is there a way to know where is the location of the machine running my database? Hosting my app in the same region of the database would help to keep the performance? I would like to hear some opinions about this, I've been searching the topic without much success.
2012/11/11
[ "https://Stackoverflow.com/questions/13334965", "https://Stackoverflow.com", "https://Stackoverflow.com/users/888149/" ]
You can determine the public-facing location of your Heroku DB at any given time with a `traceroute` ... but there's no guarantee that it'll stay at that location, or that there isn't any internal re-routing going on. You'd probably want to speak directly with Heroku support about ways to make sure your Heroku DB instances are local to your AWS application instances, as that certainly would benefit performance. See if you can find out which availability zone, or at least which major region, they run the DB in, and whether you can "pin" your database instance to a given region/zone. Amazon's RDS looks OK, but doesn't support PostgreSQL. Please keep nagging them to. I'd probably just run the DB on AWS if performance wasn't particularly important. Use a raid10 of provisioned IOPS EBS volumes on an EBS-optimized instance and you'll get kind-of-ok performance (but at a really big price); alternately, you can use non-crash-safe ssd-based instance store servers and rely on replication and backups to keep your data safe.
I dont have any experience on Heroku PostgreSQL. Generally of course you can run your own service on Amazon EC2 and use the managed database services of Heroku. Downsides might be * nobody guarantees, that Herouku exclusively uses AWS and you probably can't determine the physical Heroku service location within the cloud so you will have to deal with network latencies * in addition to your external traffic fees you'll have to pay for the database traffic unless you talk to a server in the same availability zone in the same region My suggestion ( without knowing any detail about the pros of Heroku ) Have a look at Amazon RDS if you don't want to run a database server on our own. <http://aws.amazon.com/de/rds/> I am operating around 70 server instances on AWS, both RDS and EC2 for more than a year now and I can't imagine any simpler way to keep your stuff running
794,391
I'm trying to solve the following congruence: $x^{17} \equiv 243 \pmod{257}$ I have worked out that the $\gcd(243,257)=1$ and that $243=3^5$ So $x^{17} \equiv 3^5 \pmod{257}$ and I don't really understand what to do next.
2014/05/14
[ "https://math.stackexchange.com/questions/794391", "https://math.stackexchange.com", "https://math.stackexchange.com/users/114091/" ]
Since $257$ is a prime number by Fermat's little theorem $a^{256}\equiv 1\mod 257\ \forall a, 257\not|a$ Now, let us find if there is a solution of the form $3^y$. If there is then the equation will become $$3^{17y-5}\equiv 1\mod 257\Rightarrow 256|17y-5$$ $y=181$ is a solution to this. So $x=3^{181}$ is one solution and all the solutions of the form $3^y$ can be obtained by solving the linear Diphontaine equation $$17y-256z=5$$. Now, if there are solutions of the form $3^ya$ where $a$ does not contain $3$ as a prime factor then the equation will read as $$a^{17}3^{17y-5}\equiv 1\mod 257$$ But I'm not sure how to solve this.
We have the following facts: $\gcd(3,257)=1,\,$ $\varphi(257)=256,\,$ and 3 is a primitive root mod 257. From the first two we know, see e.g. [When is $a^n \equiv a^{(n \;\bmod \; \varphi(m))} \pmod m$ valid](https://math.stackexchange.com/questions/565449/when-is-an-equiv-an-bmod-varphim-pmod-m-valid), $$3^n \equiv 3^{(n \;\bmod \; \varphi(257))} \equiv 3^{(n \;\bmod \; 256)} \pmod {257}$$ Make the Ansatz $x=3^y$, then $$x^{17}\equiv 3^5 \pmod {257} \iff 3^{17y-5}\equiv 1 \equiv 3^0 \pmod {257}$$ Now solve $17y-5\equiv 0 \pmod {256}\,$. The multiplicative inverse is $17^{-1} \equiv 241 \pmod {256}\,$ and $y=5\times 241 \equiv 181 \pmod {256}.\,$ Therefore a solution is$$x=3^y=3^{181} \equiv 28 \pmod {257}.$$ Now you can check that $28^{17} \equiv 243 \pmod {257}.$
794,391
I'm trying to solve the following congruence: $x^{17} \equiv 243 \pmod{257}$ I have worked out that the $\gcd(243,257)=1$ and that $243=3^5$ So $x^{17} \equiv 3^5 \pmod{257}$ and I don't really understand what to do next.
2014/05/14
[ "https://math.stackexchange.com/questions/794391", "https://math.stackexchange.com", "https://math.stackexchange.com/users/114091/" ]
We want to solve $x^{17} \equiv 3^5 \pmod{257}$. Raise both sides to the power $15$ to get $$x^{255} \equiv 3^{75} \pmod{257},$$ or equivalently $x^{-1} \equiv 3^{75} \pmod {257}$. Thus $x \equiv 3^{-75} \equiv 28 \pmod{257}$.
We have the following facts: $\gcd(3,257)=1,\,$ $\varphi(257)=256,\,$ and 3 is a primitive root mod 257. From the first two we know, see e.g. [When is $a^n \equiv a^{(n \;\bmod \; \varphi(m))} \pmod m$ valid](https://math.stackexchange.com/questions/565449/when-is-an-equiv-an-bmod-varphim-pmod-m-valid), $$3^n \equiv 3^{(n \;\bmod \; \varphi(257))} \equiv 3^{(n \;\bmod \; 256)} \pmod {257}$$ Make the Ansatz $x=3^y$, then $$x^{17}\equiv 3^5 \pmod {257} \iff 3^{17y-5}\equiv 1 \equiv 3^0 \pmod {257}$$ Now solve $17y-5\equiv 0 \pmod {256}\,$. The multiplicative inverse is $17^{-1} \equiv 241 \pmod {256}\,$ and $y=5\times 241 \equiv 181 \pmod {256}.\,$ Therefore a solution is$$x=3^y=3^{181} \equiv 28 \pmod {257}.$$ Now you can check that $28^{17} \equiv 243 \pmod {257}.$
32,964,802
Is it possible to use PHP `mail()` on localhost in 64-bit Win10? I use xampp to run localhost and tried to use this function, but it returns error `Socket Error #10060<EOL>Connection timed out`. I used this configuration on 32-bit Win and there was no problem, mails were sent without any errors. Any solutions?
2015/10/06
[ "https://Stackoverflow.com/questions/32964802", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4628427/" ]
To send mail in gmail account ->In sendmail(inside wamp folder) folder open file “sendmail.ini” in notepad for editing Change the below line in this file *smtp\_server=smtp.gmail.com* //if u r using gmail id
``` a) Open the "php.ini". For XAMPP,it is located in C:\XAMPP\php\php.ini. Find out if you are using WAMP or LAMP server. Note : Make a backup of php.ini file b) Search [mail function] in the php.ini file. You can find like below. [mail function] ; For Win32 only. ; http://php.net/smtp SMTP = localhost ; http://php.net/smtp-port smtp_port = 25 ; For Win32 only. ; http://php.net/sendmail-from ;sendmail_from = postmaster@localhost Change the localhost to the smtp server name of your ISP. No need to change the smtp_port. Leave it as 25. Change sendmail_from from postmaster@localhost to your domain email address which will be used as from address.. So for me, it will become like this. [mail function] ; For Win32 only. SMTP = smtp.example.com smtp_port = 25 ; For Win32 only. sendmail_from = info@example.com c) Restart the XAMPP or WAMP(apache server) so that changes will start working. d) Now try to send the mail using the mail() function , mail("example@example.com","Success","Great, Localhost Mail works"); ``` Mail will be sent to "example@example.com" from the localhost with Subject line "Success" and body "Great,Localhost Mail works"
34,523,247
Social Security numbers that I want to accept are: ``` xxx-xx-xxxx (ex. 123-45-6789) xxxxxxxxx (ex. 123456789) xxx xx xxxx (ex. 123 45 6789) ``` I am not a regex expert, but I wrote this (it's kind of ugly) ``` ^(\d{3}-\d{2}-\d{4})|(\d{3}\d{2}\d{4})|(\d{3}\s{1}\d{2}\s{1}\d{4})$ ``` However this social security number passes, when it should actually fail since there is only one space ``` 12345 6789 ``` So I need an updated regex that rejects things like ``` 12345 6789 123 456789 ``` To make things more complex it seems that SSNs cannot start with 000 or 666 and can go up to 899, the second and third set of numbers also cannot be all 0. I came up with this ``` ^(?!000|666)[0-8][0-9]{2}[ \-](?!00)[0-9]{2}[ \-](?!0000)[0-9]{4}$ ``` Which validates with spaces or dashes, but it fails if the number is like so ``` 123456789 ``` Ideally these set of SSNs should pass ``` 123456789 123 45 6789 123-45-6789 899-45-6789 001-23-4567 ``` And these should fail ``` 12345 6789 123 456789 123x45x6789 ABCDEEEEE 1234567890123 000-45-6789 123-00-6789 123-45-0000 666-45-6789 ```
2015/12/30
[ "https://Stackoverflow.com/questions/34523247", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1046662/" ]
To solve your problem with dashes, spaces, etc. being consistent, you can use a backreference. Make the first separator a group and allow it to be optional - `([ \-]?)`. You can then reference it with `\1` to make sure the second separator is the same as the first one: ``` ^(?!000|666)[0-9]{3}([ -]?)(?!00)[0-9]{2}\1(?!0000)[0-9]{4}$ ``` See it [here](https://regex101.com/r/rA2xA2/1) (thanks @Tushar)
More complete validation rules are available on CodeProject at <http://www.codeproject.com/Articles/651609/Validating-Social-Security-Numbers-through-Regular>. Copying the information here in case the link goes away, but also expanding on the codeproject answer a bit. A Social Security number CANNOT : * Contain all zeroes in any specific group (ie 000-##-####, ###-00-####, or ###-##-0000) * Begin with ’666′. * Begin with any value from ’900-999′ * Be ’078-05-1120′ (due to the Woolworth’s Wallet Fiasco) * Be ’219-09-9999′ (appeared in an advertisement for the Social Security Administration) This RegEx taken from the referenced CodeProject article will validate all Social Security numbers according to all the rules - requires dashes as separators. ``` ^(?!219-09-9999|078-05-1120)(?!666|000|9\d{2})\d{3}-(?!00)\d{2}-(?!0{4})\d{4}$ ``` Same with spaces, instead of dashes ``` ^(?!219 09 9999|078 05 1120)(?!666|000|9\d{2})\d{3} (?!00)\d{2} (?!0{4})\d{4}$ ``` Finally, this will validate numbers without spaces or dashes ``` ^(?!219099999|078051120)(?!666|000|9\d{2})\d{3}(?!00)\d{2}(?!0{4})\d{4}$ ``` Combining the three cases above, we get the ### Answer ``` ^((?!219-09-9999|078-05-1120)(?!666|000|9\d{2})\d{3}-(?!00)\d{2}-(?!0{4})\d{4})|((?!219 09 9999|078 05 1120)(?!666|000|9\d{2})\d{3} (?!00)\d{2} (?!0{4})\d{4})|((?!219099999|078051120)(?!666|000|9\d{2})\d{3}(?!00)\d{2}(?!0{4})\d{4})$ ```
34,523,247
Social Security numbers that I want to accept are: ``` xxx-xx-xxxx (ex. 123-45-6789) xxxxxxxxx (ex. 123456789) xxx xx xxxx (ex. 123 45 6789) ``` I am not a regex expert, but I wrote this (it's kind of ugly) ``` ^(\d{3}-\d{2}-\d{4})|(\d{3}\d{2}\d{4})|(\d{3}\s{1}\d{2}\s{1}\d{4})$ ``` However this social security number passes, when it should actually fail since there is only one space ``` 12345 6789 ``` So I need an updated regex that rejects things like ``` 12345 6789 123 456789 ``` To make things more complex it seems that SSNs cannot start with 000 or 666 and can go up to 899, the second and third set of numbers also cannot be all 0. I came up with this ``` ^(?!000|666)[0-8][0-9]{2}[ \-](?!00)[0-9]{2}[ \-](?!0000)[0-9]{4}$ ``` Which validates with spaces or dashes, but it fails if the number is like so ``` 123456789 ``` Ideally these set of SSNs should pass ``` 123456789 123 45 6789 123-45-6789 899-45-6789 001-23-4567 ``` And these should fail ``` 12345 6789 123 456789 123x45x6789 ABCDEEEEE 1234567890123 000-45-6789 123-00-6789 123-45-0000 666-45-6789 ```
2015/12/30
[ "https://Stackoverflow.com/questions/34523247", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1046662/" ]
To solve your problem with dashes, spaces, etc. being consistent, you can use a backreference. Make the first separator a group and allow it to be optional - `([ \-]?)`. You can then reference it with `\1` to make sure the second separator is the same as the first one: ``` ^(?!000|666)[0-9]{3}([ -]?)(?!00)[0-9]{2}\1(?!0000)[0-9]{4}$ ``` See it [here](https://regex101.com/r/rA2xA2/1) (thanks @Tushar)
I had a requirement to validate SSN's. This regex will validate SSN for below rules 1. Matches dashes, spaces or no spaces 2. Numbers, 9 digits, non-alphanumeric 3. Exclude all zeros 4. Exclude beginning characters `666,000,900,999,123456789,111111111,222222222,333333333,444444444,555555555,666666666,777777777,888888888,999999999` 5. Exclude ending characters `0000` ``` ^(?!123([ -]?)45([ -]?)6789)(?!\b(\d)\3+\b)(?!000|666|900|999)[0-9]{3}([ -]?)(?!00)[0-9]{2}\4(?!0000)[0-9]{4}$ ``` Explanation ``` ^ - Beginning of string (?!123([ -]?)45([ -]?)6789) - Don't match 123456789, 123-45-6789, 123 45 6789 (?!\b(\d)\3+\b) - Don't match 00000000,111111111...999999999. Repeat same with space and dashes. '\3' is for backtracking to (\d) (?!000|666|900|999) - Don't match SSN that begins with 000,666,900 or 999. ([ -]?) - Check for space and dash. '?' is used to make space and dash optional. ? is 0 or 1 occurence of previous character. (?!00) - the 4th and 5th characters cannot be 00. \4 - Backtracking to check for space and dash again after the 5th character. (?!0000) - The last 4 characters cannot be all zeros. $ - End of string Backtracking is used to repeat a captured group (). Each group is represented sequentially 1,2,3..so on ``` See here for more explanation and examples <https://regex101.com/r/rA2xA2/3>
34,523,247
Social Security numbers that I want to accept are: ``` xxx-xx-xxxx (ex. 123-45-6789) xxxxxxxxx (ex. 123456789) xxx xx xxxx (ex. 123 45 6789) ``` I am not a regex expert, but I wrote this (it's kind of ugly) ``` ^(\d{3}-\d{2}-\d{4})|(\d{3}\d{2}\d{4})|(\d{3}\s{1}\d{2}\s{1}\d{4})$ ``` However this social security number passes, when it should actually fail since there is only one space ``` 12345 6789 ``` So I need an updated regex that rejects things like ``` 12345 6789 123 456789 ``` To make things more complex it seems that SSNs cannot start with 000 or 666 and can go up to 899, the second and third set of numbers also cannot be all 0. I came up with this ``` ^(?!000|666)[0-8][0-9]{2}[ \-](?!00)[0-9]{2}[ \-](?!0000)[0-9]{4}$ ``` Which validates with spaces or dashes, but it fails if the number is like so ``` 123456789 ``` Ideally these set of SSNs should pass ``` 123456789 123 45 6789 123-45-6789 899-45-6789 001-23-4567 ``` And these should fail ``` 12345 6789 123 456789 123x45x6789 ABCDEEEEE 1234567890123 000-45-6789 123-00-6789 123-45-0000 666-45-6789 ```
2015/12/30
[ "https://Stackoverflow.com/questions/34523247", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1046662/" ]
More complete validation rules are available on CodeProject at <http://www.codeproject.com/Articles/651609/Validating-Social-Security-Numbers-through-Regular>. Copying the information here in case the link goes away, but also expanding on the codeproject answer a bit. A Social Security number CANNOT : * Contain all zeroes in any specific group (ie 000-##-####, ###-00-####, or ###-##-0000) * Begin with ’666′. * Begin with any value from ’900-999′ * Be ’078-05-1120′ (due to the Woolworth’s Wallet Fiasco) * Be ’219-09-9999′ (appeared in an advertisement for the Social Security Administration) This RegEx taken from the referenced CodeProject article will validate all Social Security numbers according to all the rules - requires dashes as separators. ``` ^(?!219-09-9999|078-05-1120)(?!666|000|9\d{2})\d{3}-(?!00)\d{2}-(?!0{4})\d{4}$ ``` Same with spaces, instead of dashes ``` ^(?!219 09 9999|078 05 1120)(?!666|000|9\d{2})\d{3} (?!00)\d{2} (?!0{4})\d{4}$ ``` Finally, this will validate numbers without spaces or dashes ``` ^(?!219099999|078051120)(?!666|000|9\d{2})\d{3}(?!00)\d{2}(?!0{4})\d{4}$ ``` Combining the three cases above, we get the ### Answer ``` ^((?!219-09-9999|078-05-1120)(?!666|000|9\d{2})\d{3}-(?!00)\d{2}-(?!0{4})\d{4})|((?!219 09 9999|078 05 1120)(?!666|000|9\d{2})\d{3} (?!00)\d{2} (?!0{4})\d{4})|((?!219099999|078051120)(?!666|000|9\d{2})\d{3}(?!00)\d{2}(?!0{4})\d{4})$ ```
I had a requirement to validate SSN's. This regex will validate SSN for below rules 1. Matches dashes, spaces or no spaces 2. Numbers, 9 digits, non-alphanumeric 3. Exclude all zeros 4. Exclude beginning characters `666,000,900,999,123456789,111111111,222222222,333333333,444444444,555555555,666666666,777777777,888888888,999999999` 5. Exclude ending characters `0000` ``` ^(?!123([ -]?)45([ -]?)6789)(?!\b(\d)\3+\b)(?!000|666|900|999)[0-9]{3}([ -]?)(?!00)[0-9]{2}\4(?!0000)[0-9]{4}$ ``` Explanation ``` ^ - Beginning of string (?!123([ -]?)45([ -]?)6789) - Don't match 123456789, 123-45-6789, 123 45 6789 (?!\b(\d)\3+\b) - Don't match 00000000,111111111...999999999. Repeat same with space and dashes. '\3' is for backtracking to (\d) (?!000|666|900|999) - Don't match SSN that begins with 000,666,900 or 999. ([ -]?) - Check for space and dash. '?' is used to make space and dash optional. ? is 0 or 1 occurence of previous character. (?!00) - the 4th and 5th characters cannot be 00. \4 - Backtracking to check for space and dash again after the 5th character. (?!0000) - The last 4 characters cannot be all zeros. $ - End of string Backtracking is used to repeat a captured group (). Each group is represented sequentially 1,2,3..so on ``` See here for more explanation and examples <https://regex101.com/r/rA2xA2/3>
17,377,725
I have two queries that I am not sure how to run as one doing some simple math. ``` SELECT count(*) FROM CUSTOMERINFO where member between '2013-01-01' and '2013-12-31' ``` Returns: 7823 ``` select COUNT(DISTINCT ORDERINFO.OrderID) from orderinfo, orderiteminfo where code = '810samp' AND ORDERINFO.OrderID = ORDERITEMINFO.OrderID AND orderinfo.PrepareDate between '2013-01-01' and '2013-12-31' ``` Returns: 4106 I need to have the query return: 4106 / 7823 X 100
2013/06/29
[ "https://Stackoverflow.com/questions/17377725", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2533695/" ]
More than likely, those computers do not have some required Qt library that your program is using. See the tutorial here: <http://doc.qt.io/qt-5/windows-deployment.html> Another easy check would be to install Qt on another computer, move your .exe over and see if it runs. If it does, you certainly did not deploy your application correctly. Edited to add this helpful link since this seems to be the exact same issue people are seeing: <https://bugreports.qt.io/browse/QTBUG-28766>
If you have cygwin installed then you can run `ldd <your_app.exe>` and see list of libraries which are required by your application. After doing so copy your exe to another folder and libraries which are required by it. This should be OK for LGPL license but I AM NOT A LAWYER so please consult some smarter people which are familiar with legal issues.
17,377,725
I have two queries that I am not sure how to run as one doing some simple math. ``` SELECT count(*) FROM CUSTOMERINFO where member between '2013-01-01' and '2013-12-31' ``` Returns: 7823 ``` select COUNT(DISTINCT ORDERINFO.OrderID) from orderinfo, orderiteminfo where code = '810samp' AND ORDERINFO.OrderID = ORDERITEMINFO.OrderID AND orderinfo.PrepareDate between '2013-01-01' and '2013-12-31' ``` Returns: 4106 I need to have the query return: 4106 / 7823 X 100
2013/06/29
[ "https://Stackoverflow.com/questions/17377725", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2533695/" ]
More than likely, those computers do not have some required Qt library that your program is using. See the tutorial here: <http://doc.qt.io/qt-5/windows-deployment.html> Another easy check would be to install Qt on another computer, move your .exe over and see if it runs. If it does, you certainly did not deploy your application correctly. Edited to add this helpful link since this seems to be the exact same issue people are seeing: <https://bugreports.qt.io/browse/QTBUG-28766>
You are deploying a mingw compiled application, this requires you to supply the following DLL-Files, additionally to the Qt-DLL's used in your application: ``` icudt51.dll icuin51.dll icuuc51.dll libstdc++-6.dll (eventually) platforms/qminimal.dll platforms/qwindows.dll libgcc_s_dw2-1.dll (eventually) ``` Those can be found in your mingw-directory found in your SDK installation. It is also important the suppied DLL's fit the compiler version.
17,377,725
I have two queries that I am not sure how to run as one doing some simple math. ``` SELECT count(*) FROM CUSTOMERINFO where member between '2013-01-01' and '2013-12-31' ``` Returns: 7823 ``` select COUNT(DISTINCT ORDERINFO.OrderID) from orderinfo, orderiteminfo where code = '810samp' AND ORDERINFO.OrderID = ORDERITEMINFO.OrderID AND orderinfo.PrepareDate between '2013-01-01' and '2013-12-31' ``` Returns: 4106 I need to have the query return: 4106 / 7823 X 100
2013/06/29
[ "https://Stackoverflow.com/questions/17377725", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2533695/" ]
More than likely, those computers do not have some required Qt library that your program is using. See the tutorial here: <http://doc.qt.io/qt-5/windows-deployment.html> Another easy check would be to install Qt on another computer, move your .exe over and see if it runs. If it does, you certainly did not deploy your application correctly. Edited to add this helpful link since this seems to be the exact same issue people are seeing: <https://bugreports.qt.io/browse/QTBUG-28766>
This is a bug in Qt. It is because of a missing DLL but it is a plugin DLL so it doesn't show up in depends.exe, and Qt doesn't look for it where it should. Long story short, if you copy the qwindows.dll (or qwindowsd.dll for debug builds) onto your deployment machine and put in the SAME ABSOLUTE PATH as it came from, i.e. c:\Qt\5.1.0......\mingw48\_32\plugins\platforms\qwindows.dll, then your app should work. The presence of a blank qt.conf file in the same directory did not affect things on my development machine but it did STOP the app from working on my deployment machine. See this comment/bug report for more information: <https://bugreports.qt.io/browse/QTBUG-28766?focusedCommentId=216317&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-216317>
17,377,725
I have two queries that I am not sure how to run as one doing some simple math. ``` SELECT count(*) FROM CUSTOMERINFO where member between '2013-01-01' and '2013-12-31' ``` Returns: 7823 ``` select COUNT(DISTINCT ORDERINFO.OrderID) from orderinfo, orderiteminfo where code = '810samp' AND ORDERINFO.OrderID = ORDERITEMINFO.OrderID AND orderinfo.PrepareDate between '2013-01-01' and '2013-12-31' ``` Returns: 4106 I need to have the query return: 4106 / 7823 X 100
2013/06/29
[ "https://Stackoverflow.com/questions/17377725", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2533695/" ]
More than likely, those computers do not have some required Qt library that your program is using. See the tutorial here: <http://doc.qt.io/qt-5/windows-deployment.html> Another easy check would be to install Qt on another computer, move your .exe over and see if it runs. If it does, you certainly did not deploy your application correctly. Edited to add this helpful link since this seems to be the exact same issue people are seeing: <https://bugreports.qt.io/browse/QTBUG-28766>
This is a bug on Windows: <https://bugreports.qt-project.org/browse/QTBUG-28766> Specifically, Qt only looks for qwindows.dll (which *is* required despite what `depends.exe` says - it is dynamically loaded) in the hard-coded absolute path that it is installed in on your development machine, i.e. `c:\Qt\.....\plugins\platforms`. There is a file called qt.conf which you are supposed to be able to use to change the search paths but it does not work. Fortunately Joost Bloemen came up with a workaround in that bug report: ``` ... #include <windows.h> #include <QFileInfo> int main(int argc, char* argv[]) { // Bug workaround. See https://bugreports.qt-project.org/browse/QTBUG-28766 wchar_t dirpath[MAX_PATH]; GetModuleFileName(0, dirpath, MAX_PATH); QFileInfo dir(QString::fromWCharArray(dirpath)); QApplication::addLibraryPath(dir.absolutePath()); QApplication a(argc, argv); ... ``` And then put `qwindows.dll` (*you don't need `qminimal.dll`*) in a subdirectory of your EXE called `platforms`. (You can put it in `.\plugins\platforms` instead if you like, then you just need to change `dir.absolutePath()` to `dir.absolutePath() + "/plugins"` above.
17,377,725
I have two queries that I am not sure how to run as one doing some simple math. ``` SELECT count(*) FROM CUSTOMERINFO where member between '2013-01-01' and '2013-12-31' ``` Returns: 7823 ``` select COUNT(DISTINCT ORDERINFO.OrderID) from orderinfo, orderiteminfo where code = '810samp' AND ORDERINFO.OrderID = ORDERITEMINFO.OrderID AND orderinfo.PrepareDate between '2013-01-01' and '2013-12-31' ``` Returns: 4106 I need to have the query return: 4106 / 7823 X 100
2013/06/29
[ "https://Stackoverflow.com/questions/17377725", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2533695/" ]
If you have cygwin installed then you can run `ldd <your_app.exe>` and see list of libraries which are required by your application. After doing so copy your exe to another folder and libraries which are required by it. This should be OK for LGPL license but I AM NOT A LAWYER so please consult some smarter people which are familiar with legal issues.
This is a bug in Qt. It is because of a missing DLL but it is a plugin DLL so it doesn't show up in depends.exe, and Qt doesn't look for it where it should. Long story short, if you copy the qwindows.dll (or qwindowsd.dll for debug builds) onto your deployment machine and put in the SAME ABSOLUTE PATH as it came from, i.e. c:\Qt\5.1.0......\mingw48\_32\plugins\platforms\qwindows.dll, then your app should work. The presence of a blank qt.conf file in the same directory did not affect things on my development machine but it did STOP the app from working on my deployment machine. See this comment/bug report for more information: <https://bugreports.qt.io/browse/QTBUG-28766?focusedCommentId=216317&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-216317>
17,377,725
I have two queries that I am not sure how to run as one doing some simple math. ``` SELECT count(*) FROM CUSTOMERINFO where member between '2013-01-01' and '2013-12-31' ``` Returns: 7823 ``` select COUNT(DISTINCT ORDERINFO.OrderID) from orderinfo, orderiteminfo where code = '810samp' AND ORDERINFO.OrderID = ORDERITEMINFO.OrderID AND orderinfo.PrepareDate between '2013-01-01' and '2013-12-31' ``` Returns: 4106 I need to have the query return: 4106 / 7823 X 100
2013/06/29
[ "https://Stackoverflow.com/questions/17377725", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2533695/" ]
If you have cygwin installed then you can run `ldd <your_app.exe>` and see list of libraries which are required by your application. After doing so copy your exe to another folder and libraries which are required by it. This should be OK for LGPL license but I AM NOT A LAWYER so please consult some smarter people which are familiar with legal issues.
This is a bug on Windows: <https://bugreports.qt-project.org/browse/QTBUG-28766> Specifically, Qt only looks for qwindows.dll (which *is* required despite what `depends.exe` says - it is dynamically loaded) in the hard-coded absolute path that it is installed in on your development machine, i.e. `c:\Qt\.....\plugins\platforms`. There is a file called qt.conf which you are supposed to be able to use to change the search paths but it does not work. Fortunately Joost Bloemen came up with a workaround in that bug report: ``` ... #include <windows.h> #include <QFileInfo> int main(int argc, char* argv[]) { // Bug workaround. See https://bugreports.qt-project.org/browse/QTBUG-28766 wchar_t dirpath[MAX_PATH]; GetModuleFileName(0, dirpath, MAX_PATH); QFileInfo dir(QString::fromWCharArray(dirpath)); QApplication::addLibraryPath(dir.absolutePath()); QApplication a(argc, argv); ... ``` And then put `qwindows.dll` (*you don't need `qminimal.dll`*) in a subdirectory of your EXE called `platforms`. (You can put it in `.\plugins\platforms` instead if you like, then you just need to change `dir.absolutePath()` to `dir.absolutePath() + "/plugins"` above.
17,377,725
I have two queries that I am not sure how to run as one doing some simple math. ``` SELECT count(*) FROM CUSTOMERINFO where member between '2013-01-01' and '2013-12-31' ``` Returns: 7823 ``` select COUNT(DISTINCT ORDERINFO.OrderID) from orderinfo, orderiteminfo where code = '810samp' AND ORDERINFO.OrderID = ORDERITEMINFO.OrderID AND orderinfo.PrepareDate between '2013-01-01' and '2013-12-31' ``` Returns: 4106 I need to have the query return: 4106 / 7823 X 100
2013/06/29
[ "https://Stackoverflow.com/questions/17377725", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2533695/" ]
You are deploying a mingw compiled application, this requires you to supply the following DLL-Files, additionally to the Qt-DLL's used in your application: ``` icudt51.dll icuin51.dll icuuc51.dll libstdc++-6.dll (eventually) platforms/qminimal.dll platforms/qwindows.dll libgcc_s_dw2-1.dll (eventually) ``` Those can be found in your mingw-directory found in your SDK installation. It is also important the suppied DLL's fit the compiler version.
This is a bug in Qt. It is because of a missing DLL but it is a plugin DLL so it doesn't show up in depends.exe, and Qt doesn't look for it where it should. Long story short, if you copy the qwindows.dll (or qwindowsd.dll for debug builds) onto your deployment machine and put in the SAME ABSOLUTE PATH as it came from, i.e. c:\Qt\5.1.0......\mingw48\_32\plugins\platforms\qwindows.dll, then your app should work. The presence of a blank qt.conf file in the same directory did not affect things on my development machine but it did STOP the app from working on my deployment machine. See this comment/bug report for more information: <https://bugreports.qt.io/browse/QTBUG-28766?focusedCommentId=216317&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-216317>
17,377,725
I have two queries that I am not sure how to run as one doing some simple math. ``` SELECT count(*) FROM CUSTOMERINFO where member between '2013-01-01' and '2013-12-31' ``` Returns: 7823 ``` select COUNT(DISTINCT ORDERINFO.OrderID) from orderinfo, orderiteminfo where code = '810samp' AND ORDERINFO.OrderID = ORDERITEMINFO.OrderID AND orderinfo.PrepareDate between '2013-01-01' and '2013-12-31' ``` Returns: 4106 I need to have the query return: 4106 / 7823 X 100
2013/06/29
[ "https://Stackoverflow.com/questions/17377725", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2533695/" ]
You are deploying a mingw compiled application, this requires you to supply the following DLL-Files, additionally to the Qt-DLL's used in your application: ``` icudt51.dll icuin51.dll icuuc51.dll libstdc++-6.dll (eventually) platforms/qminimal.dll platforms/qwindows.dll libgcc_s_dw2-1.dll (eventually) ``` Those can be found in your mingw-directory found in your SDK installation. It is also important the suppied DLL's fit the compiler version.
This is a bug on Windows: <https://bugreports.qt-project.org/browse/QTBUG-28766> Specifically, Qt only looks for qwindows.dll (which *is* required despite what `depends.exe` says - it is dynamically loaded) in the hard-coded absolute path that it is installed in on your development machine, i.e. `c:\Qt\.....\plugins\platforms`. There is a file called qt.conf which you are supposed to be able to use to change the search paths but it does not work. Fortunately Joost Bloemen came up with a workaround in that bug report: ``` ... #include <windows.h> #include <QFileInfo> int main(int argc, char* argv[]) { // Bug workaround. See https://bugreports.qt-project.org/browse/QTBUG-28766 wchar_t dirpath[MAX_PATH]; GetModuleFileName(0, dirpath, MAX_PATH); QFileInfo dir(QString::fromWCharArray(dirpath)); QApplication::addLibraryPath(dir.absolutePath()); QApplication a(argc, argv); ... ``` And then put `qwindows.dll` (*you don't need `qminimal.dll`*) in a subdirectory of your EXE called `platforms`. (You can put it in `.\plugins\platforms` instead if you like, then you just need to change `dir.absolutePath()` to `dir.absolutePath() + "/plugins"` above.
17,377,725
I have two queries that I am not sure how to run as one doing some simple math. ``` SELECT count(*) FROM CUSTOMERINFO where member between '2013-01-01' and '2013-12-31' ``` Returns: 7823 ``` select COUNT(DISTINCT ORDERINFO.OrderID) from orderinfo, orderiteminfo where code = '810samp' AND ORDERINFO.OrderID = ORDERITEMINFO.OrderID AND orderinfo.PrepareDate between '2013-01-01' and '2013-12-31' ``` Returns: 4106 I need to have the query return: 4106 / 7823 X 100
2013/06/29
[ "https://Stackoverflow.com/questions/17377725", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2533695/" ]
This is a bug in Qt. It is because of a missing DLL but it is a plugin DLL so it doesn't show up in depends.exe, and Qt doesn't look for it where it should. Long story short, if you copy the qwindows.dll (or qwindowsd.dll for debug builds) onto your deployment machine and put in the SAME ABSOLUTE PATH as it came from, i.e. c:\Qt\5.1.0......\mingw48\_32\plugins\platforms\qwindows.dll, then your app should work. The presence of a blank qt.conf file in the same directory did not affect things on my development machine but it did STOP the app from working on my deployment machine. See this comment/bug report for more information: <https://bugreports.qt.io/browse/QTBUG-28766?focusedCommentId=216317&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-216317>
This is a bug on Windows: <https://bugreports.qt-project.org/browse/QTBUG-28766> Specifically, Qt only looks for qwindows.dll (which *is* required despite what `depends.exe` says - it is dynamically loaded) in the hard-coded absolute path that it is installed in on your development machine, i.e. `c:\Qt\.....\plugins\platforms`. There is a file called qt.conf which you are supposed to be able to use to change the search paths but it does not work. Fortunately Joost Bloemen came up with a workaround in that bug report: ``` ... #include <windows.h> #include <QFileInfo> int main(int argc, char* argv[]) { // Bug workaround. See https://bugreports.qt-project.org/browse/QTBUG-28766 wchar_t dirpath[MAX_PATH]; GetModuleFileName(0, dirpath, MAX_PATH); QFileInfo dir(QString::fromWCharArray(dirpath)); QApplication::addLibraryPath(dir.absolutePath()); QApplication a(argc, argv); ... ``` And then put `qwindows.dll` (*you don't need `qminimal.dll`*) in a subdirectory of your EXE called `platforms`. (You can put it in `.\plugins\platforms` instead if you like, then you just need to change `dir.absolutePath()` to `dir.absolutePath() + "/plugins"` above.
67,290
In a table with 4 rows and 4 columns I try to merge different cells in every row while preserving the table layout. As there are never more than 3 cells in a row, a table column seems to be dropped. If I add an empty row containing 4 cells there are 4 columns. Question: is it possible to preserve all columns without adding an empty row? Thank you. Here is my goal: ``` ------------------- | 1 | ------------------- | 2 | 14 | ------------------- | 3 | 7 | 15 | ------------------- | 4 | 8 | 12 | ------------------- ``` And here, what I get: ``` -------------- | 1 | -------------- | 2 | 14 | -------------- | 3 | 7 | 15 | -------------- | 4 | 8 | 12 | -------------- ``` The code: ``` \documentclass[10pt]{article} \usepackage{multicol} \begin{document} \section{A} {\begin{tabular}{|l|l|l|l|} \hline \multicolumn{4}{|l|}{1} \\ \hline \multicolumn{3}{|l|}{2} & 14 \\ \hline 3 & \multicolumn{2}{|l|}{7} & 15 \\ \hline 4 & 8 & \multicolumn{2}{|l|}{12} \\ \hline \end{tabular}} \section{B} {\begin{tabular}{|l|l|l|l|} \hline \multicolumn{4}{|l|}{1} \\ \hline \multicolumn{3}{|l|}{2} & 14 \\ \hline & & & \\ \hline 3 & \multicolumn{2}{|l|}{7} & 15 \\ \hline 4 & 8 & \multicolumn{2}{|l|}{12} \\ \hline \end{tabular}} \section{Goal} I would like to have a table as in section B but without the third (empty) row. \end{document} ```
2012/08/15
[ "https://tex.stackexchange.com/questions/67290", "https://tex.stackexchange.com", "https://tex.stackexchange.com/users/17626/" ]
The following is probably what you're after: ![enter image description here](https://i.stack.imgur.com/y6YQQ.png) ``` \documentclass[10pt]{article} \begin{document} \section{A} \begin{tabular}{|l|l|l|l|} \hline \multicolumn{4}{|l|}{1} \\ \hline \multicolumn{3}{|l|}{2} & 14 \\ \hline 3 & \multicolumn{2}{|l|}{7} & 15 \\ \hline 4 & 8 & \multicolumn{2}{|l|}{12} \\ \hline \end{tabular} \section{B} \begin{tabular}{|l|l|l|l|} & & \phantom{12} & \\[-\normalbaselineskip] % fake/empty row \hline \multicolumn{4}{|l|}{1} \\ \hline \multicolumn{3}{|l|}{2} & 14 \\ \hline 3 & \multicolumn{2}{|l|}{7} & 15 \\ \hline 4 & 8 & \multicolumn{2}{|l|}{12} \\ \hline \end{tabular} \section{Goal} I would like to have a table as in section B but without the third (empty) row. \end{document}​ ``` The motivation behind this solution stems from what is commonly used in the `tabbing` environment where you specify the tabbing intervals and then `\kill` the row. Note that you don't need [`multicol`](http://ctan.org/pkg/multicol) for this, since the default `tabular` is supported in LaTeX.
It seems that you want to have a 4 column table, but only have 3 columns of data. If you know the width of the additional column you want, you can add that as `\hphantom{14}` (assuming that the width of the other column is equivalent to the width of the digits `14`: ![enter image description here](https://i.stack.imgur.com/VbpnS.png) Note: ----- * The additional `\hspace*{\tabcolsep}` is required to take into account the separation that is added in between column tables. Code: ----- ``` \documentclass[10pt]{article} \usepackage{multicol} \begin{document} \section{A} {\begin{tabular}{|l|l|l|l|} \hline \multicolumn{4}{|l|}{1} \\ \hline \multicolumn{3}{|l|}{2} & 14 \\ \hline 3 & \multicolumn{2}{|l|}{7} & 15 \\ \hline 4 & 8 & \multicolumn{2}{|l|}{12} \\ \hline \end{tabular}} \section{B} {\begin{tabular}{|l|l|l|l|} \hline \multicolumn{4}{|l|}{1} \\ \hline \multicolumn{3}{|l|}{2} & 14 \\ \hline & & & \\ \hline 3 & \multicolumn{2}{|l|}{7} & 15 \\ \hline 4 & 8 & \multicolumn{2}{|l|}{12} \\ \hline \end{tabular}} \section{Goal} I would like to have a table as in section B but without the third (empty) row. \section{C} {\begin{tabular}{|l|l|l|l|} \hline \multicolumn{4}{|l|}{1} \\ % \hline 1 & & & \\ \hline \multicolumn{3}{|l|}{2} & 14 \\ \hline 3 & \multicolumn{2}{|l|}{7\hspace*{\tabcolsep}\hphantom{14}} & 15 \\ \hline 4 & 8 & \multicolumn{2}{|l|}{12} \\ \hline \end{tabular}} \end{document} ```
67,290
In a table with 4 rows and 4 columns I try to merge different cells in every row while preserving the table layout. As there are never more than 3 cells in a row, a table column seems to be dropped. If I add an empty row containing 4 cells there are 4 columns. Question: is it possible to preserve all columns without adding an empty row? Thank you. Here is my goal: ``` ------------------- | 1 | ------------------- | 2 | 14 | ------------------- | 3 | 7 | 15 | ------------------- | 4 | 8 | 12 | ------------------- ``` And here, what I get: ``` -------------- | 1 | -------------- | 2 | 14 | -------------- | 3 | 7 | 15 | -------------- | 4 | 8 | 12 | -------------- ``` The code: ``` \documentclass[10pt]{article} \usepackage{multicol} \begin{document} \section{A} {\begin{tabular}{|l|l|l|l|} \hline \multicolumn{4}{|l|}{1} \\ \hline \multicolumn{3}{|l|}{2} & 14 \\ \hline 3 & \multicolumn{2}{|l|}{7} & 15 \\ \hline 4 & 8 & \multicolumn{2}{|l|}{12} \\ \hline \end{tabular}} \section{B} {\begin{tabular}{|l|l|l|l|} \hline \multicolumn{4}{|l|}{1} \\ \hline \multicolumn{3}{|l|}{2} & 14 \\ \hline & & & \\ \hline 3 & \multicolumn{2}{|l|}{7} & 15 \\ \hline 4 & 8 & \multicolumn{2}{|l|}{12} \\ \hline \end{tabular}} \section{Goal} I would like to have a table as in section B but without the third (empty) row. \end{document} ```
2012/08/15
[ "https://tex.stackexchange.com/questions/67290", "https://tex.stackexchange.com", "https://tex.stackexchange.com/users/17626/" ]
The following is probably what you're after: ![enter image description here](https://i.stack.imgur.com/y6YQQ.png) ``` \documentclass[10pt]{article} \begin{document} \section{A} \begin{tabular}{|l|l|l|l|} \hline \multicolumn{4}{|l|}{1} \\ \hline \multicolumn{3}{|l|}{2} & 14 \\ \hline 3 & \multicolumn{2}{|l|}{7} & 15 \\ \hline 4 & 8 & \multicolumn{2}{|l|}{12} \\ \hline \end{tabular} \section{B} \begin{tabular}{|l|l|l|l|} & & \phantom{12} & \\[-\normalbaselineskip] % fake/empty row \hline \multicolumn{4}{|l|}{1} \\ \hline \multicolumn{3}{|l|}{2} & 14 \\ \hline 3 & \multicolumn{2}{|l|}{7} & 15 \\ \hline 4 & 8 & \multicolumn{2}{|l|}{12} \\ \hline \end{tabular} \section{Goal} I would like to have a table as in section B but without the third (empty) row. \end{document}​ ``` The motivation behind this solution stems from what is commonly used in the `tabbing` environment where you specify the tabbing intervals and then `\kill` the row. Note that you don't need [`multicol`](http://ctan.org/pkg/multicol) for this, since the default `tabular` is supported in LaTeX.
It's a feature of the underlying `\halign` primitive that any column boundary that is spanned in every row is removed from the column width calculation. Perhaps the easiest thing is to change the first line to ``` \hline \multicolumn{2}{|l}{1}&\multicolumn{1}{l}{} &\ ``` ![enter image description here](https://i.stack.imgur.com/gCrsh.png)
67,290
In a table with 4 rows and 4 columns I try to merge different cells in every row while preserving the table layout. As there are never more than 3 cells in a row, a table column seems to be dropped. If I add an empty row containing 4 cells there are 4 columns. Question: is it possible to preserve all columns without adding an empty row? Thank you. Here is my goal: ``` ------------------- | 1 | ------------------- | 2 | 14 | ------------------- | 3 | 7 | 15 | ------------------- | 4 | 8 | 12 | ------------------- ``` And here, what I get: ``` -------------- | 1 | -------------- | 2 | 14 | -------------- | 3 | 7 | 15 | -------------- | 4 | 8 | 12 | -------------- ``` The code: ``` \documentclass[10pt]{article} \usepackage{multicol} \begin{document} \section{A} {\begin{tabular}{|l|l|l|l|} \hline \multicolumn{4}{|l|}{1} \\ \hline \multicolumn{3}{|l|}{2} & 14 \\ \hline 3 & \multicolumn{2}{|l|}{7} & 15 \\ \hline 4 & 8 & \multicolumn{2}{|l|}{12} \\ \hline \end{tabular}} \section{B} {\begin{tabular}{|l|l|l|l|} \hline \multicolumn{4}{|l|}{1} \\ \hline \multicolumn{3}{|l|}{2} & 14 \\ \hline & & & \\ \hline 3 & \multicolumn{2}{|l|}{7} & 15 \\ \hline 4 & 8 & \multicolumn{2}{|l|}{12} \\ \hline \end{tabular}} \section{Goal} I would like to have a table as in section B but without the third (empty) row. \end{document} ```
2012/08/15
[ "https://tex.stackexchange.com/questions/67290", "https://tex.stackexchange.com", "https://tex.stackexchange.com/users/17626/" ]
The following is probably what you're after: ![enter image description here](https://i.stack.imgur.com/y6YQQ.png) ``` \documentclass[10pt]{article} \begin{document} \section{A} \begin{tabular}{|l|l|l|l|} \hline \multicolumn{4}{|l|}{1} \\ \hline \multicolumn{3}{|l|}{2} & 14 \\ \hline 3 & \multicolumn{2}{|l|}{7} & 15 \\ \hline 4 & 8 & \multicolumn{2}{|l|}{12} \\ \hline \end{tabular} \section{B} \begin{tabular}{|l|l|l|l|} & & \phantom{12} & \\[-\normalbaselineskip] % fake/empty row \hline \multicolumn{4}{|l|}{1} \\ \hline \multicolumn{3}{|l|}{2} & 14 \\ \hline 3 & \multicolumn{2}{|l|}{7} & 15 \\ \hline 4 & 8 & \multicolumn{2}{|l|}{12} \\ \hline \end{tabular} \section{Goal} I would like to have a table as in section B but without the third (empty) row. \end{document}​ ``` The motivation behind this solution stems from what is commonly used in the `tabbing` environment where you specify the tabbing intervals and then `\kill` the row. Note that you don't need [`multicol`](http://ctan.org/pkg/multicol) for this, since the default `tabular` is supported in LaTeX.
Here is what you can do with `{NiceTabular}` of `nicematrix`. With the key `hvlines`, all the rules are drawn excepted in the blocks (created by `\Block`). ``` \documentclass[10pt]{article} \usepackage{nicematrix} \begin{document} \begin{NiceTabular}{llll}[hvlines] \Block{1-4}{} 1 \\ \Block{1-3}{} 2 &&& 14 \\ 3 & \Block{1-2}{} 7 && 15 \\ 4 & 8 & \Block{1-2}{} 12 \\ \end{NiceTabular} \end{document} ``` You need several compilations (because `nicematrix` uses PGF/Tikz nodes under the hood). [![Output of the above code](https://i.stack.imgur.com/WIrQD.png)](https://i.stack.imgur.com/WIrQD.png)
67,290
In a table with 4 rows and 4 columns I try to merge different cells in every row while preserving the table layout. As there are never more than 3 cells in a row, a table column seems to be dropped. If I add an empty row containing 4 cells there are 4 columns. Question: is it possible to preserve all columns without adding an empty row? Thank you. Here is my goal: ``` ------------------- | 1 | ------------------- | 2 | 14 | ------------------- | 3 | 7 | 15 | ------------------- | 4 | 8 | 12 | ------------------- ``` And here, what I get: ``` -------------- | 1 | -------------- | 2 | 14 | -------------- | 3 | 7 | 15 | -------------- | 4 | 8 | 12 | -------------- ``` The code: ``` \documentclass[10pt]{article} \usepackage{multicol} \begin{document} \section{A} {\begin{tabular}{|l|l|l|l|} \hline \multicolumn{4}{|l|}{1} \\ \hline \multicolumn{3}{|l|}{2} & 14 \\ \hline 3 & \multicolumn{2}{|l|}{7} & 15 \\ \hline 4 & 8 & \multicolumn{2}{|l|}{12} \\ \hline \end{tabular}} \section{B} {\begin{tabular}{|l|l|l|l|} \hline \multicolumn{4}{|l|}{1} \\ \hline \multicolumn{3}{|l|}{2} & 14 \\ \hline & & & \\ \hline 3 & \multicolumn{2}{|l|}{7} & 15 \\ \hline 4 & 8 & \multicolumn{2}{|l|}{12} \\ \hline \end{tabular}} \section{Goal} I would like to have a table as in section B but without the third (empty) row. \end{document} ```
2012/08/15
[ "https://tex.stackexchange.com/questions/67290", "https://tex.stackexchange.com", "https://tex.stackexchange.com/users/17626/" ]
It's a feature of the underlying `\halign` primitive that any column boundary that is spanned in every row is removed from the column width calculation. Perhaps the easiest thing is to change the first line to ``` \hline \multicolumn{2}{|l}{1}&\multicolumn{1}{l}{} &\ ``` ![enter image description here](https://i.stack.imgur.com/gCrsh.png)
It seems that you want to have a 4 column table, but only have 3 columns of data. If you know the width of the additional column you want, you can add that as `\hphantom{14}` (assuming that the width of the other column is equivalent to the width of the digits `14`: ![enter image description here](https://i.stack.imgur.com/VbpnS.png) Note: ----- * The additional `\hspace*{\tabcolsep}` is required to take into account the separation that is added in between column tables. Code: ----- ``` \documentclass[10pt]{article} \usepackage{multicol} \begin{document} \section{A} {\begin{tabular}{|l|l|l|l|} \hline \multicolumn{4}{|l|}{1} \\ \hline \multicolumn{3}{|l|}{2} & 14 \\ \hline 3 & \multicolumn{2}{|l|}{7} & 15 \\ \hline 4 & 8 & \multicolumn{2}{|l|}{12} \\ \hline \end{tabular}} \section{B} {\begin{tabular}{|l|l|l|l|} \hline \multicolumn{4}{|l|}{1} \\ \hline \multicolumn{3}{|l|}{2} & 14 \\ \hline & & & \\ \hline 3 & \multicolumn{2}{|l|}{7} & 15 \\ \hline 4 & 8 & \multicolumn{2}{|l|}{12} \\ \hline \end{tabular}} \section{Goal} I would like to have a table as in section B but without the third (empty) row. \section{C} {\begin{tabular}{|l|l|l|l|} \hline \multicolumn{4}{|l|}{1} \\ % \hline 1 & & & \\ \hline \multicolumn{3}{|l|}{2} & 14 \\ \hline 3 & \multicolumn{2}{|l|}{7\hspace*{\tabcolsep}\hphantom{14}} & 15 \\ \hline 4 & 8 & \multicolumn{2}{|l|}{12} \\ \hline \end{tabular}} \end{document} ```
67,290
In a table with 4 rows and 4 columns I try to merge different cells in every row while preserving the table layout. As there are never more than 3 cells in a row, a table column seems to be dropped. If I add an empty row containing 4 cells there are 4 columns. Question: is it possible to preserve all columns without adding an empty row? Thank you. Here is my goal: ``` ------------------- | 1 | ------------------- | 2 | 14 | ------------------- | 3 | 7 | 15 | ------------------- | 4 | 8 | 12 | ------------------- ``` And here, what I get: ``` -------------- | 1 | -------------- | 2 | 14 | -------------- | 3 | 7 | 15 | -------------- | 4 | 8 | 12 | -------------- ``` The code: ``` \documentclass[10pt]{article} \usepackage{multicol} \begin{document} \section{A} {\begin{tabular}{|l|l|l|l|} \hline \multicolumn{4}{|l|}{1} \\ \hline \multicolumn{3}{|l|}{2} & 14 \\ \hline 3 & \multicolumn{2}{|l|}{7} & 15 \\ \hline 4 & 8 & \multicolumn{2}{|l|}{12} \\ \hline \end{tabular}} \section{B} {\begin{tabular}{|l|l|l|l|} \hline \multicolumn{4}{|l|}{1} \\ \hline \multicolumn{3}{|l|}{2} & 14 \\ \hline & & & \\ \hline 3 & \multicolumn{2}{|l|}{7} & 15 \\ \hline 4 & 8 & \multicolumn{2}{|l|}{12} \\ \hline \end{tabular}} \section{Goal} I would like to have a table as in section B but without the third (empty) row. \end{document} ```
2012/08/15
[ "https://tex.stackexchange.com/questions/67290", "https://tex.stackexchange.com", "https://tex.stackexchange.com/users/17626/" ]
It seems that you want to have a 4 column table, but only have 3 columns of data. If you know the width of the additional column you want, you can add that as `\hphantom{14}` (assuming that the width of the other column is equivalent to the width of the digits `14`: ![enter image description here](https://i.stack.imgur.com/VbpnS.png) Note: ----- * The additional `\hspace*{\tabcolsep}` is required to take into account the separation that is added in between column tables. Code: ----- ``` \documentclass[10pt]{article} \usepackage{multicol} \begin{document} \section{A} {\begin{tabular}{|l|l|l|l|} \hline \multicolumn{4}{|l|}{1} \\ \hline \multicolumn{3}{|l|}{2} & 14 \\ \hline 3 & \multicolumn{2}{|l|}{7} & 15 \\ \hline 4 & 8 & \multicolumn{2}{|l|}{12} \\ \hline \end{tabular}} \section{B} {\begin{tabular}{|l|l|l|l|} \hline \multicolumn{4}{|l|}{1} \\ \hline \multicolumn{3}{|l|}{2} & 14 \\ \hline & & & \\ \hline 3 & \multicolumn{2}{|l|}{7} & 15 \\ \hline 4 & 8 & \multicolumn{2}{|l|}{12} \\ \hline \end{tabular}} \section{Goal} I would like to have a table as in section B but without the third (empty) row. \section{C} {\begin{tabular}{|l|l|l|l|} \hline \multicolumn{4}{|l|}{1} \\ % \hline 1 & & & \\ \hline \multicolumn{3}{|l|}{2} & 14 \\ \hline 3 & \multicolumn{2}{|l|}{7\hspace*{\tabcolsep}\hphantom{14}} & 15 \\ \hline 4 & 8 & \multicolumn{2}{|l|}{12} \\ \hline \end{tabular}} \end{document} ```
Here is what you can do with `{NiceTabular}` of `nicematrix`. With the key `hvlines`, all the rules are drawn excepted in the blocks (created by `\Block`). ``` \documentclass[10pt]{article} \usepackage{nicematrix} \begin{document} \begin{NiceTabular}{llll}[hvlines] \Block{1-4}{} 1 \\ \Block{1-3}{} 2 &&& 14 \\ 3 & \Block{1-2}{} 7 && 15 \\ 4 & 8 & \Block{1-2}{} 12 \\ \end{NiceTabular} \end{document} ``` You need several compilations (because `nicematrix` uses PGF/Tikz nodes under the hood). [![Output of the above code](https://i.stack.imgur.com/WIrQD.png)](https://i.stack.imgur.com/WIrQD.png)
67,290
In a table with 4 rows and 4 columns I try to merge different cells in every row while preserving the table layout. As there are never more than 3 cells in a row, a table column seems to be dropped. If I add an empty row containing 4 cells there are 4 columns. Question: is it possible to preserve all columns without adding an empty row? Thank you. Here is my goal: ``` ------------------- | 1 | ------------------- | 2 | 14 | ------------------- | 3 | 7 | 15 | ------------------- | 4 | 8 | 12 | ------------------- ``` And here, what I get: ``` -------------- | 1 | -------------- | 2 | 14 | -------------- | 3 | 7 | 15 | -------------- | 4 | 8 | 12 | -------------- ``` The code: ``` \documentclass[10pt]{article} \usepackage{multicol} \begin{document} \section{A} {\begin{tabular}{|l|l|l|l|} \hline \multicolumn{4}{|l|}{1} \\ \hline \multicolumn{3}{|l|}{2} & 14 \\ \hline 3 & \multicolumn{2}{|l|}{7} & 15 \\ \hline 4 & 8 & \multicolumn{2}{|l|}{12} \\ \hline \end{tabular}} \section{B} {\begin{tabular}{|l|l|l|l|} \hline \multicolumn{4}{|l|}{1} \\ \hline \multicolumn{3}{|l|}{2} & 14 \\ \hline & & & \\ \hline 3 & \multicolumn{2}{|l|}{7} & 15 \\ \hline 4 & 8 & \multicolumn{2}{|l|}{12} \\ \hline \end{tabular}} \section{Goal} I would like to have a table as in section B but without the third (empty) row. \end{document} ```
2012/08/15
[ "https://tex.stackexchange.com/questions/67290", "https://tex.stackexchange.com", "https://tex.stackexchange.com/users/17626/" ]
It's a feature of the underlying `\halign` primitive that any column boundary that is spanned in every row is removed from the column width calculation. Perhaps the easiest thing is to change the first line to ``` \hline \multicolumn{2}{|l}{1}&\multicolumn{1}{l}{} &\ ``` ![enter image description here](https://i.stack.imgur.com/gCrsh.png)
Here is what you can do with `{NiceTabular}` of `nicematrix`. With the key `hvlines`, all the rules are drawn excepted in the blocks (created by `\Block`). ``` \documentclass[10pt]{article} \usepackage{nicematrix} \begin{document} \begin{NiceTabular}{llll}[hvlines] \Block{1-4}{} 1 \\ \Block{1-3}{} 2 &&& 14 \\ 3 & \Block{1-2}{} 7 && 15 \\ 4 & 8 & \Block{1-2}{} 12 \\ \end{NiceTabular} \end{document} ``` You need several compilations (because `nicematrix` uses PGF/Tikz nodes under the hood). [![Output of the above code](https://i.stack.imgur.com/WIrQD.png)](https://i.stack.imgur.com/WIrQD.png)
6,463,236
Alright, I'm making a game of sorts... I've done it with append as well -\_- When I call back and add the next item(i.e. #2 after doing #1) I get just that item in the print out... such as this: ```none > 1 You put your Hatchet into the bag Press enter to add more items ['Hatchet'] > > 2 You put your Toothbrush into the bag Press enter to add more items ['Toothbrush'] ``` I'd like for the bag to get more items in it and once the bag reaches three items it takes me to the next 'level'. I can't seem to add the items to the bag and keep them in the bag and then monitor the growing len(bag). If I call back the len(bag) it's always stuck back on 1. Is this because of the 'return' function I'm using? or is it something else? I figure I can try coding so that it goes into a new list with new bag after entering one item(seems like a ton of excessive code, but would work). I'm also pretty confident there is tons of excessive code in this script, I'm extremely new to Python and am doing an assignment/exercise from a book. I appreciate the help in advance!! ``` def beginning(): print 'Hello' def func(): firstitem=raw_input("> ") bag=[] limit=len(bag) a="Hatchet" b="Toothbrush" c="Map" if firstitem=="1": bag.insert(1, 'Hatchet') print 'You put your %s into the bag' % a print 'Press enter to add more items' print bag limit=len(bag) if limit == int(3): beginning() item=raw_input("> ") return func() if firstitem=="2": bag.insert(2, 'Toothbrush') print 'You put your %s into the bag' % b print 'Press enter to add more items' print bag limit=len(bag) if limit == int(3): beginning() item=raw_input("> ") return func() if firstitem=="3": bag.insert(3, 'Map') print 'You put your %s into the bag' % c print 'Press enter to add more items' print bag limit=len(bag) if limit == int(3): beginning() item=raw_input("> ") return func() ``` OK so if I make the new func. is that under the existing one? or complete new?
2011/06/24
[ "https://Stackoverflow.com/questions/6463236", "https://Stackoverflow.com", "https://Stackoverflow.com/users/813430/" ]
Your problem is that you're adding something to `bag`, but then you're recursing into the start of `func` again, where it has a different scope. It then assigns `[]` to `bag`, leaving it empty. Something you could do is make `func` take an optional argument: ``` def func(bag=None): if bag is None: bag = [] # ... return func(bag) ``` Additionally, `append` probably really is the right thing to do here.
bag is a list not a dict. If you want to add items to a list, you should use append.
6,463,236
Alright, I'm making a game of sorts... I've done it with append as well -\_- When I call back and add the next item(i.e. #2 after doing #1) I get just that item in the print out... such as this: ```none > 1 You put your Hatchet into the bag Press enter to add more items ['Hatchet'] > > 2 You put your Toothbrush into the bag Press enter to add more items ['Toothbrush'] ``` I'd like for the bag to get more items in it and once the bag reaches three items it takes me to the next 'level'. I can't seem to add the items to the bag and keep them in the bag and then monitor the growing len(bag). If I call back the len(bag) it's always stuck back on 1. Is this because of the 'return' function I'm using? or is it something else? I figure I can try coding so that it goes into a new list with new bag after entering one item(seems like a ton of excessive code, but would work). I'm also pretty confident there is tons of excessive code in this script, I'm extremely new to Python and am doing an assignment/exercise from a book. I appreciate the help in advance!! ``` def beginning(): print 'Hello' def func(): firstitem=raw_input("> ") bag=[] limit=len(bag) a="Hatchet" b="Toothbrush" c="Map" if firstitem=="1": bag.insert(1, 'Hatchet') print 'You put your %s into the bag' % a print 'Press enter to add more items' print bag limit=len(bag) if limit == int(3): beginning() item=raw_input("> ") return func() if firstitem=="2": bag.insert(2, 'Toothbrush') print 'You put your %s into the bag' % b print 'Press enter to add more items' print bag limit=len(bag) if limit == int(3): beginning() item=raw_input("> ") return func() if firstitem=="3": bag.insert(3, 'Map') print 'You put your %s into the bag' % c print 'Press enter to add more items' print bag limit=len(bag) if limit == int(3): beginning() item=raw_input("> ") return func() ``` OK so if I make the new func. is that under the existing one? or complete new?
2011/06/24
[ "https://Stackoverflow.com/questions/6463236", "https://Stackoverflow.com", "https://Stackoverflow.com/users/813430/" ]
Your problem is that you're adding something to `bag`, but then you're recursing into the start of `func` again, where it has a different scope. It then assigns `[]` to `bag`, leaving it empty. Something you could do is make `func` take an optional argument: ``` def func(bag=None): if bag is None: bag = [] # ... return func(bag) ``` Additionally, `append` probably really is the right thing to do here.
The reason why you always have the only one item in bag list is because you recreate it each time you call your function so you need to find a way how to correctly initialize it. Also it is better to use append instead of insert in your case. Please find below my sample code(not sure that this is a good idea to write code this way - so don't beat me too much for it): ``` def beginning(): print 'Hello' return [] def func(bag): item = raw_input("Enter your choice here > ") limit = len(bag) things = {'1':"Hatchet", '2':"Toothbrush", '3':"Map", '77':'Leave', '100':'backward'} if things.get(item).lower() == 'leave': print 'Bye' return elif things.get(item).lower() == 'backward': while len(bag)!=0: print bag, bag.pop() return bag.append(things.get(item)) print 'You put your %s into the bag' % things.get(item) print 'Press enter to add more items' print bag if len(bag) == 3: bag = beginning() return func(bag) func(beginning()) ```
2,027,352
The idea would be to replace ERB with templates that are pure XHTML and that the view would be pure code manipulating the template content. Have this been done already ?
2010/01/08
[ "https://Stackoverflow.com/questions/2027352", "https://Stackoverflow.com", "https://Stackoverflow.com/users/191068/" ]
There used to be [Lilu](http://InfoQ.Com/news/2007/07/mockup-driven-dev-lilu/) by [Yuri Rashkovskii](http://Rashkovskii.Com/), but it is no longer maintained. It is [still available](http://Gitorious.Org/lilu/), though, so if you're interested you can maintain it yourself. (It's very little code, actually, and the templating part proper doesn't need to change anyway. The only part that probably *does* need to change is the integration into the Rails view engine, and that should be fairly trivial, now that Rails 3 actually does *have* a proper view engine.) A newer system that leverages HTML5's `data-` attributes, is [RuHL](http://StoneAn.Com/page/ruhl/) by [Andrew Stone](http://StoneAn.Com/). Here's a quick taste (stolen from the website): ``` <!-- view.html --> <html> <body> <p data-ruhl="say_hello"/> </body> </html> # model.rb def say_hello "Hello World" end <!-- result.html --> <html> <body> <p>Hello World</p> </body> </html> ```
I'm not sure if this is exactly what you mean, but mustache sounds similar: <http://github.com/defunkt/mustache> <http://www.rubyinside.com/mustache-for-logicfree-views-in-your-ruby-web-apps-2599.html>
2,027,352
The idea would be to replace ERB with templates that are pure XHTML and that the view would be pure code manipulating the template content. Have this been done already ?
2010/01/08
[ "https://Stackoverflow.com/questions/2027352", "https://Stackoverflow.com", "https://Stackoverflow.com/users/191068/" ]
Trellis is an attempt to create a component framework in Ruby. It's borrows more from Tapestry, but should have similarities to Wicket. <http://www.trellisframework.org/>
I'm not sure if this is exactly what you mean, but mustache sounds similar: <http://github.com/defunkt/mustache> <http://www.rubyinside.com/mustache-for-logicfree-views-in-your-ruby-web-apps-2599.html>
2,027,352
The idea would be to replace ERB with templates that are pure XHTML and that the view would be pure code manipulating the template content. Have this been done already ?
2010/01/08
[ "https://Stackoverflow.com/questions/2027352", "https://Stackoverflow.com", "https://Stackoverflow.com/users/191068/" ]
There used to be [Lilu](http://InfoQ.Com/news/2007/07/mockup-driven-dev-lilu/) by [Yuri Rashkovskii](http://Rashkovskii.Com/), but it is no longer maintained. It is [still available](http://Gitorious.Org/lilu/), though, so if you're interested you can maintain it yourself. (It's very little code, actually, and the templating part proper doesn't need to change anyway. The only part that probably *does* need to change is the integration into the Rails view engine, and that should be fairly trivial, now that Rails 3 actually does *have* a proper view engine.) A newer system that leverages HTML5's `data-` attributes, is [RuHL](http://StoneAn.Com/page/ruhl/) by [Andrew Stone](http://StoneAn.Com/). Here's a quick taste (stolen from the website): ``` <!-- view.html --> <html> <body> <p data-ruhl="say_hello"/> </body> </html> # model.rb def say_hello "Hello World" end <!-- result.html --> <html> <body> <p>Hello World</p> </body> </html> ```
Trellis is an attempt to create a component framework in Ruby. It's borrows more from Tapestry, but should have similarities to Wicket. <http://www.trellisframework.org/>
11,556,430
i am using installshield msi project type. in this i am executing msiexec.exe /x[productcode] /qn /norestart - this is generating an error code 1722. can anyone please tell me what does this exactly mean? and how can i counter it? error 1722 : There is a problem with this Windows Installer package. A program run as part of the setup did not finish as expected. Contact your support personnel or package vendor. Action [2], location: [3], command: [4] i'm giving following settings - working dir - systemfolder filename and command line - msiexec.exe /x[ProductCode] /qn /norestart i have also tried REBOOT=ReallySuppress,REBOOT=S, REBOOT="ReallySuppress". can anyone please help?
2012/07/19
[ "https://Stackoverflow.com/questions/11556430", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1372278/" ]
Are you trying to run msiexec as a custom action from within an MSI? You can't do that. The second instance of msiexec is trying to instantiate the mutex, but can't as it's being held by the installation already in progress. If you're wanting to remove an already installed product as part of your installation, just use [the upgrade table](http://msdn.microsoft.com/en-us/library/windows/desktop/aa372374%28v=vs.85%29.aspx).
1722 is a generic error when a custom action encounters an error. Check whether ur customaction returs zero on success. Either u can ignore the return value of ur custom action EXE. or u should make ur custom action to return zero on success. also try /qb instead of /qn so that u could get the error (if any) occurred from windows installer. and if u got that you could fix it soon and later change it to /qn
46,566,364
Assume we have next t-SQL code: ``` ;WITH [CTE] AS ( SELECT 0 [A], 'FAULT' [B] UNION ALL SELECT 1 [A], '1' [B] UNION ALL SELECT 2 [A], '2' [B] ), [CTE2] AS ( SELECT [B] FROM [CTE] WHERE [A] > 0 ) SELECT * FROM [CTE2] WHERE 1 IN (SELECT [B] FROM [CTE2]) ``` This code faults with an error: > > "Conversion failed when converting the varchar value 'FAULT' to data type int." > > > CTE just prepares data. CTE2 filters data, so It should return two records, where [B] = '1' and [B] = '2'. And then CTE2 is used in the IN clause. 1 is an Integer. So results of (SELECT [Value] FROM [CTE2]) must be converted to Integer. Why does it try to convert string 'FAULT' to Integer? CTE2 does not return this string.
2017/10/04
[ "https://Stackoverflow.com/questions/46566364", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2032097/" ]
add ``` compile 'com.google.firebase:firebase-firestore:11.4.2' ``` You don't need com.google.firebase:firebase-database if you use Firestore alone. and you don't need to compile all google services. ``` buildscript { dependencies { classpath 'com.google.gms:google-services:3.1.0' } } dependencies { compile 'com.google.android.gms:play-services-auth:11.4.2' compile 'com.google.firebase:firebase-auth:11.4.2' compile 'com.google.firebase:firebase-storage:11.4.2' compile 'com.google.firebase:firebase-core:11.4.2' compile 'com.google.firebase:firebase-firestore:11.4.2' } apply plugin: 'com.google.gms.google-services' ``` But if you want to change versions easier to avoid conflict you should use gradle "ext" : ``` buildscript { ext.play_service_version = '11.4.2' ext.firebase_version = '11.4.2' dependencies { classpath 'com.google.gms:google-services:3.1.0' } } dependencies { compile "com.google.android.gms:play-services-auth:${play_service_version}" compile "com.google.firebase:firebase-auth:${firebase_version}" compile "com.google.firebase:firebase-storage:${firebase_version}" compile "com.google.firebase:firebase-core:${firebase_version}" compile "com.google.firebase:firebase-firestore:${firebase_version}" } apply plugin: 'com.google.gms.google-services ``` Keep in mind that play-service-version and firebase-version should be the same.
Use `compile 'com.google.firebase:firebase-firestore:11.4.2'` Cloud Firestore was introduced in [Google Play services 11.4.2](https://developers.google.com/android/guides/releases)
46,566,364
Assume we have next t-SQL code: ``` ;WITH [CTE] AS ( SELECT 0 [A], 'FAULT' [B] UNION ALL SELECT 1 [A], '1' [B] UNION ALL SELECT 2 [A], '2' [B] ), [CTE2] AS ( SELECT [B] FROM [CTE] WHERE [A] > 0 ) SELECT * FROM [CTE2] WHERE 1 IN (SELECT [B] FROM [CTE2]) ``` This code faults with an error: > > "Conversion failed when converting the varchar value 'FAULT' to data type int." > > > CTE just prepares data. CTE2 filters data, so It should return two records, where [B] = '1' and [B] = '2'. And then CTE2 is used in the IN clause. 1 is an Integer. So results of (SELECT [Value] FROM [CTE2]) must be converted to Integer. Why does it try to convert string 'FAULT' to Integer? CTE2 does not return this string.
2017/10/04
[ "https://Stackoverflow.com/questions/46566364", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2032097/" ]
Use `compile 'com.google.firebase:firebase-firestore:11.4.2'` Cloud Firestore was introduced in [Google Play services 11.4.2](https://developers.google.com/android/guides/releases)
Do not forget to add this line in the bottom of `build.gradle`: ``` apply plugin: 'com.google.gms.google-services' ```
46,566,364
Assume we have next t-SQL code: ``` ;WITH [CTE] AS ( SELECT 0 [A], 'FAULT' [B] UNION ALL SELECT 1 [A], '1' [B] UNION ALL SELECT 2 [A], '2' [B] ), [CTE2] AS ( SELECT [B] FROM [CTE] WHERE [A] > 0 ) SELECT * FROM [CTE2] WHERE 1 IN (SELECT [B] FROM [CTE2]) ``` This code faults with an error: > > "Conversion failed when converting the varchar value 'FAULT' to data type int." > > > CTE just prepares data. CTE2 filters data, so It should return two records, where [B] = '1' and [B] = '2'. And then CTE2 is used in the IN clause. 1 is an Integer. So results of (SELECT [Value] FROM [CTE2]) must be converted to Integer. Why does it try to convert string 'FAULT' to Integer? CTE2 does not return this string.
2017/10/04
[ "https://Stackoverflow.com/questions/46566364", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2032097/" ]
Use `compile 'com.google.firebase:firebase-firestore:11.4.2'` Cloud Firestore was introduced in [Google Play services 11.4.2](https://developers.google.com/android/guides/releases)
How about your SDK versions? it is in the build.gradle app level make sure its the latest: ``` android { compileSdkVersion 26 buildToolsVersion "26.0.0" ```
46,566,364
Assume we have next t-SQL code: ``` ;WITH [CTE] AS ( SELECT 0 [A], 'FAULT' [B] UNION ALL SELECT 1 [A], '1' [B] UNION ALL SELECT 2 [A], '2' [B] ), [CTE2] AS ( SELECT [B] FROM [CTE] WHERE [A] > 0 ) SELECT * FROM [CTE2] WHERE 1 IN (SELECT [B] FROM [CTE2]) ``` This code faults with an error: > > "Conversion failed when converting the varchar value 'FAULT' to data type int." > > > CTE just prepares data. CTE2 filters data, so It should return two records, where [B] = '1' and [B] = '2'. And then CTE2 is used in the IN clause. 1 is an Integer. So results of (SELECT [Value] FROM [CTE2]) must be converted to Integer. Why does it try to convert string 'FAULT' to Integer? CTE2 does not return this string.
2017/10/04
[ "https://Stackoverflow.com/questions/46566364", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2032097/" ]
add ``` compile 'com.google.firebase:firebase-firestore:11.4.2' ``` You don't need com.google.firebase:firebase-database if you use Firestore alone. and you don't need to compile all google services. ``` buildscript { dependencies { classpath 'com.google.gms:google-services:3.1.0' } } dependencies { compile 'com.google.android.gms:play-services-auth:11.4.2' compile 'com.google.firebase:firebase-auth:11.4.2' compile 'com.google.firebase:firebase-storage:11.4.2' compile 'com.google.firebase:firebase-core:11.4.2' compile 'com.google.firebase:firebase-firestore:11.4.2' } apply plugin: 'com.google.gms.google-services' ``` But if you want to change versions easier to avoid conflict you should use gradle "ext" : ``` buildscript { ext.play_service_version = '11.4.2' ext.firebase_version = '11.4.2' dependencies { classpath 'com.google.gms:google-services:3.1.0' } } dependencies { compile "com.google.android.gms:play-services-auth:${play_service_version}" compile "com.google.firebase:firebase-auth:${firebase_version}" compile "com.google.firebase:firebase-storage:${firebase_version}" compile "com.google.firebase:firebase-core:${firebase_version}" compile "com.google.firebase:firebase-firestore:${firebase_version}" } apply plugin: 'com.google.gms.google-services ``` Keep in mind that play-service-version and firebase-version should be the same.
Do not forget to add this line in the bottom of `build.gradle`: ``` apply plugin: 'com.google.gms.google-services' ```
46,566,364
Assume we have next t-SQL code: ``` ;WITH [CTE] AS ( SELECT 0 [A], 'FAULT' [B] UNION ALL SELECT 1 [A], '1' [B] UNION ALL SELECT 2 [A], '2' [B] ), [CTE2] AS ( SELECT [B] FROM [CTE] WHERE [A] > 0 ) SELECT * FROM [CTE2] WHERE 1 IN (SELECT [B] FROM [CTE2]) ``` This code faults with an error: > > "Conversion failed when converting the varchar value 'FAULT' to data type int." > > > CTE just prepares data. CTE2 filters data, so It should return two records, where [B] = '1' and [B] = '2'. And then CTE2 is used in the IN clause. 1 is an Integer. So results of (SELECT [Value] FROM [CTE2]) must be converted to Integer. Why does it try to convert string 'FAULT' to Integer? CTE2 does not return this string.
2017/10/04
[ "https://Stackoverflow.com/questions/46566364", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2032097/" ]
add ``` compile 'com.google.firebase:firebase-firestore:11.4.2' ``` You don't need com.google.firebase:firebase-database if you use Firestore alone. and you don't need to compile all google services. ``` buildscript { dependencies { classpath 'com.google.gms:google-services:3.1.0' } } dependencies { compile 'com.google.android.gms:play-services-auth:11.4.2' compile 'com.google.firebase:firebase-auth:11.4.2' compile 'com.google.firebase:firebase-storage:11.4.2' compile 'com.google.firebase:firebase-core:11.4.2' compile 'com.google.firebase:firebase-firestore:11.4.2' } apply plugin: 'com.google.gms.google-services' ``` But if you want to change versions easier to avoid conflict you should use gradle "ext" : ``` buildscript { ext.play_service_version = '11.4.2' ext.firebase_version = '11.4.2' dependencies { classpath 'com.google.gms:google-services:3.1.0' } } dependencies { compile "com.google.android.gms:play-services-auth:${play_service_version}" compile "com.google.firebase:firebase-auth:${firebase_version}" compile "com.google.firebase:firebase-storage:${firebase_version}" compile "com.google.firebase:firebase-core:${firebase_version}" compile "com.google.firebase:firebase-firestore:${firebase_version}" } apply plugin: 'com.google.gms.google-services ``` Keep in mind that play-service-version and firebase-version should be the same.
How about your SDK versions? it is in the build.gradle app level make sure its the latest: ``` android { compileSdkVersion 26 buildToolsVersion "26.0.0" ```
70,862,312
Consider this simple C program : test.c ``` int g=10; int main(){ g++; return 0; } ``` Now my question is if g is put into the data segment before execution. A picture may help clarify even better what I mean : [![enter image description here](https://i.stack.imgur.com/EwR9C.png)](https://i.stack.imgur.com/EwR9C.png) 1. Which scenario is correct ? 2. Is the g variable put into data segment before execution ? If so who is responsible for doing so ? I mean there must be some sort of STORE[xxxx],10 instruction somewhere during the process. 3. Does the code segment only contain the main() function translated into machine instructions ?
2022/01/26
[ "https://Stackoverflow.com/questions/70862312", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14210576/" ]
As far as I know about express framework. Express exposes us to a lot of useful functions. If we don't `require` or `import` express in our application then, Our application will not be able to use those functions. For example if you are creating some REST APIs then, We need our APIs to take `form-data` or `raw` as input. If we want to allow our application to take `raw-json` as input then, we need to add a middleware which consumes a built-in express function. ``` app.use(express.json()) ``` If you want create an application that has a seperate folder for all the routes. Then, we use `express.Routes()` for that. That's how we create routes file in seperate routes folder: ``` import express from 'express'; import userController from 'path/to/user/controller'; const router = express.Router(); router.post('/follow/:userid/:following', helper.verifyToken, userController.follow); router.get('/someRoute', userController.someAction); export default router; ``` Similarly, If we want to serve some static `HTML` or some `react-build`. Then, we use `express.static()` inside `app.use()` middleware like this: ``` app.use(express.static('/path/to/static/folder')); ```
As long as you don't need access to the express module elsewhere in this file, then doing: ``` const app = require('express')(); ``` is the best way. But if we require to use to this express module again and again. Such as below ``` const app = require('express')(); const friendsRouter = require('express').Router(); ``` **Then it becomes a problem and you have require it again and again.** So to make our code less redundant, we use normal given approach. As in below code: ``` const express = require('express'); const app = express(); const friendRouter = express.Router(); ```
6,656,380
First of all I shall say that I think I got how it should be done but my code will not compile any way I try. I based my assumption on [this official example of empty ptree trick](http://www.boost.org/doc/libs/1_46_1/libs/property_tree/examples/empty_ptree_trick.cpp). There you can find next line: ``` const ptree &settings = pt.get_child("settings", empty_ptree<ptree>()); ``` Which shows that it is (or should be) possible to get subptree out from ptree. So I assumed we could iterate thru ptree with something like `BOOST_FOREACH` in such manner: ``` BOOST_FOREACH(const boost::property_tree::ptree &v, config.get_child("servecies")) { } ``` But I get next error: > > Error 1 error C2440: 'initializing' : cannot convert from 'std::pair<\_Ty1,\_Ty2>' to 'const boost::property\_tree::ptree &' > > > or if I try ``` BOOST_FOREACH(boost::property_tree::ptree &v, config.get_child("servecies", boost::property_tree::empty_ptree<boost::property_tree::ptree>())) { } ``` I get: > > Error 1 error C2039: 'empty\_ptree' : is not a member of 'boost::property\_tree' > > > So what shall I do: how to iterate thru Boost Ptree and get sub Ptrees? ***Update:*** I also tried such code ``` BOOST_FOREACH(boost::property_tree::ptree::value_type &v, config.get_child("path.to.array_of_objects")) { std::cout << "First data: " << v.first.data() << std::endl; boost::property_tree::ptree subtree = (boost::property_tree::ptree) v.second ; BOOST_FOREACH(boost::property_tree::ptree::value_type &vs, subtree) { std::cout << "Sub data: " << vs.first.data() << std::endl; } } ``` This compiles, does not throw any exeptions but does not cout any `Sub data`, it just skeeps thru this cycle. ***Update 2:*** Hm... something probably went wrong in my xml - now I get correct results with that code.
2011/07/11
[ "https://Stackoverflow.com/questions/6656380", "https://Stackoverflow.com", "https://Stackoverflow.com/users/434051/" ]
The property tree iterators point to pairs of the form `(key, tree)` of type `ptree::value_type`. The standard loop for iterating through the children of the node at `path` therefore looks like: ``` BOOST_FOREACH(const ptree::value_type &v, pt.get_child(path)) { // v.first is the name of the child. // v.second is the child tree. } ```
I had the same problem with iterating trough JSON sub nodes ``` boost::property_tree::read_json(streamJSON, ptJSON); ``` If you have a structure like: ``` { playlists: [ { id: "1", x: "something" shows: [ { val: "test" }, { val: "test1" }, { val: "test2" } ] }, { id: "2" x: "else", shows: [ { val: "test3" } ] } ] } ``` You can iterate trough child nodes like this: ``` BOOST_FOREACH(boost::property_tree::ptree::value_type &playlist, ptJSON.get_child("playlists")) { unsigned long uiPlaylistId = playlist.second.get<unsigned long>("id"); BOOST_FOREACH(boost::property_tree::ptree::value_type &show, playlist.second.get_child("shows.")) { std::string strVal = show.second.get<std::string>("val"); } } ``` I could not find anything about path selector "shows." to select sub array. (notice the dot at the end) Some good documentation can be found here: <http://kaalus.atspace.com/ptree/doc/index.html> Hope this helps someone.
6,656,380
First of all I shall say that I think I got how it should be done but my code will not compile any way I try. I based my assumption on [this official example of empty ptree trick](http://www.boost.org/doc/libs/1_46_1/libs/property_tree/examples/empty_ptree_trick.cpp). There you can find next line: ``` const ptree &settings = pt.get_child("settings", empty_ptree<ptree>()); ``` Which shows that it is (or should be) possible to get subptree out from ptree. So I assumed we could iterate thru ptree with something like `BOOST_FOREACH` in such manner: ``` BOOST_FOREACH(const boost::property_tree::ptree &v, config.get_child("servecies")) { } ``` But I get next error: > > Error 1 error C2440: 'initializing' : cannot convert from 'std::pair<\_Ty1,\_Ty2>' to 'const boost::property\_tree::ptree &' > > > or if I try ``` BOOST_FOREACH(boost::property_tree::ptree &v, config.get_child("servecies", boost::property_tree::empty_ptree<boost::property_tree::ptree>())) { } ``` I get: > > Error 1 error C2039: 'empty\_ptree' : is not a member of 'boost::property\_tree' > > > So what shall I do: how to iterate thru Boost Ptree and get sub Ptrees? ***Update:*** I also tried such code ``` BOOST_FOREACH(boost::property_tree::ptree::value_type &v, config.get_child("path.to.array_of_objects")) { std::cout << "First data: " << v.first.data() << std::endl; boost::property_tree::ptree subtree = (boost::property_tree::ptree) v.second ; BOOST_FOREACH(boost::property_tree::ptree::value_type &vs, subtree) { std::cout << "Sub data: " << vs.first.data() << std::endl; } } ``` This compiles, does not throw any exeptions but does not cout any `Sub data`, it just skeeps thru this cycle. ***Update 2:*** Hm... something probably went wrong in my xml - now I get correct results with that code.
2011/07/11
[ "https://Stackoverflow.com/questions/6656380", "https://Stackoverflow.com", "https://Stackoverflow.com/users/434051/" ]
The property tree iterators point to pairs of the form `(key, tree)` of type `ptree::value_type`. The standard loop for iterating through the children of the node at `path` therefore looks like: ``` BOOST_FOREACH(const ptree::value_type &v, pt.get_child(path)) { // v.first is the name of the child. // v.second is the child tree. } ```
Using C++11, you can use the following to iterate through all the children of the node at `path`: ``` ptree children = pt.get_child(path); for (const auto& kv : children) { // kv is of type ptree::value_type // kv.first is the name of the child // kv.second is the child tree } ```
6,656,380
First of all I shall say that I think I got how it should be done but my code will not compile any way I try. I based my assumption on [this official example of empty ptree trick](http://www.boost.org/doc/libs/1_46_1/libs/property_tree/examples/empty_ptree_trick.cpp). There you can find next line: ``` const ptree &settings = pt.get_child("settings", empty_ptree<ptree>()); ``` Which shows that it is (or should be) possible to get subptree out from ptree. So I assumed we could iterate thru ptree with something like `BOOST_FOREACH` in such manner: ``` BOOST_FOREACH(const boost::property_tree::ptree &v, config.get_child("servecies")) { } ``` But I get next error: > > Error 1 error C2440: 'initializing' : cannot convert from 'std::pair<\_Ty1,\_Ty2>' to 'const boost::property\_tree::ptree &' > > > or if I try ``` BOOST_FOREACH(boost::property_tree::ptree &v, config.get_child("servecies", boost::property_tree::empty_ptree<boost::property_tree::ptree>())) { } ``` I get: > > Error 1 error C2039: 'empty\_ptree' : is not a member of 'boost::property\_tree' > > > So what shall I do: how to iterate thru Boost Ptree and get sub Ptrees? ***Update:*** I also tried such code ``` BOOST_FOREACH(boost::property_tree::ptree::value_type &v, config.get_child("path.to.array_of_objects")) { std::cout << "First data: " << v.first.data() << std::endl; boost::property_tree::ptree subtree = (boost::property_tree::ptree) v.second ; BOOST_FOREACH(boost::property_tree::ptree::value_type &vs, subtree) { std::cout << "Sub data: " << vs.first.data() << std::endl; } } ``` This compiles, does not throw any exeptions but does not cout any `Sub data`, it just skeeps thru this cycle. ***Update 2:*** Hm... something probably went wrong in my xml - now I get correct results with that code.
2011/07/11
[ "https://Stackoverflow.com/questions/6656380", "https://Stackoverflow.com", "https://Stackoverflow.com/users/434051/" ]
Using C++11, you can use the following to iterate through all the children of the node at `path`: ``` ptree children = pt.get_child(path); for (const auto& kv : children) { // kv is of type ptree::value_type // kv.first is the name of the child // kv.second is the child tree } ```
I had the same problem with iterating trough JSON sub nodes ``` boost::property_tree::read_json(streamJSON, ptJSON); ``` If you have a structure like: ``` { playlists: [ { id: "1", x: "something" shows: [ { val: "test" }, { val: "test1" }, { val: "test2" } ] }, { id: "2" x: "else", shows: [ { val: "test3" } ] } ] } ``` You can iterate trough child nodes like this: ``` BOOST_FOREACH(boost::property_tree::ptree::value_type &playlist, ptJSON.get_child("playlists")) { unsigned long uiPlaylistId = playlist.second.get<unsigned long>("id"); BOOST_FOREACH(boost::property_tree::ptree::value_type &show, playlist.second.get_child("shows.")) { std::string strVal = show.second.get<std::string>("val"); } } ``` I could not find anything about path selector "shows." to select sub array. (notice the dot at the end) Some good documentation can be found here: <http://kaalus.atspace.com/ptree/doc/index.html> Hope this helps someone.
3,727,774
How to create an offline enabled web-application such that when user visits hxxp://mywebsite/ and is offline than hxxp://mywebsite/offline/ is displayed. [There are about 100 different dynamic pages in my website, so I cannot afford to hardcode all of them in the cache manifest file]
2010/09/16
[ "https://Stackoverflow.com/questions/3727774", "https://Stackoverflow.com", "https://Stackoverflow.com/users/434196/" ]
I reference "manifest.php" instead of "cache.manifest", then my php file looks like this: ``` <?php header('Content-Type: text/cache-manifest'); echo "CACHE MANIFEST\n"; $hashes = ""; $dir = new RecursiveDirectoryIterator("."); foreach(new RecursiveIteratorIterator($dir) as $file) { $info = pathinfo($file); if ($file->IsFile() && $file != "./manifest.php" && substr($file->getFilename(), 0, 1) != ".") { echo $file . "\n"; $hashes .= md5_file($file); } } echo "# Hash: " . md5($hashes) . "\n"; ?> ``` The file hashes keep it up-to-date so that if any files change the manifest changes as well. Hope that helps :)
It's not possible to use wildcards in the cache manifest, at least it doesn't work in any current browser as far as I'm aware. An alternative approach might be to generate your cache manifest dynamically, and let a script generate all those fallback entries.
3,727,774
How to create an offline enabled web-application such that when user visits hxxp://mywebsite/ and is offline than hxxp://mywebsite/offline/ is displayed. [There are about 100 different dynamic pages in my website, so I cannot afford to hardcode all of them in the cache manifest file]
2010/09/16
[ "https://Stackoverflow.com/questions/3727774", "https://Stackoverflow.com", "https://Stackoverflow.com/users/434196/" ]
``` CACHE MANIFEST CACHE: /Offline/OfflineIndex.html FALLBACK: / /Offline/OfflineIndex.html NETWORK: * ``` This will cause all your pages across the entire site to redirect to offline when offline. The only issue is with the page that declares the manifest as that page is always cached. This means you cannot declare the manifest on every page because every visited page will then be cached itself and not redirect. So what you can do is declare your manifest on another html file (IE. Synchronize.html) then from default check whether or not your app has been made available for offline by storing a cookie or localcache value. If not redirect to synchronize.html with the manifest declared, set the localcache value, and redirect back to index. OFFLINE AWESOMENESSSSSSSSSSS!!!!
It's not possible to use wildcards in the cache manifest, at least it doesn't work in any current browser as far as I'm aware. An alternative approach might be to generate your cache manifest dynamically, and let a script generate all those fallback entries.
3,727,774
How to create an offline enabled web-application such that when user visits hxxp://mywebsite/ and is offline than hxxp://mywebsite/offline/ is displayed. [There are about 100 different dynamic pages in my website, so I cannot afford to hardcode all of them in the cache manifest file]
2010/09/16
[ "https://Stackoverflow.com/questions/3727774", "https://Stackoverflow.com", "https://Stackoverflow.com/users/434196/" ]
It's not possible to use wildcards in the cache manifest, at least it doesn't work in any current browser as far as I'm aware. An alternative approach might be to generate your cache manifest dynamically, and let a script generate all those fallback entries.
Reference your manifest file in an invisible iframe in your index page. That way your index page isn't cached as it is normally by default and you have total control over your fallbacks... No need for unreliable cookies or localStorage!
3,727,774
How to create an offline enabled web-application such that when user visits hxxp://mywebsite/ and is offline than hxxp://mywebsite/offline/ is displayed. [There are about 100 different dynamic pages in my website, so I cannot afford to hardcode all of them in the cache manifest file]
2010/09/16
[ "https://Stackoverflow.com/questions/3727774", "https://Stackoverflow.com", "https://Stackoverflow.com/users/434196/" ]
``` CACHE MANIFEST CACHE: /Offline/OfflineIndex.html FALLBACK: / /Offline/OfflineIndex.html NETWORK: * ``` This will cause all your pages across the entire site to redirect to offline when offline. The only issue is with the page that declares the manifest as that page is always cached. This means you cannot declare the manifest on every page because every visited page will then be cached itself and not redirect. So what you can do is declare your manifest on another html file (IE. Synchronize.html) then from default check whether or not your app has been made available for offline by storing a cookie or localcache value. If not redirect to synchronize.html with the manifest declared, set the localcache value, and redirect back to index. OFFLINE AWESOMENESSSSSSSSSSS!!!!
I reference "manifest.php" instead of "cache.manifest", then my php file looks like this: ``` <?php header('Content-Type: text/cache-manifest'); echo "CACHE MANIFEST\n"; $hashes = ""; $dir = new RecursiveDirectoryIterator("."); foreach(new RecursiveIteratorIterator($dir) as $file) { $info = pathinfo($file); if ($file->IsFile() && $file != "./manifest.php" && substr($file->getFilename(), 0, 1) != ".") { echo $file . "\n"; $hashes .= md5_file($file); } } echo "# Hash: " . md5($hashes) . "\n"; ?> ``` The file hashes keep it up-to-date so that if any files change the manifest changes as well. Hope that helps :)
3,727,774
How to create an offline enabled web-application such that when user visits hxxp://mywebsite/ and is offline than hxxp://mywebsite/offline/ is displayed. [There are about 100 different dynamic pages in my website, so I cannot afford to hardcode all of them in the cache manifest file]
2010/09/16
[ "https://Stackoverflow.com/questions/3727774", "https://Stackoverflow.com", "https://Stackoverflow.com/users/434196/" ]
I reference "manifest.php" instead of "cache.manifest", then my php file looks like this: ``` <?php header('Content-Type: text/cache-manifest'); echo "CACHE MANIFEST\n"; $hashes = ""; $dir = new RecursiveDirectoryIterator("."); foreach(new RecursiveIteratorIterator($dir) as $file) { $info = pathinfo($file); if ($file->IsFile() && $file != "./manifest.php" && substr($file->getFilename(), 0, 1) != ".") { echo $file . "\n"; $hashes .= md5_file($file); } } echo "# Hash: " . md5($hashes) . "\n"; ?> ``` The file hashes keep it up-to-date so that if any files change the manifest changes as well. Hope that helps :)
Reference your manifest file in an invisible iframe in your index page. That way your index page isn't cached as it is normally by default and you have total control over your fallbacks... No need for unreliable cookies or localStorage!
3,727,774
How to create an offline enabled web-application such that when user visits hxxp://mywebsite/ and is offline than hxxp://mywebsite/offline/ is displayed. [There are about 100 different dynamic pages in my website, so I cannot afford to hardcode all of them in the cache manifest file]
2010/09/16
[ "https://Stackoverflow.com/questions/3727774", "https://Stackoverflow.com", "https://Stackoverflow.com/users/434196/" ]
``` CACHE MANIFEST CACHE: /Offline/OfflineIndex.html FALLBACK: / /Offline/OfflineIndex.html NETWORK: * ``` This will cause all your pages across the entire site to redirect to offline when offline. The only issue is with the page that declares the manifest as that page is always cached. This means you cannot declare the manifest on every page because every visited page will then be cached itself and not redirect. So what you can do is declare your manifest on another html file (IE. Synchronize.html) then from default check whether or not your app has been made available for offline by storing a cookie or localcache value. If not redirect to synchronize.html with the manifest declared, set the localcache value, and redirect back to index. OFFLINE AWESOMENESSSSSSSSSSS!!!!
Reference your manifest file in an invisible iframe in your index page. That way your index page isn't cached as it is normally by default and you have total control over your fallbacks... No need for unreliable cookies or localStorage!
253
I wonder if we have enough interest to start up a blog. I would love to see a blog on here, there's a lot of stuff we could cover. In order to start up a blog though we've gotta follow the guidelines [here](http://blogoverflow.com/getting-started/). 1. Raise the idea on the child meta. A community blog needs the involvement of community members. **done** 2. Define the scope and purpose of the blog. Is the blog about the site? Is it about the site’s topic? Is it about the industry around the topic? Keep in mind the audience of your community and their interests. Another generic blog about may not be all that interesting. 3. Recruit contributors. Who will write entries for the blog? Starting a blog is a bit like going through the buffet line. Be realistic – don’t let your eyes be bigger than your stomach. Think seriously about if and how often you will be able to contribute a blog post, including research/prep time. 4. Plan a schedule. Given the results of steps #2 and #3, think about a rough idea of a schedule for the blog. Will there be one post a week, posted Mondays? Will there be posts on Tuesdays and posts on Fridays? You don’t need to be pushing out posts daily, but I would say at least one post a week.
2012/01/19
[ "https://movies.meta.stackexchange.com/questions/253", "https://movies.meta.stackexchange.com", "https://movies.meta.stackexchange.com/users/52/" ]
I also think it's still too early to start a blog, but once the community has grown a little more this could really help promote the site further. Especially well-written reviews about new movies might really help attract some search-engine traffic. Movie analyses and other bits about movie history could also link to interesting questions on the site itself and provide a starting point for interested readers to browse. If we get to the point of starting a blog, I would certainly be interested in taking part.
I wouldn't mind doing a blog about movies, reviews, services, etc, but I don't know how reliably I could update it but if it was ok for me to toss a few articles in here or there that would be a good match.
253
I wonder if we have enough interest to start up a blog. I would love to see a blog on here, there's a lot of stuff we could cover. In order to start up a blog though we've gotta follow the guidelines [here](http://blogoverflow.com/getting-started/). 1. Raise the idea on the child meta. A community blog needs the involvement of community members. **done** 2. Define the scope and purpose of the blog. Is the blog about the site? Is it about the site’s topic? Is it about the industry around the topic? Keep in mind the audience of your community and their interests. Another generic blog about may not be all that interesting. 3. Recruit contributors. Who will write entries for the blog? Starting a blog is a bit like going through the buffet line. Be realistic – don’t let your eyes be bigger than your stomach. Think seriously about if and how often you will be able to contribute a blog post, including research/prep time. 4. Plan a schedule. Given the results of steps #2 and #3, think about a rough idea of a schedule for the blog. Will there be one post a week, posted Mondays? Will there be posts on Tuesdays and posts on Fridays? You don’t need to be pushing out posts daily, but I would say at least one post a week.
2012/01/19
[ "https://movies.meta.stackexchange.com/questions/253", "https://movies.meta.stackexchange.com", "https://movies.meta.stackexchange.com/users/52/" ]
I'm writing reviews on a facebook page at the moment that could easily be transferred here.
I wouldn't mind doing a blog about movies, reviews, services, etc, but I don't know how reliably I could update it but if it was ok for me to toss a few articles in here or there that would be a good match.
253
I wonder if we have enough interest to start up a blog. I would love to see a blog on here, there's a lot of stuff we could cover. In order to start up a blog though we've gotta follow the guidelines [here](http://blogoverflow.com/getting-started/). 1. Raise the idea on the child meta. A community blog needs the involvement of community members. **done** 2. Define the scope and purpose of the blog. Is the blog about the site? Is it about the site’s topic? Is it about the industry around the topic? Keep in mind the audience of your community and their interests. Another generic blog about may not be all that interesting. 3. Recruit contributors. Who will write entries for the blog? Starting a blog is a bit like going through the buffet line. Be realistic – don’t let your eyes be bigger than your stomach. Think seriously about if and how often you will be able to contribute a blog post, including research/prep time. 4. Plan a schedule. Given the results of steps #2 and #3, think about a rough idea of a schedule for the blog. Will there be one post a week, posted Mondays? Will there be posts on Tuesdays and posts on Fridays? You don’t need to be pushing out posts daily, but I would say at least one post a week.
2012/01/19
[ "https://movies.meta.stackexchange.com/questions/253", "https://movies.meta.stackexchange.com", "https://movies.meta.stackexchange.com/users/52/" ]
**No, unfortunately we couldn't!** As to [this announcement](https://meta.stackexchange.com/q/244467/162011) the SE framework will not start any new community blogs in the near future, which puts a hold to all blog proposal efforts (for now?).
I wouldn't mind doing a blog about movies, reviews, services, etc, but I don't know how reliably I could update it but if it was ok for me to toss a few articles in here or there that would be a good match.
253
I wonder if we have enough interest to start up a blog. I would love to see a blog on here, there's a lot of stuff we could cover. In order to start up a blog though we've gotta follow the guidelines [here](http://blogoverflow.com/getting-started/). 1. Raise the idea on the child meta. A community blog needs the involvement of community members. **done** 2. Define the scope and purpose of the blog. Is the blog about the site? Is it about the site’s topic? Is it about the industry around the topic? Keep in mind the audience of your community and their interests. Another generic blog about may not be all that interesting. 3. Recruit contributors. Who will write entries for the blog? Starting a blog is a bit like going through the buffet line. Be realistic – don’t let your eyes be bigger than your stomach. Think seriously about if and how often you will be able to contribute a blog post, including research/prep time. 4. Plan a schedule. Given the results of steps #2 and #3, think about a rough idea of a schedule for the blog. Will there be one post a week, posted Mondays? Will there be posts on Tuesdays and posts on Fridays? You don’t need to be pushing out posts daily, but I would say at least one post a week.
2012/01/19
[ "https://movies.meta.stackexchange.com/questions/253", "https://movies.meta.stackexchange.com", "https://movies.meta.stackexchange.com/users/52/" ]
I also think it's still too early to start a blog, but once the community has grown a little more this could really help promote the site further. Especially well-written reviews about new movies might really help attract some search-engine traffic. Movie analyses and other bits about movie history could also link to interesting questions on the site itself and provide a starting point for interested readers to browse. If we get to the point of starting a blog, I would certainly be interested in taking part.
I'm writing reviews on a facebook page at the moment that could easily be transferred here.
253
I wonder if we have enough interest to start up a blog. I would love to see a blog on here, there's a lot of stuff we could cover. In order to start up a blog though we've gotta follow the guidelines [here](http://blogoverflow.com/getting-started/). 1. Raise the idea on the child meta. A community blog needs the involvement of community members. **done** 2. Define the scope and purpose of the blog. Is the blog about the site? Is it about the site’s topic? Is it about the industry around the topic? Keep in mind the audience of your community and their interests. Another generic blog about may not be all that interesting. 3. Recruit contributors. Who will write entries for the blog? Starting a blog is a bit like going through the buffet line. Be realistic – don’t let your eyes be bigger than your stomach. Think seriously about if and how often you will be able to contribute a blog post, including research/prep time. 4. Plan a schedule. Given the results of steps #2 and #3, think about a rough idea of a schedule for the blog. Will there be one post a week, posted Mondays? Will there be posts on Tuesdays and posts on Fridays? You don’t need to be pushing out posts daily, but I would say at least one post a week.
2012/01/19
[ "https://movies.meta.stackexchange.com/questions/253", "https://movies.meta.stackexchange.com", "https://movies.meta.stackexchange.com/users/52/" ]
I also think it's still too early to start a blog, but once the community has grown a little more this could really help promote the site further. Especially well-written reviews about new movies might really help attract some search-engine traffic. Movie analyses and other bits about movie history could also link to interesting questions on the site itself and provide a starting point for interested readers to browse. If we get to the point of starting a blog, I would certainly be interested in taking part.
**No, unfortunately we couldn't!** As to [this announcement](https://meta.stackexchange.com/q/244467/162011) the SE framework will not start any new community blogs in the near future, which puts a hold to all blog proposal efforts (for now?).
18,654,955
I have a property on a page that gets a query-string value, I need this to be on all related pages. The pages already inherit a base class, and I don't want the property here as not everything that inherits this base class needs this particular property. My idea was to create an interface with this property and have every page that needs the property implement this interface. Is this good practice, or should I inherit the base class into another class with just this property and then have all pages inherit this instead of the base? Thanks
2013/09/06
[ "https://Stackoverflow.com/questions/18654955", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1835758/" ]
I assume the implementation of the property will be the same on all pages that need them? If you use an interface, all pages need to implement this, which will lead to a lot of copy/paste code. Isn't it better to write some kind of provider class to which you can pass your page instance (if needed) and use this class to fetch the property? You better use composition over inheritance here I think, because if you create another base class you will extend your page hierarchy with yet another base class.
I would say it does not matter much, but i prefer another inheritance level because you only have to write the code once. With the Interface you are more flexible, maybe you want in some cases no Auto Property but a check for null or something like that. So if it is always the same Property then go with a inherited second base class, if you have different checks in the getter or setter then go with the interface.
18,654,955
I have a property on a page that gets a query-string value, I need this to be on all related pages. The pages already inherit a base class, and I don't want the property here as not everything that inherits this base class needs this particular property. My idea was to create an interface with this property and have every page that needs the property implement this interface. Is this good practice, or should I inherit the base class into another class with just this property and then have all pages inherit this instead of the base? Thanks
2013/09/06
[ "https://Stackoverflow.com/questions/18654955", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1835758/" ]
I assume the implementation of the property will be the same on all pages that need them? If you use an interface, all pages need to implement this, which will lead to a lot of copy/paste code. Isn't it better to write some kind of provider class to which you can pass your page instance (if needed) and use this class to fetch the property? You better use composition over inheritance here I think, because if you create another base class you will extend your page hierarchy with yet another base class.
Interfaces do not require you to duplicate the code! You can use delegation. This is similar to the accepted answer except in one way. An interface can be used to expose a contract to other classes that allow them to interact with your class in a consistent and powerful way. A key question then becomes, will external code ever want to "know" whether you Form has that functionality? [delegation-instead-of-inheritance](https://stackoverflow.com/questions/832536/when-to-use-delegation-instead-of-inheritance)
48,199,388
I have the following text file. ``` [box_1] show ethernet show adjacency show log [box_2] run ethernet run adjacency show log ``` I need to write a robot file, where if it encounters [box\_1], it will run, ``` run ethernet run adjacency show log ``` And if it encounters [box\_2], it will run the following commands under that. This is my robot code: ``` ${File}= Get File Resources\\Source\\textfile.txt @{list}= Split to lines ${File} Log ${list} ${op}= Get From List ${list} 0 log ${op} ${first_line}= Get Slice From List ${list} 1 :FOR ${line} IN @{first_line} \ ${result}= Run Keyword If '${op}'=='[${box_1}]' and run_command ${line} \ ${result}= Run Keyword If '${op}'=='[${box_2}]' and run_command ${line} ``` But its only taking identifying the [box\_1] and not going to [box\_2]. And there can be multiple number of boxes followed by the commands. Can someone please help? Thanks.
2018/01/11
[ "https://Stackoverflow.com/questions/48199388", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9190087/" ]
Although @Psytho is right, it is not entirely sufficient to solve the issues. In the below example I've added the required Libraries and a custom keyword to mimic the run command `Operatingsystem` keyword. In this example I skip the headers and execute the commands. In a similar way you can use the value in `${match[0]}` to learn which header is currently active and use it in your determination what to do. ``` *** Settings *** Library String Library Collections Library OperatingSystem *** Test Cases *** TC v1 ${File}= Get File textfile.txt @{lines}= Split to lines ${File} :FOR ${line} IN @{lines} \ ${match} Get Regexp Matches ${line} \\[(.*)\\] 1 \ ${count} Get Length ${match} \ ${result} Run Keyword If ${count} == 0 run_custom_command ${line} TC v2 @{commands} Get Commands box_2 textfile.txt :FOR ${command} IN @{commands} \ run_custom_command ${command} @{commands} Get Commands box_1 textfile.txt :FOR ${command} IN @{commands} \ run_custom_command ${command} *** Keywords *** Run Custom Command [Arguments] ${command} Log Run Command: ${command} [return] SUCCESS Get Commands [Arguments] ${ENV} ${filepath} ${string}= Get File ${filepath} ${match}= Get Regexp Matches ${string} \\[${ENV}\\]\\n((.|\\n)*?)(\\[|$) 1 @{lines}= Split to lines ${match[0]} [Return] ${lines} ``` EDIT: Added a second option that relies on just a regular expression.
You assign `${op}` only once in `${op}= Get From List ${list} 0` and never change it. That is why it is always `[box_1]` and never becomes `[box_2]`. You must moe the assignment into `FOR`-loop and change the rest of code so that the commands between different `box`-es are executed.
48,199,388
I have the following text file. ``` [box_1] show ethernet show adjacency show log [box_2] run ethernet run adjacency show log ``` I need to write a robot file, where if it encounters [box\_1], it will run, ``` run ethernet run adjacency show log ``` And if it encounters [box\_2], it will run the following commands under that. This is my robot code: ``` ${File}= Get File Resources\\Source\\textfile.txt @{list}= Split to lines ${File} Log ${list} ${op}= Get From List ${list} 0 log ${op} ${first_line}= Get Slice From List ${list} 1 :FOR ${line} IN @{first_line} \ ${result}= Run Keyword If '${op}'=='[${box_1}]' and run_command ${line} \ ${result}= Run Keyword If '${op}'=='[${box_2}]' and run_command ${line} ``` But its only taking identifying the [box\_1] and not going to [box\_2]. And there can be multiple number of boxes followed by the commands. Can someone please help? Thanks.
2018/01/11
[ "https://Stackoverflow.com/questions/48199388", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9190087/" ]
You assign `${op}` only once in `${op}= Get From List ${list} 0` and never change it. That is why it is always `[box_1]` and never becomes `[box_2]`. You must moe the assignment into `FOR`-loop and change the rest of code so that the commands between different `box`-es are executed.
``` *** Variables *** ${A} A ${B} B ${C} c *** Keywords *** Test Log To Console ${A} Log To Console ${B} Log To Console ${C} [Return] ${A} ${B} ${C} *** Test Cases *** Test1 ${A0} ${B0} ${C0} Test Log To Console ${A0} Log To Console ${B0} Log To Console ${C0} When you are calling the keyword in the test case u can assign the return variables as above.` ```
48,199,388
I have the following text file. ``` [box_1] show ethernet show adjacency show log [box_2] run ethernet run adjacency show log ``` I need to write a robot file, where if it encounters [box\_1], it will run, ``` run ethernet run adjacency show log ``` And if it encounters [box\_2], it will run the following commands under that. This is my robot code: ``` ${File}= Get File Resources\\Source\\textfile.txt @{list}= Split to lines ${File} Log ${list} ${op}= Get From List ${list} 0 log ${op} ${first_line}= Get Slice From List ${list} 1 :FOR ${line} IN @{first_line} \ ${result}= Run Keyword If '${op}'=='[${box_1}]' and run_command ${line} \ ${result}= Run Keyword If '${op}'=='[${box_2}]' and run_command ${line} ``` But its only taking identifying the [box\_1] and not going to [box\_2]. And there can be multiple number of boxes followed by the commands. Can someone please help? Thanks.
2018/01/11
[ "https://Stackoverflow.com/questions/48199388", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9190087/" ]
Although @Psytho is right, it is not entirely sufficient to solve the issues. In the below example I've added the required Libraries and a custom keyword to mimic the run command `Operatingsystem` keyword. In this example I skip the headers and execute the commands. In a similar way you can use the value in `${match[0]}` to learn which header is currently active and use it in your determination what to do. ``` *** Settings *** Library String Library Collections Library OperatingSystem *** Test Cases *** TC v1 ${File}= Get File textfile.txt @{lines}= Split to lines ${File} :FOR ${line} IN @{lines} \ ${match} Get Regexp Matches ${line} \\[(.*)\\] 1 \ ${count} Get Length ${match} \ ${result} Run Keyword If ${count} == 0 run_custom_command ${line} TC v2 @{commands} Get Commands box_2 textfile.txt :FOR ${command} IN @{commands} \ run_custom_command ${command} @{commands} Get Commands box_1 textfile.txt :FOR ${command} IN @{commands} \ run_custom_command ${command} *** Keywords *** Run Custom Command [Arguments] ${command} Log Run Command: ${command} [return] SUCCESS Get Commands [Arguments] ${ENV} ${filepath} ${string}= Get File ${filepath} ${match}= Get Regexp Matches ${string} \\[${ENV}\\]\\n((.|\\n)*?)(\\[|$) 1 @{lines}= Split to lines ${match[0]} [Return] ${lines} ``` EDIT: Added a second option that relies on just a regular expression.
``` *** Variables *** ${A} A ${B} B ${C} c *** Keywords *** Test Log To Console ${A} Log To Console ${B} Log To Console ${C} [Return] ${A} ${B} ${C} *** Test Cases *** Test1 ${A0} ${B0} ${C0} Test Log To Console ${A0} Log To Console ${B0} Log To Console ${C0} When you are calling the keyword in the test case u can assign the return variables as above.` ```
21,362,372
I'm developing a Windows Phone unofficial client for Imgur, the documentation talks about Comments endpoints/data models...but there isn't any method to retrieve comments about a specific image or album. Anyone known how to retrive them...if is possible? Thanks
2014/01/26
[ "https://Stackoverflow.com/questions/21362372", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2401333/" ]
After a month I understand how to retrieve them: just putting "/comments" after album or image id. Stupid incomplete API documentation.
To clarify I want to add few things: Indeed You need to put `'/comments`', so in the end Your url should look like: `https://api.imgur.com/3/gallery/cUkfS9L/comments/best`. The id (`'cUkfS9L'` here) may be the id of IMAGE, not only gallery. But what's more important, and where I had a problem: It looks like this doesn't work for newest images. I tried it for a list of newest images (got by `'(...)time/all(...)'` sorting in query) and noticed that getting comments works for like 4th page of my images. My solution was changing `"time/all"` to `"top"`. Now I had much older images and getting comments worked well for them.
14,870,668
My web hosting provider said that they are changing to php 5.4 from 5.2.17 ,and i try to run my site in local with the php 5.4, I got full of issuses like this > > Strict Standards: Non-static method JError::isError() should not be called statically, assuming $this from incompatible context in D:\xampp\htdocs\indoor\libraries\joomla\application\application.php on line 721 > > > So I need to upgrade my joomla version which is near to 1.5, presently I am using 1.5.24
2013/02/14
[ "https://Stackoverflow.com/questions/14870668", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1948688/" ]
Strict standards mode is a PHP setting that tells it to throw warning messages when the code does certain things which are not technically correct. PHP can, however, cope with these issues -- as per the message in the question, PHP is able to make an assumption about the code in this case and carry on. These strict mode warnings have always been there; the reason you're getting them in 5.4 and not in 5.2 is because in 5.4 they are enabled by default, whereas in 5.2 they default to being switched off. Basically, with each new version, PHP is slowly getting stricter about obsolete or poor programming practices. This is generally a good thing, but does leave older code with problems when you upgrade. But strict mode isn't compulsory; it can be disabled. So if all you're getting are warnings about strict mode, the quickest way to deal with the problem is to switch it off. You can do this in the `PHP.ini` or `.htaccess` files, or in PHP itself using `ini_set()`. * PHP.ini: `error_reporting=30719` * .htaccess: `php_value error_reporting 30719` * in your PHP code: `error_reporting(E_ALL & ~E_STRICT);` (30719 is eqivalent to `E_ALL` (32767) minus `E_STRICT` (2048), but the names E\_ALL and E\_STRICT aren't valid in the ini files so you have to use the numeric values) In general, it would be better to upgrade your system to software that doesn't cause Strict Mode warnings; maybe a newer version of Joomla would help with this. But in the short term this will prevent the strict mode warnings from coming up, and hopefully help you make the transition to the new PHP version. Hope that helps.
This is your internal joomla error as your calling a global function statically.Use the debugger and run your page in debug mode.
14,870,668
My web hosting provider said that they are changing to php 5.4 from 5.2.17 ,and i try to run my site in local with the php 5.4, I got full of issuses like this > > Strict Standards: Non-static method JError::isError() should not be called statically, assuming $this from incompatible context in D:\xampp\htdocs\indoor\libraries\joomla\application\application.php on line 721 > > > So I need to upgrade my joomla version which is near to 1.5, presently I am using 1.5.24
2013/02/14
[ "https://Stackoverflow.com/questions/14870668", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1948688/" ]
Strict standards mode is a PHP setting that tells it to throw warning messages when the code does certain things which are not technically correct. PHP can, however, cope with these issues -- as per the message in the question, PHP is able to make an assumption about the code in this case and carry on. These strict mode warnings have always been there; the reason you're getting them in 5.4 and not in 5.2 is because in 5.4 they are enabled by default, whereas in 5.2 they default to being switched off. Basically, with each new version, PHP is slowly getting stricter about obsolete or poor programming practices. This is generally a good thing, but does leave older code with problems when you upgrade. But strict mode isn't compulsory; it can be disabled. So if all you're getting are warnings about strict mode, the quickest way to deal with the problem is to switch it off. You can do this in the `PHP.ini` or `.htaccess` files, or in PHP itself using `ini_set()`. * PHP.ini: `error_reporting=30719` * .htaccess: `php_value error_reporting 30719` * in your PHP code: `error_reporting(E_ALL & ~E_STRICT);` (30719 is eqivalent to `E_ALL` (32767) minus `E_STRICT` (2048), but the names E\_ALL and E\_STRICT aren't valid in the ini files so you have to use the numeric values) In general, it would be better to upgrade your system to software that doesn't cause Strict Mode warnings; maybe a newer version of Joomla would help with this. But in the short term this will prevent the strict mode warnings from coming up, and hopefully help you make the transition to the new PHP version. Hope that helps.
Yes it is better to upgrade your joomla version now because there is no security updates for joomla 1.5. Also remember that all new extensions developed are in compatible with joomla 2.5 and you can't use it for 1.5.
14,870,668
My web hosting provider said that they are changing to php 5.4 from 5.2.17 ,and i try to run my site in local with the php 5.4, I got full of issuses like this > > Strict Standards: Non-static method JError::isError() should not be called statically, assuming $this from incompatible context in D:\xampp\htdocs\indoor\libraries\joomla\application\application.php on line 721 > > > So I need to upgrade my joomla version which is near to 1.5, presently I am using 1.5.24
2013/02/14
[ "https://Stackoverflow.com/questions/14870668", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1948688/" ]
Strict standards mode is a PHP setting that tells it to throw warning messages when the code does certain things which are not technically correct. PHP can, however, cope with these issues -- as per the message in the question, PHP is able to make an assumption about the code in this case and carry on. These strict mode warnings have always been there; the reason you're getting them in 5.4 and not in 5.2 is because in 5.4 they are enabled by default, whereas in 5.2 they default to being switched off. Basically, with each new version, PHP is slowly getting stricter about obsolete or poor programming practices. This is generally a good thing, but does leave older code with problems when you upgrade. But strict mode isn't compulsory; it can be disabled. So if all you're getting are warnings about strict mode, the quickest way to deal with the problem is to switch it off. You can do this in the `PHP.ini` or `.htaccess` files, or in PHP itself using `ini_set()`. * PHP.ini: `error_reporting=30719` * .htaccess: `php_value error_reporting 30719` * in your PHP code: `error_reporting(E_ALL & ~E_STRICT);` (30719 is eqivalent to `E_ALL` (32767) minus `E_STRICT` (2048), but the names E\_ALL and E\_STRICT aren't valid in the ini files so you have to use the numeric values) In general, it would be better to upgrade your system to software that doesn't cause Strict Mode warnings; maybe a newer version of Joomla would help with this. But in the short term this will prevent the strict mode warnings from coming up, and hopefully help you make the transition to the new PHP version. Hope that helps.
PHP Strict Standards: `"Non-static method JTable::getInstance() should not be called statically, assuming $this from incompatible context"` [Source: http://mytecharticle.com/?p=1484](http://mytecharticle.com/?p=1484)
20,706
I'm reading about the derivation of shallow water equations, and I have a hard time understanding why $$ w(\eta) = \frac{D\eta}{Dt}$$ where $w$ is the vertical velocity, $\eta$ is the (top or bottom) vertical boundary of the layer and $D/Dt$ is the material derivative. In Atmospheric and Oceanic Fluid Dynamics (2nd ed. 2017, chapter 3.1.2), Vallis gives the following explanation: > > At the top the vertical velocity is the material derivative of the > position of a particular fluid element. But the position of the fluid > at the top is just $\eta$, and therefore > $$ w(\eta) = \frac{D\eta}{Dt}$$ > > > Why is the vertical velocity at the top the material derivative? *Edit:* Added a schematic illustration of the shallow layer. As you see, $\eta$ is not assumed to be constant. [![Shallow layer](https://i.stack.imgur.com/WyYWR.png)](https://i.stack.imgur.com/WyYWR.png)
2021/01/20
[ "https://earthscience.stackexchange.com/questions/20706", "https://earthscience.stackexchange.com", "https://earthscience.stackexchange.com/users/21677/" ]
This is a statement of the kinematic free surface boundary condition: there can be no normal flow through the boundary, only tangential flow along it. Equivalently, the normal velocity (relative to the interface) of the free surface position is the same as the velocity of the fluid. Defining the position of the free surface as $$ z = \eta(x,y,t) $$ then taking the material derivative $$\frac{\partial z}{\partial t} + u\frac{\partial z}{\partial x} + v\frac{\partial z}{\partial y} + w\frac{\partial z}{\partial z} = \frac{D\eta}{Dt} $$ Every term on the LHS besides $\frac{\partial z}{\partial z}=1$ goes to $0$ due to the fact that $z$ is an independent coordinate (see this [answer](https://math.stackexchange.com/a/3067984) for reference), leaving us with $$w(z=\eta) = \frac{D\eta}{Dt}$$
As a refresher, let's refer back to the definition of the material derivative: $$\frac{D}{Dt}=\frac{\partial}{\partial t}+u\frac{\partial}{\partial x}+v\frac{\partial}{\partial y}+w\frac{\partial}{\partial z}$$ If we apply it to $\eta$, then we get: $$\frac{D \eta}{Dt}=\frac{\partial \eta}{\partial t}+u\frac{\partial\eta}{\partial x}+v\frac{\partial\eta}{\partial y}+w\frac{\partial\eta}{\partial z}$$ Let's, for a second, consider that $\eta$ is the height of the fluid. We can replace $\eta$ with $z$ evaluated at the fluid level. Thus, we get $$\frac{Dz}{Dt}|^{fluid}=\frac{\partial z}{\partial t}|^{fluid}+u\frac{\partial z}{\partial x}|^{fluid}+v\frac{\partial z}{\partial y}|^{fluid}+w\frac{\partial z}{\partial z}|^{fluid}$$ Since there is only one Eulerian derivative that is dependent on $z$, it follows $$\frac{D\eta}{Dt}=\frac{Dz}{Dt}|^{fluid}=w\frac{\partial z}{\partial z}|^{fluid}=w|^{fluid}=w(\eta)$$
58,703,635
For example I have a column: ``` x <- c(-0.5, 1.1, 6.0, 4.5, 0.1, -0.2) ``` I want to add a new column where each value is assigned with a 3 percentage group For example : * if x -3<=x<0 => group -3 * if x 3<=x<6 => group 6 So I will have a new column: c(-3, 3, 9, 6, 3, -3)
2019/11/05
[ "https://Stackoverflow.com/questions/58703635", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11214389/" ]
You can use `findInterval` or `cut` for this ``` x <- c(-0.5, 1.1, 6.0, 4.5, 0.1, -0.2) brks <- seq(-3, 9, 3) lbls <- c(-3,3,6,9) lbls[findInterval(x, brks)] #[1] -3 3 9 6 3 -3 ``` Or as mentioned by @StupidWolf using `cut` ``` cut(x, breaks=brks,right=FALSE, labels=lbls) ```
Base R solution: ``` # Define the value using the ranges: num_frame$perc_group <- ifelse(num_frame$num_vec < 0 & num_frame$num_vec >= -3, -3, ifelse(num_frame$num_vec == 0, 0, ifelse(num_frame$num_vec > 0 & num_frame$num_vec <= 3, 3, 6))) ``` Data: ``` num_frame <- structure(list(num_vec = c(-0.5, 1.1, 6, 4.5, 0.1, -0.2)), class = "data.frame", row.names = c(NA, -6L)) ```
4,586,011
I was trying to compute the following integral: $$I=\int\_0^1\int\_0^1\cdots \int\_0^1 \frac{n \max\{x\_1,x\_2,\ldots,x\_n\}}{x\_1+x\_2+\ldots+x\_n}dx\_1dx\_2\ldots dx\_n.$$ My attempt was: Let $X\_1,X\_2, \ldots, X\_n$ be a collection of i.i.d. uniform random variables on $(0,1)$. Then, $$I= n\mathbb{E}\left[\frac{\max\{X\_1,X\_2,\ldots,X\_n\}}{X\_1+X\_2+\ldots+X\_n} \right] = n\mathbb{E}\left[\max\_{1\leqslant i \leqslant n}\frac{X\_i}{X\_1+X\_2+\ldots+X\_n} \right].$$ Now, I understand that $$\left\{\frac{X\_i}{X\_1+X\_2+\ldots+X\_n}\right\}\_{1\leqslant i \leqslant n}$$ is an identically distributed sequence of random variables but I don't know how to proceed further. Any further help using either probability or general integral calculus is much appreciated. Thank you very much for your time and attention.
2022/11/27
[ "https://math.stackexchange.com/questions/4586011", "https://math.stackexchange.com", "https://math.stackexchange.com/users/91784/" ]
Let $n\geq 2$. First, note that $x\_1,x\_2,\cdots,x\_n$ are equally distributed, and each has a $1/n$ chance of being the largest element, so your integral is equal to $n$ times the integral over the region of $[0,1]^n$ where $x\_n$ is the largest element of $x\_1,x\_2,\cdots, x\_n$. More explicitly, we have that \begin{equation} \begin{split} I&=n\int\_0^1\int\_0^1\cdots\int\_0^1\frac{\max\{x\_1,x\_2,\cdots,x\_n\}}{x\_1+x\_2+\cdots+x\_n}dx\_1dx\_2\cdots dx\_n\\ &=n^2\int\_0^1\int\_0^{x\_n}\cdots\int\_0^{x\_n}\frac{x\_n}{x\_1+x\_2+\cdots+x\_n}dx\_1dx\_2\cdots dx\_n\\ &=n^2\int\_0^1\int\_0^{x\_n}\cdots\int\_0^{x\_n}\frac{1}{x\_1/x\_n+x\_2/x\_n+\cdots+1}dx\_1dx\_2\cdots dx\_n\\ &=n^2\int\_0^1\int\_0^1\cdots\int\_0^1\frac{x\_n^{n-1}}{x\_1+x\_2+\cdots+1}dx\_1dx\_2\cdots dx\_n\\ &=n^2\left[\int\_0^1 x\_n^{n-1}dx\_n\right]\left[\int\_0^1\cdots\int\_0^1\frac{1}{x\_1+x\_2+\cdots+1}dx\_1dx\_2\cdots dx\_{n-1}\right]\\ &=n\int\_0^1\cdots\int\_0^1\frac{1}{x\_1+x\_2+\cdots+1}dx\_1dx\_2\cdots dx\_{n-1}\\ \end{split} \end{equation} Letting $A\_k(u)$ be the PDF of the distribution for the sum $X\_1+X\_2+\cdots+X\_k$ of $k$ uniform variables on $[0,1]$ (known as the [Irwin-Hall distribution](https://en.wikipedia.org/wiki/Irwin%E2%80%93Hall_distribution)), we may simplify $$I=n\int\_0^{n-1} \frac{A\_{n-1}(u)}{u+1}du$$ In fact, $A\_{n-1}(u)$ has the explicit closed form $$A\_{n-1}(u)=\frac{1}{(n-2)!}\sum\_{k=0}^{n-1}(-1)^k{n-1\choose k}(u-k)^{n-2}H(u-k)$$ where $$H(x)= \begin{cases} 1,&x\geq 0\\ 0,&x<0\\ \end{cases}$$ is the Heavside step function. \begin{equation} \begin{split} I&=\frac{n}{(n-2)!}\sum\_{k=0}^{n-1}(-1)^k{n-1\choose k}\int\_0^{n-1}\frac{(u-k)^{n-2}}{u+1}H(u-k)du\\ &=\frac{n}{(n-2)!}\sum\_{k=0}^{n-1}(-1)^k{n-1\choose k}\int\_k^{n-1}\frac{(u-k)^{n-2}}{u+1}du\\ &=\frac{n}{(n-2)!}\sum\_{k=0}^{n-1}(-1)^k{n-1\choose k}\int\_k^{n-1}\sum\_{m=0}^{n-2}(-1)^m(u+1)^{n-3-m}(k+1)^mdu\\ &=\frac{n}{(n-2)!}\sum\_{k=0}^{n-1}(-1)^k{n-1\choose k}\left[(-1)^n(k+1)^{n-2} \log(u+1)+\sum\_{m=0}^{n-3}(-1)^m\frac{(u+1)^{n-2-m}}{n-2-m}(k+1)^m\right]\_{u=k}^{n-1}\\ &=\frac{n}{(n-2)!}\sum\_{k=0}^{n-1}(-1)^k{n-1\choose k}[(-1)^{n+1}(k+1)^{n-2}\log(k+1)+P\_n(k)]\\ \end{split} \end{equation} Where $P\_n(k)$ is a polynomial in $k$ of degree $n-2$. It is [well known](https://en.m.wikipedia.org/wiki/Finite_difference#Higher-order_differences) that for any function $f(x)$, the $p$-th forward difference of $f(x)$ at $0$ is given by $$\Delta^p[f](0)=\sum\_{k=0}^p(-1)^{p-k}{p\choose k}f(k)$$ so since $P\_n(k)$ has degree $n-2$, then $$0=\Delta^{n-1}[P\_n](0)=\sum\_{k=0}^{n-1}(-1)^{n-k-1}{n-1\choose k}P\_n(k)$$ We may therefore simplify to get $$I=\frac{n}{(n-2)!}\sum\_{k=0}^{n-1}(-1)^{n-k-1}{n-1\choose k}(k+1)^{n-2}\log(k+1)$$ Some reindexing and algebraic manipulation brings us to our final closed form $$\boxed{I=\frac{1}{(n-2)!}\sum\_{k=2}^n(-1)^{n-k}{n\choose k}k^{n-1}\log(k)}$$ for $n\geq 2$, and $I=1$ for $n=1$.
This is a partial answer on the basis of a partial analysis which might nevertheless be interesting. **Mathematica algorithm** Apart from the first few values of $n$ which I have calculated "by hand" I took the problem to calculate the integral we call here $i(n)$ as a nice exercise in Mathematica: Writing $$\frac{1}{\sum\_{i=1}^{n} x\_i} =\frac{1}{p}\int\_{0}^{1} p^{\sum\_{i=1}^{n} {x\_i}}\;dp$$ we have to calculate the kernel integral $$\kappa(p)= n \int\_{[0,1]^n}\max(x\_1, ..., x\_n) \prod\_{i=1}^{n} dx\_i p^{x\_i}$$ which, for reasons of symmetry, can be written as $$\kappa(p)=n! n \int\_{[0,1]^n}x\_n\; \text{Boole}(0\le x\_1\le...\le x\_n) \prod\_{i=1}^{n} dx\_i p^{x\_i}$$ Here $\text{Boole}(True)=1$ and $\text{Boole}(False)=0$. Finally we have to calculate $$i(n) = \frac{1}{p}\int\_{0}^{1} \kappa(p)\;dp$$ I implemented this for $n=1..10$ in the following Mathematica code ``` Table[x[0] = 0; i1 = n! n Integrate[ x[n] p^(Sum[x[i], {i, 1, n}] - 1) Boole[ Less @@ Table[x[i - 1], {i, 1, n + 1}]], Sequence @@ Table[{x[i], 0, 1}, {i, 1, n}]]; {n, Integrate[i1, {p, 0, 1}]}, {n, 1, 10}] ``` which gives $$ \begin{array}{c} \{1,1\} \\ \{2,2\log (2)\} \\ \left\{3,3\log \left(\frac{27}{16}\right)\right\} \\ \left\{4,4(11 \log (4)-\frac{27 \log (3)}{2})\right\} \\ \left\{5,5(-\frac{1}{3} 272 \log (2)+27 \log (3)+\frac{125 \log (5)}{6})\right\} \\ \left\{6,\frac{6}{24} (6496 \log (2)+486 \log (3)-3125 \log (5))\right\} \\ \left\{7,\frac{7}{120} (-87808 \log (2)-43011 \log (3)+46875 \log (5)+16807 \log (7))\right\} \\ \left\{8,\frac{8}{720} (2053376 \log (2)+964467 \log (3)-546875 \log (5)-823543 \log (7))\right\} \\ \left\{9,9(\frac{-33922048 \log (2)-3024621 \log (3)+2734375 \log (5)+11529602 \log (7)}{2520})\right\} \\ \left\{10,10(\frac{1067291648 \log (2)-281722779 \log (3)+25390625 \log (5)-242121642 \log (7)}{20160})\right\} \\ \end{array} $$ Starting at $n=6$ we observe a factor $\frac{1}{(n-2)!}$.
4,586,011
I was trying to compute the following integral: $$I=\int\_0^1\int\_0^1\cdots \int\_0^1 \frac{n \max\{x\_1,x\_2,\ldots,x\_n\}}{x\_1+x\_2+\ldots+x\_n}dx\_1dx\_2\ldots dx\_n.$$ My attempt was: Let $X\_1,X\_2, \ldots, X\_n$ be a collection of i.i.d. uniform random variables on $(0,1)$. Then, $$I= n\mathbb{E}\left[\frac{\max\{X\_1,X\_2,\ldots,X\_n\}}{X\_1+X\_2+\ldots+X\_n} \right] = n\mathbb{E}\left[\max\_{1\leqslant i \leqslant n}\frac{X\_i}{X\_1+X\_2+\ldots+X\_n} \right].$$ Now, I understand that $$\left\{\frac{X\_i}{X\_1+X\_2+\ldots+X\_n}\right\}\_{1\leqslant i \leqslant n}$$ is an identically distributed sequence of random variables but I don't know how to proceed further. Any further help using either probability or general integral calculus is much appreciated. Thank you very much for your time and attention.
2022/11/27
[ "https://math.stackexchange.com/questions/4586011", "https://math.stackexchange.com", "https://math.stackexchange.com/users/91784/" ]
Let $n\geq 2$. First, note that $x\_1,x\_2,\cdots,x\_n$ are equally distributed, and each has a $1/n$ chance of being the largest element, so your integral is equal to $n$ times the integral over the region of $[0,1]^n$ where $x\_n$ is the largest element of $x\_1,x\_2,\cdots, x\_n$. More explicitly, we have that \begin{equation} \begin{split} I&=n\int\_0^1\int\_0^1\cdots\int\_0^1\frac{\max\{x\_1,x\_2,\cdots,x\_n\}}{x\_1+x\_2+\cdots+x\_n}dx\_1dx\_2\cdots dx\_n\\ &=n^2\int\_0^1\int\_0^{x\_n}\cdots\int\_0^{x\_n}\frac{x\_n}{x\_1+x\_2+\cdots+x\_n}dx\_1dx\_2\cdots dx\_n\\ &=n^2\int\_0^1\int\_0^{x\_n}\cdots\int\_0^{x\_n}\frac{1}{x\_1/x\_n+x\_2/x\_n+\cdots+1}dx\_1dx\_2\cdots dx\_n\\ &=n^2\int\_0^1\int\_0^1\cdots\int\_0^1\frac{x\_n^{n-1}}{x\_1+x\_2+\cdots+1}dx\_1dx\_2\cdots dx\_n\\ &=n^2\left[\int\_0^1 x\_n^{n-1}dx\_n\right]\left[\int\_0^1\cdots\int\_0^1\frac{1}{x\_1+x\_2+\cdots+1}dx\_1dx\_2\cdots dx\_{n-1}\right]\\ &=n\int\_0^1\cdots\int\_0^1\frac{1}{x\_1+x\_2+\cdots+1}dx\_1dx\_2\cdots dx\_{n-1}\\ \end{split} \end{equation} Letting $A\_k(u)$ be the PDF of the distribution for the sum $X\_1+X\_2+\cdots+X\_k$ of $k$ uniform variables on $[0,1]$ (known as the [Irwin-Hall distribution](https://en.wikipedia.org/wiki/Irwin%E2%80%93Hall_distribution)), we may simplify $$I=n\int\_0^{n-1} \frac{A\_{n-1}(u)}{u+1}du$$ In fact, $A\_{n-1}(u)$ has the explicit closed form $$A\_{n-1}(u)=\frac{1}{(n-2)!}\sum\_{k=0}^{n-1}(-1)^k{n-1\choose k}(u-k)^{n-2}H(u-k)$$ where $$H(x)= \begin{cases} 1,&x\geq 0\\ 0,&x<0\\ \end{cases}$$ is the Heavside step function. \begin{equation} \begin{split} I&=\frac{n}{(n-2)!}\sum\_{k=0}^{n-1}(-1)^k{n-1\choose k}\int\_0^{n-1}\frac{(u-k)^{n-2}}{u+1}H(u-k)du\\ &=\frac{n}{(n-2)!}\sum\_{k=0}^{n-1}(-1)^k{n-1\choose k}\int\_k^{n-1}\frac{(u-k)^{n-2}}{u+1}du\\ &=\frac{n}{(n-2)!}\sum\_{k=0}^{n-1}(-1)^k{n-1\choose k}\int\_k^{n-1}\sum\_{m=0}^{n-2}(-1)^m(u+1)^{n-3-m}(k+1)^mdu\\ &=\frac{n}{(n-2)!}\sum\_{k=0}^{n-1}(-1)^k{n-1\choose k}\left[(-1)^n(k+1)^{n-2} \log(u+1)+\sum\_{m=0}^{n-3}(-1)^m\frac{(u+1)^{n-2-m}}{n-2-m}(k+1)^m\right]\_{u=k}^{n-1}\\ &=\frac{n}{(n-2)!}\sum\_{k=0}^{n-1}(-1)^k{n-1\choose k}[(-1)^{n+1}(k+1)^{n-2}\log(k+1)+P\_n(k)]\\ \end{split} \end{equation} Where $P\_n(k)$ is a polynomial in $k$ of degree $n-2$. It is [well known](https://en.m.wikipedia.org/wiki/Finite_difference#Higher-order_differences) that for any function $f(x)$, the $p$-th forward difference of $f(x)$ at $0$ is given by $$\Delta^p[f](0)=\sum\_{k=0}^p(-1)^{p-k}{p\choose k}f(k)$$ so since $P\_n(k)$ has degree $n-2$, then $$0=\Delta^{n-1}[P\_n](0)=\sum\_{k=0}^{n-1}(-1)^{n-k-1}{n-1\choose k}P\_n(k)$$ We may therefore simplify to get $$I=\frac{n}{(n-2)!}\sum\_{k=0}^{n-1}(-1)^{n-k-1}{n-1\choose k}(k+1)^{n-2}\log(k+1)$$ Some reindexing and algebraic manipulation brings us to our final closed form $$\boxed{I=\frac{1}{(n-2)!}\sum\_{k=2}^n(-1)^{n-k}{n\choose k}k^{n-1}\log(k)}$$ for $n\geq 2$, and $I=1$ for $n=1$.
Two answers have already given explicit formulas for $I$. It may be of interest to see the behaviour of $I$ for large $n$, which is not immediate from the expression given by C-RAM. An asymptotic expansion for large $n$ may be derived via [Laplace's method](http://dlmf.nist.gov/2.3.iii) applied to the integral representation given by Carl Schildkraut: \begin{align\*} I &= (n - 1)\int\_0^{ + \infty } {\left( {\frac{{1 - {\rm e}^{ - u} }}{u}} \right)^n {\rm d}u} = (n - 1)\int\_0^{ + \infty } {\exp \left( { - n\log \left( {\frac{u}{{1 - {\rm e}^{ - u} }}} \right)} \right){\rm d}u} \\ & \sim \frac{{n - 1}}{n}\sum\limits\_{k = 0}^\infty {\frac{{a\_k }}{{n^k }}} = 2 + \sum\limits\_{k = 1}^\infty {\frac{{b\_k }}{{n^k }}} = 2 - \frac{4}{{3n}} + \frac{8}{{45n^3 }} + \frac{{56}}{{135n^4 }} + \frac{{152}}{{189n^5 }} + \frac{{1256}}{{945n^6 }} + \ldots , \end{align\*} where $b\_k = a\_k - a\_{k - 1}$ and $$ a\_k = \left[ {\frac{{{\rm d}^k }}{{{\rm d}u^k }}\left( {\frac{u}{{\log \left( {\frac{u}{{1 - {\rm e}^{ - u} }}} \right)}}} \right)^{k + 1} } \right]\_{u = 0} = \left[ {\frac{{{\rm d}^k }}{{{\rm d}u^k }}\left( {\frac{u}{{\frac{u}{2} - \log \left( {\frac{{\sinh (u/2)}}{{u/2}}} \right)}}} \right)^{k + 1} } \right]\_{u = 0}. $$ Using the [known](https://functions.wolfram.com/ElementaryFunctions/Sinh/06/05/0002/) power series of $\log(\sinh (z)/z)$, it may be shown that $$ a\_k = \sum\limits\_{m = 0}^k 2^{m + k + 1} \frac{{(m + k)!}}{{m!}}B\_{k,m} \!\left( {\frac{1}{{24}},0, - \frac{1}{{2880}}, \ldots ,\frac{{B\_{k - m + 2} }}{{(k - m + 2)(k - m + 2)!}}} \right) , $$ where $B\_{k,m}$ are the [ordinary Bell polynomials](https://en.wikipedia.org/wiki/Bell_polynomials#Ordinary_Bell_polynomials) and $B\_m$ are the [Bernoulli numbers](https://dlmf.nist.gov/24.2).
4,586,011
I was trying to compute the following integral: $$I=\int\_0^1\int\_0^1\cdots \int\_0^1 \frac{n \max\{x\_1,x\_2,\ldots,x\_n\}}{x\_1+x\_2+\ldots+x\_n}dx\_1dx\_2\ldots dx\_n.$$ My attempt was: Let $X\_1,X\_2, \ldots, X\_n$ be a collection of i.i.d. uniform random variables on $(0,1)$. Then, $$I= n\mathbb{E}\left[\frac{\max\{X\_1,X\_2,\ldots,X\_n\}}{X\_1+X\_2+\ldots+X\_n} \right] = n\mathbb{E}\left[\max\_{1\leqslant i \leqslant n}\frac{X\_i}{X\_1+X\_2+\ldots+X\_n} \right].$$ Now, I understand that $$\left\{\frac{X\_i}{X\_1+X\_2+\ldots+X\_n}\right\}\_{1\leqslant i \leqslant n}$$ is an identically distributed sequence of random variables but I don't know how to proceed further. Any further help using either probability or general integral calculus is much appreciated. Thank you very much for your time and attention.
2022/11/27
[ "https://math.stackexchange.com/questions/4586011", "https://math.stackexchange.com", "https://math.stackexchange.com/users/91784/" ]
Here's a start, which reduces the problem to a one-variable integral of a simple function, and may be of interest even though I don't know how to finish it yet. --- For $n=1$, the integral is clearly $1$. Now, let $c\_n=\mathbb E[1/(X\_1+\cdots+X\_n)]$ where $X\_1,\dots,X\_n\sim\operatorname{Unif}([0,1])$ independently. Write $X=X\_1+\cdots+X\_n$ for notational simplicity. We have $$I\_n=n\mathbb E\left[\frac{\max X\_i}X\right]=nc\_n-n\mathbb E\left[\frac{1-\max X\_i}X\right].$$ Note that $1-\max X\_i$ is the probability that, if $T\sim\operatorname{Unif}([0,1])$, $T>X\_1,\dots,X\_n$. This means that \begin{align\*} I\_n&=nc\_n-n\int\_0^1\mathbb E\left[\frac{[t>X\_1][t>X\_2]\cdots[t>X\_n]}X\right]dt\\&=nc\_n-n\int\_0^1t^n\mathbb E\left[\frac1X\bigg|X\_1,\dots,X\_n<t\right]dt. \end{align\*} Conditioned on being less than $t$, each $X\_i$ follows the distribution $\operatorname{Unif}([0,1])$, and so $\mathbb E[1/X\mid X\_1,\dots,X\_n<t]=t^{-1}c\_n$, giving $$I\_n=nc\_n-n\int\_0^1 t^{n-1}c\_ndt=(n-1)c\_n.$$ So, it suffices to compute $c\_n$, i.e. $$c\_n=\int\_{[0,1]^n}\frac1{x\_1+\cdots+x\_n}d\mathbf x.$$ We once again do this by way of an additional variable: \begin{align\*} c\_n&=\int\_{[0,1]^n}\frac1{x\_1+\cdots+x\_n}d\mathbf x\\ &=\int\_{[0,1]^n}\int\_0^1 t^{x\_1+\cdots+x\_n}\frac{dt}td\mathbf x\\ &=\int\_0^1 \left(\int\_0^1 t^x dx\right)^n\frac{dt}t=\int\_0^1 \left(\frac{t-1}{\log t}\right)^n\frac{dt}t=\int\_0^1 \frac{(1-t)^n}{t\log(1/t)^n}dt. \end{align\*} Substituting $u=\log(1/t)$, so that $du=-dt/t$, we have $$c\_n=\int\_0^\infty \left(\frac{1-e^{-u}}u\right)^ndu.$$ So $$\boxed{I=(n-1)\int\_0^\infty\left(\frac{1-e^{-u}}u\right)^ndu}.$$
This is a partial answer on the basis of a partial analysis which might nevertheless be interesting. **Mathematica algorithm** Apart from the first few values of $n$ which I have calculated "by hand" I took the problem to calculate the integral we call here $i(n)$ as a nice exercise in Mathematica: Writing $$\frac{1}{\sum\_{i=1}^{n} x\_i} =\frac{1}{p}\int\_{0}^{1} p^{\sum\_{i=1}^{n} {x\_i}}\;dp$$ we have to calculate the kernel integral $$\kappa(p)= n \int\_{[0,1]^n}\max(x\_1, ..., x\_n) \prod\_{i=1}^{n} dx\_i p^{x\_i}$$ which, for reasons of symmetry, can be written as $$\kappa(p)=n! n \int\_{[0,1]^n}x\_n\; \text{Boole}(0\le x\_1\le...\le x\_n) \prod\_{i=1}^{n} dx\_i p^{x\_i}$$ Here $\text{Boole}(True)=1$ and $\text{Boole}(False)=0$. Finally we have to calculate $$i(n) = \frac{1}{p}\int\_{0}^{1} \kappa(p)\;dp$$ I implemented this for $n=1..10$ in the following Mathematica code ``` Table[x[0] = 0; i1 = n! n Integrate[ x[n] p^(Sum[x[i], {i, 1, n}] - 1) Boole[ Less @@ Table[x[i - 1], {i, 1, n + 1}]], Sequence @@ Table[{x[i], 0, 1}, {i, 1, n}]]; {n, Integrate[i1, {p, 0, 1}]}, {n, 1, 10}] ``` which gives $$ \begin{array}{c} \{1,1\} \\ \{2,2\log (2)\} \\ \left\{3,3\log \left(\frac{27}{16}\right)\right\} \\ \left\{4,4(11 \log (4)-\frac{27 \log (3)}{2})\right\} \\ \left\{5,5(-\frac{1}{3} 272 \log (2)+27 \log (3)+\frac{125 \log (5)}{6})\right\} \\ \left\{6,\frac{6}{24} (6496 \log (2)+486 \log (3)-3125 \log (5))\right\} \\ \left\{7,\frac{7}{120} (-87808 \log (2)-43011 \log (3)+46875 \log (5)+16807 \log (7))\right\} \\ \left\{8,\frac{8}{720} (2053376 \log (2)+964467 \log (3)-546875 \log (5)-823543 \log (7))\right\} \\ \left\{9,9(\frac{-33922048 \log (2)-3024621 \log (3)+2734375 \log (5)+11529602 \log (7)}{2520})\right\} \\ \left\{10,10(\frac{1067291648 \log (2)-281722779 \log (3)+25390625 \log (5)-242121642 \log (7)}{20160})\right\} \\ \end{array} $$ Starting at $n=6$ we observe a factor $\frac{1}{(n-2)!}$.
4,586,011
I was trying to compute the following integral: $$I=\int\_0^1\int\_0^1\cdots \int\_0^1 \frac{n \max\{x\_1,x\_2,\ldots,x\_n\}}{x\_1+x\_2+\ldots+x\_n}dx\_1dx\_2\ldots dx\_n.$$ My attempt was: Let $X\_1,X\_2, \ldots, X\_n$ be a collection of i.i.d. uniform random variables on $(0,1)$. Then, $$I= n\mathbb{E}\left[\frac{\max\{X\_1,X\_2,\ldots,X\_n\}}{X\_1+X\_2+\ldots+X\_n} \right] = n\mathbb{E}\left[\max\_{1\leqslant i \leqslant n}\frac{X\_i}{X\_1+X\_2+\ldots+X\_n} \right].$$ Now, I understand that $$\left\{\frac{X\_i}{X\_1+X\_2+\ldots+X\_n}\right\}\_{1\leqslant i \leqslant n}$$ is an identically distributed sequence of random variables but I don't know how to proceed further. Any further help using either probability or general integral calculus is much appreciated. Thank you very much for your time and attention.
2022/11/27
[ "https://math.stackexchange.com/questions/4586011", "https://math.stackexchange.com", "https://math.stackexchange.com/users/91784/" ]
Here's a start, which reduces the problem to a one-variable integral of a simple function, and may be of interest even though I don't know how to finish it yet. --- For $n=1$, the integral is clearly $1$. Now, let $c\_n=\mathbb E[1/(X\_1+\cdots+X\_n)]$ where $X\_1,\dots,X\_n\sim\operatorname{Unif}([0,1])$ independently. Write $X=X\_1+\cdots+X\_n$ for notational simplicity. We have $$I\_n=n\mathbb E\left[\frac{\max X\_i}X\right]=nc\_n-n\mathbb E\left[\frac{1-\max X\_i}X\right].$$ Note that $1-\max X\_i$ is the probability that, if $T\sim\operatorname{Unif}([0,1])$, $T>X\_1,\dots,X\_n$. This means that \begin{align\*} I\_n&=nc\_n-n\int\_0^1\mathbb E\left[\frac{[t>X\_1][t>X\_2]\cdots[t>X\_n]}X\right]dt\\&=nc\_n-n\int\_0^1t^n\mathbb E\left[\frac1X\bigg|X\_1,\dots,X\_n<t\right]dt. \end{align\*} Conditioned on being less than $t$, each $X\_i$ follows the distribution $\operatorname{Unif}([0,1])$, and so $\mathbb E[1/X\mid X\_1,\dots,X\_n<t]=t^{-1}c\_n$, giving $$I\_n=nc\_n-n\int\_0^1 t^{n-1}c\_ndt=(n-1)c\_n.$$ So, it suffices to compute $c\_n$, i.e. $$c\_n=\int\_{[0,1]^n}\frac1{x\_1+\cdots+x\_n}d\mathbf x.$$ We once again do this by way of an additional variable: \begin{align\*} c\_n&=\int\_{[0,1]^n}\frac1{x\_1+\cdots+x\_n}d\mathbf x\\ &=\int\_{[0,1]^n}\int\_0^1 t^{x\_1+\cdots+x\_n}\frac{dt}td\mathbf x\\ &=\int\_0^1 \left(\int\_0^1 t^x dx\right)^n\frac{dt}t=\int\_0^1 \left(\frac{t-1}{\log t}\right)^n\frac{dt}t=\int\_0^1 \frac{(1-t)^n}{t\log(1/t)^n}dt. \end{align\*} Substituting $u=\log(1/t)$, so that $du=-dt/t$, we have $$c\_n=\int\_0^\infty \left(\frac{1-e^{-u}}u\right)^ndu.$$ So $$\boxed{I=(n-1)\int\_0^\infty\left(\frac{1-e^{-u}}u\right)^ndu}.$$
Two answers have already given explicit formulas for $I$. It may be of interest to see the behaviour of $I$ for large $n$, which is not immediate from the expression given by C-RAM. An asymptotic expansion for large $n$ may be derived via [Laplace's method](http://dlmf.nist.gov/2.3.iii) applied to the integral representation given by Carl Schildkraut: \begin{align\*} I &= (n - 1)\int\_0^{ + \infty } {\left( {\frac{{1 - {\rm e}^{ - u} }}{u}} \right)^n {\rm d}u} = (n - 1)\int\_0^{ + \infty } {\exp \left( { - n\log \left( {\frac{u}{{1 - {\rm e}^{ - u} }}} \right)} \right){\rm d}u} \\ & \sim \frac{{n - 1}}{n}\sum\limits\_{k = 0}^\infty {\frac{{a\_k }}{{n^k }}} = 2 + \sum\limits\_{k = 1}^\infty {\frac{{b\_k }}{{n^k }}} = 2 - \frac{4}{{3n}} + \frac{8}{{45n^3 }} + \frac{{56}}{{135n^4 }} + \frac{{152}}{{189n^5 }} + \frac{{1256}}{{945n^6 }} + \ldots , \end{align\*} where $b\_k = a\_k - a\_{k - 1}$ and $$ a\_k = \left[ {\frac{{{\rm d}^k }}{{{\rm d}u^k }}\left( {\frac{u}{{\log \left( {\frac{u}{{1 - {\rm e}^{ - u} }}} \right)}}} \right)^{k + 1} } \right]\_{u = 0} = \left[ {\frac{{{\rm d}^k }}{{{\rm d}u^k }}\left( {\frac{u}{{\frac{u}{2} - \log \left( {\frac{{\sinh (u/2)}}{{u/2}}} \right)}}} \right)^{k + 1} } \right]\_{u = 0}. $$ Using the [known](https://functions.wolfram.com/ElementaryFunctions/Sinh/06/05/0002/) power series of $\log(\sinh (z)/z)$, it may be shown that $$ a\_k = \sum\limits\_{m = 0}^k 2^{m + k + 1} \frac{{(m + k)!}}{{m!}}B\_{k,m} \!\left( {\frac{1}{{24}},0, - \frac{1}{{2880}}, \ldots ,\frac{{B\_{k - m + 2} }}{{(k - m + 2)(k - m + 2)!}}} \right) , $$ where $B\_{k,m}$ are the [ordinary Bell polynomials](https://en.wikipedia.org/wiki/Bell_polynomials#Ordinary_Bell_polynomials) and $B\_m$ are the [Bernoulli numbers](https://dlmf.nist.gov/24.2).
4,586,011
I was trying to compute the following integral: $$I=\int\_0^1\int\_0^1\cdots \int\_0^1 \frac{n \max\{x\_1,x\_2,\ldots,x\_n\}}{x\_1+x\_2+\ldots+x\_n}dx\_1dx\_2\ldots dx\_n.$$ My attempt was: Let $X\_1,X\_2, \ldots, X\_n$ be a collection of i.i.d. uniform random variables on $(0,1)$. Then, $$I= n\mathbb{E}\left[\frac{\max\{X\_1,X\_2,\ldots,X\_n\}}{X\_1+X\_2+\ldots+X\_n} \right] = n\mathbb{E}\left[\max\_{1\leqslant i \leqslant n}\frac{X\_i}{X\_1+X\_2+\ldots+X\_n} \right].$$ Now, I understand that $$\left\{\frac{X\_i}{X\_1+X\_2+\ldots+X\_n}\right\}\_{1\leqslant i \leqslant n}$$ is an identically distributed sequence of random variables but I don't know how to proceed further. Any further help using either probability or general integral calculus is much appreciated. Thank you very much for your time and attention.
2022/11/27
[ "https://math.stackexchange.com/questions/4586011", "https://math.stackexchange.com", "https://math.stackexchange.com/users/91784/" ]
Two answers have already given explicit formulas for $I$. It may be of interest to see the behaviour of $I$ for large $n$, which is not immediate from the expression given by C-RAM. An asymptotic expansion for large $n$ may be derived via [Laplace's method](http://dlmf.nist.gov/2.3.iii) applied to the integral representation given by Carl Schildkraut: \begin{align\*} I &= (n - 1)\int\_0^{ + \infty } {\left( {\frac{{1 - {\rm e}^{ - u} }}{u}} \right)^n {\rm d}u} = (n - 1)\int\_0^{ + \infty } {\exp \left( { - n\log \left( {\frac{u}{{1 - {\rm e}^{ - u} }}} \right)} \right){\rm d}u} \\ & \sim \frac{{n - 1}}{n}\sum\limits\_{k = 0}^\infty {\frac{{a\_k }}{{n^k }}} = 2 + \sum\limits\_{k = 1}^\infty {\frac{{b\_k }}{{n^k }}} = 2 - \frac{4}{{3n}} + \frac{8}{{45n^3 }} + \frac{{56}}{{135n^4 }} + \frac{{152}}{{189n^5 }} + \frac{{1256}}{{945n^6 }} + \ldots , \end{align\*} where $b\_k = a\_k - a\_{k - 1}$ and $$ a\_k = \left[ {\frac{{{\rm d}^k }}{{{\rm d}u^k }}\left( {\frac{u}{{\log \left( {\frac{u}{{1 - {\rm e}^{ - u} }}} \right)}}} \right)^{k + 1} } \right]\_{u = 0} = \left[ {\frac{{{\rm d}^k }}{{{\rm d}u^k }}\left( {\frac{u}{{\frac{u}{2} - \log \left( {\frac{{\sinh (u/2)}}{{u/2}}} \right)}}} \right)^{k + 1} } \right]\_{u = 0}. $$ Using the [known](https://functions.wolfram.com/ElementaryFunctions/Sinh/06/05/0002/) power series of $\log(\sinh (z)/z)$, it may be shown that $$ a\_k = \sum\limits\_{m = 0}^k 2^{m + k + 1} \frac{{(m + k)!}}{{m!}}B\_{k,m} \!\left( {\frac{1}{{24}},0, - \frac{1}{{2880}}, \ldots ,\frac{{B\_{k - m + 2} }}{{(k - m + 2)(k - m + 2)!}}} \right) , $$ where $B\_{k,m}$ are the [ordinary Bell polynomials](https://en.wikipedia.org/wiki/Bell_polynomials#Ordinary_Bell_polynomials) and $B\_m$ are the [Bernoulli numbers](https://dlmf.nist.gov/24.2).
This is a partial answer on the basis of a partial analysis which might nevertheless be interesting. **Mathematica algorithm** Apart from the first few values of $n$ which I have calculated "by hand" I took the problem to calculate the integral we call here $i(n)$ as a nice exercise in Mathematica: Writing $$\frac{1}{\sum\_{i=1}^{n} x\_i} =\frac{1}{p}\int\_{0}^{1} p^{\sum\_{i=1}^{n} {x\_i}}\;dp$$ we have to calculate the kernel integral $$\kappa(p)= n \int\_{[0,1]^n}\max(x\_1, ..., x\_n) \prod\_{i=1}^{n} dx\_i p^{x\_i}$$ which, for reasons of symmetry, can be written as $$\kappa(p)=n! n \int\_{[0,1]^n}x\_n\; \text{Boole}(0\le x\_1\le...\le x\_n) \prod\_{i=1}^{n} dx\_i p^{x\_i}$$ Here $\text{Boole}(True)=1$ and $\text{Boole}(False)=0$. Finally we have to calculate $$i(n) = \frac{1}{p}\int\_{0}^{1} \kappa(p)\;dp$$ I implemented this for $n=1..10$ in the following Mathematica code ``` Table[x[0] = 0; i1 = n! n Integrate[ x[n] p^(Sum[x[i], {i, 1, n}] - 1) Boole[ Less @@ Table[x[i - 1], {i, 1, n + 1}]], Sequence @@ Table[{x[i], 0, 1}, {i, 1, n}]]; {n, Integrate[i1, {p, 0, 1}]}, {n, 1, 10}] ``` which gives $$ \begin{array}{c} \{1,1\} \\ \{2,2\log (2)\} \\ \left\{3,3\log \left(\frac{27}{16}\right)\right\} \\ \left\{4,4(11 \log (4)-\frac{27 \log (3)}{2})\right\} \\ \left\{5,5(-\frac{1}{3} 272 \log (2)+27 \log (3)+\frac{125 \log (5)}{6})\right\} \\ \left\{6,\frac{6}{24} (6496 \log (2)+486 \log (3)-3125 \log (5))\right\} \\ \left\{7,\frac{7}{120} (-87808 \log (2)-43011 \log (3)+46875 \log (5)+16807 \log (7))\right\} \\ \left\{8,\frac{8}{720} (2053376 \log (2)+964467 \log (3)-546875 \log (5)-823543 \log (7))\right\} \\ \left\{9,9(\frac{-33922048 \log (2)-3024621 \log (3)+2734375 \log (5)+11529602 \log (7)}{2520})\right\} \\ \left\{10,10(\frac{1067291648 \log (2)-281722779 \log (3)+25390625 \log (5)-242121642 \log (7)}{20160})\right\} \\ \end{array} $$ Starting at $n=6$ we observe a factor $\frac{1}{(n-2)!}$.
18,211,102
I have a class that accepts character arrays. I realize that std::string is preferred for working with strings but this is an excercise to learn about pointers and allocating dynamic memory. The problem I am having is with the overloaded addition operator. I allocate new memory to the size of the two char arrays being concatenated, plus a terminating null character. When I put breakpoints on the for loops I can see the program is iterating through the left hand operand pointer(p) and then the right hand operand pointer(q), but the individual chars are not being stored to temp\_str. I am fairly new to C++ so I am sure I am missing something basic about pointers and/or dynamic memory. Any help/advice would be appreciated. Thanks. ``` #include <iostream> #include <cstring> using std::cout; using std::endl; class CStr { private: int m_length; char* m_pstr; public: // Constructor CStr (const char* s = "Default String") { cout << "Constructor called\n"; m_length = strlen(s) + 1; // Store the length of the string m_pstr = new char[m_length]; // Allocate space for the string strcpy_s(m_pstr,m_length,s); // Copy string to memory } // Copy constructor CStr (const CStr& aStr) { cout << "Copy constructor called\n"; m_length = aStr.m_length; // Get length of the object to be copied m_pstr = new char [m_length]; // Allocate space for the string strcpy_s(m_pstr, m_length, aStr.m_pstr); // Copy string to memory } // Assignment operator CStr& operator=(const CStr& aStr) { cout << "Assignment operator called\n"; if(this == &aStr) // Check addresses, if equal return *this; // return the 1st operand m_length = aStr.m_length; // Get length of the rhs operand delete [] m_pstr; // Release memory for the lhs operand m_pstr = new char[m_length]; // Allocate space for the string strcpy_s(m_pstr, m_length, aStr.m_pstr); // Copy rhs operand string to the lhs operand return *this; // Return a reference to the lhs operand } // Addition operator CStr operator+(const CStr& aStr) const { cout << "Addition operator called\n"; // get the lengths of the strings size_t rhs_length = strlen(aStr.m_pstr); // length of rhs operand size_t lhs_length = strlen(this->m_pstr); // length of lhs operand char* temp_str = new char[lhs_length + rhs_length + 1]; // Allocate memory to hold concatenated string // plus terminating null character char* p = this->m_pstr; char* q = aStr.m_pstr; for (p; *p!=0; p++) // Increment lhs string pointer *temp_str++ = *p; // Store character for (q; *q!=0; q++) // Increment rhs string pointer *temp_str++ = *q; // Store character *temp_str++ = '\0'; // Null character at the end return CStr(temp_str); } // Destructor ~CStr () { cout << Print() << " has been destroyed\n"; delete [] m_pstr; // Free memory assigned to the pointer } // Print function char* Print() const { return m_pstr; } }; int main() { CStr s1("foo"); CStr s2("bar"); CStr s3 = s1 + s2; } ```
2013/08/13
[ "https://Stackoverflow.com/questions/18211102", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2678389/" ]
If you want to put some data to every page it is easy to use interceptor: ``` public class PagePopulationInterceptor extends HandlerInterceptorAdapter { @Autowired private UserService userService; @Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { if(modelAndView != null) { User user = userService.findOne(request); modelAndView.addObject("myUserProfile", user); } } } ``` To make this work also declare interceptor in webmvc-config.xml (spring configuration for webapp): ``` <mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/**"/> <bean class="com.yourcompany.yourapp.util.PagePopulationInterceptor" /> </mvc:interceptor> <!-- other interceptors (locale, theme and so on) --> </mvc:interceptors> ```
you can extend HandlerInterceptorAdapter and add common modelAttributes thr
55,210,794
So, from the documentation is almost clear what the three entities from the title are, but it is not very clear what their purpose is. Constants are common in many languages. You don't want to write `3.14` all over your code and that's why you define a constant `PI` that, by the nature of the thing it represents, cannot be changed and that's why its value is *constant* in time. Defining a variable bound to another entity with `:=` is also almost clear but not really. If I bind a variable to `3.14`, isn't it the same as defining a `PI` constant? Is `$a := $b` actually defining `$a` as an *alias* to `$b` or, as some other languages call it, a *reference*? Also, references are generally used in some languages to make it clear, in object construction or function calls, that you don't want to copy an object around, but why would it be useful, in the same scope, to have ``` $number_of_cakes = 4; $also_the_number_of_cakes := $number_of_cakes; ``` ? Finally, the documentation explains *how* one can define a sigilless variable (that cannot be varied, so, actually, yet another kind of constant) but not *why* one would do that. What problems do sigilless variables solve? What's a practical scenario when a variable, a constant, a binding variable do not solve the problem that a sigilless variable solve?
2019/03/17
[ "https://Stackoverflow.com/questions/55210794", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42636/" ]
> > Constants are common in many languages. You don't want to write 3.14 all over your code and that's why you define a constant PI that, by the nature of the thing it represents, cannot be changed and that's why its value is constant in time. > > > For that you use `constant`. A `constant` is only initialized once, when first encountered during compilation, and never again, so its value remains constant throughout a program run. The compiler can rely on that. So can the reader -- provided they clearly understand what "value" means in this context.1 For example: ``` BEGIN my $bar = 42; loop { constant foo = $bar; $bar++; last if $++ > 4; print foo; # 4242424242 } ``` Note that if you didn't have the `BEGIN` then the constant would be initialized and be stuck with a value of `(Any)`. I tend to leave off the sigil to somewhat reinforce the idea it's a constant but you can use a sigil if you prefer. > > Defining a variable bound to another entity with `:=` is also almost clear but not really. If I bind a variable to `3.14`, isn't it the same as defining a `PI` constant? Is `$a := $b` actually defining `$a` as an alias to `$b` or, as some other languages call it, a reference? > > > Binding just binds the identifiers. If either changes, they both do: ``` my $a = 42; my $b := $a; $a++; $b++; say $a, $b; # 4444 ``` > > Finally, the documentation explains how one can define a sigilless variable (that cannot be varied, so, actually, another kind of constant) but not why one would do that. > > > It can be varied if the thing bound is a variable. For example: ``` my $variable = 42; # puts the value 42 INTO $variable my \variable = $variable; # binds variable to $variable say ++variable; # 43 my \variable2 = 42; # binds variable2 to 42 say ++variable2; # Cannot resolve caller prefix:<++>(Int:D); # ... candidates ... require mutable arguments ``` I personally prefer to slash sigils if an identifier is bound to an immutable basic scalar value (eg `42`) or other entirely immutable value (eg a typical `List`) and use a sigil otherwise. YMMV. > > What problems do sigilless variables solve? What's a practical scenario when a variable, a constant, a binding variable do not solve the problem that a sigilless variable solve? > > > Please add comments if what's already in my answer (or another; I see someone else has posted one) leaves you with remaining questions. Foonotes ======== 1 See [my answer to JJ's SO about use of `constant` with composite containers](https://stackoverflow.com/a/55212923/1077672).
That's not one but at 5 questions? > > If I bind a variable to 3.14, isn't it the same as defining a PI constant? > > > Well, technically it would be except for the fact that `3.14` is a `Rat`, and `pi` (aka `π`) is a `Num`. > > Is $a := $b actually defining $a as an alias to $b or, as some other languages call it, a reference? > > > It's an alias. > > $number\_of\_cakes = 4; $also\_the\_number\_of\_cakes := $number\_of\_cakes; > > > There would be little point. However, sometimes it can be handy to alias something to an element in an array, or a key in a hash, to prevent repeated lookups: ``` my %foo; my $bar := %foo<bar>; ++$bar for ^10; ``` > > What problems do sigilless variables solve? > > > Sigilless variables only solve a programming style issue, as far as I know. Some people, for whatever reason, prefer sigilless varriables. It makes it harder to interpolate, but others might find the extra curlies actually a good thing: ``` my answer := my $ = 42; say "The answer is {answer}"; ``` > > What's a practical scenario when a variable, a constant, a binding variable do not solve the problem that a sigilless variable solve? > > > In my view, sigilless variables do not solve a problem, but rather try to cater different programming styles. So I'm not sure what a correct answer to this question would be.
55,210,794
So, from the documentation is almost clear what the three entities from the title are, but it is not very clear what their purpose is. Constants are common in many languages. You don't want to write `3.14` all over your code and that's why you define a constant `PI` that, by the nature of the thing it represents, cannot be changed and that's why its value is *constant* in time. Defining a variable bound to another entity with `:=` is also almost clear but not really. If I bind a variable to `3.14`, isn't it the same as defining a `PI` constant? Is `$a := $b` actually defining `$a` as an *alias* to `$b` or, as some other languages call it, a *reference*? Also, references are generally used in some languages to make it clear, in object construction or function calls, that you don't want to copy an object around, but why would it be useful, in the same scope, to have ``` $number_of_cakes = 4; $also_the_number_of_cakes := $number_of_cakes; ``` ? Finally, the documentation explains *how* one can define a sigilless variable (that cannot be varied, so, actually, yet another kind of constant) but not *why* one would do that. What problems do sigilless variables solve? What's a practical scenario when a variable, a constant, a binding variable do not solve the problem that a sigilless variable solve?
2019/03/17
[ "https://Stackoverflow.com/questions/55210794", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42636/" ]
That's not one but at 5 questions? > > If I bind a variable to 3.14, isn't it the same as defining a PI constant? > > > Well, technically it would be except for the fact that `3.14` is a `Rat`, and `pi` (aka `π`) is a `Num`. > > Is $a := $b actually defining $a as an alias to $b or, as some other languages call it, a reference? > > > It's an alias. > > $number\_of\_cakes = 4; $also\_the\_number\_of\_cakes := $number\_of\_cakes; > > > There would be little point. However, sometimes it can be handy to alias something to an element in an array, or a key in a hash, to prevent repeated lookups: ``` my %foo; my $bar := %foo<bar>; ++$bar for ^10; ``` > > What problems do sigilless variables solve? > > > Sigilless variables only solve a programming style issue, as far as I know. Some people, for whatever reason, prefer sigilless varriables. It makes it harder to interpolate, but others might find the extra curlies actually a good thing: ``` my answer := my $ = 42; say "The answer is {answer}"; ``` > > What's a practical scenario when a variable, a constant, a binding variable do not solve the problem that a sigilless variable solve? > > > In my view, sigilless variables do not solve a problem, but rather try to cater different programming styles. So I'm not sure what a correct answer to this question would be.
Also `constant` is `our` scoped by default.
55,210,794
So, from the documentation is almost clear what the three entities from the title are, but it is not very clear what their purpose is. Constants are common in many languages. You don't want to write `3.14` all over your code and that's why you define a constant `PI` that, by the nature of the thing it represents, cannot be changed and that's why its value is *constant* in time. Defining a variable bound to another entity with `:=` is also almost clear but not really. If I bind a variable to `3.14`, isn't it the same as defining a `PI` constant? Is `$a := $b` actually defining `$a` as an *alias* to `$b` or, as some other languages call it, a *reference*? Also, references are generally used in some languages to make it clear, in object construction or function calls, that you don't want to copy an object around, but why would it be useful, in the same scope, to have ``` $number_of_cakes = 4; $also_the_number_of_cakes := $number_of_cakes; ``` ? Finally, the documentation explains *how* one can define a sigilless variable (that cannot be varied, so, actually, yet another kind of constant) but not *why* one would do that. What problems do sigilless variables solve? What's a practical scenario when a variable, a constant, a binding variable do not solve the problem that a sigilless variable solve?
2019/03/17
[ "https://Stackoverflow.com/questions/55210794", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42636/" ]
> > Constants are common in many languages. You don't want to write 3.14 all over your code and that's why you define a constant PI that, by the nature of the thing it represents, cannot be changed and that's why its value is constant in time. > > > For that you use `constant`. A `constant` is only initialized once, when first encountered during compilation, and never again, so its value remains constant throughout a program run. The compiler can rely on that. So can the reader -- provided they clearly understand what "value" means in this context.1 For example: ``` BEGIN my $bar = 42; loop { constant foo = $bar; $bar++; last if $++ > 4; print foo; # 4242424242 } ``` Note that if you didn't have the `BEGIN` then the constant would be initialized and be stuck with a value of `(Any)`. I tend to leave off the sigil to somewhat reinforce the idea it's a constant but you can use a sigil if you prefer. > > Defining a variable bound to another entity with `:=` is also almost clear but not really. If I bind a variable to `3.14`, isn't it the same as defining a `PI` constant? Is `$a := $b` actually defining `$a` as an alias to `$b` or, as some other languages call it, a reference? > > > Binding just binds the identifiers. If either changes, they both do: ``` my $a = 42; my $b := $a; $a++; $b++; say $a, $b; # 4444 ``` > > Finally, the documentation explains how one can define a sigilless variable (that cannot be varied, so, actually, another kind of constant) but not why one would do that. > > > It can be varied if the thing bound is a variable. For example: ``` my $variable = 42; # puts the value 42 INTO $variable my \variable = $variable; # binds variable to $variable say ++variable; # 43 my \variable2 = 42; # binds variable2 to 42 say ++variable2; # Cannot resolve caller prefix:<++>(Int:D); # ... candidates ... require mutable arguments ``` I personally prefer to slash sigils if an identifier is bound to an immutable basic scalar value (eg `42`) or other entirely immutable value (eg a typical `List`) and use a sigil otherwise. YMMV. > > What problems do sigilless variables solve? What's a practical scenario when a variable, a constant, a binding variable do not solve the problem that a sigilless variable solve? > > > Please add comments if what's already in my answer (or another; I see someone else has posted one) leaves you with remaining questions. Foonotes ======== 1 See [my answer to JJ's SO about use of `constant` with composite containers](https://stackoverflow.com/a/55212923/1077672).
Also `constant` is `our` scoped by default.
24,687,238
I am using a Picker View to allow the user to choose the colour theme for the entire app. I am planning on changing the colour of the navigation bar, background and possibly the tab bar (if that is possible). I've been researching how to do this but can't find any Swift examples. Could anyone please give me an example of the code I would need to use to change the navigation bar colour and navigation bar text colour? The Picker View is set up, I'm just looking for the code to change the UI colours.
2014/07/10
[ "https://Stackoverflow.com/questions/24687238", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3746428/" ]
``` UINavigationBar.appearance().barTintColor = UIColor(red: 46.0/255.0, green: 14.0/255.0, blue: 74.0/255.0, alpha: 1.0) UINavigationBar.appearance().tintColor = UIColor.whiteColor() UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor.whiteColor()] ``` Just paste this line in `didFinishLaunchingWithOptions` in your code.
I'm writing this for those that still have problems with the solutions here. I'm using Xcode Version 11.4 (11E146). The one working for me is: ``` navigationController?.navigationBar.barTintColor = UIColor.white navigationController?.navigationBar.tintColor = UIColor.black ``` BUT!, if you set the barTintColor in storyboard to any other value than "default" this 2 lines of code will have no effect. So, be carefull and set back to default barTintColor in Storyboard. Oh Apple...
24,687,238
I am using a Picker View to allow the user to choose the colour theme for the entire app. I am planning on changing the colour of the navigation bar, background and possibly the tab bar (if that is possible). I've been researching how to do this but can't find any Swift examples. Could anyone please give me an example of the code I would need to use to change the navigation bar colour and navigation bar text colour? The Picker View is set up, I'm just looking for the code to change the UI colours.
2014/07/10
[ "https://Stackoverflow.com/questions/24687238", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3746428/" ]
The `appearance()` function not always work for me. So I prefer to create a NC object and change its attributes. ```swift var navBarColor = navigationController!.navigationBar navBarColor.barTintColor = UIColor(red: 255/255.0, green: 0/255.0, blue: 0/255.0, alpha: 100.0/100.0) navBarColor.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()] ``` Also if you want to add an image instead of just text, that works as well ```swift var imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 70, height: 70)) imageView.contentMode = .ScaleAspectFit var image = UIImage(named: "logo") imageView.image = image navigationItem.titleView = imageView ```
simply call the this extension and pass the color it will automatically change the color of nav bar ``` extension UINavigationController { func setNavigationBarColor(color : UIColor){ self.navigationBar.barTintColor = color } } ``` in the view didload or in viewwill appear call ``` self.navigationController?.setNavigationBarColor(color: <#T##UIColor#>) ```
24,687,238
I am using a Picker View to allow the user to choose the colour theme for the entire app. I am planning on changing the colour of the navigation bar, background and possibly the tab bar (if that is possible). I've been researching how to do this but can't find any Swift examples. Could anyone please give me an example of the code I would need to use to change the navigation bar colour and navigation bar text colour? The Picker View is set up, I'm just looking for the code to change the UI colours.
2014/07/10
[ "https://Stackoverflow.com/questions/24687238", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3746428/" ]
Within **AppDelegate**, this has globally changed the format of the NavBar and removes the bottom line/border (which is a problem area for most people) to give you what I think you and others are looking for: ``` func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { UINavigationBar.appearance().setBackgroundImage(UIImage(), forBarPosition: UIBarPosition.Any, barMetrics: UIBarMetrics.Default) UINavigationBar.appearance().shadowImage = UIImage() UINavigationBar.appearance().tintColor = UIColor.whiteColor() UINavigationBar.appearance().barTintColor = Style.SELECTED_COLOR UINavigationBar.appearance().translucent = false UINavigationBar.appearance().clipsToBounds = false UINavigationBar.appearance().backgroundColor = Style.SELECTED_COLOR UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName : (UIFont(name: "FONT NAME", size: 18))!, NSForegroundColorAttributeName: UIColor.whiteColor()] } ``` Then you can setup a **Constants.swift** file, and contained is a Style struct with colors and fonts etc. You can then add a tableView/pickerView to any ViewController and use "availableThemes" array to allow user to change themeColor. The beautiful thing about this is you can use one reference throughout your whole app for each colour and it'll update based on the user's selected "Theme" and without one it defaults to theme1(): ``` import Foundation import UIKit struct Style { static let availableThemes = ["Theme 1","Theme 2","Theme 3"] static func loadTheme(){ let defaults = NSUserDefaults.standardUserDefaults() if let name = defaults.stringForKey("Theme"){ // Select the Theme if name == availableThemes[0] { theme1() } if name == availableThemes[1] { theme2() } if name == availableThemes[2] { theme3() } }else{ defaults.setObject(availableThemes[0], forKey: "Theme") theme1() } } // Colors specific to theme - can include multiple colours here for each one static func theme1(){ static var SELECTED_COLOR = UIColor(red:70/255, green: 38/255, blue: 92/255, alpha: 1) } static func theme2(){ static var SELECTED_COLOR = UIColor(red:255/255, green: 255/255, blue: 255/255, alpha: 1) } static func theme3(){ static var SELECTED_COLOR = UIColor(red:90/255, green: 50/255, blue: 120/255, alpha: 1) } ... ```
First set the isTranslucent property of navigationBar to false to get the desired colour. Then change the navigationBar colour like this: ``` @IBOutlet var NavigationBar: UINavigationBar! NavigationBar.isTranslucent = false NavigationBar.barTintColor = UIColor (red: 117/255, green: 23/255, blue: 49/255, alpha: 1.0) ```
24,687,238
I am using a Picker View to allow the user to choose the colour theme for the entire app. I am planning on changing the colour of the navigation bar, background and possibly the tab bar (if that is possible). I've been researching how to do this but can't find any Swift examples. Could anyone please give me an example of the code I would need to use to change the navigation bar colour and navigation bar text colour? The Picker View is set up, I'm just looking for the code to change the UI colours.
2014/07/10
[ "https://Stackoverflow.com/questions/24687238", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3746428/" ]
Use the appearance API, and barTintColor color. ``` UINavigationBar.appearance().barTintColor = UIColor.greenColor() ```
**Swift 3 and Swift 4 Compatible Xcode 9** **A Better Solution for this to make a Class for common Navigation bars** I have 5 Controllers and each controller title is changed to orange color. As each controller has 5 navigation controllers so i had to change every one color either from inspector or from code. **So i made a class instead of changing every one Navigation bar from code i just assign this class and it worked on all 5 controller Code reuse Ability.** **You just have to assign this class to Each controller and thats it.** ``` import UIKit class NabigationBar: UINavigationBar { required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) commonFeatures() } func commonFeatures() { self.backgroundColor = UIColor.white; UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.foregroundColor:ColorConstants.orangeTextColor] } } ```
24,687,238
I am using a Picker View to allow the user to choose the colour theme for the entire app. I am planning on changing the colour of the navigation bar, background and possibly the tab bar (if that is possible). I've been researching how to do this but can't find any Swift examples. Could anyone please give me an example of the code I would need to use to change the navigation bar colour and navigation bar text colour? The Picker View is set up, I'm just looking for the code to change the UI colours.
2014/07/10
[ "https://Stackoverflow.com/questions/24687238", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3746428/" ]
If you have customized navigation controller, you can use above code snippet. So in my case, I've used as following code pieces. **Swift 3.0, XCode 8.1 version** ``` navigationController.navigationBar.barTintColor = UIColor.green ``` **Navigation Bar Text:** ``` navigationController.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.orange] ``` It is very helpful talks.
Make sure to set the **Button State for .normal** ``` extension UINavigationBar { func makeContent(color: UIColor) { let attributes: [NSAttributedString.Key: Any]? = [.foregroundColor: color] self.titleTextAttributes = attributes self.topItem?.leftBarButtonItem?.setTitleTextAttributes(attributes, for: .normal) self.topItem?.rightBarButtonItem?.setTitleTextAttributes(attributes, for: .normal) } } ``` P.S iOS 12, Xcode 10.1
24,687,238
I am using a Picker View to allow the user to choose the colour theme for the entire app. I am planning on changing the colour of the navigation bar, background and possibly the tab bar (if that is possible). I've been researching how to do this but can't find any Swift examples. Could anyone please give me an example of the code I would need to use to change the navigation bar colour and navigation bar text colour? The Picker View is set up, I'm just looking for the code to change the UI colours.
2014/07/10
[ "https://Stackoverflow.com/questions/24687238", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3746428/" ]
> > Try This in AppDelegate: > > > ``` //MARK:- ~~~~~~~~~~setupApplicationUIAppearance Method func setupApplicationUIAppearance() { UIApplication.shared.statusBarView?.backgroundColor = UIColor.clear var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent } UINavigationBar.appearance().tintColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1) UINavigationBar.appearance().barTintColor = UIColor.white UINavigationBar.appearance().isTranslucent = false let attributes: [NSAttributedString.Key: AnyObject] if DeviceType.IS_IPAD{ attributes = [ NSAttributedString.Key.foregroundColor: UIColor.white, NSAttributedString.Key.font: UIFont(name: "HelveticaNeue", size: 30) ] as [NSAttributedString.Key : AnyObject] }else{ attributes = [ NSAttributedString.Key.foregroundColor: UIColor.white ] } UINavigationBar.appearance().titleTextAttributes = attributes } ``` > > iOS 13 > > > ``` func setupNavigationBar() { // if #available(iOS 13, *) { // let window = UIApplication.shared.windows.filter {$0.isKeyWindow}.first // let statusBar = UIView(frame: window?.windowScene?.statusBarManager?.statusBarFrame ?? CGRect.zero) // statusBar.backgroundColor = #colorLiteral(red: 0.2784313725, green: 0.4549019608, blue: 0.5921568627, alpha: 1) //UIColor.init(hexString: "#002856") // //statusBar.tintColor = UIColor.init(hexString: "#002856") // window?.addSubview(statusBar) // UINavigationBar.appearance().tintColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1) // UINavigationBar.appearance().barTintColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1) // UINavigationBar.appearance().isTranslucent = false // UINavigationBar.appearance().backgroundColor = #colorLiteral(red: 0.2784313725, green: 0.4549019608, blue: 0.5921568627, alpha: 1) // UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor : UIColor.white] // } // else // { UIApplication.shared.statusBarView?.backgroundColor = #colorLiteral(red: 0.2784313725, green: 0.4549019608, blue: 0.5921568627, alpha: 1) UINavigationBar.appearance().tintColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1) UINavigationBar.appearance().barTintColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1) UINavigationBar.appearance().isTranslucent = false UINavigationBar.appearance().backgroundColor = #colorLiteral(red: 0.2784313725, green: 0.4549019608, blue: 0.5921568627, alpha: 1) UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor : UIColor.white] // } } ``` > > Extensions > > > ``` extension UIApplication { var statusBarView: UIView? { if responds(to: Selector(("statusBar"))) { return value(forKey: "statusBar") as? UIView } return nil }} ```
My two cents: a) setting navigationBar.barTintColor / titleTextAttributes do work in any view (pushed, added..and so on in init.. b) setting appearence does not work everywhere: * You can call it on AppDelegate * " " 1st level view * if You call it again in subsequent pushed views, does MNOT work SwiftUI note: a) does not apply (no navigationBar, unless you pass via UIViewControllerRepresentable trick..) b) is valid for SwiftUI: same behaviour.
24,687,238
I am using a Picker View to allow the user to choose the colour theme for the entire app. I am planning on changing the colour of the navigation bar, background and possibly the tab bar (if that is possible). I've been researching how to do this but can't find any Swift examples. Could anyone please give me an example of the code I would need to use to change the navigation bar colour and navigation bar text colour? The Picker View is set up, I'm just looking for the code to change the UI colours.
2014/07/10
[ "https://Stackoverflow.com/questions/24687238", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3746428/" ]
In iOS 15, UIKit has extended the usage of the scrollEdgeAppearance, which by default produces a transparent background, to all navigation bars. Set scrollEdgeAppearance as below code. ``` if #available(iOS 15, *) { let appearance = UINavigationBarAppearance() appearance.configureWithOpaqueBackground() appearance.backgroundColor = < your tint color > navigationController?.navigationBar.standardAppearance = appearance; navigationController?.navigationBar.scrollEdgeAppearance = navigationController?.navigationBar.standardAppearance } ```
Make sure to set the **Button State for .normal** ``` extension UINavigationBar { func makeContent(color: UIColor) { let attributes: [NSAttributedString.Key: Any]? = [.foregroundColor: color] self.titleTextAttributes = attributes self.topItem?.leftBarButtonItem?.setTitleTextAttributes(attributes, for: .normal) self.topItem?.rightBarButtonItem?.setTitleTextAttributes(attributes, for: .normal) } } ``` P.S iOS 12, Xcode 10.1
24,687,238
I am using a Picker View to allow the user to choose the colour theme for the entire app. I am planning on changing the colour of the navigation bar, background and possibly the tab bar (if that is possible). I've been researching how to do this but can't find any Swift examples. Could anyone please give me an example of the code I would need to use to change the navigation bar colour and navigation bar text colour? The Picker View is set up, I'm just looking for the code to change the UI colours.
2014/07/10
[ "https://Stackoverflow.com/questions/24687238", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3746428/" ]
Navigation Bar: ``` navigationController?.navigationBar.barTintColor = UIColor.green ``` Replace greenColor with whatever UIColor you want, you can use an RGB too if you prefer. Navigation Bar Text: ``` navigationController?.navigationBar.titleTextAttributes = [.foregroundColor: UIColor.orange] ``` Replace orangeColor with whatever color you like. Tab Bar: ``` tabBarController?.tabBar.barTintColor = UIColor.brown ``` Tab Bar Text: ``` tabBarController?.tabBar.tintColor = UIColor.yellow ``` On the last two, replace brownColor and yellowColor with the color of your choice.
**Swift 4:** **Perfectly working code to change the navigation bar appearance at application level.** [![enter image description here](https://i.stack.imgur.com/rSnvn.png)](https://i.stack.imgur.com/rSnvn.png) ``` // MARK: Navigation Bar Customisation // To change background colour. UINavigationBar.appearance().barTintColor = .init(red: 23.0/255, green: 197.0/255, blue: 157.0/255, alpha: 1.0) // To change colour of tappable items. UINavigationBar.appearance().tintColor = .white // To apply textAttributes to title i.e. colour, font etc. UINavigationBar.appearance().titleTextAttributes = [.foregroundColor : UIColor.white, .font : UIFont.init(name: "AvenirNext-DemiBold", size: 22.0)!] // To control navigation bar's translucency. UINavigationBar.appearance().isTranslucent = false ``` Happy Coding!
24,687,238
I am using a Picker View to allow the user to choose the colour theme for the entire app. I am planning on changing the colour of the navigation bar, background and possibly the tab bar (if that is possible). I've been researching how to do this but can't find any Swift examples. Could anyone please give me an example of the code I would need to use to change the navigation bar colour and navigation bar text colour? The Picker View is set up, I'm just looking for the code to change the UI colours.
2014/07/10
[ "https://Stackoverflow.com/questions/24687238", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3746428/" ]
**Updated for Swift 3, 4, 4.2, 5+** ``` // setup navBar..... UINavigationBar.appearance().barTintColor = .black UINavigationBar.appearance().tintColor = .white UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white] UINavigationBar.appearance().isTranslucent = false ``` **Swift 4** ``` UINavigationBar.appearance().barTintColor = .black UINavigationBar.appearance().tintColor = .white UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white] UINavigationBar.appearance().isTranslucent = false ``` **Swift 4.2, 5+** ``` UINavigationBar.appearance().barTintColor = .black UINavigationBar.appearance().tintColor = .white UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white] UINavigationBar.appearance().isTranslucent = false ``` if you want to work with large title, add this line: ``` UINavigationBar.navigationBar.prefersLargeTitles = true ``` Also can check here : <https://github.com/hasnine/iOSUtilitiesSource>
Swift 3 ------- ``` UINavigationBar.appearance().barTintColor = UIColor(colorLiteralRed: 51/255, green: 90/255, blue: 149/255, alpha: 1) ``` This will set your navigation bar color like Facebook bar color :)