Posts

Showing posts from May, 2001

Bind Function To Kivy Button

Answer : I don't think any of the answers are very clear. Neither explains that problem is that the callback given to on_press gets called with a parameter, the instance of button, so LoginScreen.auth must accept a parameter after the self : def auth(self, button): print('button pressed:', instance) The problem is not that on_press must be given via Button.bind or that the callback must be a function, it can be a bound method, and the docs cited by other answer and by comments link to ButtonbBhavior which indicates that OP use of on_press in constructor was fine: self.hello = Button(text="hello", on_press=self.auth) would have worked if auth had been as described above. If you read the Button documentation, the key seems to be to use the bind function: def callback(instance): print('The button <%s> is being pressed' % instance.text) btn1 = Button(text='Hello world 1') btn1.bind(on_press=callback)

Cannot Open Large Concatenated Zip File With Unzip, Though It Opened Fine With Archive Utility, Get A Central Directory Error

Answer : Try zip -F science_team_meeting_archive.zip -O science_team_meeting_archive.fixed.zip If that doesn't work, you just need more 'F's zip -FF science_team_meeting_archive.zip -O science_team_meeting_archive.fixed.zip If either of these work, you then unzip normally with: unzip science_team_meeting_archive.fixed.zip For more info about this, use: man zip 7z x I had the same issue with unzip %x on Linux for a .zip file larger than 4GB, compounded with a only DEFLATED entries can have EXT descriptor error. The command 7z x resolved all my issues though. Be careful though, the command 7z x will extract all files with a path rooted in the current directory. The option -o allows to specify an output directory.

Calling Php Function From Javascript Code Example

Example 1: call javascript function from php // The most basic method <?php echo '<script type="text/javascript">' , 'someJsFunc();' , // Or Whatever '</script>' ; ?> // However, if what you are trying to achieve requires more complexity, // You might be better off adding the V8JS module, see link below Example 2: call php function in js < script > var phpadd = <?php echo add ( 1 , 2 ) ; ?> //call the php add function var phpmult = <?php echo mult ( 1 , 2 ) ; ?> //call the php mult function var phpdivide = <?php echo divide ( 1 , 2 ) ; ?> //call the php divide function </ script >

Class.instance Python Code Example

Example 1: call instance class python # define class class example : # define __call__ function def __call__ ( self ) : print ( "It worked!" ) # create instance g = example ( ) # when attempting to call instance of class it will call the __class method g ( ) # prints It worked! Example 2: making an instance of a class in puython #!/usr/bin/python class Employee : 'Common base class for all employees' empCount = 0 def __init__ ( self , name , salary ) : self . name = name self . salary = salary Employee . empCount += 1 def displayCount ( self ) : print "Total Employee %d" % Employee . empCount def displayEmployee ( self ) : print "Name : " , self . name , ", Salary: " , self . salary "This would create first object of Employee class" emp1 = Employee ( "Zara" , 2000 ) "This would create second object of Empl

Switch Case Python W3school Code Example

Example: else if python if ( condion ) : result elif ( condition ) : results else : result

Bracing A Polygon Without Triangles

Image
Answer : Any rigid framework, hence all regular polygons, can be converted to a triangle-free equivalent. Simply chaining copies of the 12 12 12 -vertex triangle-free braced square shown in the question (which I discovered) along the two collinear edges gives a rigid line segment of arbitrary whole number length without triangles: Then any triangular grid can be mimicked without triangles as follows (all straight fuchsia edges are made with the graph chaining construction above, all black edges are single sticks): For example, to brace the hexagon without triangles: However, the above hexagon bracing is quite big. Another approach to triangle-free bracing is the virtual edge : in any embedding of the cubical graph with one edge removed, the distance between the two degree- 2 2 2 vertices (incident to the missing edge) must always be 1 1 1 . This leads to the following triangle-free rigid regular hexagon in 16 16 16 vertices and 29 29 29 edges (Shibuya commit proof): Th

Android Toolbar Code Example

Example 1: android toolbar with menus @Override public boolean onCreateOptionsMenu ( Menu menu ) { getMenuInflater ( ) . inflate ( R . menu . main_menu , menu ) ; return true ; } Example 2: android toolbar example < ? xml version = "1.0" encoding = "utf-8" ? > < LinearLayout xmlns : android = "http://schemas.android.com/apk/res/android" android : layout_width = "match_parent" android : layout_height = "match_parent" android : background = "@android:color/white" > < android . support . v7 . widget . Toolbar android : id = "@+id/toolbar" android : layout_width = "match_parent" android : layout_height = "58dp" android : background = "?attr/colorPrimary" android : minHeight = "?attr/actionBarSize" android : titleTextColor = "#ffffff" > < / android . support . v7 . widget . Toolbar > < / LinearLayout >

Array Filter Object Javascript Code Example

Example 1: how to filter object in javascript // use filter() function. Let say we have array of object. let arr = [ { name : "John" , age : 30 } , { name : "Grin" , age : 10 } , { name : "Marie" , age : 50 } , ] ; //Now I want an array in which person having age more than 40 is not //there, i.e, I want to filter it out using age property. So let newArr = arr . filter ( ( person ) => ( return person . age <= 40 ) ) ; //filter function expects a function if it return true then it added //into new array, otherwise it is ignored. So new Array would be /* [ {name: "John", age: 30}, {name: "Grin", age: 10}, ] */ Example 2: how to filter an array of objects in javascript let arr = [ { id : 1 , title : 'A' , status : true } , { id : 3 , title : 'B' , status : true } , { id : 2 , title : 'xys' , status : true } ] ; //find where title=B let x = arr . filter ( ( a )

Armstrong Number Wiki Code Example

Example 1: armstrong number sum of cubes of the digits Example 2: armstrong number temp=n; while(n>0) { r=n%10; sum=sum+(r*r*r); n=n/10; } if(temp==sum) printf("armstrong number "); else printf("not armstrong number"); return 0; Example 3: Armstrong number Enter the Number:

Background Image Circle Avatar Flutter Assets Code Example

Example 1: circle avatar from image asset flutter CircleAvatar ( radius : 16.0 , child : ClipRRect ( child : Image . asset ( 'profile-generic.png' ) , borderRadius : BorderRadius . circular ( 50.0 ) , ) , ) , Example 2: how to make an image contained in circle avatar in flutter CircleAvatar ( radius : 30.0 , backgroundImage : NetworkImage ( "${snapshot.data.hitsList[index].previewUrl}" ) , backgroundColor : Colors . transparent , )

Textit Latex Code Example

Example 1: latex bold text \textbf { text } Example 2: latex italic \emph { accident }

C++ Print Double With 2 Decimal Places Code Example

Example 1: how to specify how many decimal to print out with std::cout # include <iostream> # include <iomanip> int main ( ) { double d = 122.345 ; std :: cout << std :: fixed << std :: setprecision ( 2 ) << d ; } //result that get print out: 122.34 Example 2: how to format decimal palces in c++ std :: cout << std :: setprecision ( 2 ) << std :: fixed ; // where the 2 is how many decimal places you want // note you need to <iomanip>

Android: How Does Bitmap Recycle() Work?

Answer : The first bitmap is not garbage collected when you decode the second one. Garbage Collector will do it later whenever it decides. If you want to free memory ASAP you should call recycle() just before decoding the second bitmap. If you want to load really big image you should resample it. Here's an example: Strange out of memory issue while loading an image to a Bitmap object. I think the problem is this: On pre-Honeycomb versions of Android, the actual raw bitmap data is not stored in VM memory but in native memory instead. This native memory is freed when the corresponding java Bitmap object is GC'd. However , when you run out of native memory, the dalvik GC isn't triggered, so it is possible that your app uses very little of the java memory, so the dalvik GC is never invoked, yet it uses tons of native memory for bitmaps which eventually causes an OOM error. At least that's my guess. Thankfully in Honeycomb and later, all bitmap data is stored in

Ansible Date Variable

Answer : The command ansible localhost -m setup basically says "run the setup module against localhost", and the setup module gathers the facts that you see in the output. When you run the echo command these facts don't exist since the setup module wasn't run. A better method to testing things like this would be to use ansible-playbook to run a playbook that looks something like this: - hosts: localhost tasks: - debug: var=ansible_date_time - debug: msg="the current date is {{ ansible_date_time.date }}" Because this runs as a playbook facts for localhost are gathered before the tasks are run. The output of the above playbook will be something like this: PLAY [localhost] ************************************************** GATHERING FACTS *************************************************************** ok: [localhost] TASK: [debug var=ansible_date_time] ******************************************* ok: [localhost] => { "a

How To Use Setprecision In Visual Studio Code Example

Example 1: set precision in c++ // setprecision example # include <iostream> // std::cout, std::fixed # include <iomanip> // std::setprecision int main ( ) { double f = 3.14159 ; std :: cout << std :: setprecision ( 5 ) << f << '\n' ; std :: cout << std :: setprecision ( 9 ) << f << '\n' ; std :: cout << std :: fixed ; std :: cout << std :: setprecision ( 5 ) << f << '\n' ; std :: cout << std :: setprecision ( 9 ) << f << '\n' ; return 0 ; } Example 2: set precision with fixed c++ int x = 109887 ; cout << fixed << setprecision ( 3 ) << x ;

Angular 4 CLI Too Slow After Ng Serve And When Updating

Answer : i solved my problem. What happened is that our components and other resources are all imported in app.module.ts . Because of this, the page loads all the resources every time the page loads. My solution was to apply Lazy Loading to load only those resources that are specific to the routes that i am accessing and it did fix up the loading issue. You have this problem is because your dev PC have not enough memory to handle the build as nodejs is consuming a lot of memory when you run expensive npm tasks. And the bigger your project the more memory is required to complete the task. The problem can get even worse if you want to run ng serve + ng t + ng whatewer at the same time. Check the Task manager -> Perfomrmance tab then run ng serve and you will see what I am talking about. I had struggled by the same problem until I put another 8gb RAM in my dev PC. So yes it is normal.

Can An Optional Parameter Be Null In TypeScript?

Answer : To answer my own question after trying... The types null and undefined are handled as separate types. The optional type is special, also allowing arguments to be left out of function calls. 1. Without a union or optional, nothing except the type itself is allowed. function foo(bar: string) { console.info(bar); } foo("Hello World!"); // OK foo(null); // Error foo(undefined); // Error foo() // Error 2. To additionally allow null , a union with null can be made. function foo(bar: string | null) { console.info(bar); } foo("Hello World!"); // OK foo(null); // OK foo(undefined); // Error foo() // Error 3. Allowing undefined works similarly. Note that the argument cannot be left out or null . function foo(bar: string | undefined) { console.info(bar); } foo("Hello World!"); // OK foo(null); // Error foo(undefined); // OK foo() // Error 4. You can also allow both, but the argument MUST still be given. function foo(b

Addclassname Using Get ElementByClassName Javascript Code Example

Example: javascript add class to element var someElement = document . getElementById ( "myElement" ) ; someElement . className += " newclass" ; //add "newclass" to element (space in front is important)

All Compiler Errors Have To Be Fixed Before You Can Enter Play Mode Code Example

Example: all compiler errors have to be fixed before entering playmode HOW TO GET RID OF All "compiler errors have to be fixed before you can enter playmode" 1 - check in the console tab if you have some errors in a code you wrote //the ones in red are the ones that probably are bothering you 2 - if you already fixed all the errors and you didnt get rid of it, try restarting unity 3 - if it didnt work just make another project 4 - if it DIDNT work reinstall unity 5 - if it didnt work call the the tech support 6 - if it didnt work restart yourselve

Catch Error If Iframe Src Fails To Load . Error :-"Refused To Display 'http://www.google.co.in/' In A Frame.."

Answer : You wont be able to do this from the client side because of the Same Origin Policy set by the browsers. You wont be able to get much information from the iFrame other than basic properties like its width and height. Also, google sets in its response header an 'X-Frame-Options' of SAMEORIGIN. Even if you did an ajax call to google you wont be able to inspect the response because the browser enforcing Same Origin Policy. So, the only option is to make the request from your server to see if you can display the site in your IFrame. So, on your server.. your web app would make a request to www.google.com and then inspect the response to see if it has a header argument of X-Frame-Options. If it does exist then you know the IFrame will error. I think that you can bind the load event of the iframe, the event fires when the iframe content is fully loaded. At the same time you can start a setTimeout, if the iFrame is loaded clear the timeout alternatively let th

Centering An Image In A Div Css Code Example

Example 1: css align center //HTML < div class = " parent " > < span > Hello World </ span > </ div > //CSS .parent { display: flex; justify-content: center; align-items: center; } Example 2: image center in div img { display: block; margin-left: auto; margin-right: auto; width: 40%; } Example 3: center with css .parent { position: relative; } .child { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); } Example 4: how to center an image element inside a block in css img { display:block; margin-left: auto; margin-right:auto; } Example 5: html css center text on page < style > body { background : white } section { background : black ; color : white ; border-radius : 1 em ; padding : 1 em ; position : absolute ; top : 50 % ; left : 50 % ; margin-right : -50 % ; transform : translate ( -50 % , -50 % ) } </ style &g

Blackstone Castle Minecraft Code Example

Example: types of bastion minecraft hey , are you into modding or something ?

Assigning The Return Value Of New By Reference Is Deprecated

Answer : In PHP5 this idiom is deprecated $obj_md =& new MDB2(); You sure you've not missed an ampersand in your sample code? That would generate the warning you state, but it is not required and can be removed. To see why this idiom was used in PHP4, see this manual page (note that PHP4 is long dead and this link is to an archived version of the relevant page) I recently moved a site using SimplePie (http://simplepie.org/) from a server that was using PHP 5.2.17 to one that is using PHP 5.3.2. It was after this move that I began receiving a list of error messages such as this one: Deprecated: Assigning the return value of new by reference is deprecated in .../php/simplepie.inc on line 738 After reviewing several discussions of this issue, I cleared things up by replacing all the instances of =& new with = new in the simplepie.inc file. I'm not experienced enough to know if this will work in all instances where these error messages are received

Can I Use React-select In React-native?

Answer : You can't use select2 or react-select with react-native, because it's DOM based and so, it will work only in navigator, not in react-native The closest react-native equivalent I've found is react-native-multiple-select, you can find it on github at https://github.com/toystars/react-native-multiple-select or install it with npm i react-native-multiple-select Probably the closest to what you want that comes bundled with React Native is http://facebook.github.io/react-native/docs/picker.html The Picker component will give you a tumbler thing on iOS and a dropdown on Android Alternatively maybe this 3rd party component is closer to what you want: https://github.com/bulenttastan/react-native-list-popover From How to use React native select box

Assembly: REP MOVS Mechanism

Answer : For questions about particular instructions always consult the instruction set reference. In this case, you will need to look up rep and movs . In short, rep repeats the following string operation ecx times. movs copies data from ds:esi to es:edi and increments or decrements the pointers based on the setting of the direction flag. As such, repeating it will move a range of memory to somewhere else. PS: usually the operation size is encoded as an instruction suffix, so people use movsb and movsd to indicate byte or dword operation. Some assemblers however allow specifying the size as in your example, by byte ptr or dword ptr . Also, the operands are implicit in the instruction, and you can not modify them. The short explanation about syntax At the assembly-code level, two forms of this instruction are allowed: the “explicit-operands” form and the “nooperand” form. The explicit-operands form allows the source and the destination address of the memory to be

Binary Semaphore Vs Mutex Code Example

Example: Difference between mutex and binary semaphore A Mutex(acquire(),release()) is different than a semaphore as it is a locking mechanism while a semaphore(wait(),signal()) is a signalling mechanism.A binary semaphore can be used as a Mutex but a Mutex can never be used as a semaphore.

Angular 4+ NgOnDestroy() In Service - Destroy Observable

Answer : OnDestroy lifecycle hook is available in providers. According to the docs: Lifecycle hook that is called when a directive, pipe or service is destroyed. Here's an example: @Injectable() class Service implements OnDestroy { ngOnDestroy() { console.log('Service destroy') } } @Component({ selector: 'foo', template: `foo`, providers: [Service] }) export class Foo implements OnDestroy { constructor(service: Service) {} ngOnDestroy() { console.log('foo destroy') } } @Component({ selector: 'my-app', template: `<foo *ngIf="isFoo"></foo>`, }) export class App { isFoo = true; constructor() { setTimeout(() => { this.isFoo = false; }, 1000) } } Notice that in the code above Service is an instance that belongs to Foo component, so it can be destroyed when Foo is destroyed. For providers that belong to root injector this will happen on application destroy, t