qid
int64
1
74.7M
question
stringlengths
15
58.3k
date
stringlengths
10
10
metadata
list
response_j
stringlengths
4
30.2k
response_k
stringlengths
11
36.5k
53,670,223
So I know that you should declare char arrays to be one element bigger than the word you want to put there because of the `\0` that has to be at the end, but what about char arrays that I don't want to use as words? I'm currently writing a program in which i store an array of keyboard letters that have some function assigned to them. Should I still end this array with `\0`?
2018/12/07
[ "https://Stackoverflow.com/questions/53670223", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5900271/" ]
That is probably not necessary. A null terminator is not a requirement for arrays of `char`; it is a requirement for "C-strings", things that you intend to use as unitary blobs of data, particularly if you intend to pass them to C API functions. It's the conventional way that the "length" of the string is determined. But if you just want a collection of `char`s to use independently then knock yourself out. **We cannot see your code, but it sounds to me like you don't want or need it in this case.**
`\0` will certainly make it easier when wanting to use functions like `strlen`, `strcmp`, `strcat`and the like, but is not required. An aside - We have an entire enterprise code base built upon strings (char arrays) with no null terminators in the database. Works just fine.
53,670,223
So I know that you should declare char arrays to be one element bigger than the word you want to put there because of the `\0` that has to be at the end, but what about char arrays that I don't want to use as words? I'm currently writing a program in which i store an array of keyboard letters that have some function assigned to them. Should I still end this array with `\0`?
2018/12/07
[ "https://Stackoverflow.com/questions/53670223", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5900271/" ]
If you're using C++, you should probably just use `std::string` or `std::vector<char>` or even `std::array<char>` and not worry about terminators.
`\0` will certainly make it easier when wanting to use functions like `strlen`, `strcmp`, `strcat`and the like, but is not required. An aside - We have an entire enterprise code base built upon strings (char arrays) with no null terminators in the database. Works just fine.
53,670,223
So I know that you should declare char arrays to be one element bigger than the word you want to put there because of the `\0` that has to be at the end, but what about char arrays that I don't want to use as words? I'm currently writing a program in which i store an array of keyboard letters that have some function assigned to them. Should I still end this array with `\0`?
2018/12/07
[ "https://Stackoverflow.com/questions/53670223", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5900271/" ]
That is probably not necessary. A null terminator is not a requirement for arrays of `char`; it is a requirement for "C-strings", things that you intend to use as unitary blobs of data, particularly if you intend to pass them to C API functions. It's the conventional way that the "length" of the string is determined. But if you just want a collection of `char`s to use independently then knock yourself out. **We cannot see your code, but it sounds to me like you don't want or need it in this case.**
It depends on what you are trying to do, if you are trying to define a *C-style string then, you need the terminator since the C-library won't be able to calculate the size of the string and other things if you don't*... In C++, though, the size of the string is already stored inside the `std::string` class along with the dynamic array of `char`s... But if you just need a free container for storing characters where you don't need it to do *C-string-like* things... You are free to do: ``` char hello[128]; // 128 elements, do anything with them... ``` Without the terminator... In your case, you are **storing** values, not creating a *string*, and you won't probably treat it as a string either, so doing it **without** the null-terminator, suffices...
53,670,223
So I know that you should declare char arrays to be one element bigger than the word you want to put there because of the `\0` that has to be at the end, but what about char arrays that I don't want to use as words? I'm currently writing a program in which i store an array of keyboard letters that have some function assigned to them. Should I still end this array with `\0`?
2018/12/07
[ "https://Stackoverflow.com/questions/53670223", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5900271/" ]
If you're using C++, you should probably just use `std::string` or `std::vector<char>` or even `std::array<char>` and not worry about terminators.
It depends on what you are trying to do, if you are trying to define a *C-style string then, you need the terminator since the C-library won't be able to calculate the size of the string and other things if you don't*... In C++, though, the size of the string is already stored inside the `std::string` class along with the dynamic array of `char`s... But if you just need a free container for storing characters where you don't need it to do *C-string-like* things... You are free to do: ``` char hello[128]; // 128 elements, do anything with them... ``` Without the terminator... In your case, you are **storing** values, not creating a *string*, and you won't probably treat it as a string either, so doing it **without** the null-terminator, suffices...
53,670,223
So I know that you should declare char arrays to be one element bigger than the word you want to put there because of the `\0` that has to be at the end, but what about char arrays that I don't want to use as words? I'm currently writing a program in which i store an array of keyboard letters that have some function assigned to them. Should I still end this array with `\0`?
2018/12/07
[ "https://Stackoverflow.com/questions/53670223", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5900271/" ]
The array should have, at least, the same number of elements as the data you will put there. So, if: * you don't need the '\0' * you won't place it there * you won't use routines that will depend on an '\0' to tell you the array size ... you are good with not using the trailing '\0'
If you're using C++, you should probably just use `std::string` or `std::vector<char>` or even `std::array<char>` and not worry about terminators.
53,670,223
So I know that you should declare char arrays to be one element bigger than the word you want to put there because of the `\0` that has to be at the end, but what about char arrays that I don't want to use as words? I'm currently writing a program in which i store an array of keyboard letters that have some function assigned to them. Should I still end this array with `\0`?
2018/12/07
[ "https://Stackoverflow.com/questions/53670223", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5900271/" ]
That is probably not necessary. A null terminator is not a requirement for arrays of `char`; it is a requirement for "C-strings", things that you intend to use as unitary blobs of data, particularly if you intend to pass them to C API functions. It's the conventional way that the "length" of the string is determined. But if you just want a collection of `char`s to use independently then knock yourself out. **We cannot see your code, but it sounds to me like you don't want or need it in this case.**
The array should have, at least, the same number of elements as the data you will put there. So, if: * you don't need the '\0' * you won't place it there * you won't use routines that will depend on an '\0' to tell you the array size ... you are good with not using the trailing '\0'
53,670,223
So I know that you should declare char arrays to be one element bigger than the word you want to put there because of the `\0` that has to be at the end, but what about char arrays that I don't want to use as words? I'm currently writing a program in which i store an array of keyboard letters that have some function assigned to them. Should I still end this array with `\0`?
2018/12/07
[ "https://Stackoverflow.com/questions/53670223", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5900271/" ]
It depends on what you are trying to do, if you are trying to define a *C-style string then, you need the terminator since the C-library won't be able to calculate the size of the string and other things if you don't*... In C++, though, the size of the string is already stored inside the `std::string` class along with the dynamic array of `char`s... But if you just need a free container for storing characters where you don't need it to do *C-string-like* things... You are free to do: ``` char hello[128]; // 128 elements, do anything with them... ``` Without the terminator... In your case, you are **storing** values, not creating a *string*, and you won't probably treat it as a string either, so doing it **without** the null-terminator, suffices...
`\0` will certainly make it easier when wanting to use functions like `strlen`, `strcmp`, `strcat`and the like, but is not required. An aside - We have an entire enterprise code base built upon strings (char arrays) with no null terminators in the database. Works just fine.
53,670,223
So I know that you should declare char arrays to be one element bigger than the word you want to put there because of the `\0` that has to be at the end, but what about char arrays that I don't want to use as words? I'm currently writing a program in which i store an array of keyboard letters that have some function assigned to them. Should I still end this array with `\0`?
2018/12/07
[ "https://Stackoverflow.com/questions/53670223", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5900271/" ]
It depends on usage. If you want to use it not as just byte array, but as c-string with probably usage of some standard string algorithms (`strcmp` and so on), or output to the stream - your array should ends with `\0`.
It depends on what you are trying to do, if you are trying to define a *C-style string then, you need the terminator since the C-library won't be able to calculate the size of the string and other things if you don't*... In C++, though, the size of the string is already stored inside the `std::string` class along with the dynamic array of `char`s... But if you just need a free container for storing characters where you don't need it to do *C-string-like* things... You are free to do: ``` char hello[128]; // 128 elements, do anything with them... ``` Without the terminator... In your case, you are **storing** values, not creating a *string*, and you won't probably treat it as a string either, so doing it **without** the null-terminator, suffices...
53,670,223
So I know that you should declare char arrays to be one element bigger than the word you want to put there because of the `\0` that has to be at the end, but what about char arrays that I don't want to use as words? I'm currently writing a program in which i store an array of keyboard letters that have some function assigned to them. Should I still end this array with `\0`?
2018/12/07
[ "https://Stackoverflow.com/questions/53670223", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5900271/" ]
The array should have, at least, the same number of elements as the data you will put there. So, if: * you don't need the '\0' * you won't place it there * you won't use routines that will depend on an '\0' to tell you the array size ... you are good with not using the trailing '\0'
It depends on usage. If you want to use it not as just byte array, but as c-string with probably usage of some standard string algorithms (`strcmp` and so on), or output to the stream - your array should ends with `\0`.
53,670,223
So I know that you should declare char arrays to be one element bigger than the word you want to put there because of the `\0` that has to be at the end, but what about char arrays that I don't want to use as words? I'm currently writing a program in which i store an array of keyboard letters that have some function assigned to them. Should I still end this array with `\0`?
2018/12/07
[ "https://Stackoverflow.com/questions/53670223", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5900271/" ]
That is probably not necessary. A null terminator is not a requirement for arrays of `char`; it is a requirement for "C-strings", things that you intend to use as unitary blobs of data, particularly if you intend to pass them to C API functions. It's the conventional way that the "length" of the string is determined. But if you just want a collection of `char`s to use independently then knock yourself out. **We cannot see your code, but it sounds to me like you don't want or need it in this case.**
If you're using C++, you should probably just use `std::string` or `std::vector<char>` or even `std::array<char>` and not worry about terminators.
80,265
I recently changed the radial blur center to a corner and I would like to set it back to default (in the center). Is there any keyboard shortcut? [![enter image description here](https://i.stack.imgur.com/Q7vPn.jpg)](https://i.stack.imgur.com/Q7vPn.jpg)
2016/11/15
[ "https://graphicdesign.stackexchange.com/questions/80265", "https://graphicdesign.stackexchange.com", "https://graphicdesign.stackexchange.com/users/281/" ]
Hold down `⌘` and the Cancel button will change to Default. [![enter image description here](https://i.stack.imgur.com/zWX5R.png)](https://i.stack.imgur.com/zWX5R.png) [![enter image description here](https://i.stack.imgur.com/MDX4r.png)](https://i.stack.imgur.com/MDX4r.png) Click Default [![enter image description here](https://i.stack.imgur.com/0vXnq.png)](https://i.stack.imgur.com/0vXnq.png)
Restarting Ps will reset to default (If you know another method, please answer and i'll mark your answer)
8,569,303
I am trying to minify a third-party JavaScript library using Google Closure Compiler, but it errors out at below line: ``` inBlock.package = package = name ``` The error is > > ERROR - Parse error. missing name after . operator\*\* > > > `name` above is a local variable inside a function and `inBlock` is an input argument. Nowhere in the function is `package` declared other than that error line. I guess it may be due to `package` is a reserved keyword in JavaScript? Any idea what package is in JavaScript and how to fix it?
2011/12/20
[ "https://Stackoverflow.com/questions/8569303", "https://Stackoverflow.com", "https://Stackoverflow.com/users/325192/" ]
You're right, `package` is a reserved word in JavaScript (but only in strict mode, which will be why the code works in some places). `package` is future-reserved, which means it's not used for anything, but you can't use it to name variables. However (if you really must), you can use it to name keys in objects like this: ``` inBlock['package'] = name; // this is ok ``` As long as you use a string. You can't do this: ``` inBlock.package = name; // this is not ok ``` I would say you're better off naming it something else. --- For those wondering if this is still true today - `package` was added to the future-reserved list in ES-3 (1999), and has remained there until today. At the time of writing, we are at ES-11 (2020), where it is still unavailable. The relevant parts of the [ES-11 2020 spec](https://www.ecma-international.org/ecma-262/) are: [11.6.2 Note 2](https://www.ecma-international.org/ecma-262/#sec-keywords-and-reserved-words): > > `enum` is not currently used as a keyword in this specification. It is a future reserved word, set aside for use as a keyword in future language extensions. > > > Similarly, `implements`, `interface`, `package`, `private`, `protected`, and `public` are future reserved words in strict mode code. > > > and [12.1.1 SS: Early Errors](https://www.ecma-international.org/ecma-262/#sec-identifiers-static-semantics-early-errors): > > `Identifier`: `IdentifierName` but not `ReservedWord` > > > It is a Syntax Error if this phrase is contained in strict mode code and the StringValue of IdentifierName is: "`implements`", "`interface`", "`let`", "`package`", "`private`", "`protected`", "`public`", "`static`", or "`yield`". > > >
`package` is a keyword (from Java) reserved for possible later use in JavaScript. The solution? Name your variable something else :) If you can't change the name of `inBlock.package`, access it using the bracket notation instead: ``` inBlock['package'] ```
8,569,303
I am trying to minify a third-party JavaScript library using Google Closure Compiler, but it errors out at below line: ``` inBlock.package = package = name ``` The error is > > ERROR - Parse error. missing name after . operator\*\* > > > `name` above is a local variable inside a function and `inBlock` is an input argument. Nowhere in the function is `package` declared other than that error line. I guess it may be due to `package` is a reserved keyword in JavaScript? Any idea what package is in JavaScript and how to fix it?
2011/12/20
[ "https://Stackoverflow.com/questions/8569303", "https://Stackoverflow.com", "https://Stackoverflow.com/users/325192/" ]
You're right, `package` is a reserved word in JavaScript (but only in strict mode, which will be why the code works in some places). `package` is future-reserved, which means it's not used for anything, but you can't use it to name variables. However (if you really must), you can use it to name keys in objects like this: ``` inBlock['package'] = name; // this is ok ``` As long as you use a string. You can't do this: ``` inBlock.package = name; // this is not ok ``` I would say you're better off naming it something else. --- For those wondering if this is still true today - `package` was added to the future-reserved list in ES-3 (1999), and has remained there until today. At the time of writing, we are at ES-11 (2020), where it is still unavailable. The relevant parts of the [ES-11 2020 spec](https://www.ecma-international.org/ecma-262/) are: [11.6.2 Note 2](https://www.ecma-international.org/ecma-262/#sec-keywords-and-reserved-words): > > `enum` is not currently used as a keyword in this specification. It is a future reserved word, set aside for use as a keyword in future language extensions. > > > Similarly, `implements`, `interface`, `package`, `private`, `protected`, and `public` are future reserved words in strict mode code. > > > and [12.1.1 SS: Early Errors](https://www.ecma-international.org/ecma-262/#sec-identifiers-static-semantics-early-errors): > > `Identifier`: `IdentifierName` but not `ReservedWord` > > > It is a Syntax Error if this phrase is contained in strict mode code and the StringValue of IdentifierName is: "`implements`", "`interface`", "`let`", "`package`", "`private`", "`protected`", "`public`", "`static`", or "`yield`". > > >
According to [MDN](https://developer.mozilla.org/en/JavaScript/Reference/Reserved_Words#Words_reserved_for_possible_future_use), `package` is in the "reserved for the future" category. Depending on which version of which browser you are using and whether your code is in strict mode you may or may not be able to use those words as identifiers. In other words, you should avoid them to be safe. You *can* safely use reserved words as property names if you use this syntax: ``` inBlock["package"] = something; ``` But that doesn't help you with your `package` variable. Can you rename it?
8,569,303
I am trying to minify a third-party JavaScript library using Google Closure Compiler, but it errors out at below line: ``` inBlock.package = package = name ``` The error is > > ERROR - Parse error. missing name after . operator\*\* > > > `name` above is a local variable inside a function and `inBlock` is an input argument. Nowhere in the function is `package` declared other than that error line. I guess it may be due to `package` is a reserved keyword in JavaScript? Any idea what package is in JavaScript and how to fix it?
2011/12/20
[ "https://Stackoverflow.com/questions/8569303", "https://Stackoverflow.com", "https://Stackoverflow.com/users/325192/" ]
You're right, `package` is a reserved word in JavaScript (but only in strict mode, which will be why the code works in some places). `package` is future-reserved, which means it's not used for anything, but you can't use it to name variables. However (if you really must), you can use it to name keys in objects like this: ``` inBlock['package'] = name; // this is ok ``` As long as you use a string. You can't do this: ``` inBlock.package = name; // this is not ok ``` I would say you're better off naming it something else. --- For those wondering if this is still true today - `package` was added to the future-reserved list in ES-3 (1999), and has remained there until today. At the time of writing, we are at ES-11 (2020), where it is still unavailable. The relevant parts of the [ES-11 2020 spec](https://www.ecma-international.org/ecma-262/) are: [11.6.2 Note 2](https://www.ecma-international.org/ecma-262/#sec-keywords-and-reserved-words): > > `enum` is not currently used as a keyword in this specification. It is a future reserved word, set aside for use as a keyword in future language extensions. > > > Similarly, `implements`, `interface`, `package`, `private`, `protected`, and `public` are future reserved words in strict mode code. > > > and [12.1.1 SS: Early Errors](https://www.ecma-international.org/ecma-262/#sec-identifiers-static-semantics-early-errors): > > `Identifier`: `IdentifierName` but not `ReservedWord` > > > It is a Syntax Error if this phrase is contained in strict mode code and the StringValue of IdentifierName is: "`implements`", "`interface`", "`let`", "`package`", "`private`", "`protected`", "`public`", "`static`", or "`yield`". > > >
"package" is a reserved word in ecmascript 3. ecmascript 5 reduced the reserved word set making this availables to browser that implemented it, and introduced it again in ecmascript 5 "strict" mode (which is to be the basis of future emcascript revisions). Ecmascript 5 also changed the restrictions placed on reserved words, specifically, you can use reserved words as property names (regardless of mode) but not variable names. As a result, if you put Closure Compiler into EcmaScript 5 mode you can use "inBlock.package" and it won't complain, but if you use try to use it in older IE versions (8,7,6 I believe) it will fail to parse. Most other browsers did not follow that part of the spec and are not affected.
67,802,543
how to get proxy randomly? and get only one? I've made the code as below but I don't know how to get the proxy randomly, and I want to get the proxy also based on the page, anyone know how? ``` import requests from bs4 import BeautifulSoup url = 'https://hidemy.name/en/proxy-list/?anon=34#list' r = requests.get(url,headers={"User-Agent":"Mozilla/5.0"}) soup = BeautifulSoup(r.text,"html.parser") print(soup) ```
2021/06/02
[ "https://Stackoverflow.com/questions/67802543", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15193861/" ]
Expressed in formal language, the annotation translates to: `for all 'a, 'a≤'x and 'a≤'y implies 'a≤'r` With `'x`, `'y` and `'r` the lifetimes of `x`, `y`, and the return value respectively. This links the lifetime of the return value to the lifetimes of the parameters because for that relation to hold *for all 'a*, then you must necessarily have `'x≤'r` or `'y≤'r`. The compiler will use that annotation at two times: 1. When compiling the annotated function, the compiler doesn't know the actual lifetimes of `x` and `y` and it doesn't know `'a` (since `'a` will be chosen at the call site, like all generic parameters). But it knows that when the function gets called, the caller will use some lifetime `'a` that matches the input constraints `'a≤'x` and `'a≤'y` and it checks that the code of the function respects the output constraint `'a≤'r`. 2. When calling the annotated function, the compiler will add to its constraint solver an unknown scope `'a` in which the return value can be accessed, along with the constraints that `'a≤'x` and `'a≤'y` plus whatever extra constraints are required due to the surrounding code and in particular where `x` and `y` come from and how the return value is used. If the compiler is able to find some scope `'a` that matches all the constraints, then the code compiles using that scope. Otherwise compilation fails with a "does not live long enough" error.
We can consider the case from your example code with a slight scope modification ```rust fn main() { let string1 = String::from("abcd"); { let string2 = "xyz"; let result = longest(string1.as_str(), string2); println!("The longest string is {}", result); } } fn longest<'a>(x: &'a str, y: &'a str) -> &'a str { if x.len() > y.len() { x } else { y } } ``` Here, we recognize that for the function call `longest` above, the lifetime `a` ends up being the lifetime of `string2`, because both parameters `x` and `y` must live at least as long as `a`, so if `a` were the lifetime of `string1`, then the second parameter to `longest`, which is just `string2` would not live as long as `string1` and the statement "both parameters must live at least as long as `a`" would be false. We admit that lifetime `a` is the lifetime of `string2`. We know that the string slice returned by `longest` could be either `string1` or `string2`. Since we make the constraint in the declaration that the return value also lives at least as long as lifetime `a`, we are really saying that the return value lives at least as long as `string2`, the string with the shorter of the two lifetimes. If `longest` returned `string2`, then the returned string slice would live exactly as long as lifetime `a`. If `longest` returned `string1`, however, the returned string slice would live as long as the lifetime of `string1`, which is *longer* than that of lifetime `a` (the lifetime of `string2`), so we say that the string slice returned from the function will live at least as long as `a`. An important thing to note here is that we don't know which slice `longest` is going to return, so we only allow the lifetime of the returned reference to be that of the smaller of the two lifetimes, since during the smaller of the two lifetimes, both strings are certainly still alive.
37,219,103
Thanks in advance for your help. I am having a hard time keeping my codebase clean. I want to avoid intermixing PHP, HTML, and CSS. Currently, my main site is broken down into numerous smaller tabs. The PHP code for these tabs is dynamically included after an ajax call is made. ``` elseif (file_exists('templates/custom/'.$center."/".$section."/".$tab.".php")) { include 'templates/custom/'.$center."/".$section."/".$tab.".php"; } ``` It works great but I would also like to dynamically include JavaScript from an external file. In my mind it would work like this, ``` elseif (file_exists('templates/custom/'.$center."/".$section."/".$tab.".php")) { include 'templates/custom/'.$center."/".$section."/".$tab.".php"; include 'templates/custom/'.$center."/".$section."/".$tab.".js"; } ``` **How can I dynamically include javascript based on what tab the user wants to go to while still keeping the javascript separated by tab in individual files.** I have spent the entire day looking into this issue and keep coming across examples that look like this, ``` echo "<script language='javascript' type='text/javascript'>"; echo "alert('hello worldio');"; echo "</script>"; $URL="page.php"; echo "<script>location.href='$URL'</script>"; ``` This site is a single page application. THanks again!
2016/05/13
[ "https://Stackoverflow.com/questions/37219103", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6301661/" ]
Just `print` the `<script>` tag to include it: ``` print '<script src="templates/custom/'.$center.'/'.$section.'/'.$tab.'.js'" type="text/javascript"></script>'; ```
Javascript files cannot be included by php function. Use the below code ``` elseif (file_exists('templates/custom/'.$center."/".$section."/".$tab.".php")) { include 'templates/custom/'.$center."/".$section."/".$tab.".php"; $file_path = "javascript external file path"; // replace with correct file path ?> <script language="JavaScript" type="text/javascript" src="<?php echo $file_path;?>"></script> <?php } ?> ```
37,219,103
Thanks in advance for your help. I am having a hard time keeping my codebase clean. I want to avoid intermixing PHP, HTML, and CSS. Currently, my main site is broken down into numerous smaller tabs. The PHP code for these tabs is dynamically included after an ajax call is made. ``` elseif (file_exists('templates/custom/'.$center."/".$section."/".$tab.".php")) { include 'templates/custom/'.$center."/".$section."/".$tab.".php"; } ``` It works great but I would also like to dynamically include JavaScript from an external file. In my mind it would work like this, ``` elseif (file_exists('templates/custom/'.$center."/".$section."/".$tab.".php")) { include 'templates/custom/'.$center."/".$section."/".$tab.".php"; include 'templates/custom/'.$center."/".$section."/".$tab.".js"; } ``` **How can I dynamically include javascript based on what tab the user wants to go to while still keeping the javascript separated by tab in individual files.** I have spent the entire day looking into this issue and keep coming across examples that look like this, ``` echo "<script language='javascript' type='text/javascript'>"; echo "alert('hello worldio');"; echo "</script>"; $URL="page.php"; echo "<script>location.href='$URL'</script>"; ``` This site is a single page application. THanks again!
2016/05/13
[ "https://Stackoverflow.com/questions/37219103", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6301661/" ]
Javascript files cannot be included by php function. Use the below code ``` elseif (file_exists('templates/custom/'.$center."/".$section."/".$tab.".php")) { include 'templates/custom/'.$center."/".$section."/".$tab.".php"; $file_path = "javascript external file path"; // replace with correct file path ?> <script language="JavaScript" type="text/javascript" src="<?php echo $file_path;?>"></script> <?php } ?> ```
hi in my case i use module base template that seprated to smaller parts.i have 3 main UI part in my site 1.public site js for all templates jquery,bootstrap ,... that use in all templates must put here 2.each style or template has a js folder that all public js file of this templates must be there 3.each module in template has js folder that js special for that module must be there i do it for css too.in fact when i load a module check all of this folders by ``` array_slice(scandir($st_css_style_public_path), 2) ``` and create css link or js script and print final string of addresses in my page. but some times you need to inject a peace of code directly into your page i use a folder and a file with name of plugins->plugins.php put all piece of script there get it's content and print it into my page ``` `$st_plugins .= (file_exists($st_plugin_style_public_path) ) ? file_get_contents($st_plugin_style_public_path) : ' '; ``` all of my render method in my view is this : ``` public function render($address, $data = '', $cache = 1, $showstyle = 1) { $data['LINKPREFIX'] = '/' . $this->current_holding_unique_name . '/' . $this->current_lang; if (isset($address)) { $path = explode('/', $address); $path[0] = $path[0]; $path[1] = $path[1]; } $template = $this->twig->loadTemplate($path[0] . DS . $path[1] . '.twig'); if ($showstyle) { $css_links = ''; $js_links = ''; $st_plugins = ''; //################################################## //########################## CREATING CSS,JS ADDRESS //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //####### SITE PUBLIC CSS & JS FILES $st_js_public_path = '.' . DS . PUBLIC_DIR . DS . $this->set_address($path[0]) . 'js'; $st_css_public_path = '.' . DS . PUBLIC_DIR . DS . $this->set_address($path[0]) . 'css'; if (file_exists($st_js_public_path) && is_dir($st_js_public_path)) { $ar_public_jsfile_list = array_slice(scandir($st_js_public_path), 2); foreach ($ar_public_jsfile_list as $js_file_name) { $js_links .= $this->create_css_js_link($st_js_public_path . DS . $js_file_name, 'js'); } } if (file_exists($st_css_public_path) && is_dir($st_css_public_path)) { $ar_public_cssfile_list = array_slice(scandir($st_css_public_path), 2); foreach ($ar_public_cssfile_list as $css_file_name) { $css_links .= $this->create_css_js_link($st_css_public_path . DS . $css_file_name, 'css'); } } //####### STYLE PUBLIC CSS & JS & PLUGINS FILES $st_js_style_public_path = '.' . DS . VIEW_DIR . DS . $this->current_style . DS . 'public' . DS . $this->current_direction . DS . 'js'; $st_css_style_public_path = '.' . DS . VIEW_DIR . DS . $this->current_style . DS . 'public' . DS . $this->current_direction . DS . 'css'; $st_plugin_style_public_path = '.' . DS . VIEW_DIR . DS . $this->current_style . DS . 'public' . DS . $this->current_direction . DS . 'plugins' . DS . 'plugins.php'; if (file_exists($st_css_style_public_path) && is_dir($st_css_style_public_path)) { $ar_cssfile_list = array_slice(scandir($st_css_style_public_path), 2); foreach ($ar_cssfile_list as $css_file_name) { $css_links .= $this->create_css_js_link($st_css_style_public_path . DS . $css_file_name, 'css'); } } if (file_exists($st_js_style_public_path) && is_dir($st_js_style_public_path)) { $ar_jsfile_list = array_slice(scandir($st_js_style_public_path), 2); foreach ($ar_jsfile_list as $js_file_name) { $js_links .= $this->create_css_js_link($st_js_style_public_path . DS . $js_file_name, 'js'); } } $st_plugins .= (file_exists($st_plugin_style_public_path) ) ? file_get_contents($st_plugin_style_public_path) : ' '; //####### MODULE CSS & JS FILES $st_js_style_path = '.' . DS . VIEW_DIR . DS . $this->current_style . DS . $path[0] . DS . $this->current_direction . DS . 'js'; $st_css_style_path = '.' . DS . VIEW_DIR . DS . $this->current_style . DS . $path[0] . DS . $this->current_direction . DS . 'css'; $st_plugin_path = '.' . DS . VIEW_DIR . DS . $this->current_style . DS . $path[0] . DS . $this->current_direction . DS . 'plugins' . DS . 'plugins.php'; if (file_exists($st_css_style_path) && is_dir($st_css_style_path)) { $ar_cssfile_list = array_slice(scandir($st_css_style_path), 2); foreach ($ar_cssfile_list as $css_file_name) { $css_links .= $this->create_css_js_link($st_css_style_path . DS . $css_file_name, 'css'); } } if (file_exists($st_js_style_path) && is_dir($st_js_style_path)) { $ar_jsfile_list = array_slice(scandir($st_js_style_path), 2); foreach ($ar_jsfile_list as $js_file_name) { $js_links .= $this->create_css_js_link($st_js_style_path . DS . $js_file_name, 'js'); } } $st_plugins .= (file_exists($st_plugin_path) && $showstyle ) ? file_get_contents($st_plugin_path) : ' '; //################################################ //################################################ //################################################ //################################################ //@ @ @ CREATING CSS,JS ADDRESS $data['VARCSSADDR'] = $css_links; $data['VARJSADDR'] = $js_links . $st_plugins; $data['VARURL'] = '/'; $data = array_merge($data, lang_translate::$lang); $template->display($data); } else { //$ar_langpropr = language::$ar_lanuage[session::get('current_lang')]; //$data['lang_code'] = $ar_langpropr['lang_code']; $data = array_merge($data, lang_translate::$lang); return $this->twig->render($address . '.twig', $data); } } ``` i am using twig template engine so there are some unrelated code to your question here;else part is for ajax call. conclusion: 1-you can use this structure to add or delete file from a module as easy as copy or delete a file from it's folder. 2- you can use it to create correct js or css to create address by ajax and print it in your code i hope it helped you and don't hesitate to as more question if you need
37,219,103
Thanks in advance for your help. I am having a hard time keeping my codebase clean. I want to avoid intermixing PHP, HTML, and CSS. Currently, my main site is broken down into numerous smaller tabs. The PHP code for these tabs is dynamically included after an ajax call is made. ``` elseif (file_exists('templates/custom/'.$center."/".$section."/".$tab.".php")) { include 'templates/custom/'.$center."/".$section."/".$tab.".php"; } ``` It works great but I would also like to dynamically include JavaScript from an external file. In my mind it would work like this, ``` elseif (file_exists('templates/custom/'.$center."/".$section."/".$tab.".php")) { include 'templates/custom/'.$center."/".$section."/".$tab.".php"; include 'templates/custom/'.$center."/".$section."/".$tab.".js"; } ``` **How can I dynamically include javascript based on what tab the user wants to go to while still keeping the javascript separated by tab in individual files.** I have spent the entire day looking into this issue and keep coming across examples that look like this, ``` echo "<script language='javascript' type='text/javascript'>"; echo "alert('hello worldio');"; echo "</script>"; $URL="page.php"; echo "<script>location.href='$URL'</script>"; ``` This site is a single page application. THanks again!
2016/05/13
[ "https://Stackoverflow.com/questions/37219103", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6301661/" ]
Javascript files cannot be included by php function. Use the below code ``` elseif (file_exists('templates/custom/'.$center."/".$section."/".$tab.".php")) { include 'templates/custom/'.$center."/".$section."/".$tab.".php"; $file_path = "javascript external file path"; // replace with correct file path ?> <script language="JavaScript" type="text/javascript" src="<?php echo $file_path;?>"></script> <?php } ?> ```
PHP include()'s are server-side. JavaScript is client-side. Therefore, you cannot use include() on a JavaScript. However, if you would like to load a JavaScript with a URL that you want, use this: `$url = "JAVASCRIPT URL HERE"; echo('<script src="'. $url .'"></script>');`
37,219,103
Thanks in advance for your help. I am having a hard time keeping my codebase clean. I want to avoid intermixing PHP, HTML, and CSS. Currently, my main site is broken down into numerous smaller tabs. The PHP code for these tabs is dynamically included after an ajax call is made. ``` elseif (file_exists('templates/custom/'.$center."/".$section."/".$tab.".php")) { include 'templates/custom/'.$center."/".$section."/".$tab.".php"; } ``` It works great but I would also like to dynamically include JavaScript from an external file. In my mind it would work like this, ``` elseif (file_exists('templates/custom/'.$center."/".$section."/".$tab.".php")) { include 'templates/custom/'.$center."/".$section."/".$tab.".php"; include 'templates/custom/'.$center."/".$section."/".$tab.".js"; } ``` **How can I dynamically include javascript based on what tab the user wants to go to while still keeping the javascript separated by tab in individual files.** I have spent the entire day looking into this issue and keep coming across examples that look like this, ``` echo "<script language='javascript' type='text/javascript'>"; echo "alert('hello worldio');"; echo "</script>"; $URL="page.php"; echo "<script>location.href='$URL'</script>"; ``` This site is a single page application. THanks again!
2016/05/13
[ "https://Stackoverflow.com/questions/37219103", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6301661/" ]
Just `print` the `<script>` tag to include it: ``` print '<script src="templates/custom/'.$center.'/'.$section.'/'.$tab.'.js'" type="text/javascript"></script>'; ```
hi in my case i use module base template that seprated to smaller parts.i have 3 main UI part in my site 1.public site js for all templates jquery,bootstrap ,... that use in all templates must put here 2.each style or template has a js folder that all public js file of this templates must be there 3.each module in template has js folder that js special for that module must be there i do it for css too.in fact when i load a module check all of this folders by ``` array_slice(scandir($st_css_style_public_path), 2) ``` and create css link or js script and print final string of addresses in my page. but some times you need to inject a peace of code directly into your page i use a folder and a file with name of plugins->plugins.php put all piece of script there get it's content and print it into my page ``` `$st_plugins .= (file_exists($st_plugin_style_public_path) ) ? file_get_contents($st_plugin_style_public_path) : ' '; ``` all of my render method in my view is this : ``` public function render($address, $data = '', $cache = 1, $showstyle = 1) { $data['LINKPREFIX'] = '/' . $this->current_holding_unique_name . '/' . $this->current_lang; if (isset($address)) { $path = explode('/', $address); $path[0] = $path[0]; $path[1] = $path[1]; } $template = $this->twig->loadTemplate($path[0] . DS . $path[1] . '.twig'); if ($showstyle) { $css_links = ''; $js_links = ''; $st_plugins = ''; //################################################## //########################## CREATING CSS,JS ADDRESS //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //####### SITE PUBLIC CSS & JS FILES $st_js_public_path = '.' . DS . PUBLIC_DIR . DS . $this->set_address($path[0]) . 'js'; $st_css_public_path = '.' . DS . PUBLIC_DIR . DS . $this->set_address($path[0]) . 'css'; if (file_exists($st_js_public_path) && is_dir($st_js_public_path)) { $ar_public_jsfile_list = array_slice(scandir($st_js_public_path), 2); foreach ($ar_public_jsfile_list as $js_file_name) { $js_links .= $this->create_css_js_link($st_js_public_path . DS . $js_file_name, 'js'); } } if (file_exists($st_css_public_path) && is_dir($st_css_public_path)) { $ar_public_cssfile_list = array_slice(scandir($st_css_public_path), 2); foreach ($ar_public_cssfile_list as $css_file_name) { $css_links .= $this->create_css_js_link($st_css_public_path . DS . $css_file_name, 'css'); } } //####### STYLE PUBLIC CSS & JS & PLUGINS FILES $st_js_style_public_path = '.' . DS . VIEW_DIR . DS . $this->current_style . DS . 'public' . DS . $this->current_direction . DS . 'js'; $st_css_style_public_path = '.' . DS . VIEW_DIR . DS . $this->current_style . DS . 'public' . DS . $this->current_direction . DS . 'css'; $st_plugin_style_public_path = '.' . DS . VIEW_DIR . DS . $this->current_style . DS . 'public' . DS . $this->current_direction . DS . 'plugins' . DS . 'plugins.php'; if (file_exists($st_css_style_public_path) && is_dir($st_css_style_public_path)) { $ar_cssfile_list = array_slice(scandir($st_css_style_public_path), 2); foreach ($ar_cssfile_list as $css_file_name) { $css_links .= $this->create_css_js_link($st_css_style_public_path . DS . $css_file_name, 'css'); } } if (file_exists($st_js_style_public_path) && is_dir($st_js_style_public_path)) { $ar_jsfile_list = array_slice(scandir($st_js_style_public_path), 2); foreach ($ar_jsfile_list as $js_file_name) { $js_links .= $this->create_css_js_link($st_js_style_public_path . DS . $js_file_name, 'js'); } } $st_plugins .= (file_exists($st_plugin_style_public_path) ) ? file_get_contents($st_plugin_style_public_path) : ' '; //####### MODULE CSS & JS FILES $st_js_style_path = '.' . DS . VIEW_DIR . DS . $this->current_style . DS . $path[0] . DS . $this->current_direction . DS . 'js'; $st_css_style_path = '.' . DS . VIEW_DIR . DS . $this->current_style . DS . $path[0] . DS . $this->current_direction . DS . 'css'; $st_plugin_path = '.' . DS . VIEW_DIR . DS . $this->current_style . DS . $path[0] . DS . $this->current_direction . DS . 'plugins' . DS . 'plugins.php'; if (file_exists($st_css_style_path) && is_dir($st_css_style_path)) { $ar_cssfile_list = array_slice(scandir($st_css_style_path), 2); foreach ($ar_cssfile_list as $css_file_name) { $css_links .= $this->create_css_js_link($st_css_style_path . DS . $css_file_name, 'css'); } } if (file_exists($st_js_style_path) && is_dir($st_js_style_path)) { $ar_jsfile_list = array_slice(scandir($st_js_style_path), 2); foreach ($ar_jsfile_list as $js_file_name) { $js_links .= $this->create_css_js_link($st_js_style_path . DS . $js_file_name, 'js'); } } $st_plugins .= (file_exists($st_plugin_path) && $showstyle ) ? file_get_contents($st_plugin_path) : ' '; //################################################ //################################################ //################################################ //################################################ //@ @ @ CREATING CSS,JS ADDRESS $data['VARCSSADDR'] = $css_links; $data['VARJSADDR'] = $js_links . $st_plugins; $data['VARURL'] = '/'; $data = array_merge($data, lang_translate::$lang); $template->display($data); } else { //$ar_langpropr = language::$ar_lanuage[session::get('current_lang')]; //$data['lang_code'] = $ar_langpropr['lang_code']; $data = array_merge($data, lang_translate::$lang); return $this->twig->render($address . '.twig', $data); } } ``` i am using twig template engine so there are some unrelated code to your question here;else part is for ajax call. conclusion: 1-you can use this structure to add or delete file from a module as easy as copy or delete a file from it's folder. 2- you can use it to create correct js or css to create address by ajax and print it in your code i hope it helped you and don't hesitate to as more question if you need
37,219,103
Thanks in advance for your help. I am having a hard time keeping my codebase clean. I want to avoid intermixing PHP, HTML, and CSS. Currently, my main site is broken down into numerous smaller tabs. The PHP code for these tabs is dynamically included after an ajax call is made. ``` elseif (file_exists('templates/custom/'.$center."/".$section."/".$tab.".php")) { include 'templates/custom/'.$center."/".$section."/".$tab.".php"; } ``` It works great but I would also like to dynamically include JavaScript from an external file. In my mind it would work like this, ``` elseif (file_exists('templates/custom/'.$center."/".$section."/".$tab.".php")) { include 'templates/custom/'.$center."/".$section."/".$tab.".php"; include 'templates/custom/'.$center."/".$section."/".$tab.".js"; } ``` **How can I dynamically include javascript based on what tab the user wants to go to while still keeping the javascript separated by tab in individual files.** I have spent the entire day looking into this issue and keep coming across examples that look like this, ``` echo "<script language='javascript' type='text/javascript'>"; echo "alert('hello worldio');"; echo "</script>"; $URL="page.php"; echo "<script>location.href='$URL'</script>"; ``` This site is a single page application. THanks again!
2016/05/13
[ "https://Stackoverflow.com/questions/37219103", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6301661/" ]
Just `print` the `<script>` tag to include it: ``` print '<script src="templates/custom/'.$center.'/'.$section.'/'.$tab.'.js'" type="text/javascript"></script>'; ```
PHP include()'s are server-side. JavaScript is client-side. Therefore, you cannot use include() on a JavaScript. However, if you would like to load a JavaScript with a URL that you want, use this: `$url = "JAVASCRIPT URL HERE"; echo('<script src="'. $url .'"></script>');`
121,149
I made a New York-style pizza using recipes from the Elements of Pizza book by Ken Forkish, and some of the cheese and pepperoni slid off in the oven while baking. This was my first time using these recipes and a baking steel. I believe I followed the recipes pretty faithfully, measured everything by weight, etc. The steel preheated in my home oven at 500°F for about 45 minutes to an hour as the manufacturer recommended. The book says to cook the pizza for nine to ten minutes. About five minutes in, I could hear something sizzling. When I peeked into the oven I could see the dough had puffed up, and some of the pepperoni and cheese appeared to have flowed over the edges in a couple places and was burning up on the steel. My pizza went in the oven looking like this: [![Pizza before baking](https://i.stack.imgur.com/qcnUq.jpg)](https://i.stack.imgur.com/qcnUq.jpg) It came out looking like this: [![Pizza after baking](https://i.stack.imgur.com/Ydz69.jpg)](https://i.stack.imgur.com/Ydz69.jpg) Why did this happen and how can I avoid it? **Edit:** added photos of second attempt with a smaller overflow. [![Second pizza before baking](https://i.stack.imgur.com/2p2qe.jpg)](https://i.stack.imgur.com/2p2qe.jpg) Top edge where overflow occurred: [![Second pizza after baking](https://i.stack.imgur.com/gpQ7w.jpg)](https://i.stack.imgur.com/gpQ7w.jpg) Close-up of top edge: [![Close-up of overflow site](https://i.stack.imgur.com/rYpnm.jpg)](https://i.stack.imgur.com/rYpnm.jpg)
2022/07/25
[ "https://cooking.stackexchange.com/questions/121149", "https://cooking.stackexchange.com", "https://cooking.stackexchange.com/users/100134/" ]
It likely comes down to how you've formed the crust. The "normal" method involves pushing the gas out of the middle of the crust, ideally shifting it to the outer edge. So the middle of the crust ends up fairly thin and dense, and the outer edge has more remaining bubbles. If you pull out the crust more gently, and don't squeeze the gas out, then it'll rise like a loaf of bread rather than like a pizza. The other possibility is that the crust somehow sealed to your baking surface around the edges, and vapor puffed it up and away from the baking surface in the middle. That would be indicated by the underside of the crust having a dark rim and a very pale middle. I've never seen this happen, and I'm not sure it actually could, but I thought I'd mention it for completeness.
I see two possibilities, the first is that the toppings slid off when you slid the pie off the peel, the other is that the pizza puffed up when baking and the toppings slid off then. If the pizza base sticks to the peel the tendency is to tip it up and try and shove it off, which can send your toppings flying. The trick is to use plenty of semolina or coarse corn meal between the base and the peel so it slides off. Keep the pizza flat while you do this, with enough semolina you'll find the pizza comes off the peel with just a bit of forward push. It's also possible that the base was thicker in the middle than the sides, and it puffed up when it was in the oven and your toppings slid off. To remedy this make a lip at the edge of the crust, so the edge is just a bit thicker than the rest, that way when the crust expands the edge rises more and forms a barrier. A slightly raised edge will also help keep your toppings from coming off when you slide it off the peel. Also make sure that the middle of the pizza base isn't thicker than the rest. Additionally, here are some useful tips: 1. Pepperoni sometimes curls before cooking, when topping the pizza put the edge of the curls downward so there's more contact to keep it in place 2. Press the pepperoni into the pizza a little bit It's a great looking pizza despite the topping sliding, a couple of tweaks and you're home free.
121,149
I made a New York-style pizza using recipes from the Elements of Pizza book by Ken Forkish, and some of the cheese and pepperoni slid off in the oven while baking. This was my first time using these recipes and a baking steel. I believe I followed the recipes pretty faithfully, measured everything by weight, etc. The steel preheated in my home oven at 500°F for about 45 minutes to an hour as the manufacturer recommended. The book says to cook the pizza for nine to ten minutes. About five minutes in, I could hear something sizzling. When I peeked into the oven I could see the dough had puffed up, and some of the pepperoni and cheese appeared to have flowed over the edges in a couple places and was burning up on the steel. My pizza went in the oven looking like this: [![Pizza before baking](https://i.stack.imgur.com/qcnUq.jpg)](https://i.stack.imgur.com/qcnUq.jpg) It came out looking like this: [![Pizza after baking](https://i.stack.imgur.com/Ydz69.jpg)](https://i.stack.imgur.com/Ydz69.jpg) Why did this happen and how can I avoid it? **Edit:** added photos of second attempt with a smaller overflow. [![Second pizza before baking](https://i.stack.imgur.com/2p2qe.jpg)](https://i.stack.imgur.com/2p2qe.jpg) Top edge where overflow occurred: [![Second pizza after baking](https://i.stack.imgur.com/gpQ7w.jpg)](https://i.stack.imgur.com/gpQ7w.jpg) Close-up of top edge: [![Close-up of overflow site](https://i.stack.imgur.com/rYpnm.jpg)](https://i.stack.imgur.com/rYpnm.jpg)
2022/07/25
[ "https://cooking.stackexchange.com/questions/121149", "https://cooking.stackexchange.com", "https://cooking.stackexchange.com/users/100134/" ]
I see two possibilities, the first is that the toppings slid off when you slid the pie off the peel, the other is that the pizza puffed up when baking and the toppings slid off then. If the pizza base sticks to the peel the tendency is to tip it up and try and shove it off, which can send your toppings flying. The trick is to use plenty of semolina or coarse corn meal between the base and the peel so it slides off. Keep the pizza flat while you do this, with enough semolina you'll find the pizza comes off the peel with just a bit of forward push. It's also possible that the base was thicker in the middle than the sides, and it puffed up when it was in the oven and your toppings slid off. To remedy this make a lip at the edge of the crust, so the edge is just a bit thicker than the rest, that way when the crust expands the edge rises more and forms a barrier. A slightly raised edge will also help keep your toppings from coming off when you slide it off the peel. Also make sure that the middle of the pizza base isn't thicker than the rest. Additionally, here are some useful tips: 1. Pepperoni sometimes curls before cooking, when topping the pizza put the edge of the curls downward so there's more contact to keep it in place 2. Press the pepperoni into the pizza a little bit It's a great looking pizza despite the topping sliding, a couple of tweaks and you're home free.
It doesn't look like dough/crust bubbles to me, because those usually don't deflate without obvious signs. Cheese usually falls off of crust bubbles. The pepperonis aren't the only thing that moved; the cheese also spread. It looks to me like the cheese just carried the pepperonis with it. Examples of crust bubbles: <https://www.reddit.com/r/food/comments/16znwv/you_know_those_little_air_bubbles_you_sometimes/> [![Slices of pizza in a delivery box, one with a large bubble near the edge that has no toppings and has mostly deflated.](https://i.stack.imgur.com/4LRwO.png)](https://i.stack.imgur.com/4LRwO.png)
121,149
I made a New York-style pizza using recipes from the Elements of Pizza book by Ken Forkish, and some of the cheese and pepperoni slid off in the oven while baking. This was my first time using these recipes and a baking steel. I believe I followed the recipes pretty faithfully, measured everything by weight, etc. The steel preheated in my home oven at 500°F for about 45 minutes to an hour as the manufacturer recommended. The book says to cook the pizza for nine to ten minutes. About five minutes in, I could hear something sizzling. When I peeked into the oven I could see the dough had puffed up, and some of the pepperoni and cheese appeared to have flowed over the edges in a couple places and was burning up on the steel. My pizza went in the oven looking like this: [![Pizza before baking](https://i.stack.imgur.com/qcnUq.jpg)](https://i.stack.imgur.com/qcnUq.jpg) It came out looking like this: [![Pizza after baking](https://i.stack.imgur.com/Ydz69.jpg)](https://i.stack.imgur.com/Ydz69.jpg) Why did this happen and how can I avoid it? **Edit:** added photos of second attempt with a smaller overflow. [![Second pizza before baking](https://i.stack.imgur.com/2p2qe.jpg)](https://i.stack.imgur.com/2p2qe.jpg) Top edge where overflow occurred: [![Second pizza after baking](https://i.stack.imgur.com/gpQ7w.jpg)](https://i.stack.imgur.com/gpQ7w.jpg) Close-up of top edge: [![Close-up of overflow site](https://i.stack.imgur.com/rYpnm.jpg)](https://i.stack.imgur.com/rYpnm.jpg)
2022/07/25
[ "https://cooking.stackexchange.com/questions/121149", "https://cooking.stackexchange.com", "https://cooking.stackexchange.com/users/100134/" ]
I see two possibilities, the first is that the toppings slid off when you slid the pie off the peel, the other is that the pizza puffed up when baking and the toppings slid off then. If the pizza base sticks to the peel the tendency is to tip it up and try and shove it off, which can send your toppings flying. The trick is to use plenty of semolina or coarse corn meal between the base and the peel so it slides off. Keep the pizza flat while you do this, with enough semolina you'll find the pizza comes off the peel with just a bit of forward push. It's also possible that the base was thicker in the middle than the sides, and it puffed up when it was in the oven and your toppings slid off. To remedy this make a lip at the edge of the crust, so the edge is just a bit thicker than the rest, that way when the crust expands the edge rises more and forms a barrier. A slightly raised edge will also help keep your toppings from coming off when you slide it off the peel. Also make sure that the middle of the pizza base isn't thicker than the rest. Additionally, here are some useful tips: 1. Pepperoni sometimes curls before cooking, when topping the pizza put the edge of the curls downward so there's more contact to keep it in place 2. Press the pepperoni into the pizza a little bit It's a great looking pizza despite the topping sliding, a couple of tweaks and you're home free.
Maybe a bit of folded newspaper under one of the legs of the oven might help.
121,149
I made a New York-style pizza using recipes from the Elements of Pizza book by Ken Forkish, and some of the cheese and pepperoni slid off in the oven while baking. This was my first time using these recipes and a baking steel. I believe I followed the recipes pretty faithfully, measured everything by weight, etc. The steel preheated in my home oven at 500°F for about 45 minutes to an hour as the manufacturer recommended. The book says to cook the pizza for nine to ten minutes. About five minutes in, I could hear something sizzling. When I peeked into the oven I could see the dough had puffed up, and some of the pepperoni and cheese appeared to have flowed over the edges in a couple places and was burning up on the steel. My pizza went in the oven looking like this: [![Pizza before baking](https://i.stack.imgur.com/qcnUq.jpg)](https://i.stack.imgur.com/qcnUq.jpg) It came out looking like this: [![Pizza after baking](https://i.stack.imgur.com/Ydz69.jpg)](https://i.stack.imgur.com/Ydz69.jpg) Why did this happen and how can I avoid it? **Edit:** added photos of second attempt with a smaller overflow. [![Second pizza before baking](https://i.stack.imgur.com/2p2qe.jpg)](https://i.stack.imgur.com/2p2qe.jpg) Top edge where overflow occurred: [![Second pizza after baking](https://i.stack.imgur.com/gpQ7w.jpg)](https://i.stack.imgur.com/gpQ7w.jpg) Close-up of top edge: [![Close-up of overflow site](https://i.stack.imgur.com/rYpnm.jpg)](https://i.stack.imgur.com/rYpnm.jpg)
2022/07/25
[ "https://cooking.stackexchange.com/questions/121149", "https://cooking.stackexchange.com", "https://cooking.stackexchange.com/users/100134/" ]
It likely comes down to how you've formed the crust. The "normal" method involves pushing the gas out of the middle of the crust, ideally shifting it to the outer edge. So the middle of the crust ends up fairly thin and dense, and the outer edge has more remaining bubbles. If you pull out the crust more gently, and don't squeeze the gas out, then it'll rise like a loaf of bread rather than like a pizza. The other possibility is that the crust somehow sealed to your baking surface around the edges, and vapor puffed it up and away from the baking surface in the middle. That would be indicated by the underside of the crust having a dark rim and a very pale middle. I've never seen this happen, and I'm not sure it actually could, but I thought I'd mention it for completeness.
I think it's probably bubbles, as mentioned in other answers. Since you have a relatively thin crust you can try [docking](https://www.pmq.com/dough-docking/) your dough. Docking means pressing dots into the dough so that small bubbles form instead of large ones (like crackers that have a pattern of dots). They make special tools to do this quickly but you can also do it with a fork, just remember that the goal is to press the dough together to break up bubbles, not actually go all the way through.
121,149
I made a New York-style pizza using recipes from the Elements of Pizza book by Ken Forkish, and some of the cheese and pepperoni slid off in the oven while baking. This was my first time using these recipes and a baking steel. I believe I followed the recipes pretty faithfully, measured everything by weight, etc. The steel preheated in my home oven at 500°F for about 45 minutes to an hour as the manufacturer recommended. The book says to cook the pizza for nine to ten minutes. About five minutes in, I could hear something sizzling. When I peeked into the oven I could see the dough had puffed up, and some of the pepperoni and cheese appeared to have flowed over the edges in a couple places and was burning up on the steel. My pizza went in the oven looking like this: [![Pizza before baking](https://i.stack.imgur.com/qcnUq.jpg)](https://i.stack.imgur.com/qcnUq.jpg) It came out looking like this: [![Pizza after baking](https://i.stack.imgur.com/Ydz69.jpg)](https://i.stack.imgur.com/Ydz69.jpg) Why did this happen and how can I avoid it? **Edit:** added photos of second attempt with a smaller overflow. [![Second pizza before baking](https://i.stack.imgur.com/2p2qe.jpg)](https://i.stack.imgur.com/2p2qe.jpg) Top edge where overflow occurred: [![Second pizza after baking](https://i.stack.imgur.com/gpQ7w.jpg)](https://i.stack.imgur.com/gpQ7w.jpg) Close-up of top edge: [![Close-up of overflow site](https://i.stack.imgur.com/rYpnm.jpg)](https://i.stack.imgur.com/rYpnm.jpg)
2022/07/25
[ "https://cooking.stackexchange.com/questions/121149", "https://cooking.stackexchange.com", "https://cooking.stackexchange.com/users/100134/" ]
It likely comes down to how you've formed the crust. The "normal" method involves pushing the gas out of the middle of the crust, ideally shifting it to the outer edge. So the middle of the crust ends up fairly thin and dense, and the outer edge has more remaining bubbles. If you pull out the crust more gently, and don't squeeze the gas out, then it'll rise like a loaf of bread rather than like a pizza. The other possibility is that the crust somehow sealed to your baking surface around the edges, and vapor puffed it up and away from the baking surface in the middle. That would be indicated by the underside of the crust having a dark rim and a very pale middle. I've never seen this happen, and I'm not sure it actually could, but I thought I'd mention it for completeness.
It doesn't look like dough/crust bubbles to me, because those usually don't deflate without obvious signs. Cheese usually falls off of crust bubbles. The pepperonis aren't the only thing that moved; the cheese also spread. It looks to me like the cheese just carried the pepperonis with it. Examples of crust bubbles: <https://www.reddit.com/r/food/comments/16znwv/you_know_those_little_air_bubbles_you_sometimes/> [![Slices of pizza in a delivery box, one with a large bubble near the edge that has no toppings and has mostly deflated.](https://i.stack.imgur.com/4LRwO.png)](https://i.stack.imgur.com/4LRwO.png)
121,149
I made a New York-style pizza using recipes from the Elements of Pizza book by Ken Forkish, and some of the cheese and pepperoni slid off in the oven while baking. This was my first time using these recipes and a baking steel. I believe I followed the recipes pretty faithfully, measured everything by weight, etc. The steel preheated in my home oven at 500°F for about 45 minutes to an hour as the manufacturer recommended. The book says to cook the pizza for nine to ten minutes. About five minutes in, I could hear something sizzling. When I peeked into the oven I could see the dough had puffed up, and some of the pepperoni and cheese appeared to have flowed over the edges in a couple places and was burning up on the steel. My pizza went in the oven looking like this: [![Pizza before baking](https://i.stack.imgur.com/qcnUq.jpg)](https://i.stack.imgur.com/qcnUq.jpg) It came out looking like this: [![Pizza after baking](https://i.stack.imgur.com/Ydz69.jpg)](https://i.stack.imgur.com/Ydz69.jpg) Why did this happen and how can I avoid it? **Edit:** added photos of second attempt with a smaller overflow. [![Second pizza before baking](https://i.stack.imgur.com/2p2qe.jpg)](https://i.stack.imgur.com/2p2qe.jpg) Top edge where overflow occurred: [![Second pizza after baking](https://i.stack.imgur.com/gpQ7w.jpg)](https://i.stack.imgur.com/gpQ7w.jpg) Close-up of top edge: [![Close-up of overflow site](https://i.stack.imgur.com/rYpnm.jpg)](https://i.stack.imgur.com/rYpnm.jpg)
2022/07/25
[ "https://cooking.stackexchange.com/questions/121149", "https://cooking.stackexchange.com", "https://cooking.stackexchange.com/users/100134/" ]
It likely comes down to how you've formed the crust. The "normal" method involves pushing the gas out of the middle of the crust, ideally shifting it to the outer edge. So the middle of the crust ends up fairly thin and dense, and the outer edge has more remaining bubbles. If you pull out the crust more gently, and don't squeeze the gas out, then it'll rise like a loaf of bread rather than like a pizza. The other possibility is that the crust somehow sealed to your baking surface around the edges, and vapor puffed it up and away from the baking surface in the middle. That would be indicated by the underside of the crust having a dark rim and a very pale middle. I've never seen this happen, and I'm not sure it actually could, but I thought I'd mention it for completeness.
Maybe a bit of folded newspaper under one of the legs of the oven might help.
121,149
I made a New York-style pizza using recipes from the Elements of Pizza book by Ken Forkish, and some of the cheese and pepperoni slid off in the oven while baking. This was my first time using these recipes and a baking steel. I believe I followed the recipes pretty faithfully, measured everything by weight, etc. The steel preheated in my home oven at 500°F for about 45 minutes to an hour as the manufacturer recommended. The book says to cook the pizza for nine to ten minutes. About five minutes in, I could hear something sizzling. When I peeked into the oven I could see the dough had puffed up, and some of the pepperoni and cheese appeared to have flowed over the edges in a couple places and was burning up on the steel. My pizza went in the oven looking like this: [![Pizza before baking](https://i.stack.imgur.com/qcnUq.jpg)](https://i.stack.imgur.com/qcnUq.jpg) It came out looking like this: [![Pizza after baking](https://i.stack.imgur.com/Ydz69.jpg)](https://i.stack.imgur.com/Ydz69.jpg) Why did this happen and how can I avoid it? **Edit:** added photos of second attempt with a smaller overflow. [![Second pizza before baking](https://i.stack.imgur.com/2p2qe.jpg)](https://i.stack.imgur.com/2p2qe.jpg) Top edge where overflow occurred: [![Second pizza after baking](https://i.stack.imgur.com/gpQ7w.jpg)](https://i.stack.imgur.com/gpQ7w.jpg) Close-up of top edge: [![Close-up of overflow site](https://i.stack.imgur.com/rYpnm.jpg)](https://i.stack.imgur.com/rYpnm.jpg)
2022/07/25
[ "https://cooking.stackexchange.com/questions/121149", "https://cooking.stackexchange.com", "https://cooking.stackexchange.com/users/100134/" ]
I think it's probably bubbles, as mentioned in other answers. Since you have a relatively thin crust you can try [docking](https://www.pmq.com/dough-docking/) your dough. Docking means pressing dots into the dough so that small bubbles form instead of large ones (like crackers that have a pattern of dots). They make special tools to do this quickly but you can also do it with a fork, just remember that the goal is to press the dough together to break up bubbles, not actually go all the way through.
It doesn't look like dough/crust bubbles to me, because those usually don't deflate without obvious signs. Cheese usually falls off of crust bubbles. The pepperonis aren't the only thing that moved; the cheese also spread. It looks to me like the cheese just carried the pepperonis with it. Examples of crust bubbles: <https://www.reddit.com/r/food/comments/16znwv/you_know_those_little_air_bubbles_you_sometimes/> [![Slices of pizza in a delivery box, one with a large bubble near the edge that has no toppings and has mostly deflated.](https://i.stack.imgur.com/4LRwO.png)](https://i.stack.imgur.com/4LRwO.png)
121,149
I made a New York-style pizza using recipes from the Elements of Pizza book by Ken Forkish, and some of the cheese and pepperoni slid off in the oven while baking. This was my first time using these recipes and a baking steel. I believe I followed the recipes pretty faithfully, measured everything by weight, etc. The steel preheated in my home oven at 500°F for about 45 minutes to an hour as the manufacturer recommended. The book says to cook the pizza for nine to ten minutes. About five minutes in, I could hear something sizzling. When I peeked into the oven I could see the dough had puffed up, and some of the pepperoni and cheese appeared to have flowed over the edges in a couple places and was burning up on the steel. My pizza went in the oven looking like this: [![Pizza before baking](https://i.stack.imgur.com/qcnUq.jpg)](https://i.stack.imgur.com/qcnUq.jpg) It came out looking like this: [![Pizza after baking](https://i.stack.imgur.com/Ydz69.jpg)](https://i.stack.imgur.com/Ydz69.jpg) Why did this happen and how can I avoid it? **Edit:** added photos of second attempt with a smaller overflow. [![Second pizza before baking](https://i.stack.imgur.com/2p2qe.jpg)](https://i.stack.imgur.com/2p2qe.jpg) Top edge where overflow occurred: [![Second pizza after baking](https://i.stack.imgur.com/gpQ7w.jpg)](https://i.stack.imgur.com/gpQ7w.jpg) Close-up of top edge: [![Close-up of overflow site](https://i.stack.imgur.com/rYpnm.jpg)](https://i.stack.imgur.com/rYpnm.jpg)
2022/07/25
[ "https://cooking.stackexchange.com/questions/121149", "https://cooking.stackexchange.com", "https://cooking.stackexchange.com/users/100134/" ]
I think it's probably bubbles, as mentioned in other answers. Since you have a relatively thin crust you can try [docking](https://www.pmq.com/dough-docking/) your dough. Docking means pressing dots into the dough so that small bubbles form instead of large ones (like crackers that have a pattern of dots). They make special tools to do this quickly but you can also do it with a fork, just remember that the goal is to press the dough together to break up bubbles, not actually go all the way through.
Maybe a bit of folded newspaper under one of the legs of the oven might help.
5,352,175
I've got a image... and if the image's height is greater than maxHeight, or the width is greater than maxWidth, I'd like to proportionally resize the image so that it fits in maxWidth X maxHeight.
2011/03/18
[ "https://Stackoverflow.com/questions/5352175", "https://Stackoverflow.com", "https://Stackoverflow.com/users/574078/" ]
While this can be done, what happens when the user's screen is much bigger than the native size of the image? Do you stretch it to the point of it degrading into pixels? What happens with people with smaller screens - do they have to waste time and bandwidth downloading an image that is much larger than they're capable if displaying, then depending on the browser to scale the image down? In many browsers, especially older ones, scaling images degrades them, whether making them bigger or smaller. It's best to scale them on the server, based on a large image and deliver the "right" sized image to the client. This is much more complicated. While all of this is possible, one must ask whether this really adds much value to the user experience in the first place and whether all this effort is worth it.
You can set the attributes of the image tag using JavaScript. The properties you may like to set are height, width.
10,421,613
Either with PHP or a RegExp (or both), how do I match a range of IP addresses? Sample Incoming IPs ------------------- ``` 10.210.12.12 10.253.12.12 10.210.12.254 10.210.12.95 10.210.12.60 ``` Sample Ranges ------------- ``` 10.210.12.0/24 10.210.12.0/16 10.210.*.* 10.*.*.* ``` I know that I can do this: ``` ?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?) ``` ...but it doesn't take ranges into account. It merely lets you match an incoming number to see if it's an IP address where each octet is 0-255. **EDIT:** There's also this function that I found in a comment at php.net on the ip2long function. ``` function ip_in_network($ip, $net_addr, $net_mask){ if($net_mask <= 0){ return false; } $ip_binary_string = sprintf("%032b",ip2long($ip)); $net_binary_string = sprintf("%032b",ip2long($net_addr)); return (substr_compare($ip_binary_string,$net_binary_string,0,$net_mask) === 0); } ip_in_network("192.168.2.1","192.168.2.0",24); //true ip_in_network("192.168.6.93","192.168.0.0",16); //true ip_in_network("1.6.6.6","128.168.2.0",1); //false ``` It's short and sweet, but doesn't match the asterisk situation. I also don't know if it's entirely accurate because it returns a true result on this when I thought it would be a false: ``` echo ip_in_network("192.168.2.1","192.167.0.0",1); ``` ...but perhaps I misunderstand what the /1 would be. Perhaps I needed to use /24.
2012/05/02
[ "https://Stackoverflow.com/questions/10421613", "https://Stackoverflow.com", "https://Stackoverflow.com/users/105539/" ]
Convert to 32 bit unsigned and use boolean/bitwise operations. For example, convert 192.168.25.1 to 0xC0A81901. Then, you can see if it matches the mask 192.168.25/24 by converting the dotted-decimal portion of the mask, i.e., 0xC0A81900, and creating a 24 bit mask, i.e., 0xFFFFFF00. Perform a bitwise AND between the address in question and the mask and compare to the dotted decimal portion of the mask specification. For example, ``` 0xC0A81901 AND 0xFFFFFF00 ==> 0xC0A81900 (result) compare 0xC0A81900 (result) to 0xC0A81900. ``` I don't know PHP, but google tells me that PHP has inet\_pton(), which is what I would use in C to perform the conversion from dotted-decimal to n-bit unsigned. See <http://php.net/manual/en/function.inet-pton.php>
Use strpos to match them as strings. ``` <?php $ips = array(); $ips[0] = "10.210.12.12"; $ips[1] = "10.253.12.12"; $ips[2] = "10.210.12.254"; $ips[3] = "10.210.12.95"; $ips[4] = "10.210.12.60"; $matches = array(); foreach($ips as $ip){ if(strpos($ip, "10.253.") === 0){ $matches[] = $ip; } } print_r($matches); ?> ```
10,421,613
Either with PHP or a RegExp (or both), how do I match a range of IP addresses? Sample Incoming IPs ------------------- ``` 10.210.12.12 10.253.12.12 10.210.12.254 10.210.12.95 10.210.12.60 ``` Sample Ranges ------------- ``` 10.210.12.0/24 10.210.12.0/16 10.210.*.* 10.*.*.* ``` I know that I can do this: ``` ?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?) ``` ...but it doesn't take ranges into account. It merely lets you match an incoming number to see if it's an IP address where each octet is 0-255. **EDIT:** There's also this function that I found in a comment at php.net on the ip2long function. ``` function ip_in_network($ip, $net_addr, $net_mask){ if($net_mask <= 0){ return false; } $ip_binary_string = sprintf("%032b",ip2long($ip)); $net_binary_string = sprintf("%032b",ip2long($net_addr)); return (substr_compare($ip_binary_string,$net_binary_string,0,$net_mask) === 0); } ip_in_network("192.168.2.1","192.168.2.0",24); //true ip_in_network("192.168.6.93","192.168.0.0",16); //true ip_in_network("1.6.6.6","128.168.2.0",1); //false ``` It's short and sweet, but doesn't match the asterisk situation. I also don't know if it's entirely accurate because it returns a true result on this when I thought it would be a false: ``` echo ip_in_network("192.168.2.1","192.167.0.0",1); ``` ...but perhaps I misunderstand what the /1 would be. Perhaps I needed to use /24.
2012/05/02
[ "https://Stackoverflow.com/questions/10421613", "https://Stackoverflow.com", "https://Stackoverflow.com/users/105539/" ]
Use this library: <https://github.com/S1lentium/IPTools> ``` //Check if IP is within Range: echo Range::parse('192.168.1.1-192.168.1.254')->contains(new IP('192.168.1.5')); // true echo Range::parse('::1-::ffff')->contains(new IP('::1234')); // true ```
Use strpos to match them as strings. ``` <?php $ips = array(); $ips[0] = "10.210.12.12"; $ips[1] = "10.253.12.12"; $ips[2] = "10.210.12.254"; $ips[3] = "10.210.12.95"; $ips[4] = "10.210.12.60"; $matches = array(); foreach($ips as $ip){ if(strpos($ip, "10.253.") === 0){ $matches[] = $ip; } } print_r($matches); ?> ```
10,421,613
Either with PHP or a RegExp (or both), how do I match a range of IP addresses? Sample Incoming IPs ------------------- ``` 10.210.12.12 10.253.12.12 10.210.12.254 10.210.12.95 10.210.12.60 ``` Sample Ranges ------------- ``` 10.210.12.0/24 10.210.12.0/16 10.210.*.* 10.*.*.* ``` I know that I can do this: ``` ?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?) ``` ...but it doesn't take ranges into account. It merely lets you match an incoming number to see if it's an IP address where each octet is 0-255. **EDIT:** There's also this function that I found in a comment at php.net on the ip2long function. ``` function ip_in_network($ip, $net_addr, $net_mask){ if($net_mask <= 0){ return false; } $ip_binary_string = sprintf("%032b",ip2long($ip)); $net_binary_string = sprintf("%032b",ip2long($net_addr)); return (substr_compare($ip_binary_string,$net_binary_string,0,$net_mask) === 0); } ip_in_network("192.168.2.1","192.168.2.0",24); //true ip_in_network("192.168.6.93","192.168.0.0",16); //true ip_in_network("1.6.6.6","128.168.2.0",1); //false ``` It's short and sweet, but doesn't match the asterisk situation. I also don't know if it's entirely accurate because it returns a true result on this when I thought it would be a false: ``` echo ip_in_network("192.168.2.1","192.167.0.0",1); ``` ...but perhaps I misunderstand what the /1 would be. Perhaps I needed to use /24.
2012/05/02
[ "https://Stackoverflow.com/questions/10421613", "https://Stackoverflow.com", "https://Stackoverflow.com/users/105539/" ]
I adapted an answer from php.net and made it better. ``` function netMatch($network, $ip) { $network=trim($network); $orig_network = $network; $ip = trim($ip); if ($ip == $network) { echo "used network ($network) for ($ip)\n"; return TRUE; } $network = str_replace(' ', '', $network); if (strpos($network, '*') !== FALSE) { if (strpos($network, '/') !== FALSE) { $asParts = explode('/', $network); $network = @ $asParts[0]; } $nCount = substr_count($network, '*'); $network = str_replace('*', '0', $network); if ($nCount == 1) { $network .= '/24'; } else if ($nCount == 2) { $network .= '/16'; } else if ($nCount == 3) { $network .= '/8'; } else if ($nCount > 3) { return TRUE; // if *.*.*.*, then all, so matched } } echo "from original network($orig_network), used network ($network) for ($ip)\n"; $d = strpos($network, '-'); if ($d === FALSE) { $ip_arr = explode('/', $network); if (!preg_match("@\d*\.\d*\.\d*\.\d*@", $ip_arr[0], $matches)){ $ip_arr[0].=".0"; // Alternate form 194.1.4/24 } $network_long = ip2long($ip_arr[0]); $x = ip2long($ip_arr[1]); $mask = long2ip($x) == $ip_arr[1] ? $x : (0xffffffff << (32 - $ip_arr[1])); $ip_long = ip2long($ip); return ($ip_long & $mask) == ($network_long & $mask); } else { $from = trim(ip2long(substr($network, 0, $d))); $to = trim(ip2long(substr($network, $d+1))); $ip = ip2long($ip); return ($ip>=$from and $ip<=$to); } } function ech($b) { if ($b) { echo "MATCHED\n"; } else { echo "DID NOT MATCH\n"; } } echo "CLASS A TESTS\n"; ech(netMatch('10.168.1.0-10.168.1.100', '10.168.1.90')); ech(netMatch('10.168.*.*', '10.168.1.90')); ech(netMatch('10.168.0.0/16', '10.168.1.90')); ech(netMatch('10.169.1.0/24', '10.168.1.90')); ech(netMatch('10.168.1.90', '10.168.1.90')); echo "\nCLASS B TESTS\n"; ech(netMatch('130.168.1.0-130.168.1.100', '130.168.1.90')); ech(netMatch('130.168.*.*', '130.168.1.90')); ech(netMatch('130.168.0.0/16', '130.168.1.90')); ech(netMatch('130.169.1.0/24', '130.168.1.90')); ech(netMatch('130.168.1.90', '130.168.1.90')); echo "\nCLASS C TESTS\n"; ech(netMatch('192.168.1.0-192.168.1.100', '192.168.1.90')); ech(netMatch('192.168.*.*', '192.168.1.90')); ech(netMatch('192.168.0.0/16', '192.168.1.90')); ech(netMatch('192.169.1.0/24', '192.168.1.90')); ech(netMatch('192.168.1.90', '192.168.1.90')); echo "\nCLASS D TESTS\n"; ech(netMatch('230.168.1.0-230.168.1.100', '230.168.1.90')); ech(netMatch('230.168.*.*', '230.168.1.90')); ech(netMatch('230.168.0.0/16', '230.168.1.90')); ech(netMatch('230.169.1.0/24', '230.168.1.90')); ech(netMatch('230.168.1.90', '230.168.1.90')); echo "\nCLASS E TESTS\n"; ech(netMatch('250.168.1.0-250.168.1.100', '250.168.1.90')); ech(netMatch('250.168.*.*', '250.168.1.90')); ech(netMatch('250.168.0.0/16', '250.168.1.90')); ech(netMatch('250.169.1.0/24', '250.168.1.90')); ech(netMatch('250.168.1.90', '250.168.1.90')); ``` This results with: ``` CLASS A TESTS from orig network (10.168.1.0-10.168.1.100) used network (10.168.1.0-10.168.1.100) for (10.168.1.90) MATCHED from orig network (10.168.*.*) used network (10.168.0.0/16) for (10.168.1.90) MATCHED from orig network (10.168.0.0/16) used network (10.168.0.0/16) for (10.168.1.90) MATCHED from orig network (10.169.1.0/24) used network (10.169.1.0/24) for (10.168.1.90) DID NOT MATCH used network (10.168.1.90) for (10.168.1.90) MATCHED CLASS B TESTS from orig network (130.168.1.0-130.168.1.100) used network (130.168.1.0-130.168.1.100) for (130.168.1.90) MATCHED from orig network (130.168.*.*) used network (130.168.0.0/16) for (130.168.1.90) MATCHED from orig network (130.168.0.0/16) used network (130.168.0.0/16) for (130.168.1.90) MATCHED from orig network (130.169.1.0/24) used network (130.169.1.0/24) for (130.168.1.90) DID NOT MATCH used network (130.168.1.90) for (130.168.1.90) MATCHED CLASS C TESTS from orig network (192.168.1.0-192.168.1.100) used network (192.168.1.0-192.168.1.100) for (192.168.1.90) MATCHED from orig network (192.168.*.*) used network (192.168.0.0/16) for (192.168.1.90) MATCHED from orig network (192.168.0.0/16) used network (192.168.0.0/16) for (192.168.1.90) MATCHED from orig network (192.169.1.0/24) used network (192.169.1.0/24) for (192.168.1.90) DID NOT MATCH used network (192.168.1.90) for (192.168.1.90) MATCHED CLASS D TESTS from orig network (230.168.1.0-230.168.1.100) used network (230.168.1.0-230.168.1.100) for (230.168.1.90) MATCHED from orig network (230.168.*.*) used network (230.168.0.0/16) for (230.168.1.90) MATCHED from orig network (230.168.0.0/16) used network (230.168.0.0/16) for (230.168.1.90) MATCHED from orig network (230.169.1.0/24) used network (230.169.1.0/24) for (230.168.1.90) DID NOT MATCH used network (230.168.1.90) for (230.168.1.90) MATCHED CLASS E TESTS from orig network (250.168.1.0-250.168.1.100) used network (250.168.1.0-250.168.1.100) for (250.168.1.90) MATCHED from orig network (250.168.*.*) used network (250.168.0.0/16) for (250.168.1.90) MATCHED from orig network (250.168.0.0/16) used network (250.168.0.0/16) for (250.168.1.90) MATCHED from orig network (250.169.1.0/24) used network (250.169.1.0/24) for (250.168.1.90) DID NOT MATCH used network (250.168.1.90) for (250.168.1.90) MATCHED ```
Convert to 32 bit unsigned and use boolean/bitwise operations. For example, convert 192.168.25.1 to 0xC0A81901. Then, you can see if it matches the mask 192.168.25/24 by converting the dotted-decimal portion of the mask, i.e., 0xC0A81900, and creating a 24 bit mask, i.e., 0xFFFFFF00. Perform a bitwise AND between the address in question and the mask and compare to the dotted decimal portion of the mask specification. For example, ``` 0xC0A81901 AND 0xFFFFFF00 ==> 0xC0A81900 (result) compare 0xC0A81900 (result) to 0xC0A81900. ``` I don't know PHP, but google tells me that PHP has inet\_pton(), which is what I would use in C to perform the conversion from dotted-decimal to n-bit unsigned. See <http://php.net/manual/en/function.inet-pton.php>
10,421,613
Either with PHP or a RegExp (or both), how do I match a range of IP addresses? Sample Incoming IPs ------------------- ``` 10.210.12.12 10.253.12.12 10.210.12.254 10.210.12.95 10.210.12.60 ``` Sample Ranges ------------- ``` 10.210.12.0/24 10.210.12.0/16 10.210.*.* 10.*.*.* ``` I know that I can do this: ``` ?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?) ``` ...but it doesn't take ranges into account. It merely lets you match an incoming number to see if it's an IP address where each octet is 0-255. **EDIT:** There's also this function that I found in a comment at php.net on the ip2long function. ``` function ip_in_network($ip, $net_addr, $net_mask){ if($net_mask <= 0){ return false; } $ip_binary_string = sprintf("%032b",ip2long($ip)); $net_binary_string = sprintf("%032b",ip2long($net_addr)); return (substr_compare($ip_binary_string,$net_binary_string,0,$net_mask) === 0); } ip_in_network("192.168.2.1","192.168.2.0",24); //true ip_in_network("192.168.6.93","192.168.0.0",16); //true ip_in_network("1.6.6.6","128.168.2.0",1); //false ``` It's short and sweet, but doesn't match the asterisk situation. I also don't know if it's entirely accurate because it returns a true result on this when I thought it would be a false: ``` echo ip_in_network("192.168.2.1","192.167.0.0",1); ``` ...but perhaps I misunderstand what the /1 would be. Perhaps I needed to use /24.
2012/05/02
[ "https://Stackoverflow.com/questions/10421613", "https://Stackoverflow.com", "https://Stackoverflow.com/users/105539/" ]
Use this library: <https://github.com/S1lentium/IPTools> ``` //Check if IP is within Range: echo Range::parse('192.168.1.1-192.168.1.254')->contains(new IP('192.168.1.5')); // true echo Range::parse('::1-::ffff')->contains(new IP('::1234')); // true ```
Regex really doesn't sound like the right tool to deal with subnet masks (at least not in decimal). It can be done, but it will be ugly. I strongly suggest parsing the string into 4 integers, combining to a 32-bit int, and then using standard bitwise operations (basically a bitwise-AND, and then a comparison).
10,421,613
Either with PHP or a RegExp (or both), how do I match a range of IP addresses? Sample Incoming IPs ------------------- ``` 10.210.12.12 10.253.12.12 10.210.12.254 10.210.12.95 10.210.12.60 ``` Sample Ranges ------------- ``` 10.210.12.0/24 10.210.12.0/16 10.210.*.* 10.*.*.* ``` I know that I can do this: ``` ?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?) ``` ...but it doesn't take ranges into account. It merely lets you match an incoming number to see if it's an IP address where each octet is 0-255. **EDIT:** There's also this function that I found in a comment at php.net on the ip2long function. ``` function ip_in_network($ip, $net_addr, $net_mask){ if($net_mask <= 0){ return false; } $ip_binary_string = sprintf("%032b",ip2long($ip)); $net_binary_string = sprintf("%032b",ip2long($net_addr)); return (substr_compare($ip_binary_string,$net_binary_string,0,$net_mask) === 0); } ip_in_network("192.168.2.1","192.168.2.0",24); //true ip_in_network("192.168.6.93","192.168.0.0",16); //true ip_in_network("1.6.6.6","128.168.2.0",1); //false ``` It's short and sweet, but doesn't match the asterisk situation. I also don't know if it's entirely accurate because it returns a true result on this when I thought it would be a false: ``` echo ip_in_network("192.168.2.1","192.167.0.0",1); ``` ...but perhaps I misunderstand what the /1 would be. Perhaps I needed to use /24.
2012/05/02
[ "https://Stackoverflow.com/questions/10421613", "https://Stackoverflow.com", "https://Stackoverflow.com/users/105539/" ]
I've improved on the above example (I have a netmask with /29 so it doesn't work). ``` function check_netmask($mask, $ip) { @list($net, $bits) = explode('/', $mask); $bits = isset($bits) ? $bits : 32; $bitmask = -pow(2, 32-$bits) & 0x00000000FFFFFFFF; $netmask = ip2long($net) & $bitmask; $ip_bits = ip2long($ip) & $bitmask; return (($netmask ^ $ip_bits) == 0); } ``` If you want to see it in action, add this: ``` print("IP Bits: " . str_pad(decbin(ip2long($ip)), 32, '0', STR_PAD_LEFT)); print "\n"; print("Bitmask: " . str_pad(decbin($bitmask), 32, '0', STR_PAD_LEFT)); print "\n"; print("Netmask: " . str_pad(decbin($netmask), 32, '0', STR_PAD_LEFT)); print "\n"; print("Match: " . str_pad(decbin($netmask ^ $ip_bits), 32, '0', STR_PAD_LEFT)); print "\n"; ``` Run it with something like this: ``` print var_dump(check_netmask($argv[1], $argv[2])); ```
Regex really doesn't sound like the right tool to deal with subnet masks (at least not in decimal). It can be done, but it will be ugly. I strongly suggest parsing the string into 4 integers, combining to a 32-bit int, and then using standard bitwise operations (basically a bitwise-AND, and then a comparison).
10,421,613
Either with PHP or a RegExp (or both), how do I match a range of IP addresses? Sample Incoming IPs ------------------- ``` 10.210.12.12 10.253.12.12 10.210.12.254 10.210.12.95 10.210.12.60 ``` Sample Ranges ------------- ``` 10.210.12.0/24 10.210.12.0/16 10.210.*.* 10.*.*.* ``` I know that I can do this: ``` ?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?) ``` ...but it doesn't take ranges into account. It merely lets you match an incoming number to see if it's an IP address where each octet is 0-255. **EDIT:** There's also this function that I found in a comment at php.net on the ip2long function. ``` function ip_in_network($ip, $net_addr, $net_mask){ if($net_mask <= 0){ return false; } $ip_binary_string = sprintf("%032b",ip2long($ip)); $net_binary_string = sprintf("%032b",ip2long($net_addr)); return (substr_compare($ip_binary_string,$net_binary_string,0,$net_mask) === 0); } ip_in_network("192.168.2.1","192.168.2.0",24); //true ip_in_network("192.168.6.93","192.168.0.0",16); //true ip_in_network("1.6.6.6","128.168.2.0",1); //false ``` It's short and sweet, but doesn't match the asterisk situation. I also don't know if it's entirely accurate because it returns a true result on this when I thought it would be a false: ``` echo ip_in_network("192.168.2.1","192.167.0.0",1); ``` ...but perhaps I misunderstand what the /1 would be. Perhaps I needed to use /24.
2012/05/02
[ "https://Stackoverflow.com/questions/10421613", "https://Stackoverflow.com", "https://Stackoverflow.com/users/105539/" ]
I adapted an answer from php.net and made it better. ``` function netMatch($network, $ip) { $network=trim($network); $orig_network = $network; $ip = trim($ip); if ($ip == $network) { echo "used network ($network) for ($ip)\n"; return TRUE; } $network = str_replace(' ', '', $network); if (strpos($network, '*') !== FALSE) { if (strpos($network, '/') !== FALSE) { $asParts = explode('/', $network); $network = @ $asParts[0]; } $nCount = substr_count($network, '*'); $network = str_replace('*', '0', $network); if ($nCount == 1) { $network .= '/24'; } else if ($nCount == 2) { $network .= '/16'; } else if ($nCount == 3) { $network .= '/8'; } else if ($nCount > 3) { return TRUE; // if *.*.*.*, then all, so matched } } echo "from original network($orig_network), used network ($network) for ($ip)\n"; $d = strpos($network, '-'); if ($d === FALSE) { $ip_arr = explode('/', $network); if (!preg_match("@\d*\.\d*\.\d*\.\d*@", $ip_arr[0], $matches)){ $ip_arr[0].=".0"; // Alternate form 194.1.4/24 } $network_long = ip2long($ip_arr[0]); $x = ip2long($ip_arr[1]); $mask = long2ip($x) == $ip_arr[1] ? $x : (0xffffffff << (32 - $ip_arr[1])); $ip_long = ip2long($ip); return ($ip_long & $mask) == ($network_long & $mask); } else { $from = trim(ip2long(substr($network, 0, $d))); $to = trim(ip2long(substr($network, $d+1))); $ip = ip2long($ip); return ($ip>=$from and $ip<=$to); } } function ech($b) { if ($b) { echo "MATCHED\n"; } else { echo "DID NOT MATCH\n"; } } echo "CLASS A TESTS\n"; ech(netMatch('10.168.1.0-10.168.1.100', '10.168.1.90')); ech(netMatch('10.168.*.*', '10.168.1.90')); ech(netMatch('10.168.0.0/16', '10.168.1.90')); ech(netMatch('10.169.1.0/24', '10.168.1.90')); ech(netMatch('10.168.1.90', '10.168.1.90')); echo "\nCLASS B TESTS\n"; ech(netMatch('130.168.1.0-130.168.1.100', '130.168.1.90')); ech(netMatch('130.168.*.*', '130.168.1.90')); ech(netMatch('130.168.0.0/16', '130.168.1.90')); ech(netMatch('130.169.1.0/24', '130.168.1.90')); ech(netMatch('130.168.1.90', '130.168.1.90')); echo "\nCLASS C TESTS\n"; ech(netMatch('192.168.1.0-192.168.1.100', '192.168.1.90')); ech(netMatch('192.168.*.*', '192.168.1.90')); ech(netMatch('192.168.0.0/16', '192.168.1.90')); ech(netMatch('192.169.1.0/24', '192.168.1.90')); ech(netMatch('192.168.1.90', '192.168.1.90')); echo "\nCLASS D TESTS\n"; ech(netMatch('230.168.1.0-230.168.1.100', '230.168.1.90')); ech(netMatch('230.168.*.*', '230.168.1.90')); ech(netMatch('230.168.0.0/16', '230.168.1.90')); ech(netMatch('230.169.1.0/24', '230.168.1.90')); ech(netMatch('230.168.1.90', '230.168.1.90')); echo "\nCLASS E TESTS\n"; ech(netMatch('250.168.1.0-250.168.1.100', '250.168.1.90')); ech(netMatch('250.168.*.*', '250.168.1.90')); ech(netMatch('250.168.0.0/16', '250.168.1.90')); ech(netMatch('250.169.1.0/24', '250.168.1.90')); ech(netMatch('250.168.1.90', '250.168.1.90')); ``` This results with: ``` CLASS A TESTS from orig network (10.168.1.0-10.168.1.100) used network (10.168.1.0-10.168.1.100) for (10.168.1.90) MATCHED from orig network (10.168.*.*) used network (10.168.0.0/16) for (10.168.1.90) MATCHED from orig network (10.168.0.0/16) used network (10.168.0.0/16) for (10.168.1.90) MATCHED from orig network (10.169.1.0/24) used network (10.169.1.0/24) for (10.168.1.90) DID NOT MATCH used network (10.168.1.90) for (10.168.1.90) MATCHED CLASS B TESTS from orig network (130.168.1.0-130.168.1.100) used network (130.168.1.0-130.168.1.100) for (130.168.1.90) MATCHED from orig network (130.168.*.*) used network (130.168.0.0/16) for (130.168.1.90) MATCHED from orig network (130.168.0.0/16) used network (130.168.0.0/16) for (130.168.1.90) MATCHED from orig network (130.169.1.0/24) used network (130.169.1.0/24) for (130.168.1.90) DID NOT MATCH used network (130.168.1.90) for (130.168.1.90) MATCHED CLASS C TESTS from orig network (192.168.1.0-192.168.1.100) used network (192.168.1.0-192.168.1.100) for (192.168.1.90) MATCHED from orig network (192.168.*.*) used network (192.168.0.0/16) for (192.168.1.90) MATCHED from orig network (192.168.0.0/16) used network (192.168.0.0/16) for (192.168.1.90) MATCHED from orig network (192.169.1.0/24) used network (192.169.1.0/24) for (192.168.1.90) DID NOT MATCH used network (192.168.1.90) for (192.168.1.90) MATCHED CLASS D TESTS from orig network (230.168.1.0-230.168.1.100) used network (230.168.1.0-230.168.1.100) for (230.168.1.90) MATCHED from orig network (230.168.*.*) used network (230.168.0.0/16) for (230.168.1.90) MATCHED from orig network (230.168.0.0/16) used network (230.168.0.0/16) for (230.168.1.90) MATCHED from orig network (230.169.1.0/24) used network (230.169.1.0/24) for (230.168.1.90) DID NOT MATCH used network (230.168.1.90) for (230.168.1.90) MATCHED CLASS E TESTS from orig network (250.168.1.0-250.168.1.100) used network (250.168.1.0-250.168.1.100) for (250.168.1.90) MATCHED from orig network (250.168.*.*) used network (250.168.0.0/16) for (250.168.1.90) MATCHED from orig network (250.168.0.0/16) used network (250.168.0.0/16) for (250.168.1.90) MATCHED from orig network (250.169.1.0/24) used network (250.169.1.0/24) for (250.168.1.90) DID NOT MATCH used network (250.168.1.90) for (250.168.1.90) MATCHED ```
Regex really doesn't sound like the right tool to deal with subnet masks (at least not in decimal). It can be done, but it will be ugly. I strongly suggest parsing the string into 4 integers, combining to a 32-bit int, and then using standard bitwise operations (basically a bitwise-AND, and then a comparison).
10,421,613
Either with PHP or a RegExp (or both), how do I match a range of IP addresses? Sample Incoming IPs ------------------- ``` 10.210.12.12 10.253.12.12 10.210.12.254 10.210.12.95 10.210.12.60 ``` Sample Ranges ------------- ``` 10.210.12.0/24 10.210.12.0/16 10.210.*.* 10.*.*.* ``` I know that I can do this: ``` ?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?) ``` ...but it doesn't take ranges into account. It merely lets you match an incoming number to see if it's an IP address where each octet is 0-255. **EDIT:** There's also this function that I found in a comment at php.net on the ip2long function. ``` function ip_in_network($ip, $net_addr, $net_mask){ if($net_mask <= 0){ return false; } $ip_binary_string = sprintf("%032b",ip2long($ip)); $net_binary_string = sprintf("%032b",ip2long($net_addr)); return (substr_compare($ip_binary_string,$net_binary_string,0,$net_mask) === 0); } ip_in_network("192.168.2.1","192.168.2.0",24); //true ip_in_network("192.168.6.93","192.168.0.0",16); //true ip_in_network("1.6.6.6","128.168.2.0",1); //false ``` It's short and sweet, but doesn't match the asterisk situation. I also don't know if it's entirely accurate because it returns a true result on this when I thought it would be a false: ``` echo ip_in_network("192.168.2.1","192.167.0.0",1); ``` ...but perhaps I misunderstand what the /1 would be. Perhaps I needed to use /24.
2012/05/02
[ "https://Stackoverflow.com/questions/10421613", "https://Stackoverflow.com", "https://Stackoverflow.com/users/105539/" ]
I adapted an answer from php.net and made it better. ``` function netMatch($network, $ip) { $network=trim($network); $orig_network = $network; $ip = trim($ip); if ($ip == $network) { echo "used network ($network) for ($ip)\n"; return TRUE; } $network = str_replace(' ', '', $network); if (strpos($network, '*') !== FALSE) { if (strpos($network, '/') !== FALSE) { $asParts = explode('/', $network); $network = @ $asParts[0]; } $nCount = substr_count($network, '*'); $network = str_replace('*', '0', $network); if ($nCount == 1) { $network .= '/24'; } else if ($nCount == 2) { $network .= '/16'; } else if ($nCount == 3) { $network .= '/8'; } else if ($nCount > 3) { return TRUE; // if *.*.*.*, then all, so matched } } echo "from original network($orig_network), used network ($network) for ($ip)\n"; $d = strpos($network, '-'); if ($d === FALSE) { $ip_arr = explode('/', $network); if (!preg_match("@\d*\.\d*\.\d*\.\d*@", $ip_arr[0], $matches)){ $ip_arr[0].=".0"; // Alternate form 194.1.4/24 } $network_long = ip2long($ip_arr[0]); $x = ip2long($ip_arr[1]); $mask = long2ip($x) == $ip_arr[1] ? $x : (0xffffffff << (32 - $ip_arr[1])); $ip_long = ip2long($ip); return ($ip_long & $mask) == ($network_long & $mask); } else { $from = trim(ip2long(substr($network, 0, $d))); $to = trim(ip2long(substr($network, $d+1))); $ip = ip2long($ip); return ($ip>=$from and $ip<=$to); } } function ech($b) { if ($b) { echo "MATCHED\n"; } else { echo "DID NOT MATCH\n"; } } echo "CLASS A TESTS\n"; ech(netMatch('10.168.1.0-10.168.1.100', '10.168.1.90')); ech(netMatch('10.168.*.*', '10.168.1.90')); ech(netMatch('10.168.0.0/16', '10.168.1.90')); ech(netMatch('10.169.1.0/24', '10.168.1.90')); ech(netMatch('10.168.1.90', '10.168.1.90')); echo "\nCLASS B TESTS\n"; ech(netMatch('130.168.1.0-130.168.1.100', '130.168.1.90')); ech(netMatch('130.168.*.*', '130.168.1.90')); ech(netMatch('130.168.0.0/16', '130.168.1.90')); ech(netMatch('130.169.1.0/24', '130.168.1.90')); ech(netMatch('130.168.1.90', '130.168.1.90')); echo "\nCLASS C TESTS\n"; ech(netMatch('192.168.1.0-192.168.1.100', '192.168.1.90')); ech(netMatch('192.168.*.*', '192.168.1.90')); ech(netMatch('192.168.0.0/16', '192.168.1.90')); ech(netMatch('192.169.1.0/24', '192.168.1.90')); ech(netMatch('192.168.1.90', '192.168.1.90')); echo "\nCLASS D TESTS\n"; ech(netMatch('230.168.1.0-230.168.1.100', '230.168.1.90')); ech(netMatch('230.168.*.*', '230.168.1.90')); ech(netMatch('230.168.0.0/16', '230.168.1.90')); ech(netMatch('230.169.1.0/24', '230.168.1.90')); ech(netMatch('230.168.1.90', '230.168.1.90')); echo "\nCLASS E TESTS\n"; ech(netMatch('250.168.1.0-250.168.1.100', '250.168.1.90')); ech(netMatch('250.168.*.*', '250.168.1.90')); ech(netMatch('250.168.0.0/16', '250.168.1.90')); ech(netMatch('250.169.1.0/24', '250.168.1.90')); ech(netMatch('250.168.1.90', '250.168.1.90')); ``` This results with: ``` CLASS A TESTS from orig network (10.168.1.0-10.168.1.100) used network (10.168.1.0-10.168.1.100) for (10.168.1.90) MATCHED from orig network (10.168.*.*) used network (10.168.0.0/16) for (10.168.1.90) MATCHED from orig network (10.168.0.0/16) used network (10.168.0.0/16) for (10.168.1.90) MATCHED from orig network (10.169.1.0/24) used network (10.169.1.0/24) for (10.168.1.90) DID NOT MATCH used network (10.168.1.90) for (10.168.1.90) MATCHED CLASS B TESTS from orig network (130.168.1.0-130.168.1.100) used network (130.168.1.0-130.168.1.100) for (130.168.1.90) MATCHED from orig network (130.168.*.*) used network (130.168.0.0/16) for (130.168.1.90) MATCHED from orig network (130.168.0.0/16) used network (130.168.0.0/16) for (130.168.1.90) MATCHED from orig network (130.169.1.0/24) used network (130.169.1.0/24) for (130.168.1.90) DID NOT MATCH used network (130.168.1.90) for (130.168.1.90) MATCHED CLASS C TESTS from orig network (192.168.1.0-192.168.1.100) used network (192.168.1.0-192.168.1.100) for (192.168.1.90) MATCHED from orig network (192.168.*.*) used network (192.168.0.0/16) for (192.168.1.90) MATCHED from orig network (192.168.0.0/16) used network (192.168.0.0/16) for (192.168.1.90) MATCHED from orig network (192.169.1.0/24) used network (192.169.1.0/24) for (192.168.1.90) DID NOT MATCH used network (192.168.1.90) for (192.168.1.90) MATCHED CLASS D TESTS from orig network (230.168.1.0-230.168.1.100) used network (230.168.1.0-230.168.1.100) for (230.168.1.90) MATCHED from orig network (230.168.*.*) used network (230.168.0.0/16) for (230.168.1.90) MATCHED from orig network (230.168.0.0/16) used network (230.168.0.0/16) for (230.168.1.90) MATCHED from orig network (230.169.1.0/24) used network (230.169.1.0/24) for (230.168.1.90) DID NOT MATCH used network (230.168.1.90) for (230.168.1.90) MATCHED CLASS E TESTS from orig network (250.168.1.0-250.168.1.100) used network (250.168.1.0-250.168.1.100) for (250.168.1.90) MATCHED from orig network (250.168.*.*) used network (250.168.0.0/16) for (250.168.1.90) MATCHED from orig network (250.168.0.0/16) used network (250.168.0.0/16) for (250.168.1.90) MATCHED from orig network (250.169.1.0/24) used network (250.169.1.0/24) for (250.168.1.90) DID NOT MATCH used network (250.168.1.90) for (250.168.1.90) MATCHED ```
Use strpos to match them as strings. ``` <?php $ips = array(); $ips[0] = "10.210.12.12"; $ips[1] = "10.253.12.12"; $ips[2] = "10.210.12.254"; $ips[3] = "10.210.12.95"; $ips[4] = "10.210.12.60"; $matches = array(); foreach($ips as $ip){ if(strpos($ip, "10.253.") === 0){ $matches[] = $ip; } } print_r($matches); ?> ```
10,421,613
Either with PHP or a RegExp (or both), how do I match a range of IP addresses? Sample Incoming IPs ------------------- ``` 10.210.12.12 10.253.12.12 10.210.12.254 10.210.12.95 10.210.12.60 ``` Sample Ranges ------------- ``` 10.210.12.0/24 10.210.12.0/16 10.210.*.* 10.*.*.* ``` I know that I can do this: ``` ?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?) ``` ...but it doesn't take ranges into account. It merely lets you match an incoming number to see if it's an IP address where each octet is 0-255. **EDIT:** There's also this function that I found in a comment at php.net on the ip2long function. ``` function ip_in_network($ip, $net_addr, $net_mask){ if($net_mask <= 0){ return false; } $ip_binary_string = sprintf("%032b",ip2long($ip)); $net_binary_string = sprintf("%032b",ip2long($net_addr)); return (substr_compare($ip_binary_string,$net_binary_string,0,$net_mask) === 0); } ip_in_network("192.168.2.1","192.168.2.0",24); //true ip_in_network("192.168.6.93","192.168.0.0",16); //true ip_in_network("1.6.6.6","128.168.2.0",1); //false ``` It's short and sweet, but doesn't match the asterisk situation. I also don't know if it's entirely accurate because it returns a true result on this when I thought it would be a false: ``` echo ip_in_network("192.168.2.1","192.167.0.0",1); ``` ...but perhaps I misunderstand what the /1 would be. Perhaps I needed to use /24.
2012/05/02
[ "https://Stackoverflow.com/questions/10421613", "https://Stackoverflow.com", "https://Stackoverflow.com/users/105539/" ]
I've improved on the above example (I have a netmask with /29 so it doesn't work). ``` function check_netmask($mask, $ip) { @list($net, $bits) = explode('/', $mask); $bits = isset($bits) ? $bits : 32; $bitmask = -pow(2, 32-$bits) & 0x00000000FFFFFFFF; $netmask = ip2long($net) & $bitmask; $ip_bits = ip2long($ip) & $bitmask; return (($netmask ^ $ip_bits) == 0); } ``` If you want to see it in action, add this: ``` print("IP Bits: " . str_pad(decbin(ip2long($ip)), 32, '0', STR_PAD_LEFT)); print "\n"; print("Bitmask: " . str_pad(decbin($bitmask), 32, '0', STR_PAD_LEFT)); print "\n"; print("Netmask: " . str_pad(decbin($netmask), 32, '0', STR_PAD_LEFT)); print "\n"; print("Match: " . str_pad(decbin($netmask ^ $ip_bits), 32, '0', STR_PAD_LEFT)); print "\n"; ``` Run it with something like this: ``` print var_dump(check_netmask($argv[1], $argv[2])); ```
Use strpos to match them as strings. ``` <?php $ips = array(); $ips[0] = "10.210.12.12"; $ips[1] = "10.253.12.12"; $ips[2] = "10.210.12.254"; $ips[3] = "10.210.12.95"; $ips[4] = "10.210.12.60"; $matches = array(); foreach($ips as $ip){ if(strpos($ip, "10.253.") === 0){ $matches[] = $ip; } } print_r($matches); ?> ```
10,421,613
Either with PHP or a RegExp (or both), how do I match a range of IP addresses? Sample Incoming IPs ------------------- ``` 10.210.12.12 10.253.12.12 10.210.12.254 10.210.12.95 10.210.12.60 ``` Sample Ranges ------------- ``` 10.210.12.0/24 10.210.12.0/16 10.210.*.* 10.*.*.* ``` I know that I can do this: ``` ?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?) ``` ...but it doesn't take ranges into account. It merely lets you match an incoming number to see if it's an IP address where each octet is 0-255. **EDIT:** There's also this function that I found in a comment at php.net on the ip2long function. ``` function ip_in_network($ip, $net_addr, $net_mask){ if($net_mask <= 0){ return false; } $ip_binary_string = sprintf("%032b",ip2long($ip)); $net_binary_string = sprintf("%032b",ip2long($net_addr)); return (substr_compare($ip_binary_string,$net_binary_string,0,$net_mask) === 0); } ip_in_network("192.168.2.1","192.168.2.0",24); //true ip_in_network("192.168.6.93","192.168.0.0",16); //true ip_in_network("1.6.6.6","128.168.2.0",1); //false ``` It's short and sweet, but doesn't match the asterisk situation. I also don't know if it's entirely accurate because it returns a true result on this when I thought it would be a false: ``` echo ip_in_network("192.168.2.1","192.167.0.0",1); ``` ...but perhaps I misunderstand what the /1 would be. Perhaps I needed to use /24.
2012/05/02
[ "https://Stackoverflow.com/questions/10421613", "https://Stackoverflow.com", "https://Stackoverflow.com/users/105539/" ]
I've improved on the above example (I have a netmask with /29 so it doesn't work). ``` function check_netmask($mask, $ip) { @list($net, $bits) = explode('/', $mask); $bits = isset($bits) ? $bits : 32; $bitmask = -pow(2, 32-$bits) & 0x00000000FFFFFFFF; $netmask = ip2long($net) & $bitmask; $ip_bits = ip2long($ip) & $bitmask; return (($netmask ^ $ip_bits) == 0); } ``` If you want to see it in action, add this: ``` print("IP Bits: " . str_pad(decbin(ip2long($ip)), 32, '0', STR_PAD_LEFT)); print "\n"; print("Bitmask: " . str_pad(decbin($bitmask), 32, '0', STR_PAD_LEFT)); print "\n"; print("Netmask: " . str_pad(decbin($netmask), 32, '0', STR_PAD_LEFT)); print "\n"; print("Match: " . str_pad(decbin($netmask ^ $ip_bits), 32, '0', STR_PAD_LEFT)); print "\n"; ``` Run it with something like this: ``` print var_dump(check_netmask($argv[1], $argv[2])); ```
Convert to 32 bit unsigned and use boolean/bitwise operations. For example, convert 192.168.25.1 to 0xC0A81901. Then, you can see if it matches the mask 192.168.25/24 by converting the dotted-decimal portion of the mask, i.e., 0xC0A81900, and creating a 24 bit mask, i.e., 0xFFFFFF00. Perform a bitwise AND between the address in question and the mask and compare to the dotted decimal portion of the mask specification. For example, ``` 0xC0A81901 AND 0xFFFFFF00 ==> 0xC0A81900 (result) compare 0xC0A81900 (result) to 0xC0A81900. ``` I don't know PHP, but google tells me that PHP has inet\_pton(), which is what I would use in C to perform the conversion from dotted-decimal to n-bit unsigned. See <http://php.net/manual/en/function.inet-pton.php>
10,421,613
Either with PHP or a RegExp (or both), how do I match a range of IP addresses? Sample Incoming IPs ------------------- ``` 10.210.12.12 10.253.12.12 10.210.12.254 10.210.12.95 10.210.12.60 ``` Sample Ranges ------------- ``` 10.210.12.0/24 10.210.12.0/16 10.210.*.* 10.*.*.* ``` I know that I can do this: ``` ?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?) ``` ...but it doesn't take ranges into account. It merely lets you match an incoming number to see if it's an IP address where each octet is 0-255. **EDIT:** There's also this function that I found in a comment at php.net on the ip2long function. ``` function ip_in_network($ip, $net_addr, $net_mask){ if($net_mask <= 0){ return false; } $ip_binary_string = sprintf("%032b",ip2long($ip)); $net_binary_string = sprintf("%032b",ip2long($net_addr)); return (substr_compare($ip_binary_string,$net_binary_string,0,$net_mask) === 0); } ip_in_network("192.168.2.1","192.168.2.0",24); //true ip_in_network("192.168.6.93","192.168.0.0",16); //true ip_in_network("1.6.6.6","128.168.2.0",1); //false ``` It's short and sweet, but doesn't match the asterisk situation. I also don't know if it's entirely accurate because it returns a true result on this when I thought it would be a false: ``` echo ip_in_network("192.168.2.1","192.167.0.0",1); ``` ...but perhaps I misunderstand what the /1 would be. Perhaps I needed to use /24.
2012/05/02
[ "https://Stackoverflow.com/questions/10421613", "https://Stackoverflow.com", "https://Stackoverflow.com/users/105539/" ]
Use this library: <https://github.com/S1lentium/IPTools> ``` //Check if IP is within Range: echo Range::parse('192.168.1.1-192.168.1.254')->contains(new IP('192.168.1.5')); // true echo Range::parse('::1-::ffff')->contains(new IP('::1234')); // true ```
Convert to 32 bit unsigned and use boolean/bitwise operations. For example, convert 192.168.25.1 to 0xC0A81901. Then, you can see if it matches the mask 192.168.25/24 by converting the dotted-decimal portion of the mask, i.e., 0xC0A81900, and creating a 24 bit mask, i.e., 0xFFFFFF00. Perform a bitwise AND between the address in question and the mask and compare to the dotted decimal portion of the mask specification. For example, ``` 0xC0A81901 AND 0xFFFFFF00 ==> 0xC0A81900 (result) compare 0xC0A81900 (result) to 0xC0A81900. ``` I don't know PHP, but google tells me that PHP has inet\_pton(), which is what I would use in C to perform the conversion from dotted-decimal to n-bit unsigned. See <http://php.net/manual/en/function.inet-pton.php>
16,092,982
Sorry for my bad english, I'm creating a form that takes some values specifying reporting options in my codeigniter project. I want to show error messages created in my callback functions. I have 3 callback functions as "**checkStartDate()**, **checkFinishDate()** and **checkIssueExists()**" If validation part handles an error like "required" that doesn't set in callback, it's okay. But when i set an error message in callback function, they doesn't show up. The important thing; **if "required" rule doesn't pass, my all callback errors show up as they should**. But if "required" condition pass, there is no error message. I have that problem with error messages, the callback functions work properly. They return FALSE when i give wrong values. Here is my code: view: ``` <div id="newIssue"> <p> Fill the form below, add your issue to searching pool.</br> </p> <?php if( isset($_GET['validationErrors']) ) echo $_GET['validationErrors']; ?> <?=form_open("main/add-to-pool");?> <table class="form-table"> <tr> <td>Issue </td> <td><?=form_input('issue', $this->input->post('issue'));?></td> </tr> <tr> <td>Report timing </td> <td> <?php $options = array( 'daily' => 'Every day', 'weekly' => 'Every week', 'monthly' => 'Every month', ); echo form_dropdown('timing', $options, 'weekly'); ?> </td> </tr> <tr> <td>Start Date </td> <td> <?=form_input(array('name' => 'startDate', 'type' => 'date'), $this->input->post('startDate'));?> </td> </tr> <tr> <td>Finish Date </td> <td> <?=form_input(array('name' => 'finishDate', 'type' => 'date'), $this->input->post('finishDate'));?> </td> </tr> <tr> <td>Location based </td> <td>&nbsp&nbsp <?php echo form_radio(array( 'name' => "location", 'class' => "radio", 'checked' => TRUE )); ?> Yes <?php echo form_radio(array( 'name' => "location", 'class' => "radio", 'checked' => FALSE )); ?> No </td> </tr> <tr> <td></td> <td> <div style="float:right"> <?php echo form_submit(array( 'class' => 'btn btn-info', 'id' => 'addToPool', 'name' => 'addToPool', 'value' => 'Add to Pool' )); ?> </div> </td> </tr> </table> <?=form_close();?> ``` controller: ``` public function addToPool() { $this->load->library('form_validation'); $this->form_validation->set_rules('issue', 'Issue', 'required|trim|xss_clean|callback_checkIssueExists'); $this->form_validation->set_rules('timing', 'Report Timing', 'required|trim|xss_clean'); $this->form_validation->set_rules('startDate', 'Start Date', 'required|trim|xss_clean|callback_checkStartDate'); $this->form_validation->set_rules('finishDate', 'Finish Date', 'required|trim|xss_clean|callback_checkFinishDate'); if ($this->form_validation->run()) { $issueContent = preg_replace("/\s+/"," ", $this->input->post('issue') ); $startDate = date("Y-m-d H:i:s", strtotime($this->input->post('startDate'))); $finishDate = date("Y-m-d H:i:s", strtotime($this->input->post('finishDate'))); $issue = new Issue(); $issue->setContent($this->clearTurkishCharacters($issueContent)); $issue->setTrContent($issueContent); $issue->setCreatedDate(date("Y-m-d H:i:s")); $issue->setUpdatedDate(date("Y-m-d H:i:s")); $issue->setStartDate($startDate); $issue->setFinishDate($startDate); $user = new User(); $user->setUsername($this->session->userdata('username')); $user->dbToUser(); $issue->setUser($user); if ($issue->issueToDb()) { $_GET['newIssueFancyBox'] = "close"; $this->home(); } else echo "An error occured while adding user to database!"; } else { $_GET['validationErrors'] = validation_errors('<div class="alert alert-error">','</div>'); $_GET['newIssueFancyBox'] = "open"; $this->home(); } } public function checkStartDate() { $startDate = $this->input->post('startDate'); if (strtotime($startDate) < strtotime('-1 day')) { $this->form_validation->set_message('checkStartDate', 'The %s field cannot take a value before today.'); return FALSE; } else { return TRUE; } } public function checkFinishDate() { $startDate = $this->input->post('startDate'); $finishDate = $this->input->post('finishDate'); if (strtotime($finishDate) < strtotime($startDate) || strtotime($finishDate) < strtotime('-1 day') ) { $this->form_validation->set_message('checkFinishDate', 'The %s field cannot take a value before start date.'); return FALSE; } else { return TRUE; } } public function checkIssueExists() { $this->load->model('modelIssue'); $issueContent = preg_replace("/\s+/"," ", $this->input->post('issue') ); $issue = new Issue(); $issue->setContent($issueContent); $user = new User(); $user->setUsername($this->session->userdata('username')); $user->dbToUser(); $issue->setUser($user); if( $this->modelIssue->checkIssueExists($issue) ) { $this->form_validation->set_message('checkIssueExists', 'You have already the same issue in pool.'); return FALSE; } else return TRUE; } ```
2013/04/18
[ "https://Stackoverflow.com/questions/16092982", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2156268/" ]
You should extend CI\_Form\_validation instead of using callbacks ``` class MY_Form_validation extends CI_Form_validation { public function checkIssueExists ( $modelIssue ) { // $ci =& get_instance(); //uses __get magic function instead //$modelIssue field is automatically passed as param, no need for $_POST if ( something ) { $this->form_validation->set_error ( 'checkIssueExists' , 'Some error' ) ; return false ; } else { return true ; } } /** magic function to get CI super object(object) **/ public function __get ( $object ) { $instance = &get_instance () ; return $instance->$object ; } } ``` - Like some else suggested use the error inline ``` echo form_error('field_name') ``` OR ``` foreach( validation_errors() as $error ): ... endforeach; ``` I would also setup a form\_validation.php config file in ./config ``` $config = array( 'class/method' => array( array('field'=>'', 'label'=>'', 'rules'=>'required|checkIssueExists'), ), ); ``` Your now clean controller method ``` // If the form validation cant find any key for this class/method // in config/form_validation.php // optionally you can pass in a key // ie: if($this->form_validation->run('key')) if( !$this->form_validation->run() ) { return $this->home(); } //validation must have passed ```
I've solved the problem myself, but I've figured out what happens while i'm changing my code according to @Philip's answer. In my old code, I had callback functions, then I changed them as @Philip's answer. But I was still getting no error messages i want to show. I just realized that I can't set error message when i create an User or Issue class object in the same function. In my old code (library/MY\_Form\_validation.php); ``` public function checkIssueExists() { $this->load->model('modelIssue'); $issueContent = preg_replace("/\s+/"," ", $this->input->post('issue') ); $issue = new Issue(); $issue->setContent($issueContent); $user = new User(); $user->setUsername($this->session->userdata('username')); $user->dbToUser(); $issue->setUser($user); if (!$this->modelIssue->checkIssueExists($issue->getContent(), $issue->getUser()->getUsername())) { return TRUE; } else { $this->form_validation->set_message('checkIssueExists', 'You have already the same issue in pool.'); return FALSE; } } ``` You can see the `$issue = new Issue();` and `$user = new User();` lines cause my problem. But I don't understand why It's happening. I have 3 contorller class, * Main (handles requests and basic functions like signIn(), signUp(), home(), dashboard() etc.) * User (basic user functions like getUsername(), setId(), dbToUser(), userToDb() etc.) * Issue (basic issue functions like getIssue(), setUser(), getContent() etc.) I need these functions, so i thought that i can use these classes when i need them. But in callback functions or MY\_Form\_validation.php file, i cannot use them like above. I've changed my code (and other pages dependent on my code) as below and it works now; library/MY\_Form\_validation.php; ``` public function checkIssueExists() { $issueContent = preg_replace("/\s+/"," ", $this->input->post('issue') ); $username = $this->session->userdata('username'); if (!$this->modelIssue->checkIssueExists($issueContent, $username)) { return TRUE; } else { $this->form_validation->set_message('checkIssueExists', 'You have already the same issue in pool.'); return FALSE; } } ``` But i have no idea why i cannot set error messages while i am using my classes in the same function. Thanks for your help.
2,941,251
I've been searching for quite a while now to find a way to limit wordpress tags by date and order them by the amount of times they appeared in the selected timeframe. But I've been rather unsuccesful. What I'm trying to achieve is something like the trending topics on Twitter. But in this case, 'trending tags'. By default the wordpress tagcloud displays the most popular tags of all time. Which makes no sense in my case, since I want to track current trends. Ideally it would be something like: Most popular tags of today * Obama (18 mentions) * New York (15 mentions) * Iron Man (11 mentions) * Robin Hood (7 mentions) And then multiplied for 'most popular this week' and 'most popular this month'. Does anyone know of a way to achieve this?
2010/05/31
[ "https://Stackoverflow.com/questions/2941251", "https://Stackoverflow.com", "https://Stackoverflow.com/users/354279/" ]
Okay, so what I think you probably want is to do this for say, the last 50 posts. Loop over the last `n` posts, extract the `term_id` of each tag for each post, then pass that string into the `include` argument of [`wp_tag_cloud()`](http://codex.wordpress.org/Template_Tags/wp_tag_cloud); ``` $how_many_posts = 50; $args = array( 'posts_per_page' => $how_many_posts, 'orderby' => 'date', 'order' => 'DESC', ); // get the last $how_many_posts, which we will loop over // and gather the tags of query_posts($args); // $temp_ids = array(); while (have_posts()) : the_post(); // get tags for each post $posttags = get_the_tags(); if ($posttags) { foreach($posttags as $tag) { // store each tag id value $temp_ids[] = $tag->term_id; } } endwhile; // we're done with that loop, so we need to reset the query now wp_reset_query(); $id_string = implode(',', array_unique($temp_ids)); // These are the params I use, you'll want to adjust the args // to suit the look you want $args = array( 'smallest' => 10, 'largest' => 30, 'unit' => 'px', 'number' => 150, 'format' => 'flat', 'separator' => "\n", 'orderby' => 'count', 'order' => 'DESC', 'include' => $id_string, // only include stored ids 'link' => 'view', 'echo' => true, ); wp_tag_cloud( $args ); ```
I'm pretty sure that Tags does not have timestamps - perhaps you could do a search for posts with specific tags for a certain timeperiod?
2,941,251
I've been searching for quite a while now to find a way to limit wordpress tags by date and order them by the amount of times they appeared in the selected timeframe. But I've been rather unsuccesful. What I'm trying to achieve is something like the trending topics on Twitter. But in this case, 'trending tags'. By default the wordpress tagcloud displays the most popular tags of all time. Which makes no sense in my case, since I want to track current trends. Ideally it would be something like: Most popular tags of today * Obama (18 mentions) * New York (15 mentions) * Iron Man (11 mentions) * Robin Hood (7 mentions) And then multiplied for 'most popular this week' and 'most popular this month'. Does anyone know of a way to achieve this?
2010/05/31
[ "https://Stackoverflow.com/questions/2941251", "https://Stackoverflow.com", "https://Stackoverflow.com/users/354279/" ]
Okay, so what I think you probably want is to do this for say, the last 50 posts. Loop over the last `n` posts, extract the `term_id` of each tag for each post, then pass that string into the `include` argument of [`wp_tag_cloud()`](http://codex.wordpress.org/Template_Tags/wp_tag_cloud); ``` $how_many_posts = 50; $args = array( 'posts_per_page' => $how_many_posts, 'orderby' => 'date', 'order' => 'DESC', ); // get the last $how_many_posts, which we will loop over // and gather the tags of query_posts($args); // $temp_ids = array(); while (have_posts()) : the_post(); // get tags for each post $posttags = get_the_tags(); if ($posttags) { foreach($posttags as $tag) { // store each tag id value $temp_ids[] = $tag->term_id; } } endwhile; // we're done with that loop, so we need to reset the query now wp_reset_query(); $id_string = implode(',', array_unique($temp_ids)); // These are the params I use, you'll want to adjust the args // to suit the look you want $args = array( 'smallest' => 10, 'largest' => 30, 'unit' => 'px', 'number' => 150, 'format' => 'flat', 'separator' => "\n", 'orderby' => 'count', 'order' => 'DESC', 'include' => $id_string, // only include stored ids 'link' => 'view', 'echo' => true, ); wp_tag_cloud( $args ); ```
I think you can look at some of the plugins and see if your have a plugin like what you need
2,941,251
I've been searching for quite a while now to find a way to limit wordpress tags by date and order them by the amount of times they appeared in the selected timeframe. But I've been rather unsuccesful. What I'm trying to achieve is something like the trending topics on Twitter. But in this case, 'trending tags'. By default the wordpress tagcloud displays the most popular tags of all time. Which makes no sense in my case, since I want to track current trends. Ideally it would be something like: Most popular tags of today * Obama (18 mentions) * New York (15 mentions) * Iron Man (11 mentions) * Robin Hood (7 mentions) And then multiplied for 'most popular this week' and 'most popular this month'. Does anyone know of a way to achieve this?
2010/05/31
[ "https://Stackoverflow.com/questions/2941251", "https://Stackoverflow.com", "https://Stackoverflow.com/users/354279/" ]
Okay, so what I think you probably want is to do this for say, the last 50 posts. Loop over the last `n` posts, extract the `term_id` of each tag for each post, then pass that string into the `include` argument of [`wp_tag_cloud()`](http://codex.wordpress.org/Template_Tags/wp_tag_cloud); ``` $how_many_posts = 50; $args = array( 'posts_per_page' => $how_many_posts, 'orderby' => 'date', 'order' => 'DESC', ); // get the last $how_many_posts, which we will loop over // and gather the tags of query_posts($args); // $temp_ids = array(); while (have_posts()) : the_post(); // get tags for each post $posttags = get_the_tags(); if ($posttags) { foreach($posttags as $tag) { // store each tag id value $temp_ids[] = $tag->term_id; } } endwhile; // we're done with that loop, so we need to reset the query now wp_reset_query(); $id_string = implode(',', array_unique($temp_ids)); // These are the params I use, you'll want to adjust the args // to suit the look you want $args = array( 'smallest' => 10, 'largest' => 30, 'unit' => 'px', 'number' => 150, 'format' => 'flat', 'separator' => "\n", 'orderby' => 'count', 'order' => 'DESC', 'include' => $id_string, // only include stored ids 'link' => 'view', 'echo' => true, ); wp_tag_cloud( $args ); ```
Yo can get the tag list with a query so you don't have to make a loop throw the last X post. ``` <ul id="footer-tags"> <?php $wpdb->show_errors(); ?> <?php global $wpdb; $term_ids = $wpdb->get_col(" SELECT term_id FROM $wpdb->term_taxonomy INNER JOIN $wpdb->term_relationships ON $wpdb->term_taxonomy.term_taxonomy_id=$wpdb->term_relationships.term_taxonomy_id INNER JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->term_relationships.object_id WHERE DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= $wpdb->posts.post_date"); if(count($term_ids) > 0){ $tags = get_tags(array( 'orderby' => 'count', 'order' => 'DESC', 'number' => 28, 'include' => $term_ids, )); foreach ( (array) $tags as $tag ) { echo '<li><a href="' . get_tag_link ($tag->term_id) . '" rel="tag">' . $tag->name . '</a></li>'; } } ?> </ul> ```
36,354,423
I am running docker-container on Amazon EC2. Currently I have added AWS Credentials to Dockerfile. Could you please let me know the best way to do this?
2016/04/01
[ "https://Stackoverflow.com/questions/36354423", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5730257/" ]
The best way is to use IAM Role and do not deal with credentials at all. (see <http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html> ) Credentials could be retrieved from `http://169.254.169.254.....` Since this is a private ip address, it could be accessible only from EC2 instances. All modern AWS client libraries "know" how to fetch, refresh and use credentials from there. So in most cases you don't even need to know about it. Just run ec2 with correct IAM role and you good to go. As an option you can pass them at the runtime as environment variables ( i.e `docker run -e AWS_ACCESS_KEY_ID=xyz -e AWS_SECRET_ACCESS_KEY=aaa myimage`) You can access these environment variables by running printenv at the terminal.
Volume mounting is noted in this thread but as of `docker-compose v3.2 +` you can Bind Mount. For example, if you have a file named `.aws_creds` in the root of your project: In your service for the compose file do this for volumes: ``` volumes: # normal volume mount, already shown in thread - ./.aws_creds:/root/.aws/credentials # way 2, note this requires docker-compose v 3.2+ - type: bind source: .aws_creds # from local target: /root/.aws/credentials # to the container location ``` Using this idea, you can publicly store your docker images on docker-hub because your `aws credentials` will not physically be in the image...to have them associated, you must have the correct directory structure locally where the container is started (i.e. pulling from Git)
36,354,423
I am running docker-container on Amazon EC2. Currently I have added AWS Credentials to Dockerfile. Could you please let me know the best way to do this?
2016/04/01
[ "https://Stackoverflow.com/questions/36354423", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5730257/" ]
Another approach is to pass the keys from the host machine to the docker container. You may add the following lines to the `docker-compose` file. ```yaml services: web: build: . environment: - AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} - AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY} - AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION} ```
Volume mounting is noted in this thread but as of `docker-compose v3.2 +` you can Bind Mount. For example, if you have a file named `.aws_creds` in the root of your project: In your service for the compose file do this for volumes: ``` volumes: # normal volume mount, already shown in thread - ./.aws_creds:/root/.aws/credentials # way 2, note this requires docker-compose v 3.2+ - type: bind source: .aws_creds # from local target: /root/.aws/credentials # to the container location ``` Using this idea, you can publicly store your docker images on docker-hub because your `aws credentials` will not physically be in the image...to have them associated, you must have the correct directory structure locally where the container is started (i.e. pulling from Git)
36,354,423
I am running docker-container on Amazon EC2. Currently I have added AWS Credentials to Dockerfile. Could you please let me know the best way to do this?
2016/04/01
[ "https://Stackoverflow.com/questions/36354423", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5730257/" ]
The best way is to use IAM Role and do not deal with credentials at all. (see <http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html> ) Credentials could be retrieved from `http://169.254.169.254.....` Since this is a private ip address, it could be accessible only from EC2 instances. All modern AWS client libraries "know" how to fetch, refresh and use credentials from there. So in most cases you don't even need to know about it. Just run ec2 with correct IAM role and you good to go. As an option you can pass them at the runtime as environment variables ( i.e `docker run -e AWS_ACCESS_KEY_ID=xyz -e AWS_SECRET_ACCESS_KEY=aaa myimage`) You can access these environment variables by running printenv at the terminal.
If someone still face the same issue after following the instructions mentioned in accepted answer then make sure that you are not passing environment variables from two different sources. In my case I was passing environment variables to `docker run` via a file and as parameters which was causing the variables passed as parameters show no effect. So the following command did not work for me: ``` docker run --env-file ./env.list -e AWS_ACCESS_KEY_ID=ABCD -e AWS_SECRET_ACCESS_KEY=PQRST IMAGE_NAME:v1.0.1 ``` Moving the aws credentials into the mentioned `env.list` file helped.
36,354,423
I am running docker-container on Amazon EC2. Currently I have added AWS Credentials to Dockerfile. Could you please let me know the best way to do this?
2016/04/01
[ "https://Stackoverflow.com/questions/36354423", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5730257/" ]
A lot has changed in Docker since this question was asked, so here's an attempt at an updated answer. First, specifically with AWS credentials on containers already running inside of the cloud, using IAM roles as [Vor suggests](https://stackoverflow.com/a/36357388/596285) is a really good option. If you can do that, then add one more plus one to his answer and skip the rest of this. --- Once you start running things outside of the cloud, or have a different type of secret, there are two key places that I **recommend against** storing secrets: 1. Environment variables: when these are defined on a container, every process inside the container has access to them, they are visible via /proc, apps may dump their environment to stdout where it gets stored in the logs, and most importantly, they appear in clear text when you inspect the container. 2. In the image itself: images often get pushed to registries where many users have pull access, sometimes without any credentials required to pull the image. Even if you delete the secret from one layer, the image can be disassembled with common Linux utilities like `tar` and the secret can be found from the step where it was first added to the image. --- So what other options are there for secrets in Docker containers? **Option A:** If you need this secret only during the build of your image, cannot use the secret before the build starts, and do not have access to BuildKit yet, then a [multi-stage build](https://docs.docker.com/develop/develop-images/multistage-build/) is a best of the bad options. You would add the secret to the initial stages of the build, use it there, and then copy the output of that stage without the secret to your release stage, and only push that release stage to the registry servers. This secret is still in the image cache on the build server, so I tend to use this only as a last resort. **Option B:** Also during build time, if you can use BuildKit which was released in 18.09, there are currently [experimental features](https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/experimental.md) to allow the injection of secrets as a volume mount for a single RUN line. That mount does not get written to the image layers, so you can access the secret during build without worrying it will be pushed to a public registry server. The resulting Dockerfile looks like: ``` # syntax = docker/dockerfile:experimental FROM python:3 RUN pip install awscli RUN --mount=type=secret,id=aws,target=/root/.aws/credentials aws s3 cp s3://... ... ``` And you build it with a command in 18.09 or newer like: ```bash DOCKER_BUILDKIT=1 docker build -t your_image --secret id=aws,src=$HOME/.aws/credentials . ``` **Option C:** At runtime on a single node, without Swarm Mode or other orchestration, you can mount the credentials as a read only volume. Access to this credential requires the same access that you would have outside of docker to the same credentials file, so it's no better or worse than the scenario without docker. Most importantly, the contents of this file should not be visible when you inspect the container, view the logs, or push the image to a registry server, since the volume is outside of that in every scenario. This does require that you copy your credentials on the docker host, separate from the deploy of the container. (Note, anyone with the ability to run containers on that host can view your credential since access to the docker API is root on the host and root can view the files of any user. If you don't trust users with root on the host, then don't give them docker API access.) For a `docker run`, this looks like: ```bash docker run -v $HOME/.aws/credentials:/home/app/.aws/credentials:ro your_image ``` Or for a compose file, you'd have: ```yaml version: '3' services: app: image: your_image volumes: - $HOME/.aws/credentials:/home/app/.aws/credentials:ro ``` **Option D:** With orchestration tools like Swarm Mode and Kubernetes, we now have secrets support that's better than a volume. With Swarm Mode, the file is encrypted on the manager filesystem (though the decryption key is often there too, allowing the manager to be restarted without an admin entering a decrypt key). More importantly, the secret is only sent to the workers that need the secret (running a container with that secret), it is only stored in memory on the worker, never disk, and it is injected as a file into the container with a tmpfs mount. Users on the host outside of swarm cannot mount that secret directly into their own container, however, with open access to the docker API, they could extract the secret from a running container on the node, so again, limit who has this access to the API. From compose, this secret injection looks like: ```yaml version: '3.7' secrets: aws_creds: external: true services: app: image: your_image secrets: - source: aws_creds target: /home/user/.aws/credentials uid: '1000' gid: '1000' mode: 0700 ``` You turn on swarm mode with `docker swarm init` for a single node, then follow the directions for adding additional nodes. You can create the secret externally with `docker secret create aws_creds $HOME/.aws/credentials`. And you deploy the compose file with `docker stack deploy -c docker-compose.yml stack_name`. I often version my secrets using a script from: <https://github.com/sudo-bmitch/docker-config-update> **Option E:** Other tools exist to manage secrets, and my favorite is [Vault](https://www.vaultproject.io/) because it gives the ability to create time limited secrets that automatically expire. Every application then gets its own set of tokens to request secrets, and those tokens give them the ability to request those time limited secrets for as long as they can reach the vault server. That reduces the risk if a secret is ever taken out of your network since it will either not work or be quick to expire. The functionality specific to AWS for Vault is documented at <https://www.vaultproject.io/docs/secrets/aws/index.html>
Volume mounting is noted in this thread but as of `docker-compose v3.2 +` you can Bind Mount. For example, if you have a file named `.aws_creds` in the root of your project: In your service for the compose file do this for volumes: ``` volumes: # normal volume mount, already shown in thread - ./.aws_creds:/root/.aws/credentials # way 2, note this requires docker-compose v 3.2+ - type: bind source: .aws_creds # from local target: /root/.aws/credentials # to the container location ``` Using this idea, you can publicly store your docker images on docker-hub because your `aws credentials` will not physically be in the image...to have them associated, you must have the correct directory structure locally where the container is started (i.e. pulling from Git)
36,354,423
I am running docker-container on Amazon EC2. Currently I have added AWS Credentials to Dockerfile. Could you please let me know the best way to do this?
2016/04/01
[ "https://Stackoverflow.com/questions/36354423", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5730257/" ]
A lot has changed in Docker since this question was asked, so here's an attempt at an updated answer. First, specifically with AWS credentials on containers already running inside of the cloud, using IAM roles as [Vor suggests](https://stackoverflow.com/a/36357388/596285) is a really good option. If you can do that, then add one more plus one to his answer and skip the rest of this. --- Once you start running things outside of the cloud, or have a different type of secret, there are two key places that I **recommend against** storing secrets: 1. Environment variables: when these are defined on a container, every process inside the container has access to them, they are visible via /proc, apps may dump their environment to stdout where it gets stored in the logs, and most importantly, they appear in clear text when you inspect the container. 2. In the image itself: images often get pushed to registries where many users have pull access, sometimes without any credentials required to pull the image. Even if you delete the secret from one layer, the image can be disassembled with common Linux utilities like `tar` and the secret can be found from the step where it was first added to the image. --- So what other options are there for secrets in Docker containers? **Option A:** If you need this secret only during the build of your image, cannot use the secret before the build starts, and do not have access to BuildKit yet, then a [multi-stage build](https://docs.docker.com/develop/develop-images/multistage-build/) is a best of the bad options. You would add the secret to the initial stages of the build, use it there, and then copy the output of that stage without the secret to your release stage, and only push that release stage to the registry servers. This secret is still in the image cache on the build server, so I tend to use this only as a last resort. **Option B:** Also during build time, if you can use BuildKit which was released in 18.09, there are currently [experimental features](https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/experimental.md) to allow the injection of secrets as a volume mount for a single RUN line. That mount does not get written to the image layers, so you can access the secret during build without worrying it will be pushed to a public registry server. The resulting Dockerfile looks like: ``` # syntax = docker/dockerfile:experimental FROM python:3 RUN pip install awscli RUN --mount=type=secret,id=aws,target=/root/.aws/credentials aws s3 cp s3://... ... ``` And you build it with a command in 18.09 or newer like: ```bash DOCKER_BUILDKIT=1 docker build -t your_image --secret id=aws,src=$HOME/.aws/credentials . ``` **Option C:** At runtime on a single node, without Swarm Mode or other orchestration, you can mount the credentials as a read only volume. Access to this credential requires the same access that you would have outside of docker to the same credentials file, so it's no better or worse than the scenario without docker. Most importantly, the contents of this file should not be visible when you inspect the container, view the logs, or push the image to a registry server, since the volume is outside of that in every scenario. This does require that you copy your credentials on the docker host, separate from the deploy of the container. (Note, anyone with the ability to run containers on that host can view your credential since access to the docker API is root on the host and root can view the files of any user. If you don't trust users with root on the host, then don't give them docker API access.) For a `docker run`, this looks like: ```bash docker run -v $HOME/.aws/credentials:/home/app/.aws/credentials:ro your_image ``` Or for a compose file, you'd have: ```yaml version: '3' services: app: image: your_image volumes: - $HOME/.aws/credentials:/home/app/.aws/credentials:ro ``` **Option D:** With orchestration tools like Swarm Mode and Kubernetes, we now have secrets support that's better than a volume. With Swarm Mode, the file is encrypted on the manager filesystem (though the decryption key is often there too, allowing the manager to be restarted without an admin entering a decrypt key). More importantly, the secret is only sent to the workers that need the secret (running a container with that secret), it is only stored in memory on the worker, never disk, and it is injected as a file into the container with a tmpfs mount. Users on the host outside of swarm cannot mount that secret directly into their own container, however, with open access to the docker API, they could extract the secret from a running container on the node, so again, limit who has this access to the API. From compose, this secret injection looks like: ```yaml version: '3.7' secrets: aws_creds: external: true services: app: image: your_image secrets: - source: aws_creds target: /home/user/.aws/credentials uid: '1000' gid: '1000' mode: 0700 ``` You turn on swarm mode with `docker swarm init` for a single node, then follow the directions for adding additional nodes. You can create the secret externally with `docker secret create aws_creds $HOME/.aws/credentials`. And you deploy the compose file with `docker stack deploy -c docker-compose.yml stack_name`. I often version my secrets using a script from: <https://github.com/sudo-bmitch/docker-config-update> **Option E:** Other tools exist to manage secrets, and my favorite is [Vault](https://www.vaultproject.io/) because it gives the ability to create time limited secrets that automatically expire. Every application then gets its own set of tokens to request secrets, and those tokens give them the ability to request those time limited secrets for as long as they can reach the vault server. That reduces the risk if a secret is ever taken out of your network since it will either not work or be quick to expire. The functionality specific to AWS for Vault is documented at <https://www.vaultproject.io/docs/secrets/aws/index.html>
If someone still face the same issue after following the instructions mentioned in accepted answer then make sure that you are not passing environment variables from two different sources. In my case I was passing environment variables to `docker run` via a file and as parameters which was causing the variables passed as parameters show no effect. So the following command did not work for me: ``` docker run --env-file ./env.list -e AWS_ACCESS_KEY_ID=ABCD -e AWS_SECRET_ACCESS_KEY=PQRST IMAGE_NAME:v1.0.1 ``` Moving the aws credentials into the mentioned `env.list` file helped.
36,354,423
I am running docker-container on Amazon EC2. Currently I have added AWS Credentials to Dockerfile. Could you please let me know the best way to do this?
2016/04/01
[ "https://Stackoverflow.com/questions/36354423", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5730257/" ]
Another approach is to pass the keys from the host machine to the docker container. You may add the following lines to the `docker-compose` file. ```yaml services: web: build: . environment: - AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} - AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY} - AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION} ```
If someone still face the same issue after following the instructions mentioned in accepted answer then make sure that you are not passing environment variables from two different sources. In my case I was passing environment variables to `docker run` via a file and as parameters which was causing the variables passed as parameters show no effect. So the following command did not work for me: ``` docker run --env-file ./env.list -e AWS_ACCESS_KEY_ID=ABCD -e AWS_SECRET_ACCESS_KEY=PQRST IMAGE_NAME:v1.0.1 ``` Moving the aws credentials into the mentioned `env.list` file helped.
36,354,423
I am running docker-container on Amazon EC2. Currently I have added AWS Credentials to Dockerfile. Could you please let me know the best way to do this?
2016/04/01
[ "https://Stackoverflow.com/questions/36354423", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5730257/" ]
The best way is to use IAM Role and do not deal with credentials at all. (see <http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html> ) Credentials could be retrieved from `http://169.254.169.254.....` Since this is a private ip address, it could be accessible only from EC2 instances. All modern AWS client libraries "know" how to fetch, refresh and use credentials from there. So in most cases you don't even need to know about it. Just run ec2 with correct IAM role and you good to go. As an option you can pass them at the runtime as environment variables ( i.e `docker run -e AWS_ACCESS_KEY_ID=xyz -e AWS_SECRET_ACCESS_KEY=aaa myimage`) You can access these environment variables by running printenv at the terminal.
The following one-liner works for me even when my credentials are set up by [aws-okta](https://github.com/segmentio/aws-okta) or [saml2aws](https://github.com/Versent/saml2aws): ``` $ docker run -v$HOME/.aws:/root/.aws:ro \ -e AWS_ACCESS_KEY_ID \ -e AWS_CA_BUNDLE \ -e AWS_CLI_FILE_ENCODING \ -e AWS_CONFIG_FILE \ -e AWS_DEFAULT_OUTPUT \ -e AWS_DEFAULT_REGION \ -e AWS_PAGER \ -e AWS_PROFILE \ -e AWS_ROLE_SESSION_NAME \ -e AWS_SECRET_ACCESS_KEY \ -e AWS_SESSION_TOKEN \ -e AWS_SHARED_CREDENTIALS_FILE \ -e AWS_STS_REGIONAL_ENDPOINTS \ amazon/aws-cli s3 ls ``` Please note that for advanced use cases you might need to allow `rw` (read-write) permissions, so omit the `ro` (read-only) limitation when mounting the `.aws` volume in `-v$HOME/.aws:/root/.aws:ro`
36,354,423
I am running docker-container on Amazon EC2. Currently I have added AWS Credentials to Dockerfile. Could you please let me know the best way to do this?
2016/04/01
[ "https://Stackoverflow.com/questions/36354423", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5730257/" ]
The best way is to use IAM Role and do not deal with credentials at all. (see <http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html> ) Credentials could be retrieved from `http://169.254.169.254.....` Since this is a private ip address, it could be accessible only from EC2 instances. All modern AWS client libraries "know" how to fetch, refresh and use credentials from there. So in most cases you don't even need to know about it. Just run ec2 with correct IAM role and you good to go. As an option you can pass them at the runtime as environment variables ( i.e `docker run -e AWS_ACCESS_KEY_ID=xyz -e AWS_SECRET_ACCESS_KEY=aaa myimage`) You can access these environment variables by running printenv at the terminal.
Yet another approach is to create temporary read-only volume in docker-compose.yaml. AWS CLI and SDK (like boto3 or AWS SDK for Java etc.) are looking for `default` profile in `~/.aws/credentials` file. If you want to use other profiles, you just need also to export AWS\_PROFILE variable before running `docker-compose` command. `export AWS_PROFILE=some_other_profile_name` ```yaml version: '3' services: service-name: image: docker-image-name:latest environment: - AWS_PROFILE=${AWS_PROFILE} volumes: - ~/.aws/:/root/.aws:ro ``` In this example, I used root user on docker. If you are using other user, just change `/root/.aws` to user home directory. `:ro` - stands for read-only docker volume It is very helpful when you have multiple profiles in `~/.aws/credentials` file and you are also using MFA. Also helpful when you want to locally test docker-container before deploying it on ECS on which you have IAM Roles, but locally you don't.
36,354,423
I am running docker-container on Amazon EC2. Currently I have added AWS Credentials to Dockerfile. Could you please let me know the best way to do this?
2016/04/01
[ "https://Stackoverflow.com/questions/36354423", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5730257/" ]
Yet another approach is to create temporary read-only volume in docker-compose.yaml. AWS CLI and SDK (like boto3 or AWS SDK for Java etc.) are looking for `default` profile in `~/.aws/credentials` file. If you want to use other profiles, you just need also to export AWS\_PROFILE variable before running `docker-compose` command. `export AWS_PROFILE=some_other_profile_name` ```yaml version: '3' services: service-name: image: docker-image-name:latest environment: - AWS_PROFILE=${AWS_PROFILE} volumes: - ~/.aws/:/root/.aws:ro ``` In this example, I used root user on docker. If you are using other user, just change `/root/.aws` to user home directory. `:ro` - stands for read-only docker volume It is very helpful when you have multiple profiles in `~/.aws/credentials` file and you are also using MFA. Also helpful when you want to locally test docker-container before deploying it on ECS on which you have IAM Roles, but locally you don't.
You could create `~/aws_env_creds` containing: ```bash touch ~/aws_env_creds chmod 777 ~/aws_env_creds vi ~/aws_env_creds ``` Add these value (replace the key of yours): ``` AWS_ACCESS_KEY_ID=AK_FAKE_KEY_88RD3PNY AWS_SECRET_ACCESS_KEY=BividQsWW_FAKE_KEY_MuB5VAAsQNJtSxQQyDY2C ``` Press "esc" to save the file. Run and test the container: ```yaml my_service: build: . image: my_image env_file: - ~/aws_env_creds ```
36,354,423
I am running docker-container on Amazon EC2. Currently I have added AWS Credentials to Dockerfile. Could you please let me know the best way to do this?
2016/04/01
[ "https://Stackoverflow.com/questions/36354423", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5730257/" ]
Another approach is to pass the keys from the host machine to the docker container. You may add the following lines to the `docker-compose` file. ```yaml services: web: build: . environment: - AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} - AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY} - AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION} ```
The following one-liner works for me even when my credentials are set up by [aws-okta](https://github.com/segmentio/aws-okta) or [saml2aws](https://github.com/Versent/saml2aws): ``` $ docker run -v$HOME/.aws:/root/.aws:ro \ -e AWS_ACCESS_KEY_ID \ -e AWS_CA_BUNDLE \ -e AWS_CLI_FILE_ENCODING \ -e AWS_CONFIG_FILE \ -e AWS_DEFAULT_OUTPUT \ -e AWS_DEFAULT_REGION \ -e AWS_PAGER \ -e AWS_PROFILE \ -e AWS_ROLE_SESSION_NAME \ -e AWS_SECRET_ACCESS_KEY \ -e AWS_SESSION_TOKEN \ -e AWS_SHARED_CREDENTIALS_FILE \ -e AWS_STS_REGIONAL_ENDPOINTS \ amazon/aws-cli s3 ls ``` Please note that for advanced use cases you might need to allow `rw` (read-write) permissions, so omit the `ro` (read-only) limitation when mounting the `.aws` volume in `-v$HOME/.aws:/root/.aws:ro`
10,868,380
I have a list of buffer in vim, how can I turn all of them into tab page like ones in, say Notepad++? I know I can use `:tabe` or something to open new file in tab view, but what if I have opened several buffers in single vim and I want to turn all of them into tab pages?
2012/06/03
[ "https://Stackoverflow.com/questions/10868380", "https://Stackoverflow.com", "https://Stackoverflow.com/users/587547/" ]
You can type this command: ``` :tab ball ``` It will display all buffers in tabs.
If I understood, you have several buffers in splits and wish every one of them in a separate tab. `<Ctrl-w>T` will open a buffer in a new *tab page* removing it from the split. But *tab pages* are really not what they are in Notepad++ - separate files. In Vim they're more of a placeholders for splits, so my guess is you'll have a hard time working with them if you mean to just copy your Notepad++'s way of work to Vim.
10,868,380
I have a list of buffer in vim, how can I turn all of them into tab page like ones in, say Notepad++? I know I can use `:tabe` or something to open new file in tab view, but what if I have opened several buffers in single vim and I want to turn all of them into tab pages?
2012/06/03
[ "https://Stackoverflow.com/questions/10868380", "https://Stackoverflow.com", "https://Stackoverflow.com/users/587547/" ]
If I understood, you have several buffers in splits and wish every one of them in a separate tab. `<Ctrl-w>T` will open a buffer in a new *tab page* removing it from the split. But *tab pages* are really not what they are in Notepad++ - separate files. In Vim they're more of a placeholders for splits, so my guess is you'll have a hard time working with them if you mean to just copy your Notepad++'s way of work to Vim.
I don't know your motivations of to turn `all` buffers into tab pages. Usually, we have many buffers when doing one job, but for tabs, I think it don't have enough spaces to display the tabbars, especially in laptop. Imaging if there were 20 tabs on the top... So if you want to turn the current buffer into tab page, you can use `:tab split`. I think it is what you exactly need. You can see [why-do-vim-experts-prefer-buffers-over-tabs](https://stackoverflow.com/questions/26708822/why-do-vim-experts-prefer-buffers-over-tabs) for more help.
10,868,380
I have a list of buffer in vim, how can I turn all of them into tab page like ones in, say Notepad++? I know I can use `:tabe` or something to open new file in tab view, but what if I have opened several buffers in single vim and I want to turn all of them into tab pages?
2012/06/03
[ "https://Stackoverflow.com/questions/10868380", "https://Stackoverflow.com", "https://Stackoverflow.com/users/587547/" ]
You can type this command: ``` :tab ball ``` It will display all buffers in tabs.
I don't know your motivations of to turn `all` buffers into tab pages. Usually, we have many buffers when doing one job, but for tabs, I think it don't have enough spaces to display the tabbars, especially in laptop. Imaging if there were 20 tabs on the top... So if you want to turn the current buffer into tab page, you can use `:tab split`. I think it is what you exactly need. You can see [why-do-vim-experts-prefer-buffers-over-tabs](https://stackoverflow.com/questions/26708822/why-do-vim-experts-prefer-buffers-over-tabs) for more help.
15,211,538
Tracks for "The Hives" claims to be streamable, but are returning 404s. Here's the JSON response for Civilization's Dying id 3644317 (<http://api.soundcloud.com/tracks/3644317.json?client_id=>): ``` { "kind": "track", "id": 3644317, … "sharing": "public", "streamable": true, "embeddable_by": "all", "downloadable": false, "title": "Civilization's Dying", … "stream_url": "http://api.soundcloud.com/tracks/3644317/stream" } ``` the streamable is true and it gives a stream\_url, when trying to access it with my client\_id (like I've done with other tracks) it returns 404. Edit: Sharing is public. Added the info back to the payload and a link to the api page with the full response for reference.
2013/03/04
[ "https://Stackoverflow.com/questions/15211538", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2133450/" ]
There's currently a bug affecting some artists whose tracks are not actually streamable any more, but the API response not showing that fact. This should be fixed very shortly.
Make sure this song has "sharing" set to "public" in the returned track get request. If not, you will need to authenticate with Soundcloud. <http://developers.soundcloud.com/docs#authentication>
15,211,538
Tracks for "The Hives" claims to be streamable, but are returning 404s. Here's the JSON response for Civilization's Dying id 3644317 (<http://api.soundcloud.com/tracks/3644317.json?client_id=>): ``` { "kind": "track", "id": 3644317, … "sharing": "public", "streamable": true, "embeddable_by": "all", "downloadable": false, "title": "Civilization's Dying", … "stream_url": "http://api.soundcloud.com/tracks/3644317/stream" } ``` the streamable is true and it gives a stream\_url, when trying to access it with my client\_id (like I've done with other tracks) it returns 404. Edit: Sharing is public. Added the info back to the payload and a link to the api page with the full response for reference.
2013/03/04
[ "https://Stackoverflow.com/questions/15211538", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2133450/" ]
Make sure this song has "sharing" set to "public" in the returned track get request. If not, you will need to authenticate with Soundcloud. <http://developers.soundcloud.com/docs#authentication>
I encountered this issue as well when I tried to stream Lorde's (Royals) tracks. (Soundcloud userid: 27622444) After examining the track properties returned from the API I noticed that the `streamable` property had been set to `false` **API return data:** ``` (...) sharing: "public" state: "finished" streamable: false tag_list: "" title: "Swingin' Party" (...) ``` Hope that helps! Cheers, T
15,211,538
Tracks for "The Hives" claims to be streamable, but are returning 404s. Here's the JSON response for Civilization's Dying id 3644317 (<http://api.soundcloud.com/tracks/3644317.json?client_id=>): ``` { "kind": "track", "id": 3644317, … "sharing": "public", "streamable": true, "embeddable_by": "all", "downloadable": false, "title": "Civilization's Dying", … "stream_url": "http://api.soundcloud.com/tracks/3644317/stream" } ``` the streamable is true and it gives a stream\_url, when trying to access it with my client\_id (like I've done with other tracks) it returns 404. Edit: Sharing is public. Added the info back to the payload and a link to the api page with the full response for reference.
2013/03/04
[ "https://Stackoverflow.com/questions/15211538", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2133450/" ]
There's currently a bug affecting some artists whose tracks are not actually streamable any more, but the API response not showing that fact. This should be fixed very shortly.
I encountered this issue as well when I tried to stream Lorde's (Royals) tracks. (Soundcloud userid: 27622444) After examining the track properties returned from the API I noticed that the `streamable` property had been set to `false` **API return data:** ``` (...) sharing: "public" state: "finished" streamable: false tag_list: "" title: "Swingin' Party" (...) ``` Hope that helps! Cheers, T
481,576
I have been staring at this for an hour. How would you reduce such a matrix? \begin{bmatrix} p & 0 & a \\ b & 0 & 0 \\ q & c & r \end{bmatrix} $abc\neq0$
2013/09/01
[ "https://math.stackexchange.com/questions/481576", "https://math.stackexchange.com", "https://math.stackexchange.com/users/90855/" ]
Because $a,b,c \ne 0$ then $$ \left( {\begin{array}{\*{20}{c}} p & 0 & a \\ b & 0 & 0 \\ q & c & r \\ \end{array}} \right) \to \left( {\begin{array}{\*{20}{c}} b & 0 & 0 \\ q & c & r \\ p & 0 & a \\ \end{array}} \right)\mathop \to \limits\_{ - \frac{p}{b}{\rho \_1} + {\rho \_3}}^{ - \frac{q}{b}{\rho \_1} + {\rho \_2}} \left( {\begin{array}{\*{20}{c}} b & 0 & 0 \\ 0 & c & r \\ 0 & 0 & a \\ \end{array}} \right)\mathop \to \limits^{ - \frac{r}{a}{\rho \_3} + {\rho \_2}} \left( {\begin{array}{\*{20}{c}} b & 0 & 0 \\ 0 & c & 0 \\ 0 & 0 & a \\ \end{array}} \right)\mathop \to \limits^{\frac{1}{b}{\rho \_1},\frac{1}{c}{\rho \_2},\frac{1}{a}{\rho \_3}} \left( {\begin{array}{\*{20}{c}} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \\ \end{array}} \right). $$
If $abc\neq 0$, then $a,b,c\neq 0$. Divide the three rows by $a,b,c$ respectively and continue with other elementary row operations.
481,576
I have been staring at this for an hour. How would you reduce such a matrix? \begin{bmatrix} p & 0 & a \\ b & 0 & 0 \\ q & c & r \end{bmatrix} $abc\neq0$
2013/09/01
[ "https://math.stackexchange.com/questions/481576", "https://math.stackexchange.com", "https://math.stackexchange.com/users/90855/" ]
Because $a,b,c \ne 0$ then $$ \left( {\begin{array}{\*{20}{c}} p & 0 & a \\ b & 0 & 0 \\ q & c & r \\ \end{array}} \right) \to \left( {\begin{array}{\*{20}{c}} b & 0 & 0 \\ q & c & r \\ p & 0 & a \\ \end{array}} \right)\mathop \to \limits\_{ - \frac{p}{b}{\rho \_1} + {\rho \_3}}^{ - \frac{q}{b}{\rho \_1} + {\rho \_2}} \left( {\begin{array}{\*{20}{c}} b & 0 & 0 \\ 0 & c & r \\ 0 & 0 & a \\ \end{array}} \right)\mathop \to \limits^{ - \frac{r}{a}{\rho \_3} + {\rho \_2}} \left( {\begin{array}{\*{20}{c}} b & 0 & 0 \\ 0 & c & 0 \\ 0 & 0 & a \\ \end{array}} \right)\mathop \to \limits^{\frac{1}{b}{\rho \_1},\frac{1}{c}{\rho \_2},\frac{1}{a}{\rho \_3}} \left( {\begin{array}{\*{20}{c}} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \\ \end{array}} \right). $$
First you want a non-zero entry in the $(1, 1)$ position. There is only one element of the first column which you know is non-zero, so do a row swap to make sure that it is in the $(1, 1)$ position. Once in place, use this non-zero entry to eliminate the other entries in the first column using row operations of the form $R\_i \mapsto R\_i + kR\_1$. Then you can divide the first row by a constant to ensure that the $(1, 1)$ entry is a $1$. In the second column you want a non-zero entry in the $(2, 2)$ position if possible. As there is only one non-zero entry, do the appropriate row swap to put it in the $(2, 2)$ position. Again, you can divide the second row by a constant to ensure that the $(2, 2)$ entry is a $1$. In the third column you want a non-zero entry in the $(3, 3)$ position if possible. If done correctly, you should have the appropraite entry already in place. A row operation of the form $R\_i \mapsto R\_i + kR\_3$ should eliminate the other entry in the third column. Finally, dividing the third column by a constant should leave you with a familiar matrix.
481,576
I have been staring at this for an hour. How would you reduce such a matrix? \begin{bmatrix} p & 0 & a \\ b & 0 & 0 \\ q & c & r \end{bmatrix} $abc\neq0$
2013/09/01
[ "https://math.stackexchange.com/questions/481576", "https://math.stackexchange.com", "https://math.stackexchange.com/users/90855/" ]
Because $a,b,c \ne 0$ then $$ \left( {\begin{array}{\*{20}{c}} p & 0 & a \\ b & 0 & 0 \\ q & c & r \\ \end{array}} \right) \to \left( {\begin{array}{\*{20}{c}} b & 0 & 0 \\ q & c & r \\ p & 0 & a \\ \end{array}} \right)\mathop \to \limits\_{ - \frac{p}{b}{\rho \_1} + {\rho \_3}}^{ - \frac{q}{b}{\rho \_1} + {\rho \_2}} \left( {\begin{array}{\*{20}{c}} b & 0 & 0 \\ 0 & c & r \\ 0 & 0 & a \\ \end{array}} \right)\mathop \to \limits^{ - \frac{r}{a}{\rho \_3} + {\rho \_2}} \left( {\begin{array}{\*{20}{c}} b & 0 & 0 \\ 0 & c & 0 \\ 0 & 0 & a \\ \end{array}} \right)\mathop \to \limits^{\frac{1}{b}{\rho \_1},\frac{1}{c}{\rho \_2},\frac{1}{a}{\rho \_3}} \left( {\begin{array}{\*{20}{c}} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \\ \end{array}} \right). $$
Perhaps this is "cheating", but $$\det \begin{bmatrix} p & 0 & a \\ b & 0 & 0 \\ q & c & r \end{bmatrix} =abc \neq 0.$$ Since the determinant is non-zero, its reduced row echelon form is the identity matrix.
23,448,128
I am using the base64\_encode for sending the numeric id to url, `base64_encode($list_post['id']);` up to 99 its working fine, but after 99 its produce wrong encoded string. the last character in encoded string is = (equal sign), but when the number more than 99, for example 100 it don't show = (equal sign) at the end.
2014/05/03
[ "https://Stackoverflow.com/questions/23448128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1716293/" ]
Take a look at how padding in base64 works: <http://en.wikipedia.org/wiki/Base64#Padding> The padding (the "=" character) is not always needed and in some implementations is not even mandatory. **EDIT:** ok from your comments I see that you are using the base64 encoded string in a URL like this: ``` http://example.com/path/OTC= ``` The base64 encoding includes chars that have a special meaning in URLs so you need to use a slightly modified function (<https://stackoverflow.com/a/5835352/2737514>): ``` function base64_url_encode($input) { return strtr(base64_encode($input), '+/=', '-_,'); } function base64_url_decode($input) { return base64_decode(strtr($input, '-_,', '+/=')); } ``` However, since your code works for some numbers, maybe there is a problem with the .htaccess not parsing the url correctly, or the PHP code that interpretes the URL. I can't help more than this without seeing some other code.
it seems working fine for me Can you please test with following code ``` echo base64_encode(101); echo base64_decode(base64_encode(101)); ``` **[DEMO](http://codepad.org/RYvM7IU6)** > > Base64-encoded data takes about 33% more space than the original data. > > > So these numbers shouldnt be a problem
3,534,453
Can someone help me construct the SQL that I need to query the Projects\_dim table using the Linked Server "idwd"? To test the connection, I ran a sample query using the linked server name. To access the tables on the linked server, I used a four-part naming syntax: linked\_server\_name.catalog\_ name.schema\_name.table\_name. replacing the values, you get: ``` idwd.idwd.wimr.PROJECTS_DIM ``` of should it be the following? ``` idwd..wimr.PROJECTS_DIM ``` The database name is "idw" but the grid below shows a blank value under "catalog", which is one source of my confusion, though I believe that the more likely approach is to construct the syntax assuming that the catalog part of the qualified table name should be blank as in the following first example. ``` select * from idwd..wimr.PROJECTS_DIM Server: Msg 7314, Level 16, State 1, Line 1 OLE DB provider 'idwd' does not contain table '"wimr"."PROJECTS_DIM"'. The table either does not exist or the current user does not have permissions on that table. select * from idwd.idwd.wimr.PROJECTS_DIM Server: Msg 7312, Level 16, State 1, Line 1 Invalid use of schema and/or catalog for OLE DB provider 'MSDAORA'. A four-part name was supplied, but the provider does not expose the necessary interfaces to use a catalog and/or schema. ``` Can someone suggest what I need to do to query this table? I am using the MS OLEDB Driver for Oracle. I thought perhaps there is an issue with case-sensitivity, so I tried this: ``` select * from IDWD..WIMR.PROJECTS_DIM Server: Msg 7356, Level 16, State 1, Line 1 OLE DB provider 'MSDAORA' supplied inconsistent metadata for a column. Metadata information was changed at execution time. ``` and this: ``` select * from IDWD.IDWD.WIMR.PROJECTS_DIM Server: Msg 7312, Level 16, State 1, Line 1 Invalid use of schema and/or catalog for OLE DB provider 'MSDAORA'. A four-part name was supplied, but the provider does not expose the necessary interfaces to use a catalog and/or schema. ``` I tried to create a linked server using each of the two likely drivers: 1. Microsoft OLEDB Provider for Oracle 2. Oracle Provider for OLEDB ..without luck. Do you think it could be a driver issue? ![alt text](https://i.stack.imgur.com/Xe6CU.jpg)
2010/08/20
[ "https://Stackoverflow.com/questions/3534453", "https://Stackoverflow.com", "https://Stackoverflow.com/users/109676/" ]
You missed to google. <http://android-er.blogspot.com/2010/05/android-surfaceview.html> <http://www.droidnova.com/playing-with-graphics-in-android-part-v,188.html>
The solution is very simple. ``` //get surface view and surface holder mySurfaceView = (SurfaceView) findViewById(R.id.surfaceView); surfaceHolder = mySurfaceView.getHolder(); //place surface view holder on top of the surface view mySurfaceView.setZOrderOnTop(true); //set pixels of the surface holder to transparent to see the color of the //surface view background surfaceHolder.setFormat(PixelFormat.TRANSPARENT); ```
540
In various sub-castes, people used to practice untouchability i.e., some of the people who were considered lower castes, for example, sweepers, cleaners, etc. were ignored, and there were rules such as others were not allowed to touch them, if they did, they were ignored by the community. So why they used to do that?
2014/06/27
[ "https://hinduism.stackexchange.com/questions/540", "https://hinduism.stackexchange.com", "https://hinduism.stackexchange.com/users/130/" ]
This question has more to do with human nature than Hinduism. When people were divided into castes based upon their work, some castes declared themselves superior and called others inferior. Worshiping Gods was considered superior and noble work, so that caste became superior. Cleaning, washing etc. were considered inferior work, so that caste became inferior. I don't know which resulted in which and so on, but these feelings resulted in customs like not allowing lower caste people into temples and not allowing them to read the Vedas. Those customs further reinforced the feelings. Untouchability spread like a superstition where everybody believed in it. From this documentary [India Untouched](http://www.cultureunplugged.com/documentary/watch-online/play/5752/India-Untouched---Stories-of-a-People-Apart-) > > It exposes the continuation of caste practices and Untouchability in Sikhism, Christianity and Islam, and even amongst the communists in Kerala. > > > Untouchability is prevalent in other religions too. > > within Dalits, sub-castes practice Untouchability on the "lower" sub-castes, and a Harijan boy refuses to drink water from a Valmiki boy. > > > So untouchability is not just two-layered, it's multi-layered.
It has it's origin in practicing cleanliness when contagious diseases were in abundance, which had no cure. So the people having professions related to 'unclean' things like wastes, leather etc were prohibited from touching, accessing public places and common water supplies like lakes and wells. In course of time this became a custom.
540
In various sub-castes, people used to practice untouchability i.e., some of the people who were considered lower castes, for example, sweepers, cleaners, etc. were ignored, and there were rules such as others were not allowed to touch them, if they did, they were ignored by the community. So why they used to do that?
2014/06/27
[ "https://hinduism.stackexchange.com/questions/540", "https://hinduism.stackexchange.com", "https://hinduism.stackexchange.com/users/130/" ]
This question has more to do with human nature than Hinduism. When people were divided into castes based upon their work, some castes declared themselves superior and called others inferior. Worshiping Gods was considered superior and noble work, so that caste became superior. Cleaning, washing etc. were considered inferior work, so that caste became inferior. I don't know which resulted in which and so on, but these feelings resulted in customs like not allowing lower caste people into temples and not allowing them to read the Vedas. Those customs further reinforced the feelings. Untouchability spread like a superstition where everybody believed in it. From this documentary [India Untouched](http://www.cultureunplugged.com/documentary/watch-online/play/5752/India-Untouched---Stories-of-a-People-Apart-) > > It exposes the continuation of caste practices and Untouchability in Sikhism, Christianity and Islam, and even amongst the communists in Kerala. > > > Untouchability is prevalent in other religions too. > > within Dalits, sub-castes practice Untouchability on the "lower" sub-castes, and a Harijan boy refuses to drink water from a Valmiki boy. > > > So untouchability is not just two-layered, it's multi-layered.
Caste hierarchy and discrimination is not sanctioned by the Vedas. I mentioning an excerpt from an article by Swami Venkatraman: > > First, caste refers to jati, not varna. Jatis are the thousands of > indigenous social- occupational groups, while varna refers to the four > individualized societal functions described in many texts. > Understanding this distinction is a necessary first step. The next is > exploring whether the Purusha Sukta really sanctions a hierarchical > and discriminatory caste system? > > > This is not mere academic curiosity. The solution to any problem > relies on a correct diagnosis and even as they acknowledge the social > history of caste-based discrimination in India, it is important for > Hindus, and non-Hindus, to understand the terminology and know whether > the Sukta really does sanction a birth-based hierarchy. > > > Below is a translation of the relevant verse from *‘Purusha Sukta’*, > which is the 90th Sukta of the 10th mandala in the Rig Veda, and it > talks about the entire universe as the body of God (Purusha), and of > all creation as emerging from Him. > > > *From his mouth came forth the Brahmins* > > > *And of his arms were Rajanya made* > > > *From his thighs came the Vaishyas* > > > *And his feet gave birth to Sudras.* > > > At a literal reading, this indeed appears to define a hierarchical > system of classes with the Brahmins occupying the most prestigious > position and the Sudras being the most inferior as they emerge from > the feet. And this has pretty much become the dominant understanding > of the verse among academics. > > > The best way to demonstrate the silliness of this interpretation of > the 90th Sukta, is to actually assume it to be correct and then see > where that leads us in terms of understanding the rest of the hymn. > Thus, if the above verse indicates a hierarchical system, then > presumably the body parts of the God (Purusha) from which everything > in creation emerges, or the order in which the names are mentioned, or > both, ought to be indicative of its superiority or otherwise. > > > Let us test this understanding against translations of the next two > verses from the > > > *90th ‘Purusha Sukta’:* > > > *Of his mind, the Moon is born* > > > *Of his eyes, the shining Sun* > > > *from his mouth, Indra and Agni,* > > > *And of his life-breath, Vayu* > > > *Space unfolds from his navel* > > > *The sky well formed from his head* > > > *From His feet, the earth and His ears the Quarters* > > > *Thus they thought up all the worlds.* > > > If our assumption above were true, then the moon ought to be superior > to the sun because the mind is superior to the eyes, and also because > the moon is mentioned first. Moreover, based on where they emerge > from, Indra (the king of the Devas) ought to be inferior to both > Chandra (moon) and Surya (sun) and on par with Agni (fire), which also > is illogical. > > > A similarly absurd comparison of the space, sky, earth with the ‘four > directions’ will arise from the second verse. If the earth comes from > the God’s (Purusha) feet, is it then inferior to the moon which comes > from the mind? > > > There is clearly no hierarchy intended, but only symbolic meanings. > This can be driven home more clearly, if one considers what the > ‘Purusha Sukta’ says in its entirety. It describes the God (Purusha), > as the perennial source of all creation, as having countless heads, > eyes and legs, manifested everywhere beyond comprehension. All > creation is but fourth a part of him and the rest is thus, ambiguous. > > > The Sukta describes a great Yajna, or a ritual sacrifice, called > `Sarvahut’, or the ‘offering of all’. It was God (Purusha) himself who > is worshipped in the Yajna, which is performed by Brahma, the creative > power of the Purusha. The Devas, who are the senses of the Purusha, > are the priests. > > > Thus, the beast of sacrifice, tied to the altar is the Purusha > himself; all of nature is the altar; the Purusha’s heart is the fire, > and the Purusha himself is sacrificed in the Yajna, which is the > process of creation itself. The ‘Purusha Sukta’ does not intend to > speak about human society and its organization. > > > The translation of one of the final verses states the essence of > Hinduism clearly: > > > *I know That Purusha who is glorious* > > > *Bright as the sun, beyond all darkness.* > > > *He who knows him thus Conquers death in this birth.* > > > *I know of no other way than this.* > > > Consider the following now: > > > In the entire Rig Veda, it is only in the ‘Purusha Sukta’ that the > four varnas are mentioned. However, the ‘Purusha Sukta’ itself does > not use the word ‘varna’ and wherever the word occurs elsewhere in the > Rig Veda, it is to be noted that it is not used to refer to the four > types of people in society. > > > Moreover, Hindu sacred texts clearly relate ‘varnas’ to the ‘guna’ > i.e., behavior and character, rather than the birth. The idea that > different individuals of the same family can have different ‘varnas’ > and those individuals had a choice of ‘varnas’ are present in the *Rig > Veda* itself. > > > *“I am a reciter of hymns, my father is a healer, my mother a grinder of corn. We desire to obtain wealth through various actions”-- Rig > Veda 9.112.3* > > > *“O Indra, fond of soma, would you make me the protector of people, or would you make me a ruler, or would you make me a sage who has > consumed soma, or would you bestow infinite wealth on me?” --- Rig > Veda 3.44.5* > > > *“The four varnas were created by me according to differences in guna and karma; although the creator of this, know me as the non-doer being > immutable.” -- Bhagavad Gita 4.13* > > > <http://swarajyamag.com/culture/caste-hierarchy-and-discrimination-not-sanctioned-by-the-vedas>
540
In various sub-castes, people used to practice untouchability i.e., some of the people who were considered lower castes, for example, sweepers, cleaners, etc. were ignored, and there were rules such as others were not allowed to touch them, if they did, they were ignored by the community. So why they used to do that?
2014/06/27
[ "https://hinduism.stackexchange.com/questions/540", "https://hinduism.stackexchange.com", "https://hinduism.stackexchange.com/users/130/" ]
For your question 'So why they used to do that?' : Quoting from Dr.Koenraad Elst's 1994 Essay "Caste: The view from Belgium": > > Untouchability originates in the belief that evil spirits surround > dead and dying substances. People who work with corpses, body > excretions or animal skins had an aura of danger and impurity, so they > were kept away from mainstream society and from sacred learning and > ritual. This often took grotesque forms: thus, an untouchable had to > announce his polluting proximity with a rattle, like a leper. > > > Untouchability seems to originated from a notion of impurity associated with certain professions. This is not unique to Hindu society as it is popularly believed. [Burakumin](http://en.wikipedia.org/wiki/Burakumin) people of Japan, [Baekjeong](http://en.wikipedia.org/wiki/Baekjeong) people of Korea were considered untouchable. It seems to have arisen from basic human nature to seek safety in an age where some diseases had no cure. Hence people who had the potential to carry diseases were kept away. Untouchability is not mentioned in Vedic Samhitas. It does not have sanction in scriptures and it seems to have existed among non-Vedic Hindus too: > > ...the Tamils believed that any taking of life was dangerous, as it > released the spirits of the things that were killed. Likewise, all > who dealt with the dead or with dead substances from the body were > considered to be charged with the power of death and were thought to > be dangerous. Thus, long before the coming of the Aryans with their > notion of varna, the Tamils had groups that were considered low and > dangerous and with whom contact was closely regulated[1]. > > > This reinforces that it was based on basic human instinct to seek safety rather than sanctioned by scriptures. So even within an untouchable caste, some sub-castes might have been considered untouchable by the members of the same caste on the notion of safety. [1] [Reference](http://voiceofdharma.org/books/wiah/ch1.htm)
It has it's origin in practicing cleanliness when contagious diseases were in abundance, which had no cure. So the people having professions related to 'unclean' things like wastes, leather etc were prohibited from touching, accessing public places and common water supplies like lakes and wells. In course of time this became a custom.
540
In various sub-castes, people used to practice untouchability i.e., some of the people who were considered lower castes, for example, sweepers, cleaners, etc. were ignored, and there were rules such as others were not allowed to touch them, if they did, they were ignored by the community. So why they used to do that?
2014/06/27
[ "https://hinduism.stackexchange.com/questions/540", "https://hinduism.stackexchange.com", "https://hinduism.stackexchange.com/users/130/" ]
For your question 'So why they used to do that?' : Quoting from Dr.Koenraad Elst's 1994 Essay "Caste: The view from Belgium": > > Untouchability originates in the belief that evil spirits surround > dead and dying substances. People who work with corpses, body > excretions or animal skins had an aura of danger and impurity, so they > were kept away from mainstream society and from sacred learning and > ritual. This often took grotesque forms: thus, an untouchable had to > announce his polluting proximity with a rattle, like a leper. > > > Untouchability seems to originated from a notion of impurity associated with certain professions. This is not unique to Hindu society as it is popularly believed. [Burakumin](http://en.wikipedia.org/wiki/Burakumin) people of Japan, [Baekjeong](http://en.wikipedia.org/wiki/Baekjeong) people of Korea were considered untouchable. It seems to have arisen from basic human nature to seek safety in an age where some diseases had no cure. Hence people who had the potential to carry diseases were kept away. Untouchability is not mentioned in Vedic Samhitas. It does not have sanction in scriptures and it seems to have existed among non-Vedic Hindus too: > > ...the Tamils believed that any taking of life was dangerous, as it > released the spirits of the things that were killed. Likewise, all > who dealt with the dead or with dead substances from the body were > considered to be charged with the power of death and were thought to > be dangerous. Thus, long before the coming of the Aryans with their > notion of varna, the Tamils had groups that were considered low and > dangerous and with whom contact was closely regulated[1]. > > > This reinforces that it was based on basic human instinct to seek safety rather than sanctioned by scriptures. So even within an untouchable caste, some sub-castes might have been considered untouchable by the members of the same caste on the notion of safety. [1] [Reference](http://voiceofdharma.org/books/wiah/ch1.htm)
Caste hierarchy and discrimination is not sanctioned by the Vedas. I mentioning an excerpt from an article by Swami Venkatraman: > > First, caste refers to jati, not varna. Jatis are the thousands of > indigenous social- occupational groups, while varna refers to the four > individualized societal functions described in many texts. > Understanding this distinction is a necessary first step. The next is > exploring whether the Purusha Sukta really sanctions a hierarchical > and discriminatory caste system? > > > This is not mere academic curiosity. The solution to any problem > relies on a correct diagnosis and even as they acknowledge the social > history of caste-based discrimination in India, it is important for > Hindus, and non-Hindus, to understand the terminology and know whether > the Sukta really does sanction a birth-based hierarchy. > > > Below is a translation of the relevant verse from *‘Purusha Sukta’*, > which is the 90th Sukta of the 10th mandala in the Rig Veda, and it > talks about the entire universe as the body of God (Purusha), and of > all creation as emerging from Him. > > > *From his mouth came forth the Brahmins* > > > *And of his arms were Rajanya made* > > > *From his thighs came the Vaishyas* > > > *And his feet gave birth to Sudras.* > > > At a literal reading, this indeed appears to define a hierarchical > system of classes with the Brahmins occupying the most prestigious > position and the Sudras being the most inferior as they emerge from > the feet. And this has pretty much become the dominant understanding > of the verse among academics. > > > The best way to demonstrate the silliness of this interpretation of > the 90th Sukta, is to actually assume it to be correct and then see > where that leads us in terms of understanding the rest of the hymn. > Thus, if the above verse indicates a hierarchical system, then > presumably the body parts of the God (Purusha) from which everything > in creation emerges, or the order in which the names are mentioned, or > both, ought to be indicative of its superiority or otherwise. > > > Let us test this understanding against translations of the next two > verses from the > > > *90th ‘Purusha Sukta’:* > > > *Of his mind, the Moon is born* > > > *Of his eyes, the shining Sun* > > > *from his mouth, Indra and Agni,* > > > *And of his life-breath, Vayu* > > > *Space unfolds from his navel* > > > *The sky well formed from his head* > > > *From His feet, the earth and His ears the Quarters* > > > *Thus they thought up all the worlds.* > > > If our assumption above were true, then the moon ought to be superior > to the sun because the mind is superior to the eyes, and also because > the moon is mentioned first. Moreover, based on where they emerge > from, Indra (the king of the Devas) ought to be inferior to both > Chandra (moon) and Surya (sun) and on par with Agni (fire), which also > is illogical. > > > A similarly absurd comparison of the space, sky, earth with the ‘four > directions’ will arise from the second verse. If the earth comes from > the God’s (Purusha) feet, is it then inferior to the moon which comes > from the mind? > > > There is clearly no hierarchy intended, but only symbolic meanings. > This can be driven home more clearly, if one considers what the > ‘Purusha Sukta’ says in its entirety. It describes the God (Purusha), > as the perennial source of all creation, as having countless heads, > eyes and legs, manifested everywhere beyond comprehension. All > creation is but fourth a part of him and the rest is thus, ambiguous. > > > The Sukta describes a great Yajna, or a ritual sacrifice, called > `Sarvahut’, or the ‘offering of all’. It was God (Purusha) himself who > is worshipped in the Yajna, which is performed by Brahma, the creative > power of the Purusha. The Devas, who are the senses of the Purusha, > are the priests. > > > Thus, the beast of sacrifice, tied to the altar is the Purusha > himself; all of nature is the altar; the Purusha’s heart is the fire, > and the Purusha himself is sacrificed in the Yajna, which is the > process of creation itself. The ‘Purusha Sukta’ does not intend to > speak about human society and its organization. > > > The translation of one of the final verses states the essence of > Hinduism clearly: > > > *I know That Purusha who is glorious* > > > *Bright as the sun, beyond all darkness.* > > > *He who knows him thus Conquers death in this birth.* > > > *I know of no other way than this.* > > > Consider the following now: > > > In the entire Rig Veda, it is only in the ‘Purusha Sukta’ that the > four varnas are mentioned. However, the ‘Purusha Sukta’ itself does > not use the word ‘varna’ and wherever the word occurs elsewhere in the > Rig Veda, it is to be noted that it is not used to refer to the four > types of people in society. > > > Moreover, Hindu sacred texts clearly relate ‘varnas’ to the ‘guna’ > i.e., behavior and character, rather than the birth. The idea that > different individuals of the same family can have different ‘varnas’ > and those individuals had a choice of ‘varnas’ are present in the *Rig > Veda* itself. > > > *“I am a reciter of hymns, my father is a healer, my mother a grinder of corn. We desire to obtain wealth through various actions”-- Rig > Veda 9.112.3* > > > *“O Indra, fond of soma, would you make me the protector of people, or would you make me a ruler, or would you make me a sage who has > consumed soma, or would you bestow infinite wealth on me?” --- Rig > Veda 3.44.5* > > > *“The four varnas were created by me according to differences in guna and karma; although the creator of this, know me as the non-doer being > immutable.” -- Bhagavad Gita 4.13* > > > <http://swarajyamag.com/culture/caste-hierarchy-and-discrimination-not-sanctioned-by-the-vedas>
221,747
I need a way to change history so that Taiwan, in 2015, be using weapons manufactured and sold by mainland China as well as some US equipments--sort of like how Pakistan uses both Chinese and US weapons. There are some restrictions as presented by my world: 1. China is still runned by the Party, though it could be a more democratic variant or a more dictatoral variant. 2. Taiwan is still "de facto independent", it hasn't declare offical independence, but it hasn't been conquered by the mainland. 3. US is still opposing China's rise. How far US is planning to go to prevent China's rise though, can be changed. 4. There is a united semi-religious, semi-nationalistic group of terrorist army with global reach running amoke and causing huge amount of troubles to both US and China. They have no other common goal than to take down the current social norm and government of US, EU and China. Yes, this is the GLA from Command and Conquer Generals. 5. European is united and militarily allied with US and waried with Russia, however, they economically seek closer ties with China 6. Russia is an ally-of-convinence of China against US
2022/01/08
[ "https://worldbuilding.stackexchange.com/questions/221747", "https://worldbuilding.stackexchange.com", "https://worldbuilding.stackexchange.com/users/37911/" ]
**They are Friends** Taiwan is officially part of China (according to China that is). Unofficially the countries are separate but allied. The motivation behind China not conquering Taiwan is (a) We can do it whenever we want because we are much bigger and stronger than them. There is no need to conquer now and we'd rather save the expense. (b) A lot of our wealthy citizens have holiday homes in Taiwan where they take advantage of the increased freedoms. Thus Taiwan is a convenient way of keeping seditious behaviour off the mainland and prevent it from spreading from the upper to the lower classes. Conquering would be a big inconvenience to us as it would upset some of our more powerful citizens. We not only have to conquer the island, but also root out and deal with dissenters across all of the mainland. (c) We want to present not conquering as OUR DECISION. So being an ally is the best narrative. The Taiwanese use Chinese weapons because they are the easiest to get. In fact these weapons are provided at a slashed rate, to make Taiwan dependent on the mainland for military stuff. The fact they use Chinese weapons is made very clear to the other superpowers, as this makes it harder to seek aid from the other weapon manufacturing countries.
Okay, much of this has to rely on a lot of speculative/semi-conspiracy theories of the time (but what "what-if" scenario doesn't). The most challenging parameters you have set are: 1. Taiwan is de-facto independent, but de-jure part of China, just like today. 2. Taiwan has sufficiently amicable relations with China to import military equipment from China, despite having an independent government. These are very conflicting requirements but I think there's a way to work this out. First of all, we have to understand the relationship between KMT and CCP. While Dr. Sun Yat-Sen was still alive, the CCP was a recognized political party within ROC. Many Chinese elites of those times studied both philosophies and many of them were colleagues and have close personal ties. For a lot of them, there was no reason at the time to believe "Communism" was inherently evil, bad, or that it wouldn't work. Both the KMT and CCP were broadly committed bring power to the people and rebuilding China after the successful overthrow of Qing dynasty in 1911. Just because the Qing Empire was toppled doesn't solve a lot of inherent issues of China overnight. Local warlords, the norm of various corruption in society, these don't go away. KMT inherited a lot of these problems and the wealthy class remain wealthy, so it was very normal that Marxist ideals had its appeal. It was only after Sun Yat-sen died (1925) that Chiang Kai-Shek tried to purge the communists (1927). Many of Chiang's closest advisors and generals, were sympathetic to the CCP despite remaining loyal to KMT. This includes Chang Hsüeh-liang who kidnaped Chiang to force a ceasefire with CCP and united front against Japan, and the war hero Sun Li-jen Sun Li-jen was viewed very positively by the US and it was rumored that he would be a prime candidate for being installed as a puppet president. He's idealistic but naive. As Chiang Kai-shek once said of him, Sun Li-jen is good at fighting battles, but he's no good at winning wars. He's not much of a politician.and probably not great at managing international relations. First, Chiang Kai-shek needs to die, and most probably taking place after Chiang Kai-shek walked away from the UN in 1971 refusing US/UK's offer of being recognized as a new country (i.e. puppet state). His death would likely be due a successful CIA-assassination attempt. After that, the US political machine drums up Sun Li-jen's war hero status and install him as president of Taiwan. However, this alone is not enough. While Sun Li-jen never sees the CCP as the enemy, he simply lacks the political saavy. However, what he would likely do among his first acts as president, would be to pardon Chang Hsüeh-liang from house arrest, who would have the seniority and history to be his advisor. Both Sun Li-jen (b. 1900, d. 1990) and Chiang Hsüeh-liang (b. 1901, d. 2001) would seek to improve relations with the CCP, upholding the pan-Chinese identity. Chang would probably have the political backbone and wit to tell the US to backoff while simultaneously keep the naive Sun safe from assination when the US realized their puppet is not much of a puppet. Under Sun Li-jen, travel bans and other cross-straight restrictions would probably be relaxed a lot sooner than 1987, possibly not long after 1976 after the cultural revolution ended. This would significantly improve morale of the Waishengren who retreated/immigrated along with the KMT army from the mainland, families reunited, etc. etc. Since China hasn't build up its economy and educated class, but with improved relations with Taiwan, Taiwan would take the lead in a lot of initiatives. Today's economic environment would be VERY different as most of the Mainland's private enterprises would probably actually be owned by Taiwan, and Taiwain maintains its status as the envy of the Mainland (which today is only an outdated story Taiwanese tell themselves). However, if Sun Li-jen became president, that does not bode well for the Benshengren. Although Sun Li-jen has objected to Chiang being authoritarian, I believe Sun is more likely to uphold a pan-Chinese identity that see's Mainlanders, Waishengren, Benshengren (Taiwanese colonial-nativists who migrated from China 300 years ago) all as one people, while Benshengren a promoting a "Taiwanese" identity. If Sun Li-jen became president, I'm not sure Chiang Ching-kuo would succeed him. If Chiang Ching Kuo did not become president, many of his policies intended to be more inclusive and support Benshrengren (despite their blames and hatred of KMT) would not come to pass, and Li Teng-hui who truly catapulted Benshengren representation in politics (and paved way for the first DPP president to get elected) would not have became president. Taiwan in this alternate universe would actually be genuinely "Pro-China", though it may not necessarily have the same negative connotations today as Taiwan would take economic lead in this world. With all that setup, private enterprises would be dominated by Taiwan, but China would have the industrial base to supply Taiwan with military equipment, which they will need to use as earlier refusal to be puppeted by the US means the US would not supply Taiwan with weapons.
221,747
I need a way to change history so that Taiwan, in 2015, be using weapons manufactured and sold by mainland China as well as some US equipments--sort of like how Pakistan uses both Chinese and US weapons. There are some restrictions as presented by my world: 1. China is still runned by the Party, though it could be a more democratic variant or a more dictatoral variant. 2. Taiwan is still "de facto independent", it hasn't declare offical independence, but it hasn't been conquered by the mainland. 3. US is still opposing China's rise. How far US is planning to go to prevent China's rise though, can be changed. 4. There is a united semi-religious, semi-nationalistic group of terrorist army with global reach running amoke and causing huge amount of troubles to both US and China. They have no other common goal than to take down the current social norm and government of US, EU and China. Yes, this is the GLA from Command and Conquer Generals. 5. European is united and militarily allied with US and waried with Russia, however, they economically seek closer ties with China 6. Russia is an ally-of-convinence of China against US
2022/01/08
[ "https://worldbuilding.stackexchange.com/questions/221747", "https://worldbuilding.stackexchange.com", "https://worldbuilding.stackexchange.com/users/37911/" ]
You've already made enough change to make it happen. In our timeline, Ma Ying-jeou of the KMT was the leader of Taiwan from 2008-2016. Cross-straits relations improved greatly during his time in office. If you add in an ongoing major global terrorism threat against China, the US, and more, the focus would shift away from local disputes and US-China political rivalries towards improved security. Depending on when the terrorism began and how bad it was, reunification talks could easily have been well underway by 2015.
Okay, much of this has to rely on a lot of speculative/semi-conspiracy theories of the time (but what "what-if" scenario doesn't). The most challenging parameters you have set are: 1. Taiwan is de-facto independent, but de-jure part of China, just like today. 2. Taiwan has sufficiently amicable relations with China to import military equipment from China, despite having an independent government. These are very conflicting requirements but I think there's a way to work this out. First of all, we have to understand the relationship between KMT and CCP. While Dr. Sun Yat-Sen was still alive, the CCP was a recognized political party within ROC. Many Chinese elites of those times studied both philosophies and many of them were colleagues and have close personal ties. For a lot of them, there was no reason at the time to believe "Communism" was inherently evil, bad, or that it wouldn't work. Both the KMT and CCP were broadly committed bring power to the people and rebuilding China after the successful overthrow of Qing dynasty in 1911. Just because the Qing Empire was toppled doesn't solve a lot of inherent issues of China overnight. Local warlords, the norm of various corruption in society, these don't go away. KMT inherited a lot of these problems and the wealthy class remain wealthy, so it was very normal that Marxist ideals had its appeal. It was only after Sun Yat-sen died (1925) that Chiang Kai-Shek tried to purge the communists (1927). Many of Chiang's closest advisors and generals, were sympathetic to the CCP despite remaining loyal to KMT. This includes Chang Hsüeh-liang who kidnaped Chiang to force a ceasefire with CCP and united front against Japan, and the war hero Sun Li-jen Sun Li-jen was viewed very positively by the US and it was rumored that he would be a prime candidate for being installed as a puppet president. He's idealistic but naive. As Chiang Kai-shek once said of him, Sun Li-jen is good at fighting battles, but he's no good at winning wars. He's not much of a politician.and probably not great at managing international relations. First, Chiang Kai-shek needs to die, and most probably taking place after Chiang Kai-shek walked away from the UN in 1971 refusing US/UK's offer of being recognized as a new country (i.e. puppet state). His death would likely be due a successful CIA-assassination attempt. After that, the US political machine drums up Sun Li-jen's war hero status and install him as president of Taiwan. However, this alone is not enough. While Sun Li-jen never sees the CCP as the enemy, he simply lacks the political saavy. However, what he would likely do among his first acts as president, would be to pardon Chang Hsüeh-liang from house arrest, who would have the seniority and history to be his advisor. Both Sun Li-jen (b. 1900, d. 1990) and Chiang Hsüeh-liang (b. 1901, d. 2001) would seek to improve relations with the CCP, upholding the pan-Chinese identity. Chang would probably have the political backbone and wit to tell the US to backoff while simultaneously keep the naive Sun safe from assination when the US realized their puppet is not much of a puppet. Under Sun Li-jen, travel bans and other cross-straight restrictions would probably be relaxed a lot sooner than 1987, possibly not long after 1976 after the cultural revolution ended. This would significantly improve morale of the Waishengren who retreated/immigrated along with the KMT army from the mainland, families reunited, etc. etc. Since China hasn't build up its economy and educated class, but with improved relations with Taiwan, Taiwan would take the lead in a lot of initiatives. Today's economic environment would be VERY different as most of the Mainland's private enterprises would probably actually be owned by Taiwan, and Taiwain maintains its status as the envy of the Mainland (which today is only an outdated story Taiwanese tell themselves). However, if Sun Li-jen became president, that does not bode well for the Benshengren. Although Sun Li-jen has objected to Chiang being authoritarian, I believe Sun is more likely to uphold a pan-Chinese identity that see's Mainlanders, Waishengren, Benshengren (Taiwanese colonial-nativists who migrated from China 300 years ago) all as one people, while Benshengren a promoting a "Taiwanese" identity. If Sun Li-jen became president, I'm not sure Chiang Ching-kuo would succeed him. If Chiang Ching Kuo did not become president, many of his policies intended to be more inclusive and support Benshrengren (despite their blames and hatred of KMT) would not come to pass, and Li Teng-hui who truly catapulted Benshengren representation in politics (and paved way for the first DPP president to get elected) would not have became president. Taiwan in this alternate universe would actually be genuinely "Pro-China", though it may not necessarily have the same negative connotations today as Taiwan would take economic lead in this world. With all that setup, private enterprises would be dominated by Taiwan, but China would have the industrial base to supply Taiwan with military equipment, which they will need to use as earlier refusal to be puppeted by the US means the US would not supply Taiwan with weapons.
221,747
I need a way to change history so that Taiwan, in 2015, be using weapons manufactured and sold by mainland China as well as some US equipments--sort of like how Pakistan uses both Chinese and US weapons. There are some restrictions as presented by my world: 1. China is still runned by the Party, though it could be a more democratic variant or a more dictatoral variant. 2. Taiwan is still "de facto independent", it hasn't declare offical independence, but it hasn't been conquered by the mainland. 3. US is still opposing China's rise. How far US is planning to go to prevent China's rise though, can be changed. 4. There is a united semi-religious, semi-nationalistic group of terrorist army with global reach running amoke and causing huge amount of troubles to both US and China. They have no other common goal than to take down the current social norm and government of US, EU and China. Yes, this is the GLA from Command and Conquer Generals. 5. European is united and militarily allied with US and waried with Russia, however, they economically seek closer ties with China 6. Russia is an ally-of-convinence of China against US
2022/01/08
[ "https://worldbuilding.stackexchange.com/questions/221747", "https://worldbuilding.stackexchange.com", "https://worldbuilding.stackexchange.com/users/37911/" ]
**America First.** [![map minus the us](https://i.stack.imgur.com/fVWbw.png)](https://i.stack.imgur.com/fVWbw.png) <https://dabrownstein.com/2016/12/05/mapping-the-new-isolationism/> > > The very America First doctrine that catapulted Trump to the White > House stands, for all its championing of national self-interest, to be > best embodied by the removal of the United States from its role on the > global geopolitical map. And the removal of the United States and > England–achieved through the striking success of go-it-alone political > parties in both nations–seems to show just how outdated a five-color > map is to describe the world. > > > The US government is isolationist. Political leaders in the US are willfully ignorant and that is considered desirable by the electorate that put them there. The political leaders in power are extremely reluctant to support non-American foreign entities with money or supplies because they are foreigners. "Allies" are treated coolly and problems that do not involve American territory are considered someone else's problems. Such problems often do not even make the radar at the highest levels of the US government. Problems off the coast of China fall into this category. Career diplomats in the US carry on as best they can with foreign policy goals and world views carried over from earlier and more globally minded administrations. These persons are aware of the threat from the GLA and have a nuanced sense of the relationship with China. The "deep state" in the US is trying to keep things from getting out of control while hoping for eventual regime change in the US. These career diplomats and their counterparts in China are aware that a strong Chinese military presence in the Pacific would be noticed even by the current US political leaders. Both sides are worried about a hamhanded, disproportionate military or diplomatic response by the US. Taiwan however is considered an ally. Taiwanese military ventures in the Pacific would not be noticed by US political leaders or if noticed, dismissed. The Taiwanese are willing but undersupplied. With the US political climate there is not a good way to get American armaments and money to them or anyone else. The Chinese understand the gravity of the situation. They are willing to arm the Taiwanese on the sly. They are not going to make a big deal about it. They might even use a proxy brand based in India or Singapore. The Taiwanese also understand what is up. Internecine strife with the Chinese can be set aside to face the existential threat that is the GLA.
Okay, much of this has to rely on a lot of speculative/semi-conspiracy theories of the time (but what "what-if" scenario doesn't). The most challenging parameters you have set are: 1. Taiwan is de-facto independent, but de-jure part of China, just like today. 2. Taiwan has sufficiently amicable relations with China to import military equipment from China, despite having an independent government. These are very conflicting requirements but I think there's a way to work this out. First of all, we have to understand the relationship between KMT and CCP. While Dr. Sun Yat-Sen was still alive, the CCP was a recognized political party within ROC. Many Chinese elites of those times studied both philosophies and many of them were colleagues and have close personal ties. For a lot of them, there was no reason at the time to believe "Communism" was inherently evil, bad, or that it wouldn't work. Both the KMT and CCP were broadly committed bring power to the people and rebuilding China after the successful overthrow of Qing dynasty in 1911. Just because the Qing Empire was toppled doesn't solve a lot of inherent issues of China overnight. Local warlords, the norm of various corruption in society, these don't go away. KMT inherited a lot of these problems and the wealthy class remain wealthy, so it was very normal that Marxist ideals had its appeal. It was only after Sun Yat-sen died (1925) that Chiang Kai-Shek tried to purge the communists (1927). Many of Chiang's closest advisors and generals, were sympathetic to the CCP despite remaining loyal to KMT. This includes Chang Hsüeh-liang who kidnaped Chiang to force a ceasefire with CCP and united front against Japan, and the war hero Sun Li-jen Sun Li-jen was viewed very positively by the US and it was rumored that he would be a prime candidate for being installed as a puppet president. He's idealistic but naive. As Chiang Kai-shek once said of him, Sun Li-jen is good at fighting battles, but he's no good at winning wars. He's not much of a politician.and probably not great at managing international relations. First, Chiang Kai-shek needs to die, and most probably taking place after Chiang Kai-shek walked away from the UN in 1971 refusing US/UK's offer of being recognized as a new country (i.e. puppet state). His death would likely be due a successful CIA-assassination attempt. After that, the US political machine drums up Sun Li-jen's war hero status and install him as president of Taiwan. However, this alone is not enough. While Sun Li-jen never sees the CCP as the enemy, he simply lacks the political saavy. However, what he would likely do among his first acts as president, would be to pardon Chang Hsüeh-liang from house arrest, who would have the seniority and history to be his advisor. Both Sun Li-jen (b. 1900, d. 1990) and Chiang Hsüeh-liang (b. 1901, d. 2001) would seek to improve relations with the CCP, upholding the pan-Chinese identity. Chang would probably have the political backbone and wit to tell the US to backoff while simultaneously keep the naive Sun safe from assination when the US realized their puppet is not much of a puppet. Under Sun Li-jen, travel bans and other cross-straight restrictions would probably be relaxed a lot sooner than 1987, possibly not long after 1976 after the cultural revolution ended. This would significantly improve morale of the Waishengren who retreated/immigrated along with the KMT army from the mainland, families reunited, etc. etc. Since China hasn't build up its economy and educated class, but with improved relations with Taiwan, Taiwan would take the lead in a lot of initiatives. Today's economic environment would be VERY different as most of the Mainland's private enterprises would probably actually be owned by Taiwan, and Taiwain maintains its status as the envy of the Mainland (which today is only an outdated story Taiwanese tell themselves). However, if Sun Li-jen became president, that does not bode well for the Benshengren. Although Sun Li-jen has objected to Chiang being authoritarian, I believe Sun is more likely to uphold a pan-Chinese identity that see's Mainlanders, Waishengren, Benshengren (Taiwanese colonial-nativists who migrated from China 300 years ago) all as one people, while Benshengren a promoting a "Taiwanese" identity. If Sun Li-jen became president, I'm not sure Chiang Ching-kuo would succeed him. If Chiang Ching Kuo did not become president, many of his policies intended to be more inclusive and support Benshrengren (despite their blames and hatred of KMT) would not come to pass, and Li Teng-hui who truly catapulted Benshengren representation in politics (and paved way for the first DPP president to get elected) would not have became president. Taiwan in this alternate universe would actually be genuinely "Pro-China", though it may not necessarily have the same negative connotations today as Taiwan would take economic lead in this world. With all that setup, private enterprises would be dominated by Taiwan, but China would have the industrial base to supply Taiwan with military equipment, which they will need to use as earlier refusal to be puppeted by the US means the US would not supply Taiwan with weapons.
221,747
I need a way to change history so that Taiwan, in 2015, be using weapons manufactured and sold by mainland China as well as some US equipments--sort of like how Pakistan uses both Chinese and US weapons. There are some restrictions as presented by my world: 1. China is still runned by the Party, though it could be a more democratic variant or a more dictatoral variant. 2. Taiwan is still "de facto independent", it hasn't declare offical independence, but it hasn't been conquered by the mainland. 3. US is still opposing China's rise. How far US is planning to go to prevent China's rise though, can be changed. 4. There is a united semi-religious, semi-nationalistic group of terrorist army with global reach running amoke and causing huge amount of troubles to both US and China. They have no other common goal than to take down the current social norm and government of US, EU and China. Yes, this is the GLA from Command and Conquer Generals. 5. European is united and militarily allied with US and waried with Russia, however, they economically seek closer ties with China 6. Russia is an ally-of-convinence of China against US
2022/01/08
[ "https://worldbuilding.stackexchange.com/questions/221747", "https://worldbuilding.stackexchange.com", "https://worldbuilding.stackexchange.com/users/37911/" ]
**They are Friends** Taiwan is officially part of China (according to China that is). Unofficially the countries are separate but allied. The motivation behind China not conquering Taiwan is (a) We can do it whenever we want because we are much bigger and stronger than them. There is no need to conquer now and we'd rather save the expense. (b) A lot of our wealthy citizens have holiday homes in Taiwan where they take advantage of the increased freedoms. Thus Taiwan is a convenient way of keeping seditious behaviour off the mainland and prevent it from spreading from the upper to the lower classes. Conquering would be a big inconvenience to us as it would upset some of our more powerful citizens. We not only have to conquer the island, but also root out and deal with dissenters across all of the mainland. (c) We want to present not conquering as OUR DECISION. So being an ally is the best narrative. The Taiwanese use Chinese weapons because they are the easiest to get. In fact these weapons are provided at a slashed rate, to make Taiwan dependent on the mainland for military stuff. The fact they use Chinese weapons is made very clear to the other superpowers, as this makes it harder to seek aid from the other weapon manufacturing countries.
You've already made enough change to make it happen. In our timeline, Ma Ying-jeou of the KMT was the leader of Taiwan from 2008-2016. Cross-straits relations improved greatly during his time in office. If you add in an ongoing major global terrorism threat against China, the US, and more, the focus would shift away from local disputes and US-China political rivalries towards improved security. Depending on when the terrorism began and how bad it was, reunification talks could easily have been well underway by 2015.
221,747
I need a way to change history so that Taiwan, in 2015, be using weapons manufactured and sold by mainland China as well as some US equipments--sort of like how Pakistan uses both Chinese and US weapons. There are some restrictions as presented by my world: 1. China is still runned by the Party, though it could be a more democratic variant or a more dictatoral variant. 2. Taiwan is still "de facto independent", it hasn't declare offical independence, but it hasn't been conquered by the mainland. 3. US is still opposing China's rise. How far US is planning to go to prevent China's rise though, can be changed. 4. There is a united semi-religious, semi-nationalistic group of terrorist army with global reach running amoke and causing huge amount of troubles to both US and China. They have no other common goal than to take down the current social norm and government of US, EU and China. Yes, this is the GLA from Command and Conquer Generals. 5. European is united and militarily allied with US and waried with Russia, however, they economically seek closer ties with China 6. Russia is an ally-of-convinence of China against US
2022/01/08
[ "https://worldbuilding.stackexchange.com/questions/221747", "https://worldbuilding.stackexchange.com", "https://worldbuilding.stackexchange.com/users/37911/" ]
**They are Friends** Taiwan is officially part of China (according to China that is). Unofficially the countries are separate but allied. The motivation behind China not conquering Taiwan is (a) We can do it whenever we want because we are much bigger and stronger than them. There is no need to conquer now and we'd rather save the expense. (b) A lot of our wealthy citizens have holiday homes in Taiwan where they take advantage of the increased freedoms. Thus Taiwan is a convenient way of keeping seditious behaviour off the mainland and prevent it from spreading from the upper to the lower classes. Conquering would be a big inconvenience to us as it would upset some of our more powerful citizens. We not only have to conquer the island, but also root out and deal with dissenters across all of the mainland. (c) We want to present not conquering as OUR DECISION. So being an ally is the best narrative. The Taiwanese use Chinese weapons because they are the easiest to get. In fact these weapons are provided at a slashed rate, to make Taiwan dependent on the mainland for military stuff. The fact they use Chinese weapons is made very clear to the other superpowers, as this makes it harder to seek aid from the other weapon manufacturing countries.
[Li](https://en.wikipedia.org/wiki/Li_Keqiang) became the ruler of China in 2012, not Xi. ----------------------------------------------------------------------------------------- Li is an economics minded communist who wants to improve internal production and economics. He wants to improve production in China, gain independence from America, and deal with bureaucracy. He's a member of the factions of the groundroot communists who didn't have a rich background, and is more concerned with China. Xi Jinping is a princling, a rich and well connected member of China's noble faction, son of a powerful revolutionary, and well connected. He seeks to restore China's glory through bloodshed and war and purge anyone disloyal to him or his faction of noble communists who inherited their positions. Xi won dominion over China due to his deeper connections with other princlings of China and the military in 2012. Just change that and China would likely have much better relationships with its neighbors. Have Xi die or be injured, and have Li step up to rule.
221,747
I need a way to change history so that Taiwan, in 2015, be using weapons manufactured and sold by mainland China as well as some US equipments--sort of like how Pakistan uses both Chinese and US weapons. There are some restrictions as presented by my world: 1. China is still runned by the Party, though it could be a more democratic variant or a more dictatoral variant. 2. Taiwan is still "de facto independent", it hasn't declare offical independence, but it hasn't been conquered by the mainland. 3. US is still opposing China's rise. How far US is planning to go to prevent China's rise though, can be changed. 4. There is a united semi-religious, semi-nationalistic group of terrorist army with global reach running amoke and causing huge amount of troubles to both US and China. They have no other common goal than to take down the current social norm and government of US, EU and China. Yes, this is the GLA from Command and Conquer Generals. 5. European is united and militarily allied with US and waried with Russia, however, they economically seek closer ties with China 6. Russia is an ally-of-convinence of China against US
2022/01/08
[ "https://worldbuilding.stackexchange.com/questions/221747", "https://worldbuilding.stackexchange.com", "https://worldbuilding.stackexchange.com/users/37911/" ]
**America First.** [![map minus the us](https://i.stack.imgur.com/fVWbw.png)](https://i.stack.imgur.com/fVWbw.png) <https://dabrownstein.com/2016/12/05/mapping-the-new-isolationism/> > > The very America First doctrine that catapulted Trump to the White > House stands, for all its championing of national self-interest, to be > best embodied by the removal of the United States from its role on the > global geopolitical map. And the removal of the United States and > England–achieved through the striking success of go-it-alone political > parties in both nations–seems to show just how outdated a five-color > map is to describe the world. > > > The US government is isolationist. Political leaders in the US are willfully ignorant and that is considered desirable by the electorate that put them there. The political leaders in power are extremely reluctant to support non-American foreign entities with money or supplies because they are foreigners. "Allies" are treated coolly and problems that do not involve American territory are considered someone else's problems. Such problems often do not even make the radar at the highest levels of the US government. Problems off the coast of China fall into this category. Career diplomats in the US carry on as best they can with foreign policy goals and world views carried over from earlier and more globally minded administrations. These persons are aware of the threat from the GLA and have a nuanced sense of the relationship with China. The "deep state" in the US is trying to keep things from getting out of control while hoping for eventual regime change in the US. These career diplomats and their counterparts in China are aware that a strong Chinese military presence in the Pacific would be noticed even by the current US political leaders. Both sides are worried about a hamhanded, disproportionate military or diplomatic response by the US. Taiwan however is considered an ally. Taiwanese military ventures in the Pacific would not be noticed by US political leaders or if noticed, dismissed. The Taiwanese are willing but undersupplied. With the US political climate there is not a good way to get American armaments and money to them or anyone else. The Chinese understand the gravity of the situation. They are willing to arm the Taiwanese on the sly. They are not going to make a big deal about it. They might even use a proxy brand based in India or Singapore. The Taiwanese also understand what is up. Internecine strife with the Chinese can be set aside to face the existential threat that is the GLA.
**They are Friends** Taiwan is officially part of China (according to China that is). Unofficially the countries are separate but allied. The motivation behind China not conquering Taiwan is (a) We can do it whenever we want because we are much bigger and stronger than them. There is no need to conquer now and we'd rather save the expense. (b) A lot of our wealthy citizens have holiday homes in Taiwan where they take advantage of the increased freedoms. Thus Taiwan is a convenient way of keeping seditious behaviour off the mainland and prevent it from spreading from the upper to the lower classes. Conquering would be a big inconvenience to us as it would upset some of our more powerful citizens. We not only have to conquer the island, but also root out and deal with dissenters across all of the mainland. (c) We want to present not conquering as OUR DECISION. So being an ally is the best narrative. The Taiwanese use Chinese weapons because they are the easiest to get. In fact these weapons are provided at a slashed rate, to make Taiwan dependent on the mainland for military stuff. The fact they use Chinese weapons is made very clear to the other superpowers, as this makes it harder to seek aid from the other weapon manufacturing countries.
221,747
I need a way to change history so that Taiwan, in 2015, be using weapons manufactured and sold by mainland China as well as some US equipments--sort of like how Pakistan uses both Chinese and US weapons. There are some restrictions as presented by my world: 1. China is still runned by the Party, though it could be a more democratic variant or a more dictatoral variant. 2. Taiwan is still "de facto independent", it hasn't declare offical independence, but it hasn't been conquered by the mainland. 3. US is still opposing China's rise. How far US is planning to go to prevent China's rise though, can be changed. 4. There is a united semi-religious, semi-nationalistic group of terrorist army with global reach running amoke and causing huge amount of troubles to both US and China. They have no other common goal than to take down the current social norm and government of US, EU and China. Yes, this is the GLA from Command and Conquer Generals. 5. European is united and militarily allied with US and waried with Russia, however, they economically seek closer ties with China 6. Russia is an ally-of-convinence of China against US
2022/01/08
[ "https://worldbuilding.stackexchange.com/questions/221747", "https://worldbuilding.stackexchange.com", "https://worldbuilding.stackexchange.com/users/37911/" ]
You've already made enough change to make it happen. In our timeline, Ma Ying-jeou of the KMT was the leader of Taiwan from 2008-2016. Cross-straits relations improved greatly during his time in office. If you add in an ongoing major global terrorism threat against China, the US, and more, the focus would shift away from local disputes and US-China political rivalries towards improved security. Depending on when the terrorism began and how bad it was, reunification talks could easily have been well underway by 2015.
[Li](https://en.wikipedia.org/wiki/Li_Keqiang) became the ruler of China in 2012, not Xi. ----------------------------------------------------------------------------------------- Li is an economics minded communist who wants to improve internal production and economics. He wants to improve production in China, gain independence from America, and deal with bureaucracy. He's a member of the factions of the groundroot communists who didn't have a rich background, and is more concerned with China. Xi Jinping is a princling, a rich and well connected member of China's noble faction, son of a powerful revolutionary, and well connected. He seeks to restore China's glory through bloodshed and war and purge anyone disloyal to him or his faction of noble communists who inherited their positions. Xi won dominion over China due to his deeper connections with other princlings of China and the military in 2012. Just change that and China would likely have much better relationships with its neighbors. Have Xi die or be injured, and have Li step up to rule.
221,747
I need a way to change history so that Taiwan, in 2015, be using weapons manufactured and sold by mainland China as well as some US equipments--sort of like how Pakistan uses both Chinese and US weapons. There are some restrictions as presented by my world: 1. China is still runned by the Party, though it could be a more democratic variant or a more dictatoral variant. 2. Taiwan is still "de facto independent", it hasn't declare offical independence, but it hasn't been conquered by the mainland. 3. US is still opposing China's rise. How far US is planning to go to prevent China's rise though, can be changed. 4. There is a united semi-religious, semi-nationalistic group of terrorist army with global reach running amoke and causing huge amount of troubles to both US and China. They have no other common goal than to take down the current social norm and government of US, EU and China. Yes, this is the GLA from Command and Conquer Generals. 5. European is united and militarily allied with US and waried with Russia, however, they economically seek closer ties with China 6. Russia is an ally-of-convinence of China against US
2022/01/08
[ "https://worldbuilding.stackexchange.com/questions/221747", "https://worldbuilding.stackexchange.com", "https://worldbuilding.stackexchange.com/users/37911/" ]
**America First.** [![map minus the us](https://i.stack.imgur.com/fVWbw.png)](https://i.stack.imgur.com/fVWbw.png) <https://dabrownstein.com/2016/12/05/mapping-the-new-isolationism/> > > The very America First doctrine that catapulted Trump to the White > House stands, for all its championing of national self-interest, to be > best embodied by the removal of the United States from its role on the > global geopolitical map. And the removal of the United States and > England–achieved through the striking success of go-it-alone political > parties in both nations–seems to show just how outdated a five-color > map is to describe the world. > > > The US government is isolationist. Political leaders in the US are willfully ignorant and that is considered desirable by the electorate that put them there. The political leaders in power are extremely reluctant to support non-American foreign entities with money or supplies because they are foreigners. "Allies" are treated coolly and problems that do not involve American territory are considered someone else's problems. Such problems often do not even make the radar at the highest levels of the US government. Problems off the coast of China fall into this category. Career diplomats in the US carry on as best they can with foreign policy goals and world views carried over from earlier and more globally minded administrations. These persons are aware of the threat from the GLA and have a nuanced sense of the relationship with China. The "deep state" in the US is trying to keep things from getting out of control while hoping for eventual regime change in the US. These career diplomats and their counterparts in China are aware that a strong Chinese military presence in the Pacific would be noticed even by the current US political leaders. Both sides are worried about a hamhanded, disproportionate military or diplomatic response by the US. Taiwan however is considered an ally. Taiwanese military ventures in the Pacific would not be noticed by US political leaders or if noticed, dismissed. The Taiwanese are willing but undersupplied. With the US political climate there is not a good way to get American armaments and money to them or anyone else. The Chinese understand the gravity of the situation. They are willing to arm the Taiwanese on the sly. They are not going to make a big deal about it. They might even use a proxy brand based in India or Singapore. The Taiwanese also understand what is up. Internecine strife with the Chinese can be set aside to face the existential threat that is the GLA.
You've already made enough change to make it happen. In our timeline, Ma Ying-jeou of the KMT was the leader of Taiwan from 2008-2016. Cross-straits relations improved greatly during his time in office. If you add in an ongoing major global terrorism threat against China, the US, and more, the focus would shift away from local disputes and US-China political rivalries towards improved security. Depending on when the terrorism began and how bad it was, reunification talks could easily have been well underway by 2015.
221,747
I need a way to change history so that Taiwan, in 2015, be using weapons manufactured and sold by mainland China as well as some US equipments--sort of like how Pakistan uses both Chinese and US weapons. There are some restrictions as presented by my world: 1. China is still runned by the Party, though it could be a more democratic variant or a more dictatoral variant. 2. Taiwan is still "de facto independent", it hasn't declare offical independence, but it hasn't been conquered by the mainland. 3. US is still opposing China's rise. How far US is planning to go to prevent China's rise though, can be changed. 4. There is a united semi-religious, semi-nationalistic group of terrorist army with global reach running amoke and causing huge amount of troubles to both US and China. They have no other common goal than to take down the current social norm and government of US, EU and China. Yes, this is the GLA from Command and Conquer Generals. 5. European is united and militarily allied with US and waried with Russia, however, they economically seek closer ties with China 6. Russia is an ally-of-convinence of China against US
2022/01/08
[ "https://worldbuilding.stackexchange.com/questions/221747", "https://worldbuilding.stackexchange.com", "https://worldbuilding.stackexchange.com/users/37911/" ]
**America First.** [![map minus the us](https://i.stack.imgur.com/fVWbw.png)](https://i.stack.imgur.com/fVWbw.png) <https://dabrownstein.com/2016/12/05/mapping-the-new-isolationism/> > > The very America First doctrine that catapulted Trump to the White > House stands, for all its championing of national self-interest, to be > best embodied by the removal of the United States from its role on the > global geopolitical map. And the removal of the United States and > England–achieved through the striking success of go-it-alone political > parties in both nations–seems to show just how outdated a five-color > map is to describe the world. > > > The US government is isolationist. Political leaders in the US are willfully ignorant and that is considered desirable by the electorate that put them there. The political leaders in power are extremely reluctant to support non-American foreign entities with money or supplies because they are foreigners. "Allies" are treated coolly and problems that do not involve American territory are considered someone else's problems. Such problems often do not even make the radar at the highest levels of the US government. Problems off the coast of China fall into this category. Career diplomats in the US carry on as best they can with foreign policy goals and world views carried over from earlier and more globally minded administrations. These persons are aware of the threat from the GLA and have a nuanced sense of the relationship with China. The "deep state" in the US is trying to keep things from getting out of control while hoping for eventual regime change in the US. These career diplomats and their counterparts in China are aware that a strong Chinese military presence in the Pacific would be noticed even by the current US political leaders. Both sides are worried about a hamhanded, disproportionate military or diplomatic response by the US. Taiwan however is considered an ally. Taiwanese military ventures in the Pacific would not be noticed by US political leaders or if noticed, dismissed. The Taiwanese are willing but undersupplied. With the US political climate there is not a good way to get American armaments and money to them or anyone else. The Chinese understand the gravity of the situation. They are willing to arm the Taiwanese on the sly. They are not going to make a big deal about it. They might even use a proxy brand based in India or Singapore. The Taiwanese also understand what is up. Internecine strife with the Chinese can be set aside to face the existential threat that is the GLA.
[Li](https://en.wikipedia.org/wiki/Li_Keqiang) became the ruler of China in 2012, not Xi. ----------------------------------------------------------------------------------------- Li is an economics minded communist who wants to improve internal production and economics. He wants to improve production in China, gain independence from America, and deal with bureaucracy. He's a member of the factions of the groundroot communists who didn't have a rich background, and is more concerned with China. Xi Jinping is a princling, a rich and well connected member of China's noble faction, son of a powerful revolutionary, and well connected. He seeks to restore China's glory through bloodshed and war and purge anyone disloyal to him or his faction of noble communists who inherited their positions. Xi won dominion over China due to his deeper connections with other princlings of China and the military in 2012. Just change that and China would likely have much better relationships with its neighbors. Have Xi die or be injured, and have Li step up to rule.
22,464
I just finished making cookies. The dough was enough to make multiple batches. I only have one baking sheet. Every time a batch was ready, I used new parchment paper on the baking sheet. Is this necessary or could I just re-use the same piece of paper till all my cookies are baked?
2012/03/21
[ "https://cooking.stackexchange.com/questions/22464", "https://cooking.stackexchange.com", "https://cooking.stackexchange.com/users/4580/" ]
You can reuse parchment paper several times for your cookies (it also works for other dry dishes), depending on cooking time and temperature, with no problem. Change the paper when it gets dirty, dark and/or brittle as it may crumble beyond this point. I always do so with no difference in the results, saving both on money and waste.
Please do reuse the baking paper. It is non-biodegradable and non-recyclable because of the silicone so if you MUST use it, make it go several rounds for the sake of the environment. We always used to use butter paper (before it came in plastic containers) or plain unwaxed paper lunch wrap, greased if necessary. But for cookies, a greased tray works as well as baking paper, and buttering and flouring a tin does well for cakes. My mother lined her Christmas cake tin with several layers of greaseproof paper on the bottom and up the sides. And don’t forget that waxed lunch wrap is great for cheese, sandwiches and the top of jam jars. Jenny
38,487,323
**Problem** I am trying to push a returning variables value into an array. This is my code, however I'm returning an empty array and am not sure what's wrong. **JavaScript** ``` var my_arr = []; function foo() { var unitValue = parseFloat($('#unitVal1').val()); var percentFiner = parseFloat($('#percent1').val()); var total = unitValue * 1000; return my_arr.push({ unit: unitValue, percent: percentFiner }); } ```
2016/07/20
[ "https://Stackoverflow.com/questions/38487323", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6415924/" ]
for checking if specific files exists on a path use File.Exists(path), which will return a boolean indicating whether the file at path exists. In your case ``` if(File.Exists(@"D:\work\int\retail\store\export\one.txt")) { //do this } ``` In your example you are missing the filename. If you want to fetch the latest file from some directory use this code. ``` var directory = new DirectoryInfo(@"D:\work\int\retail\store\export"); var File = directory.GetFiles() .OrderByDescending(f => f.LastWriteTime) .First(); ``` You have to create a variavble of DirectoryInfo Class which takes directory path as parameter, Here I have passed your directory path `D:\work\int\retail\store\export`, Now `GetFiles()` function returns all the files inside the directory and I have sorted them in Descending order by `LastWriteTime` property of files, and fetched the first file which will be the latest file in the directory. Hope it helps. To get the .txt file only Please use below code. It will get you the latest txt file. ``` var directory = new DirectoryInfo(@"C:\Users\Saket\Downloads\"); var File = directory.GetFiles().Where(c=>c.Extension == ".txt") .OrderByDescending(f => f.LastWriteTime) .First(); ```
You need to mention your text file name in the path, if your txt file is called x.txt for example, you need to write the path as var FilePath = @"D:\work\int\retail\store\export\x.txt";
48,032,907
Consider this code: ``` template <typename T> class A { T x; // A bunch of functions }; std::size_t s = sizeof(A<double>); ``` Assume the `sizeof` operator is the only place where an instantiation of `A<double>` is required. Is it possible that the compiled program does **not** contain relevant code for `A<double>` (e.g. `A<double>::~A()`)?
2017/12/30
[ "https://Stackoverflow.com/questions/48032907", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5958455/" ]
> > Is it possible that the compiled program does not contain relevant code for `A<double>` (e.g. `A<double>::~A()`)? > > > Sure that's possible. ``` std::size_t s = sizeof(A<double>); ``` is just a compile time operation, and doesn't need any runtime instance of `A<double>`, so there's no need for constructors, destructors, or other *relevant code*. --- Even if there would be explicit instantiations of template function code like follows ``` if(sizeof(A<double>) <= 4) { A<double> a; // Instantiation of constructor and destructor a.x = 3.5; } ``` the compiler is allowed to optimize that code away.
Yes, sizeof() does not need the member functions and so they may well not be generated. All sizeof needs are the data members.
48,032,907
Consider this code: ``` template <typename T> class A { T x; // A bunch of functions }; std::size_t s = sizeof(A<double>); ``` Assume the `sizeof` operator is the only place where an instantiation of `A<double>` is required. Is it possible that the compiled program does **not** contain relevant code for `A<double>` (e.g. `A<double>::~A()`)?
2017/12/30
[ "https://Stackoverflow.com/questions/48032907", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5958455/" ]
The class will be instantiated, but the compiler must not instantiate any member function definition, [temp.inst]/1: > > [...] the class template specialization is **implicitly instantiated when** the specialization is referenced in a context that **requires a completely-defined object type**[...] > > > [temp.inst]/2: > > The implicit instantiation of a class template specialization causes the **implicit instantiation of the declarations, but not of the definitions**, default arguments, or noexcept-specifiers **of the class member functions**, [...] > > >
> > Is it possible that the compiled program does not contain relevant code for `A<double>` (e.g. `A<double>::~A()`)? > > > Sure that's possible. ``` std::size_t s = sizeof(A<double>); ``` is just a compile time operation, and doesn't need any runtime instance of `A<double>`, so there's no need for constructors, destructors, or other *relevant code*. --- Even if there would be explicit instantiations of template function code like follows ``` if(sizeof(A<double>) <= 4) { A<double> a; // Instantiation of constructor and destructor a.x = 3.5; } ``` the compiler is allowed to optimize that code away.
48,032,907
Consider this code: ``` template <typename T> class A { T x; // A bunch of functions }; std::size_t s = sizeof(A<double>); ``` Assume the `sizeof` operator is the only place where an instantiation of `A<double>` is required. Is it possible that the compiled program does **not** contain relevant code for `A<double>` (e.g. `A<double>::~A()`)?
2017/12/30
[ "https://Stackoverflow.com/questions/48032907", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5958455/" ]
> > Is it possible that the compiled program does not contain relevant code for `A<double>` (e.g. `A<double>::~A()`)? > > > Sure that's possible. ``` std::size_t s = sizeof(A<double>); ``` is just a compile time operation, and doesn't need any runtime instance of `A<double>`, so there's no need for constructors, destructors, or other *relevant code*. --- Even if there would be explicit instantiations of template function code like follows ``` if(sizeof(A<double>) <= 4) { A<double> a; // Instantiation of constructor and destructor a.x = 3.5; } ``` the compiler is allowed to optimize that code away.
I have built this code: ``` #include <cstddef> template <typename T> class A { T x; // A bunch of functions }; int main(const int argc, const char* argv[]) { std::size_t s = sizeof(A<double>); } ``` And launching objdump I get this output: ``` $ objdump -t a.out a.out: file format Mach-O 64-bit x86-64 SYMBOL TABLE: 0000000100000000 g F __TEXT,__text __mh_execute_header 0000000100000f90 g F __TEXT,__text _main 0000000000000000 *UND* dyld_stub_binder ``` Where we can see that no symbols associated to constructor/destructor have been generated.
48,032,907
Consider this code: ``` template <typename T> class A { T x; // A bunch of functions }; std::size_t s = sizeof(A<double>); ``` Assume the `sizeof` operator is the only place where an instantiation of `A<double>` is required. Is it possible that the compiled program does **not** contain relevant code for `A<double>` (e.g. `A<double>::~A()`)?
2017/12/30
[ "https://Stackoverflow.com/questions/48032907", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5958455/" ]
The class will be instantiated, but the compiler must not instantiate any member function definition, [temp.inst]/1: > > [...] the class template specialization is **implicitly instantiated when** the specialization is referenced in a context that **requires a completely-defined object type**[...] > > > [temp.inst]/2: > > The implicit instantiation of a class template specialization causes the **implicit instantiation of the declarations, but not of the definitions**, default arguments, or noexcept-specifiers **of the class member functions**, [...] > > >
Yes, sizeof() does not need the member functions and so they may well not be generated. All sizeof needs are the data members.
48,032,907
Consider this code: ``` template <typename T> class A { T x; // A bunch of functions }; std::size_t s = sizeof(A<double>); ``` Assume the `sizeof` operator is the only place where an instantiation of `A<double>` is required. Is it possible that the compiled program does **not** contain relevant code for `A<double>` (e.g. `A<double>::~A()`)?
2017/12/30
[ "https://Stackoverflow.com/questions/48032907", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5958455/" ]
The class will be instantiated, but the compiler must not instantiate any member function definition, [temp.inst]/1: > > [...] the class template specialization is **implicitly instantiated when** the specialization is referenced in a context that **requires a completely-defined object type**[...] > > > [temp.inst]/2: > > The implicit instantiation of a class template specialization causes the **implicit instantiation of the declarations, but not of the definitions**, default arguments, or noexcept-specifiers **of the class member functions**, [...] > > >
I have built this code: ``` #include <cstddef> template <typename T> class A { T x; // A bunch of functions }; int main(const int argc, const char* argv[]) { std::size_t s = sizeof(A<double>); } ``` And launching objdump I get this output: ``` $ objdump -t a.out a.out: file format Mach-O 64-bit x86-64 SYMBOL TABLE: 0000000100000000 g F __TEXT,__text __mh_execute_header 0000000100000f90 g F __TEXT,__text _main 0000000000000000 *UND* dyld_stub_binder ``` Where we can see that no symbols associated to constructor/destructor have been generated.
1,391,953
I am working with a collection of cards. On each card is written a set of numbers $1\le n\le N$ in ascending order. When I arrange the cards in lexicographic order on the table, no two adjacent cards share a number. The cards are designed so that when I pick a number $r$, select all the cards containing $r$, and sum the smallest numbers on each of those cards, I get the total $r$. The idea is that I can ask a friend to choose a number $1\le n\le N$, and ask them to identify the cards containing that number. From that information I can identify the number by doing a simple sum. For example if $N=4$ the three sets $\{1,4\}, \{2\}$ and $\{3,4\}$ could be written on the cards. They are in lexicographic order, no adjacent cards share a number, and any number $1\le n\le 4$ can be identified. If you choose $1$ for example, there is a single card lowest value $1$. With $4$ you pick up two cards values $1+3=4$ Given $N$ what is the smallest number of cards I need? Given the number of cards, what is the largest $N$ possible? In fact any of the five numbers $0\le n\le 4$ can be identified from this set. --- **Solution:** [to unedited question] If n is odd then solution is (n+1)/2. if n is even then solution is n/2+1. But i am getting this is a wrong answer.Where i have made a mistake? --- Note the [problem appears here](https://www.codechef.com/AUG15/problems/ADMAG) and seems to be popular mid August 2015
2015/08/10
[ "https://math.stackexchange.com/questions/1391953", "https://math.stackexchange.com", "https://math.stackexchange.com/users/261079/" ]
Do you mean like this: With four cards the sets $\{1,4,6\}; \{2,7\}; \{3,4\}; \{5,6,7\}$ allow you to distinguish between the integers $1\le n \le 7$ (and you get zero as a bonus). With five cards I get $\{1,4,6,9,12\}; \{2,7,10\}; \{3,4,11,12\}; \{5,6,7\};\{8,9,10,11,12\}$ which get me to $12$ - that seems better than you have done. I think the pattern I can see in the lowest elements of these sets will continue - but I'll leave that for you to explore - that would give a different answer from the one you have. --- > > To expand a bit. The lowest number on each card is a Fibonacci Number. Every positive integer can be written as the sum of non-consecutive Fibonacci numbers - so we can place every integer on such a card. > > >
I think the answer is ``` For 13 to 20 The answer is 6 10 11 and 12 (1,4,6,9,12) (2,7,2) (3,4,11,12) (5,6,7) (8,9,2,11,12) 5 9 (1,4,6,9) (2,7) (3,4) (5,6,7) (8,9) 5 8 (1,4,6) (2,7) (3,4) (5,6,7) (8) 5 7 (1,4,6) (2,7) (3,4) (5,6,7) 4 6 (1,4,6) (2) (3,4) (5,6) 4 5 (1,4) (2) (3,4) (5) 4 4 (1,4) (2) (3,4) 3 3 (1) (2) (3) 3 2 (1) (2) 2 1 (1) 1 ``` How to find for n term is still confusing
1,391,953
I am working with a collection of cards. On each card is written a set of numbers $1\le n\le N$ in ascending order. When I arrange the cards in lexicographic order on the table, no two adjacent cards share a number. The cards are designed so that when I pick a number $r$, select all the cards containing $r$, and sum the smallest numbers on each of those cards, I get the total $r$. The idea is that I can ask a friend to choose a number $1\le n\le N$, and ask them to identify the cards containing that number. From that information I can identify the number by doing a simple sum. For example if $N=4$ the three sets $\{1,4\}, \{2\}$ and $\{3,4\}$ could be written on the cards. They are in lexicographic order, no adjacent cards share a number, and any number $1\le n\le 4$ can be identified. If you choose $1$ for example, there is a single card lowest value $1$. With $4$ you pick up two cards values $1+3=4$ Given $N$ what is the smallest number of cards I need? Given the number of cards, what is the largest $N$ possible? In fact any of the five numbers $0\le n\le 4$ can be identified from this set. --- **Solution:** [to unedited question] If n is odd then solution is (n+1)/2. if n is even then solution is n/2+1. But i am getting this is a wrong answer.Where i have made a mistake? --- Note the [problem appears here](https://www.codechef.com/AUG15/problems/ADMAG) and seems to be popular mid August 2015
2015/08/10
[ "https://math.stackexchange.com/questions/1391953", "https://math.stackexchange.com", "https://math.stackexchange.com/users/261079/" ]
Do you mean like this: With four cards the sets $\{1,4,6\}; \{2,7\}; \{3,4\}; \{5,6,7\}$ allow you to distinguish between the integers $1\le n \le 7$ (and you get zero as a bonus). With five cards I get $\{1,4,6,9,12\}; \{2,7,10\}; \{3,4,11,12\}; \{5,6,7\};\{8,9,10,11,12\}$ which get me to $12$ - that seems better than you have done. I think the pattern I can see in the lowest elements of these sets will continue - but I'll leave that for you to explore - that would give a different answer from the one you have. --- > > To expand a bit. The lowest number on each card is a Fibonacci Number. Every positive integer can be written as the sum of non-consecutive Fibonacci numbers - so we can place every integer on such a card. > > >
Suppose with $r$ cards I can reach a total $N\_r$. With $1$ card I can reach $1$ and with no cards I can reach $0$. I add another card. If I want the total $N\_r+1$, I have to include it on card $r+1$. I can get $N\_r+2$ by writing it on card $r+1$ and on the cards containing $1$. I can get $N\_r+k$ on card $r+1$ (the lowest value on this card is $N\_r+1$) by writing it on all the cards containing $k-1$ and on card $r+1$ to get the total $k-1+N\_r+1=N\_r+k$ This goes wrong for the for the first value of $k-1$ written on card $r$, and this value is $N\_{r-1}+1$ so we are fine up to $k=N\_{r-1}+1$ Putting this together we find we can reach $N\_{r+1}=N\_r+N\_{r-1}+1$ --- The lowest number on the next card is the least number which cannot be constructed from the previous cards. It is easy to see that if the sequence falls behind because the early cards are inefficient, it can never catch up.
58,659,537
We are getting "Operation was cancelled" exception while Azure Indexer is running for larger records (around 2M+). Here are the log details - "The operation was canceled. Unable to read data from the transport connection: The I/O operation has been aborted because of either a thread exit or an application request. The I/O operation has been aborted because of either a thread exit or an application request " We are running the indexer under thread. It is working for smaller records but for larger records (1M+), it is throwing Socket Exception. Does anyone saw this error while running Azure Indexer for larger records (running for long time)? (we have already increase httpclient timeout to maximum value for serviceClient object.)
2019/11/01
[ "https://Stackoverflow.com/questions/58659537", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11903910/" ]
Use [`numpy.tile`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.tile.html): ``` cols = dataset.columns length = dataset_ts.shape[0] df_new = pd.DataFrame({'new': np.tile(cols, length)}) print (df_new) new 0 a 1 b 2 c 3 d 4 a 5 b 6 c 7 d 8 a 9 b 10 c ... ... ... ```
You could use [itertools.cycle](https://docs.python.org/3/library/itertools.html#itertools.cycle) + [itertools.islice](https://docs.python.org/3/library/itertools.html#itertools.islice): ``` import pandas as pd from itertools import cycle, islice length = 1942 data = ['a', 'b', 'c', 'd'] result = pd.DataFrame({'new': list(islice(cycle(data), length))}) print(result) ``` **Output** ``` new 0 a 1 b 2 c 3 d 4 a ... .. 1937 b 1938 c 1939 d 1940 a 1941 b [1942 rows x 1 columns] ``` As an alternative you could use [zip](https://docs.python.org/3/library/functions.html#zip) + [range](https://docs.python.org/3/library/functions.html#func-range) + cycle in a list comprehension: ``` result = pd.DataFrame({'new': [e for _, e in zip(range(length), cycle(data))] }) ```
50,175,053
I have something like : ``` #define NBR 42 #define THE_ANS_IS theAnsIsNBR ``` Currently the second macro is expand as 'theAnsIsNBR' as expected, but i want it to be expand as 'theAnsIs42' i am not sure if it is even possible !?
2018/05/04
[ "https://Stackoverflow.com/questions/50175053", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7758765/" ]
``` #define Paste(x, y) x##y #define Expand(x, y) Paste(x, y) #define NBR 42 #define THE_ANS_IS Expand(theAnsIs, NBR) ```
``` #define _CONCAT(x,y) x ## y #define CONCAT(x,y) _CONCAT(x,y) #define NBR 42 #define THE_ANS_IS CONCAT(theAnsIs, NBR) ``` This works because `##` concatenates two tokens. The problem is, they aren't expanded first. But calling another macro on them expands them, therefore you need to nest two function-like macros here.
18,622
I would like to build 3d applications that are targeted at old PCs for education. Which 3d engine do you recommend to use? What technology should I use or approach? I would like to avoid Unity3d or any other non-free frameworks, as this work I'm doing is voluntarily. It's main idea is to make learning fun, using 3d simple gaming. The target PCs are old single cpu Pentium4, or maybe even p3 (: Thank a lot for helping.
2011/10/17
[ "https://gamedev.stackexchange.com/questions/18622", "https://gamedev.stackexchange.com", "https://gamedev.stackexchange.com/users/3689/" ]
Check out the [Unity engine](http://unity3d.com/unity/engine/rendering). They've done a lot of work on making their tech work with a very wide range of hardware, and have nice tools like graphics emulation so you can see what an older machine would be drawing while on a newer machine. It's relatively cheap and has a really good workflow, so as long as you're not trying to squeeze all the performance you can out of an older machine it's hard to beat it's price/value ratio. Fundamentally, though, if you're dealing with old PCs, you're going to be limiting yourself to something probably DX7 level or so. OpenGL drivers are notoriously bad, so I'd suggest going the DirectX route. You're probably not going to have pixel shaders (those came out with DX8/9 cards I think), so you need to do everything fixed function. Unity handles all of this for you. Edit: You can download an use Unity free of charge, with certain restrictions. It doesn't play well with team development, but if you're doing small things by yourself then it's more than capable.
There are many solutions. You have to make sure you know the following * What are your skills with programming languages? * What license is acceptable? * Which OS(s) do you target? (Unix, Linux, Windows, Mac OS...) * What 3D software will you use to create the assets? * How will you manage your assets? * What kind of interaction and environment do you want to create You can answer a few of these questions while looking for an engine, but the more specific you are the more efficient you will be at choosing a 3D engine. The SDL engine is a great fit usually if you keep a low polycount. <http://www.libsdl.org/> If you need a first person perspective maybe a game engine will do? id Tech 3 Is well known and has support in its own community. I can attest it is good at running on "old hardware". <ftp://ftp.idsoftware.com/idstuff/source/quake3-1.32b-source.zip> In the meantime Google and Wikipedia lists might be helpful. Good luck.
18,622
I would like to build 3d applications that are targeted at old PCs for education. Which 3d engine do you recommend to use? What technology should I use or approach? I would like to avoid Unity3d or any other non-free frameworks, as this work I'm doing is voluntarily. It's main idea is to make learning fun, using 3d simple gaming. The target PCs are old single cpu Pentium4, or maybe even p3 (: Thank a lot for helping.
2011/10/17
[ "https://gamedev.stackexchange.com/questions/18622", "https://gamedev.stackexchange.com", "https://gamedev.stackexchange.com/users/3689/" ]
Check out the [Unity engine](http://unity3d.com/unity/engine/rendering). They've done a lot of work on making their tech work with a very wide range of hardware, and have nice tools like graphics emulation so you can see what an older machine would be drawing while on a newer machine. It's relatively cheap and has a really good workflow, so as long as you're not trying to squeeze all the performance you can out of an older machine it's hard to beat it's price/value ratio. Fundamentally, though, if you're dealing with old PCs, you're going to be limiting yourself to something probably DX7 level or so. OpenGL drivers are notoriously bad, so I'd suggest going the DirectX route. You're probably not going to have pixel shaders (those came out with DX8/9 cards I think), so you need to do everything fixed function. Unity handles all of this for you. Edit: You can download an use Unity free of charge, with certain restrictions. It doesn't play well with team development, but if you're doing small things by yourself then it's more than capable.
You might check out Ogre3D (<http://www.ogre3d.org/>) as a starting point. Ogre3D isn't necessarily a full game development engine, but it is a solid 3D rendering system. There are various demos you can down Also, check out <http://www.ogre3d.org/tikiwiki/Projects+Using+OGRE> where a number of game engines listed that use Ogre3D.
18,622
I would like to build 3d applications that are targeted at old PCs for education. Which 3d engine do you recommend to use? What technology should I use or approach? I would like to avoid Unity3d or any other non-free frameworks, as this work I'm doing is voluntarily. It's main idea is to make learning fun, using 3d simple gaming. The target PCs are old single cpu Pentium4, or maybe even p3 (: Thank a lot for helping.
2011/10/17
[ "https://gamedev.stackexchange.com/questions/18622", "https://gamedev.stackexchange.com", "https://gamedev.stackexchange.com/users/3689/" ]
You might check out Ogre3D (<http://www.ogre3d.org/>) as a starting point. Ogre3D isn't necessarily a full game development engine, but it is a solid 3D rendering system. There are various demos you can down Also, check out <http://www.ogre3d.org/tikiwiki/Projects+Using+OGRE> where a number of game engines listed that use Ogre3D.
There are many solutions. You have to make sure you know the following * What are your skills with programming languages? * What license is acceptable? * Which OS(s) do you target? (Unix, Linux, Windows, Mac OS...) * What 3D software will you use to create the assets? * How will you manage your assets? * What kind of interaction and environment do you want to create You can answer a few of these questions while looking for an engine, but the more specific you are the more efficient you will be at choosing a 3D engine. The SDL engine is a great fit usually if you keep a low polycount. <http://www.libsdl.org/> If you need a first person perspective maybe a game engine will do? id Tech 3 Is well known and has support in its own community. I can attest it is good at running on "old hardware". <ftp://ftp.idsoftware.com/idstuff/source/quake3-1.32b-source.zip> In the meantime Google and Wikipedia lists might be helpful. Good luck.
139,663
I have noticed that as soon as I save an interaction in Journey Builder, SFMC automatically adds SubscriberKey and EmailAddress fields to the Event Source DE (even when I already have an email address field) Am I supposed to use these auto generated fields then? Or Can I just ignore these? Is there a way to stop this behavior?
2016/09/06
[ "https://salesforce.stackexchange.com/questions/139663", "https://salesforce.stackexchange.com", "https://salesforce.stackexchange.com/users/26216/" ]
These fields are reserved for system use. I would not recommend removing them or populating values into these fields as this may result in unexpected behavior. I'm not exactly sure what they are used for as there is no documentation on this. Also note that when creating Event Source Data Extensions, you should avoid creating fields named 'SubscriberKey' and 'EmailAddress' as this will result in issues (I've experienced this before).
This is a confirmed bug. The downside is if you have a separate email address field (from salesforce for example) the addition of these fields by the triggered send in the journey will break the ability to use the data extension for sending test emails. No idea if it will be fixed?
10,764,160
How can I draw a simple BAR? Like this: ![simple bar](https://i.stack.imgur.com/xTL6d.png) Thank you.
2012/05/26
[ "https://Stackoverflow.com/questions/10764160", "https://Stackoverflow.com", "https://Stackoverflow.com/users/962508/" ]
Use MySQL's [`STR_TO_DATE()`](http://dev.mysql.com/doc/en/date-and-time-functions.html#function_str-to-date) function: ``` INSERT INTO my_table VALUES (STR_TO_DATE('26/5/12', '%e/%c/%y')) ```
$date = date('d/m/Y'); $date = strtotime($date); //in unix time stamp format
10,764,160
How can I draw a simple BAR? Like this: ![simple bar](https://i.stack.imgur.com/xTL6d.png) Thank you.
2012/05/26
[ "https://Stackoverflow.com/questions/10764160", "https://Stackoverflow.com", "https://Stackoverflow.com/users/962508/" ]
You need to use php's `date()` function along with `strtotime()` to convert date to any format you want. MySQL database stores the date in `YY-MM-DD` format for datetime datatype, so if for example you have a date ``` $date = '26/05/2012'; ``` You can convert it by using [date()](http://in.php.net/manual/en/function.date.php) and [strtotime()](http://in.php.net/strtotime) ``` $formatDate = date('Y-m-d', strtotime('26/05/2012')); ``` This will convert the date from `26/05/2012` to `2012-05-26` which then can be inserted into the database. If you are using a timestamp datatype to store the date in your database, then all you need is to convert the current date into unix timestamp and store in database for example. ``` $date = strtotime('26/05/2012'); //this will convert the date to unix timestamp ``` **Update:** as pointed out by @wallyk (thank you), strtotime() does not handles `dd/mm/yy` format. the fix is to replace the slash `/` by `-`m below code should work for you. ``` date('Y-m-d', strtotime(str_replace('/', '-', '26/05/2012'))); ```
Basically american date format is `MM/DD/YYYY` and you are providing `DD/MM/YYYY` so thats why `startotime()` returns you a null values on this input; and i prefer you must follow standard date format of american `(MM/DD/YYYY)` because if you are using mentioned format of date that will create more problems as well in different places .. if you check by this ``` echo date('Y-m-d', strtotime('05/26/2012') ); ``` and it is working fine ..
10,764,160
How can I draw a simple BAR? Like this: ![simple bar](https://i.stack.imgur.com/xTL6d.png) Thank you.
2012/05/26
[ "https://Stackoverflow.com/questions/10764160", "https://Stackoverflow.com", "https://Stackoverflow.com/users/962508/" ]
Use MySQL's [`STR_TO_DATE()`](http://dev.mysql.com/doc/en/date-and-time-functions.html#function_str-to-date) function: ``` INSERT INTO my_table VALUES (STR_TO_DATE('26/5/12', '%e/%c/%y')) ```
you could change your DATE column into a String Column and insert the data when ever you want 2 check if the date is right you can use a regular expression to do so
10,764,160
How can I draw a simple BAR? Like this: ![simple bar](https://i.stack.imgur.com/xTL6d.png) Thank you.
2012/05/26
[ "https://Stackoverflow.com/questions/10764160", "https://Stackoverflow.com", "https://Stackoverflow.com/users/962508/" ]
Try this: ``` $mysqldate = date("m/d/y g:i A", $datetime); ```
you could change your DATE column into a String Column and insert the data when ever you want 2 check if the date is right you can use a regular expression to do so
10,764,160
How can I draw a simple BAR? Like this: ![simple bar](https://i.stack.imgur.com/xTL6d.png) Thank you.
2012/05/26
[ "https://Stackoverflow.com/questions/10764160", "https://Stackoverflow.com", "https://Stackoverflow.com/users/962508/" ]
Try this: ``` $mysqldate = date("m/d/y g:i A", $datetime); ```
Basically american date format is `MM/DD/YYYY` and you are providing `DD/MM/YYYY` so thats why `startotime()` returns you a null values on this input; and i prefer you must follow standard date format of american `(MM/DD/YYYY)` because if you are using mentioned format of date that will create more problems as well in different places .. if you check by this ``` echo date('Y-m-d', strtotime('05/26/2012') ); ``` and it is working fine ..
10,764,160
How can I draw a simple BAR? Like this: ![simple bar](https://i.stack.imgur.com/xTL6d.png) Thank you.
2012/05/26
[ "https://Stackoverflow.com/questions/10764160", "https://Stackoverflow.com", "https://Stackoverflow.com/users/962508/" ]
$date = date('d/m/Y'); $date = strtotime($date); //in unix time stamp format
you could change your DATE column into a String Column and insert the data when ever you want 2 check if the date is right you can use a regular expression to do so
10,764,160
How can I draw a simple BAR? Like this: ![simple bar](https://i.stack.imgur.com/xTL6d.png) Thank you.
2012/05/26
[ "https://Stackoverflow.com/questions/10764160", "https://Stackoverflow.com", "https://Stackoverflow.com/users/962508/" ]
You need to use php's `date()` function along with `strtotime()` to convert date to any format you want. MySQL database stores the date in `YY-MM-DD` format for datetime datatype, so if for example you have a date ``` $date = '26/05/2012'; ``` You can convert it by using [date()](http://in.php.net/manual/en/function.date.php) and [strtotime()](http://in.php.net/strtotime) ``` $formatDate = date('Y-m-d', strtotime('26/05/2012')); ``` This will convert the date from `26/05/2012` to `2012-05-26` which then can be inserted into the database. If you are using a timestamp datatype to store the date in your database, then all you need is to convert the current date into unix timestamp and store in database for example. ``` $date = strtotime('26/05/2012'); //this will convert the date to unix timestamp ``` **Update:** as pointed out by @wallyk (thank you), strtotime() does not handles `dd/mm/yy` format. the fix is to replace the slash `/` by `-`m below code should work for you. ``` date('Y-m-d', strtotime(str_replace('/', '-', '26/05/2012'))); ```
you could change your DATE column into a String Column and insert the data when ever you want 2 check if the date is right you can use a regular expression to do so
10,764,160
How can I draw a simple BAR? Like this: ![simple bar](https://i.stack.imgur.com/xTL6d.png) Thank you.
2012/05/26
[ "https://Stackoverflow.com/questions/10764160", "https://Stackoverflow.com", "https://Stackoverflow.com/users/962508/" ]
You need to use php's `date()` function along with `strtotime()` to convert date to any format you want. MySQL database stores the date in `YY-MM-DD` format for datetime datatype, so if for example you have a date ``` $date = '26/05/2012'; ``` You can convert it by using [date()](http://in.php.net/manual/en/function.date.php) and [strtotime()](http://in.php.net/strtotime) ``` $formatDate = date('Y-m-d', strtotime('26/05/2012')); ``` This will convert the date from `26/05/2012` to `2012-05-26` which then can be inserted into the database. If you are using a timestamp datatype to store the date in your database, then all you need is to convert the current date into unix timestamp and store in database for example. ``` $date = strtotime('26/05/2012'); //this will convert the date to unix timestamp ``` **Update:** as pointed out by @wallyk (thank you), strtotime() does not handles `dd/mm/yy` format. the fix is to replace the slash `/` by `-`m below code should work for you. ``` date('Y-m-d', strtotime(str_replace('/', '-', '26/05/2012'))); ```
Try this: ``` $mysqldate = date("m/d/y g:i A", $datetime); ```