Posts

Showing posts from January, 2005

Buffering Line With Flat Cap Style Using GeoPandas?

Answer : GeoPandas isn't passing through all arguments to the shapely buffer method. Instead you can use the standard pandas apply method to call buffer on each geometry individually, e.g.: # Assumes that geometry will be the geometry column capped_lines = df.geometry.apply(lambda g: g.buffer(100, cap_style=2)) Also, not that this returns a GeoPandas GeoSeries object, so if you need the attributes (and projection for that matter, though that may be an outstanding issue) you'll need to overwite the geometry column in the original GeoDataFrame. GeoPandas now pass kwargs to shapely, so you can do below now: gdf.geometry.to_crs("epsg:3857").buffer(10, cap_style=2) PR: https://github.com/geopandas/geopandas/pull/535 Update: reason for change crs to 3857 is control on buffer radius in meter, else geopandas raise below warning: UserWarning: Geometry is in a geographic CRS. Results from 'buffer' are likely incorrect. Use 'GeoSeries.to_crs()' to

Axios Finally Method Code Example

Example: what is axios .finally on promise //The finally() method can be useful if you want to do some processing or cleanup once the promise is settled, regardless of its outcome. //So if you want to setloading to false regardless of error or success, do this axios . get ( '/products' , { params : params } ) . then ( ( response ) => { if ( isMountedRef . current ) { setProducts ( response . data . data ) ; setMeta ( response . data . meta ) ; } } ) . finally ( ( ) => { setLoading ( false ) ; } ) ;

AWS Lambda:The Provided Execution Role Does Not Have Permissions To Call DescribeNetworkInterfaces On EC2

Answer : This error is common if you try to deploy a Lambda in a VPC without giving it the required network interface related permissions ec2:DescribeNetworkInterfaces , ec2:CreateNetworkInterface , and ec2:DeleteNetworkInterface (see AWS Forum). For example, this a policy that allows to deploy a Lambda into a VPC: { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "ec2:DescribeNetworkInterfaces", "ec2:CreateNetworkInterface", "ec2:DeleteNetworkInterface", "ec2:DescribeInstances", "ec2:AttachNetworkInterface" ], "Resource": "*" } ] } If you are using terraform, just add: resource "aws_iam_role_policy_attachment" "AWSLambdaVPCAccessExecutionRole" { role = aws_iam_role.lambda.name policy_arn = "arn:aws:iam::aws:po

Bootstrap Carousel Indicators Out Of The Main Div Not Switching Automatically

Answer : DEMO Well you can make use of slide.bs.carousel option of bootstrap carousel and make the respective indicators active depending on the current slide as below: var $carousel = $('#myCarousel'); //get a reference $carousel.carousel(); $carousel.bind('slide.bs.carousel', function (e) { //attach its event var current=$(e.target).find('.item.active'); //get the current active slide $('.carousel-indicators li').removeClass('active') //remove active class from all the li of carousel indicator var indx=$(current).index(); //get its index if((indx+2)>$('.carousel-indicators li').length) indx=-1 //if index exceeds total length of indicators present set it to -1 $('.carousel-indicators li:nth-child('+(indx+2)+')').addClass('active');//set the respective indicator active }); UPDATE The answer given above just shows how to make indicators active when they are placed

Implement Stack Using Singly Linked List Code Example

Example: stack implementation using linked list in c /* * C Program to Implement a Stack using Linked List */ # include <stdio.h> # include <stdlib.h> struct node { int info ; struct node * ptr ; } * top , * top1 , * temp ; int topelement ( ) ; void push ( int data ) ; void pop ( ) ; void empty ( ) ; void display ( ) ; void destroy ( ) ; void stack_count ( ) ; void create ( ) ; int count = 0 ; void main ( ) { int no , ch , e ; printf ( "\n 1 - Push" ) ; printf ( "\n 2 - Pop" ) ; printf ( "\n 3 - Top" ) ; printf ( "\n 4 - Empty" ) ; printf ( "\n 5 - Exit" ) ; printf ( "\n 6 - Dipslay" ) ; printf ( "\n 7 - Stack Count" ) ; printf ( "\n 8 - Destroy stack" ) ; create ( ) ; while ( 1 ) { printf ( "\n Enter choice : " ) ; scanf ( "%d" ,

C Implementation Of Matlab Interp1 Function (linear Interpolation)

Answer : I've ported Luis's code to c++. It seems to be working but I haven't checked it a lot, so be aware and re-check your results. #include <vector> #include <cfloat> #include <math.h> vector< float > interp1( vector< float > &x, vector< float > &y, vector< float > &x_new ) { vector< float > y_new; y_new.reserve( x_new.size() ); std::vector< float > dx, dy, slope, intercept; dx.reserve( x.size() ); dy.reserve( x.size() ); slope.reserve( x.size() ); intercept.reserve( x.size() ); for( int i = 0; i < x.size(); ++i ){ if( i < x.size()-1 ) { dx.push_back( x[i+1] - x[i] ); dy.push_back( y[i+1] - y[i] ); slope.push_back( dy[i] / dx[i] ); intercept.push_back( y[i] - x[i] * slope[i] ); } else { dx.push_back( dx[i-1] ); dy.push_back( dy[i-1] ); slo

Cmd Sleep Command Windows 10 Code Example

Example: how to make pc sleep windows 10 through cmd rundll32.exe powrprof. dll,SetSuspendState 0,1,0

Whatsapp Floating Button Css Code Example

Example 1: how to add floating whatspp icon < link rel = "stylesheet" href = "https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" > < a href = "https : //api.whatsapp.com/send? phone = 7310747066 & text = Hola % information % . " class = "float" target = "_blank" > < i class = "fa fa-whatsapp my-float" > < / i > < / a > < ! -- CSS -- > < style > . float { position : fixed ; width : 60 px ; height : 60 px ; bottom : 40 px ; right : 40 px ; background - color : # 25 d366 ; color : #FFF ; border - radius : 50 px ; text - align : center ; font - size : 30 px ; box - shadow : 2 px 2 px 3 px # 999 ; z - index : 100 ; } . my - float { margin - top : 16 px ; } < / style > Example 2: floating whatsapp button html < script type = "text/javascript" src = "jquery-3.3.1

Check If A String Is Encoded In Base64 Using Python

Answer : I was looking for a solution to the same problem, then a very simple one just struck me in the head. All you need to do is decode, then re-encode. If the re-encoded string is equal to the encoded string, then it is base64 encoded. Here is the code: import base64 def isBase64(s): try: return base64.b64encode(base64.b64decode(s)) == s except Exception: return False That's it! Edit: Here's a version of the function that works with both the string and bytes objects in Python 3: import base64 def isBase64(sb): try: if isinstance(sb, str): # If there's any unicode here, an exception will be thrown and the function will return false sb_bytes = bytes(sb, 'ascii') elif isinstance(sb, bytes): sb_bytes = sb else: raise ValueError("Argument must be string or bytes")

How To Check If A Tree Is Bst Code Example

Example 1: check if binary search tree is valid class BTNode { constructor ( value ) { this . value = value ; this . left = null ; this . right = null ; } } /** * * @param {BTNode} tree * @returns {Boolean} */ const isBinarySearchTree = ( tree ) = > { if ( tree ) { if ( tree . left && ( tree . left . value > tree . value || ! isBinarySearchTree ( tree . left ) ) ) { return false ; } if ( tree . right && ( tree . right . value <= tree . value || ! isBinarySearchTree ( tree . right ) ) ) { return false ; } } return true ; } ; Example 2: check for bst // C++ program to check if a given tree is BST. # include <bits/stdc++.h> using namespace std ; /* A binary tree node has data, pointer to left child and a pointer to right child */ struct Node { int data ; struct Node * left , * right ; } ; /

Can Not Start Elasticsearch As A Service In Ubuntu 16.04

Answer : I found the solution for this issue. The solution comes from this discussion thread- Can’t start elasticsearch with Ubuntu 16.04 on elastic's website. It seems that to get Elasticsearch to run on 16.04 you have to set START_DAEMON to true on /etc/default/elasticsearch . It comes commented out by default, and uncommenting it makes Elasticsearch start again just fine. Be sure to use systemctl restart instead of just start because the service is started right after installation, and apparently there's some socket/pidfile/something that systemd keeps that must be released before being able to start the service again. The problem lies on log files, "No java runtime was found." Jul 30 18:28:13 dimik elasticsearch[10266]: [warning] /etc/init.d/elasticsearch: No java runtime was found Here's my solution to the problem. Check elasticsearch init file sudo nano /etc/init.d/elasticsearch search for . /usr/share/java-w

Clion Download Community Edition Code Example

Example: clion download Clion is worth it, trust me

Alternative To 2b2t Code Example

Example: 2b2t alternatives //9b9t, its a good one

Accessing Localhost (xampp) From Another Computer Over LAN Network - How To?

Image
Answer : Localhost is just a name given for the loopback, eg its like referring to yourself as "me" .. To view it from other computers, chances are you need only do http://192.168.1.56 or http://myPcsName if that doesnt work, there is a chance that there is a firewall running on your computer, or the httpd.conf is only listening on 127.0.0.1 Thanks for a detailed explanation. Just to Elaborate, in Windows, Go to Control Panel -> Firewall, in exceptions "add http and port 80". Then in Services check mark "http (web server port 80)" and "https (web server port 443)" ONLY if you need https to work also. Ok, OK, Close Then go to any computer on network and type http://computer-name (where you change the firewall and has the xampp running on it) in your web browser and happy days :) it's very easy Go to Your XAMPP Control panel Click on apache > config > Apache (httpd.conf) Search for Listen 80 and replace with Listen 8

Add User To Mysql Database Code Example

Example 1: mysql create user CREATE USER 'user'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON * . * TO 'user'@'localhost'; FLUSH PRIVILEGES; Example 2: mysql add user with all privileges CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost'; FLUSH PRIVILEGES; Example 3: create user mysql CREATE USER 'norris'@'localhost' IDENTIFIED BY 'password'; Example 4: mysql create user CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password'; #grant permissions to a specic database and/or table GRANT ALL PRIVILEGES ON database.table TO 'newuser'@'localhost'; #Or grant wildcar permission to any DB/table GRANT ALL PRIVILEGES ON *.* TO 'newuser'@'localhost'; Example 5: create user mysql CREATE USER 'newuser'@'localhost' IDENTIFIED BY 

CodeIgniter Select Query

Answer : Thats quite simple. For example, here is a random code of mine: function news_get_by_id ( $news_id ) { $this->db->select('*'); $this->db->select("DATE_FORMAT( date, '%d.%m.%Y' ) as date_human", FALSE ); $this->db->select("DATE_FORMAT( date, '%H:%i') as time_human", FALSE ); $this->db->from('news'); $this->db->where('news_id', $news_id ); $query = $this->db->get(); if ( $query->num_rows() > 0 ) { $row = $query->row_array(); return $row; } } This will return the "row" you selected as an array so you can access it like: $array = news_get_by_id ( 1 ); echo $array['date_human']; I also would strongly advise, not to chain the query like you do. Always have them separately like in my code, which is clearly a lot easier to read. Please also note that if you specify the table name

Bootstrap Container Padding Code Example

Example 1: bootstrap Margin and padding Use the margin and padding spacing utilities to control how elements and components are spaced and sized. Bootstrap 4 includes a five-level scale for spacing utilities , based on a 1 rem value default $spacer variable. Choose values for all viewports ( e.g. , .mr-3 for margin-right : 1 rem ) , or pick responsive variants to target specific viewports ( e.g. , .mr-md-3 for margin-right : 1 rem starting at the md breakpoint ) . <div class= "my-0 bg-warning" >Margin Y 0 </div> <div class= "my-1 bg-warning" >Margin Y 1 </div> <div class= "my-2 bg-warning" >Margin Y 2 </div> <div class= "my-3 bg-warning" >Margin Y 3 </div> <div class= "my-4 bg-warning" >Margin Y 4 </div> <div class= "my-5 bg-warning" >Margin Y 5 </div> <div class= "my-auto bg-warning" >Margin Y Auto</div>

Hill Cipher C Program Code Example

Example: hill cipher encryption in c # include <stdio.h> # include <math.h> float encrypt [ 3 ] [ 1 ] , decrypt [ 3 ] [ 1 ] , a [ 3 ] [ 3 ] , b [ 3 ] [ 3 ] , mes [ 3 ] [ 1 ] , c [ 3 ] [ 3 ] ; void encryption ( ) ; //encrypts the message void decryption ( ) ; //decrypts the message void getKeyMessage ( ) ; //gets key and message from user void inverse ( ) ; //finds inverse of key matrix void main ( ) { getKeyMessage ( ) ; encryption ( ) ; decryption ( ) ; } void encryption ( ) { int i , j , k ; for ( i = 0 ; i < 3 ; i ++ ) for ( j = 0 ; j < 1 ; j ++ ) for ( k = 0 ; k < 3 ; k ++ ) encrypt [ i ] [ j ] = encrypt [ i ] [ j ] + a [ i ] [ k ] * mes [ k ] [ j ] ; printf ( "\nEncrypted string is: " ) ; for ( i = 0 ; i < 3 ; i ++ ) printf ( "%c" , ( char ) ( fmod ( encrypt [ i ] [ 0 ] , 26 ) + 97 ) ) ; } void decryption ( ) { i

Android Debug Keystore Code Example

Example 1: download debug.keystore keytool -genkey -v -keystore ~/.android/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US" Example 2: android create keystore command line keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000

200 Usd In Nis Code Example

Example: 200 naira to usd Hello, World.

Bootstrap Class For Line Height 1 Code Example

Example 1: line height bootstrap 5 < p class = " lh-1 " > Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Donec sed odio dui. Cras mattis pannenkoek purus sit amet fermentum. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Nullam id dolor id nibh ultricies vehicula ut id elit. Cras mattis consectetur purus sit amet fermentum. </ p > < p class = " lh-sm " > Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Donec sed odio dui. Cras mattis pannenkoek purus sit amet fermentum. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Nullam id dolor id nibh ultricies vehicula ut id elit. Cras mattis consectetur purus sit amet fermentum. </ p > < p class = " lh-base " > Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Donec sed odio dui. Cras mattis pannenkoek purus sit amet fermentum. Praesent commodo cursus magna, vel sceleris