Posts

Showing posts from September, 2006

Accessing EJS Variable In Javascript Logic

Answer : You could directly inject the gameState variable into javascript on the page. <% if (gameState) { %> <h2>I have a game state!</h2> <script> var clientGameState = <%= gameState %> </script> <% } %> Another option might be to make an AJAX call back to the server once the page has already loaded, return the gameState JSON, and set clientGameState to the JSON response. You may also be interested in this: How can I share code between Node.js and the browser? I had the same problem. I needed to use the data not for just rendering the page, but in my js script. Because the page is just string when rendered, you have to turn the data in a string, then parse it again in js. In my case my data was a JSON array, so: <script> var test = '<%- JSON.stringify(sampleJsonData) %>'; // test is now a valid js object </script> Single quotes are there to not be mixed with double-q

Convert Date From Excel In Number Format To Date Format Python

Answer : from datetime import datetime excel_date = 42139 dt = datetime.fromordinal(datetime(1900, 1, 1).toordinal() + excel_date - 2) tt = dt.timetuple() print dt print tt As mentioned by J.F. Sebastian, this answer only works for any date after 1900/03/01 EDIT: (in answer to @R.K) If your excel_date is a float number, use this code: def floatHourToTime(fh): h, r = divmod(fh, 1) m, r = divmod(r*60, 1) return ( int(h), int(m), int(r*60), ) excel_date = 42139.23213 dt = datetime.fromordinal(datetime(1900, 1, 1).toordinal() + int(excel_date) - 2) hour, minute, second = floatHourToTime(excel_date % 1) dt = dt.replace(hour=hour, minute=minute, second=second) The module xlrd provides a function xldate_as_tuple to convert Excel's numerical date format to a tuple (year, month, day, hour, minute, nearest_second) . You can then use datetime.datetime to convert the tuple into a datetime -object. from datetime import datetime import xlrd excel_da

Css Set Div Background Image Code Example

Example 1: css background image background-image : url ( "image.png" ) ; background-position : center ; background-repeat : no-repeat ; background-size : cover ; Example 2: div background image #avatar { /* This image is 687 wide by 1024 tall, similar to your aspect ratio */ background-image : url ( 'http://i.stack.imgur.com/Dj7eP.jpg' ) ; /* make a square container */ width : 150 px ; height : 150 px ; /* fill the container, preserving aspect ratio, and cropping to fit */ background-size : cover ; /* center the image vertically and horizontally */ background-position : top center ; /* round the edges to a circle with border radius 1/2 container size */ border-radius : 50 % ; } Example 3: make image background of div background-image : url ( "photographer.jpg" ) ; Example 4: background image css html , body { background-image : url ( "your.picture" ) ; } Example 5: how to set div ba

Android Studio ERROR: Executing External Native Build For NdkBuild When Trying To Run Gstreamer Tutorial

Answer : Download the entire gstreamer android studio tutorial directory (https://gitlab.freedesktop.org/gstreamer/gst-docs/) 2)Open Android Studio -> Open an existing Android Studio Project Open the entire android tutorial directory examples/tutorials/android as a project 4)Once the project is open change the view on the left side of the screen to Project Right click near local.properties file -> New -> File Create a new file called gradle.properties In the new gradle.properties file copy and paste the below code. # gstAndroidRoot can be set to point to the unpacked GStreamer android top-level directory # containing each architecture in subdirectories, or else set the GSTREAMER_ROOT_ANDROID # environment variable to that location gstAndroidRoot=/gstreamer_android_binaries NOTE Change the gstAndroidRoot variable to your file path where you downloaded the gstreamer binaries and unzipped them. Gstreamer can be downloaded from here for Android (https://gstr

Conda Update Package To Specific Version Code Example

Example 1: conda update package # Basic syntax: conda update packagename # To update specific package in the current env conda update --all # To update all packages in the current environment conda update -n myenv --all # To update all packages in myenv environment Example 2: conda import specific version conda install < pkg > = < version > #for example conda install matplotlib=1.4.3

Css Transparent Background-color Code Example

Example 1: background color none element { background-color : transparent ; } Example 2: css background color body { background-color : green ; } Example 3: css how to make background transparent /* Use RGBA */ background-color : rgba ( 255 , 255 , 0 , 0.75 ) ; /* Transparent Yellow */ Example 4: background color css rgb body { background-color : rgb ( 255 , 255 , 255 ) ; } Example 5: css opacity example .opacity30 { opacity : 0.3 ; filter : alpha ( opacity= 30 ) ; /* For IE8 and earlier */ } Example 6: background color transparent div { background : transparent }

How To Input String With Spaces In C Using Scanf Code Example

Example: how to store a user input with spaces in c # include <stdio.h> int main ( ) { char name [ 20 ] ; printf ( "Enter a name : " ) ; scanf ( "%[^\n]%*c" , & name ) ; printf ( "the name entered is: %s\n" , name ) ; return 0 ; }

C# Serilog: How To Log With String Interpolation And Keep Argument Names In Message Templates?

Answer : Add this file to your project. It has ILogger extension methods VerboseInterpolated() , DebugInterpolated() and so on. There are also unit tests here. Usage with format string string name = "John"; // add 'Interpolated' to method name: InformationInterpolated() instead of Information() // add name of the property after the expression. Name is passed to the logger logger.InformationInterpolated($"length of name '{name:name}' is {name.Length:Length}"); But be careful : it's all too easy to use the wrong method. If you accidentally use the Serilog's method, for example logger.Debug($"length = {length:propertyNameForLogger}") , it will log length = propertyNameForLogger , so no argument value will be logged. This is due to propertyNameForLogger is format for your value. Usage with anonymous types string name = "John"; // add 'Interpolated' to method name: InformationInterpolated() instead of

Convert Jsonarray To Arraylist Java Code Example

Example 1: jsonarray to list java JSONArray data = new JSONArray ( ) ; //create data from this -> [{"thumb_url":"tb-1370913834.jpg","event_id":...}] List < JSONObject > list = data . stream ( ) . map ( o - > ( JSONObject ) o ) . collect ( Collectors . toList ( ) ) ; Example 2: arraylist to json array ArrayList < String > list = new ArrayList < String > ( ) ; list . add ( "foo" ) ; list . add ( "baar" ) ; JSONArray jsArray = new JSONArray ( list ) ; Example 3: convert json to arraylist java // Top of file import java . lang . reflect . Type ; // ... private void parseJSON ( ) { Gson gson = new Gson ( ) ; Type type = new TypeToken < List < ContactModel >> ( ) { } . getType ( ) ; List < ContactModel > contactList = gson . fromJson ( jsonString , type ) ; for ( ContactModel contact : contactList ) { Log . i ( "Contact Details" , con

Can I Take Legion On Tali's Loyalty Mission, Complete All Loyalty Missions (including His), And Still Save My Whole Crew?

Answer : You can perform all the loyalty missions, take Legion on Tali's loyalty mission, and save your entire crew if you do the following: Do everything but Tali's loyalty mission. Do the mission to obtain the Reaper IFF. Do Tali's loyalty mission. Do Legion's loyalty mission. At this point, you should actually be out of things to do, and you'll be wondering why the Collectors haven't attacked yet. Go click your galaxy map. This should trigger the Collector invasion. Once it is over, go straight through the Omega IV relay. You don't have anything else left to do anyway! I believe that you can make 3 jumps with the Normandy once you obtain the Reaper IFF before the collector attack. So it should be possible to obtain Legion, jump straight to Tali's loyalty mission, and then immediately do Legion's mission. Once the crew is abducted, its uncertain how many more missions you can do before half the crew dies, but general consensus seems

Count Children In Firebase Realtime Database Code Example

Example 1: firebase database get child count String change = dataSnapshot.getValue(String.class); Example 2: firebase database get child count dbRef.removeEventListener(changeListener);

Bukkit Events List Code Example

Example: bukkit event list You can find it on the javadocs, http://jd.bukkit.org/