Posts

Showing posts from February, 2005

Create An Empty List In Python With Certain Size

Answer : You cannot assign to a list like lst[i] = something , unless the list already is initialized with at least i+1 elements. You need to use append to add elements to the end of the list. lst.append(something) . (You could use the assignment notation if you were using a dictionary). Creating an empty list: >>> l = [None] * 10 >>> l [None, None, None, None, None, None, None, None, None, None] Assigning a value to an existing element of the above list: >>> l[1] = 5 >>> l [None, 5, None, None, None, None, None, None, None, None] Keep in mind that something like l[15] = 5 would still fail, as our list has only 10 elements. range(x) creates a list from [0, 1, 2, ... x-1] # 2.X only. Use list(range(10)) in 3.X. >>> l = range(10) >>> l [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] Using a function to create a list: >>> def display(): ... s1 = [] ... for i in range(9): # This is just to tell you how to create a list. ...

About Android Launchmode "singleTask"

Image
Answer : You sound right. Why don't you test it. There is also this app that can help explain launch mode: https://play.google.com/store/apps/details?id=com.novoda.demos.activitylaunchmode Sources are at https://github.com/gnorsilva/Activities-LaunchMode-demo The ActivityC will be removed from task1 and ActivityB becomes the top Activity. Yes, you are Right... ActivityC will be removed from i.e. the onDestroy method of the ActivityC will be called. Hence when the user launches Task 1 again, the ActivityB is shown rather than ActivityC. Have created 2 Tasks (Projects) and uploaded the same @ SendSpace. Try it out... If you look at androids documentation it says " A "singleTask" activity allows other activities to be part of its task. It's always at the root of its task, but other activities (necessarily "standard" and "singleTop" activities) can be launched into that task." This means that when you click the hom

Allow 2 Decimal Places In

Answer : Instead of step="any" , which allows for any number of decimal places, use step=".01" , which allows up to two decimal places. More details in the spec: https://www.w3.org/TR/html/sec-forms.html#the-step-attribute If case anyone is looking for a regex that allows only numbers with an optional 2 decimal places ^\d*(\.\d{0,2})?$ For an example, I have found solution below to be fairly reliable HTML: <input name="my_field" pattern="^\d*(\.\d{0,2})?$" /> JS / JQuery: $(document).on('keydown', 'input[pattern]', function(e){ var input = $(this); var oldVal = input.val(); var regex = new RegExp(input.attr('pattern'), 'g'); setTimeout(function(){ var newVal = input.val(); if(!regex.test(newVal)){ input.val(oldVal); } }, 0); }); Update setTimeout is not working correctly anymore for this, maybe browsers have changed. Some other async solution will need to be devised

Allow Multiple Run Time Permission

Answer : First parameter is android.app.Activity type, You can't pass context at this place so use this instead of context like below code :- if (ActivityCompat.shouldShowRequestPermissionRationale (this, READ_PHONE_STATE) ||ActivityCompat.shouldShowRequestPermissionRationale (this, WRITE_EXTERNAL_STORAGE)|| ActivityCompat.shouldShowRequestPermissionRationale (this, CAMERA) || ActivityCompat.shouldShowRequestPermissionRationale (this, READ_CONTACTS) || ActivityCompat.shouldShowRequestPermissionRationale (this, CALL_PHONE) || ActivityCompat.shouldShowRequestPermissionRationale (this, ACCESS_FINE_LOCATION) || ActivityCompat.shouldShowRequestPermissionRationale (this, READ_SMS))

Html Css Text Bold Code Example

Example 1: css bold text .text { font-weight : bold ; } Example 2: css text bold font-weight : bold ; Example 3: css bold text /* Keyword values */ font-weight : bold ; /* Keyword values relative to the parent */ font-weight : bolder ; /* Numeric keyword values */ font-weight : 700 ; // bold font-weight : 800 ; font-weight : 900 ; Example 4: html make text bold <b> Bold Text </b>

Check If List Contains Item Python Code Example

Example 1: python check if list contains # To check if a certain element is contained in a list use 'in' bikes = [ 'trek' , 'redline' , 'giant' ] 'trek' in bikes # Output: # True Example 2: python check if list contains value if value in list : #do stuff #Also to check if it doesn't contain if value not in list : #do stuff

W3schools C Language Code Example

Example 1: c++ # include <bits/stdc++.h> using namespace std ; int main ( ) { return 0 ; } Example 2: c++ slslegal . com

How To Use Props In A Function Inside A Functional Component In React Code Example

Example 1: function component with props import React from "react" function Checkbox ( props ) { return ( < div > < input type = "checkbox" / > < label > { props . value } < / label > < / div > ) } export default Checkbox Example 2: how to use props in functional component in react import React , { useState } from 'react' ; import './App.css' ; import Todo from './components/Todo' function App ( ) { const [ todos , setTodos ] = useState ( [ { id : 1 , title : 'This is first list' } , { id : 2 , title : 'This is second list' } , { id : 3 , title : 'This is third list' } , ] ) ; return ( < div className = "App" > < h1 > < / h1 &

Add Element In Dict Python Code Example

Example 1: how to add an item to a dictionary in python a_dictonary = { } a_dictonary . update ( { "Key" : "Value" } ) Example 2: python append to dictionary dict = { 1 : 'one' , 2 : 'two' } # Print out the dict print ( dict ) # Add something to it dict [ 3 ] = 'three' # Print it out to see it has changed print ( dict ) Example 3: adding one element in dictionary python mydict = { 'score1' : 41 , 'score2' : 23 } mydict [ 'score3' ] = 45 # using dict[key] = value print ( mydict ) Example 4: Python dict add item # This automatically creates a new element where # Your key = key, The value you want to input = value dictionary_name [ key ] = value

Android Lollipop Set Status Bar Text Color

Answer : You can not set the status bar text color by specifying any color explicitly But you can try below alternative which is Added in API 23, You can use "android:windowLightStatusBar" attribute in two ways "android:windowLightStatusBar" = true, status bar text color will be compatible (grey) when status bar color is light "android:windowLightStatusBar" = false, status bar text color will be compatible (white) when status bar color is dark <style name="statusBarStyle" parent="@android:style/Theme.DeviceDefault.Light"> <item name="android:statusBarColor">@color/status_bar_color</item> <item name="android:windowLightStatusBar">false</item> </style> You can check above api in below link - https://developer.android.com/reference/android/R.attr.html#windowLightStatusBar Here's a Java implementation of Gandalf458's answer. /** Changes the

Static Variable In C ++ Code Example

Example: static variable in c++ /* this example show where and how static variables are used */ # include <iostream> # include <string> //doing "using namespace std" is generally a bad practice, this is an exception using namespace std ; class Player { int health = 200 ; string name = "Name" ; //static keyword static int count = 0 ; public : //constructor Player ( string set_name ) : name { set_name } { count ++ ; } //destructor ~ Player ( ) { count -- ; } int how_many_player_are_there ( ) { return count ; } } ; int main ( ) { Player * a = new Player ( "some name" ) ; cout << "Player count: " << * a . how_many_player_are_there ( ) << std :: endl ; Player * b = new Player ( "some name" ) ; cout << "Player count: " << * a . how_many_player_are_there (

Css ToUppercase Code Example

Example 1: css all caps .uppercase { text-transform: uppercase; } #example { text-transform: none; /* No capitalization, the text renders as it is (default) */ text-transform: capitalize; /* Transforms the first character of each word to uppercase */ text-transform: uppercase; /* Transforms all characters to uppercase */ text-transform: lowercase; /* Transforms all characters to lowercase */ text-transform: initial; /* Sets this property to its default value */ text-transform: inherit; /* Inherits this property from its parent element */ } Example 2: css all uppercase to capitalize .link { text-transform: lowercase; } .link::first-line { text-transform: capitalize; }

To Get Whole Window Width In Javascript Code Example

Example 1: how to get the height of window in javascript //get screen height of the device by using window.innerHeight //get screen width of the device by using window.innerWidth Example 2: get screen width javascript window.screen.width //or just screen.width

Python String Reverse Code Example

Example 1: python reverse string 'String' [ :: - 1 ] # -> 'gnirtS' Example 2: how to reverse a string in python # in order to make a string reversed in python # you have to use the slicing as following string = "racecar" print ( string [ :: - 1 ] ) Example 3: reverse string in python 'hello world' [ :: - 1 ] 'dlrow olleh' Example 4: how to reverse a string in python 'your sting' [ :: - 1 ] Example 5: python string reverse 'hello world' [ :: - 1 ] # 'dlrow olleh' Example 6: reverse string method python # linear def reverse ( s ) : str = "" for i in s : str = i + str return str # splicing 'hello world' [ :: - 1 ] # reversed & join def reverse ( string ) : string = "" . join ( reversed ( string ) ) return string

Adding VirtualHost Fails: Access Forbidden Error 403 (XAMPP) (Windows 7)

Answer : Okay: This is what I did now and it's solved: My httpd-vhosts.conf looks like this now: <VirtualHost dropbox.local:80> DocumentRoot "E:/Documenten/Dropbox/Dropbox/dummy-htdocs" ServerName dropbox.local ErrorLog "logs/dropbox.local-error.log" CustomLog "logs/dropbox.local-access.log" combined <Directory "E:/Documenten/Dropbox/Dropbox/dummy-htdocs"> # AllowOverride All # Deprecated # Order Allow,Deny # Deprecated # Allow from all # Deprecated # --New way of doing it Require all granted </Directory> </VirtualHost> First, I saw that it's necessary to have set the <Directory xx:xx> options. So I put the <Directory > [..] </Directory> -part INSIDE the <VirtualHost > [..] </VirtualHost> . After that, I added AllowOverride AuthConfig Indexes to the <Directory> options. Now htt

Css Scale3d()() Example

The scale3d() CSS function defines a transformation that resizes an element in 3D space. Because the amount of scaling is defined by a vector, it can resize different dimensions at different scales. Its result is a <transform-function> data type. This scaling transformation is characterized by a three-dimensional vector. Its coordinates define how much scaling is done in each direction. If all three coordinates are equal, the scaling is uniform ( isotropic ) and the aspect ratio of the element is preserved (this is a homothetic transformation). When a coordinate value is outside the [-1, 1] range, the element grows along that dimension; when inside, it shrinks. If it is negative, the result a point reflection in that dimension. A value of 1 has no effect. Syntax The scale3d() function is specified with three values, which represent the amount of scaling to be applied in each direction. scale3d ( sx , sy , sz ) Values sx Is a <number> representing the absciss

2d Camera Follow Unity Code Example

Example 1: camera follow player unity 2d using System . Collections ; using System . Collections . Generic ; using UnityEngine ; public class CameraController : MonoBehaviour { //Object you want to follow public Transform target ; //Set to z -10 public Vector3 offset ; //How much delay on the follow [ Range ( 1 , 10 ) ] public float smoothing ; private void FixedUpdate ( ) { Follow ( ) ; } void Follow ( ) { Vector3 targetPosition = target . position + offset ; Vector3 smoothPosition = Vector3 . Lerp ( transform . position , targetPosition , smoothing * Time . fixedDeltaTime ) ; transform . position = smoothPosition ; } } Example 2: how to make camera follow player unity 2d public class CameraFollow : MonoBehaviour { public GameObject Target ; private Vector3 Offset ; // Start is called before the first frame update void Start ( ) {

128-bit Values - From XMM Registers To General Purpose

Answer : You cannot move the upper bits of an XMM register into a general purpose register directly. You'll have to follow a two-step process, which may or may not involve a roundtrip to memory or the destruction of a register. in registers (SSE2) movq rax,xmm0 ;lower 64 bits movhlps xmm0,xmm0 ;move high 64 bits to low 64 bits. movq rbx,xmm0 ;high 64 bits. punpckhqdq xmm0,xmm0 is the SSE2 integer equivalent of movhlps xmm0,xmm0 . Some CPUs may avoid a cycle or two of bypass latency if xmm0 was last written by an integer instruction, not FP. via memory (SSE2) movdqu [mem],xmm0 mov rax,[mem] mov rbx,[mem+8] slow, but does not destroy xmm register (SSE4.1) mov rax,xmm0 pextrq rbx,xmm0,1 ;3 cycle latency on Ryzen! (and 2 uops) A hybrid strategy is possible, e.g. store to memory, movd/q e/rax,xmm0 so it's ready quickly, then reload the higher elements. (Store-forwarding latency is not much worse than ALU, though.) That gives you a bal

Directory.getcurrentdirectory() Code Example

Example 1: c# get current directory string currentDir = System . IO . Directory . GetCurrentDirectory ( ) ; //returns the current directory of the application when executing Example 2: get current directory c# \ System . IO . Path . GetDirectoryName ( Assembly . GetEntryAssembly ( ) . Location ) ; Example 3: c# get script directory string appPath = System . IO . Path . GetDirectoryName ( Application . ExecutablePath ) ;