Posts

Showing posts from August 30, 2018

In Laravel, the best way to pass different types of flash messages in the session

Image
Clash Royale CLAN TAG #URR8PPP In Laravel, the best way to pass different types of flash messages in the session I'm making my first app in Laravel and am trying to get my head around the session flash messages. As far as I'm aware in my controller action I can set a flash message either by going Redirect::to('users/login')->with('message', 'Thanks for registering!'); //is this actually OK? For the case of redirecting to another route, or Session::flash('message', 'This is a message!'); In my master blade template I'd then have: @if(Session::has('message')) <p class="alert alert-info"> Session::get('message') </p> @endif As you may have noticed I'm using Bootstrap 3 in my app and would like to make use of the different message classes: alert-info , alert-warning , alert-danger etc. alert-info alert-warning alert-danger Assuming that in my controller I know what type of message I'

AppleScript + QuickTime — batch trim + create edit + export video

Image
Clash Royale CLAN TAG #URR8PPP AppleScript + QuickTime — batch trim + create edit + export video I'm looking for some help. What I'm trying to do is to have AppleScript open a folder of videos, then get QuickTime to randomly trim them (as in the start frame from where it trims) and then have a variable length of the trim itself (say random between 1sec to 2sec as boundaries for the new 'clip'). After trimming and creating the new 'edit' (it would add this new random trimming to all the videos in the folder then add to timeline). QT then needs to export the edit to a new folder. In summary, trying to make a quick auto-editing app that can just pick random selects from a folder full of videos then save an edit to a new video. ANY help with this would be hugely appreciated! I've been trying but to nail avail (I'm fairly new to coding to going around in circles). Thanks! Dylan My advice would be to avoid trying to AppleScript QuickTime as it's

Add transparent picture over plot

Image
Clash Royale CLAN TAG #URR8PPP Add transparent picture over plot My python script below adds a picture (a generated rectangle on this simple example) and GPS track on a map generated with Basemap module. Now I would like to make both track an rectangle transparent. No problem for the track via alpha kwarg but I cannot figure how to do it for the picture. alpha import matplotlib.pyplot as plt from PIL import Image from matplotlib.offsetbox import AnnotationBbox, OffsetImage from mpl_toolkits.basemap import Basemap lats = [ 45, 15 ] lons = [ 0 , 100 ] fig = plt.figure( dpi = 300 ) ax = plt.subplot(111) myBaseMap = Basemap( projection='ortho', lat_0=lats[-1], lon_0=lons[-1] ) myBaseMap.bluemarble() planeImg = Image.new('RGB', (600, 300), color = 'red') planeXY = myBaseMap( lons[-1], lats[-1] ) x,y = myBaseMap( lons, lats ) plt.plot( x, y, color='r', alpha=0.5, linewidth=3 ) imagebox = OffsetImage( planeImg , zoom=.4 ) ab = AnnotationBbox( imagebox, myBas

Speed difference between inserting html and changing display style property

Image
Clash Royale CLAN TAG #URR8PPP Speed difference between inserting html and changing display style property Assuming you have a relatively small piece of HTML (let's say under 100 tags and <4KB in size) and you want to occasionally display and hide it from your user (think menu, modal... etc). Is the fastest approach to hide and show it using css, such as: //Hide: document.getElementById('my_element').style.display = 'none'; //Show: document.getElementById('my_element').style.display = 'block'; Or to insert and remove it: //Hide document.getElementById('my_element_container').innerHTML = ''; //Show: const my_element_html = contents of the element; document.getElementById('my_element_container').innerHTML = my_element_html; // Note: insertAdjacentHTML is obviously faster when the container has other elements, but I'm showcasing this using innerHTML to get my point across, not necessarily because it's always the mo

Difference between malloc and calloc with std::string

Image
Clash Royale CLAN TAG #URR8PPP Difference between malloc and calloc with std::string I have recently gotten into C++ and I've encountered a problem working with malloc. The code below does not print out "Success" (Program crashes with exit code 0xC0000005) whereas if I use calloc instead everything works fine. int main() std::string* pointer = (std::string*) malloc(4 * sizeof(std::string)); for(int i = 0; i < 4; i++) pointer[i] = "test"; std::cout << "Success" << std::endl; return 0; The code below works. calloc(4, sizeof(std::string)); Malloc also works if I allocate like 12 times the normal amount. Can somebody explain this behavior ? Does this have something to do with std::string ? Consider reading a good book. – Passer By Aug 12 at 12:06 Don't use malloc / calloc / realloc / free in C++. Use new / new / delete / delete that properly call constructors/destructors. Or even better, use containers and/or smart

If this earth were cube shaped would it be possible during Magellanic era using a float ship to figure out that the earth is cube shaped?

Image
Clash Royale CLAN TAG #URR8PPP If this earth were cube shaped would it be possible during Magellanic era using a float ship to figure out that the earth is cube shaped? If this earth were cubed shape would it be possible for Magellan to prove that the earth is cube-shaped without going to space and looking at earth? It might seem strange to think that earth might be shaped like a cube. Remember I am not saying perfect cube but rounded cube at the edge. Do you remember Comet 67P/Churyumov-Gerasimenko where spacecraft Rosetta landed? It was odd shaped. So couldn't earth be odd shaped other than a sphere? If Magellan had to prove what the shape of the earth is like that then would it be possible for him to prove that earth is cube-shaped using his floating ship? I just want to know if it were possible. I don't think earth could be cube shaped... This was raised in another question before but you have to remember that earth is a lot larger than a comet made out of rock and ic

using longest common substring solution for solving longest palindrome substring

Image
Clash Royale CLAN TAG #URR8PPP using longest common substring solution for solving longest palindrome substring I was trying to solved longest palindrome substring problem using longest common substring by reversing the main string. But my algo is failing for below examples: "abadefdaba" expected outcome : aba but i m getting output as abad. Seems I am missing some condition in my program: string longestPalindrome(string A) int **dp = new int*[A.length()+1]; for(int i=0;i<=A.length();i++) dp[i] = new int[A.length()]; string B = A; reverse(B.begin(), B.end()); int res = INT_MIN; int max_i = INT_MIN; for(int i=0;i<= A.length();i++) for(int j=0;j<=A.length();j++) if(i==0 return A.substr(max_i-res,res); Any palindrome that occurs in A will also occur in the reversal of A , but the converse is not true. Your program never checks to see whether its output is a palindrome. – Joe Farrell Aug 12 at 13:12 A A By clicking "Post Your Answer&quo

What's the right way to float right or left using the material-ui appbar with material-ui-next?

Image
Clash Royale CLAN TAG #URR8PPP What's the right way to float right or left using the material-ui appbar with material-ui-next? I can't figure out if I'm using the right approach to get the login/logout buttons to float right in while using material-ui-next ("material-ui": "^1.0.0-beta.22",) It seems they removed iconElementRight= from the api. Do we have to use the <Grid> now in the appbar? It feels kinds of cludgy. What's the right way to float buttons (e.g. login) in the appbar? iconElementRight= <Grid> <AppBar position="static"> <Toolbar> <Grid container spacing=24> <Grid item xs=11> <Typography type="title" color="inherit"> Title </Typography> </Grid> <Grid item xs=1> <div> <HeartIcon /> <Button raised color="accent"> Login </Button> </div> </Grid> </Grid> </Toolbar> </AppBar

Laravel validation rule for JSON object

Image
Clash Royale CLAN TAG #URR8PPP Laravel validation rule for JSON object Is it possible to make validation rule for JSON object in Laravel? I'm using Laravel 5.6 version. email "status": "", // required "merge_fields": "FNAME": "", // required "LNAME": "", // required "ADDRESS": "", "PHONE": "" how you are sending it to laravel? share that code? – C2486 Aug 22 at 3:09 By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Rewrite HTML file using only JavaScript in header

Image
Clash Royale CLAN TAG #URR8PPP Rewrite HTML file using only JavaScript in header I have an HTML file with this code: <html> <head> <script> function saveTextArea() var newText = document.getElementById("textArea"); <!-- rewrite this file with <textarea id = 'textArea'> newText </textarea> --> </script> </head> <body> <button id = 'saveBtn'>Save</button> <br> <textarea id='textArea1'>MyText</textarea> </body> </html> My use case is: In the browser, I rewrite what is in textarea. After, I press on the save button. In that moment I want to rewrite my HTML file with the new text in textarea, such that when reopening HTML file it will have a new text. I want to do that without additional files. Can it be done using only javascript in the header? If yes, how? It is recommended that you use a server-side language for this. – hev1 Aug 12 at 13:

Does memory fencing blocks threads in multi-core CPUs?

Image
Clash Royale CLAN TAG #URR8PPP Does memory fencing blocks threads in multi-core CPUs? I was reading the Intel instruction set guide 64-ia-32 guide to get an idea on memory fences. My question is that for an example with SFENCE, in order to make sure that all store operations are globally visible, does the multi-core CPU parks all the threads even running on other cores till the cache coherence achieved ? @Stephen C - why don’t you make this comment an answer? – theMayer Aug 12 at 13:28 1 Answer 1 Barriers don't make other threads/cores wait. They make some operations in the current thread wait , depending on what kind of barrier it is. Out-of-order execution of non-memory instructions isn't necessarily blocked. Barriers don't even make your loads/stores visible to other threads any faster; CPU cores already commit (retired) stores from the store buffer to L1d cache as fast as possible. (After all the necessary MESI coherency rules have been followed, and x86

Error when install Cocoapods

Image
Clash Royale CLAN TAG #URR8PPP Error when install Cocoapods I am trying to install CocoaPods on my Mac. When i run this command: sudo gem install cocoapods sudo gem install cocoapods it returns this: Fetching: cocoapods-core-1.5.3.gem (100%) Successfully installed cocoapods-core-1.5.3 ERROR: Error installing cocoapods: invalid gem: package metadata is missing in /Library/Ruby/Gems/2.3.0/cache/cocoapods-deintegrate-1.0.2.gem What is casing this issue and how do I install CocoaPods? I have exactly same problem – Mahdi Bashirpour Aug 12 at 10:17 1 Answer 1 I'd recommend using Homebrew to install CocoaPods. If you are not already using Homebrew, it is a package manager for macOS, hugely popular among developers of all types. It makes installing packages like CocoaPods hassle free. To install Homebrew, follow the instructions on the homepage Paste that at a Terminal prompt. /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/