Posts

Showing posts from July, 2010

Classlist.toggle Javascript Code Example

Example 1: toggle css class in javascript /* var or const followed by its name */ . getElementById ( /* HTML element ID */ ) ; /* var or const's name */ . classList . toggle ( /* Name of CSS class */ ) ; // I hope this helps! Example 2: classname toggle js document . getElementById ( 'myButton' ) . onclick = function ( ) { this . classList . toggle ( 'active' ) ; } Example 3: js classlist classList . item ( index ) ; // Returns the item in the list by its index, or undefined if index is greater than or equal to the list's length classList . contains ( token ) ; // Returns true if the list contains the given token, otherwise false. classList . add ( token1 [ , ... tokenN ] ) ; // Adds the specified token(s) to the list. classList . remove ( token1 [ , ... tokenN ] ) ; // Removes the specified token(s) from the list. classList . replace ( oldToken , newToken ) ; // Replaces token with newToken. classList . supports ( token ) ; // R

Chart.js Doughnut With Rounded Edges And Text Centered

Image
Answer : With v2.1.3, you can use the pluginService to do this Preview Script // round corners Chart.pluginService.register({ afterUpdate: function (chart) { if (chart.config.options.elements.arc.roundedCornersFor !== undefined) { var arc = chart.getDatasetMeta(0).data[chart.config.options.elements.arc.roundedCornersFor]; arc.round = { x: (chart.chartArea.left + chart.chartArea.right) / 2, y: (chart.chartArea.top + chart.chartArea.bottom) / 2, radius: (chart.outerRadius + chart.innerRadius) / 2, thickness: (chart.outerRadius - chart.innerRadius) / 2 - 1, backgroundColor: arc._model.backgroundColor } } }, afterDraw: function (chart) { if (chart.config.options.elements.arc.roundedCornersFor !== undefined) { var ctx = chart.chart.ctx; var arc = chart.getDatasetMeta(0).data[chart.config.options.eleme

ASP.NET Core MVC Mixed Route/FromBody Model Binding & Validation

Image
Answer : Install-Package HybridModelBinding Add to Statrup: services.AddMvc() .AddHybridModelBinder(); Model: public class Person { public int Id { get; set; } public string Name { get; set; } public string FavoriteColor { get; set; } } Controller: [HttpPost] [Route("people/{id}")] public IActionResult Post([FromHybrid]Person model) { } Request: curl -X POST -H "Accept: application/json" -H "Content-Type:application/json" -d '{ "id": 999, "name": "Bill Boga", "favoriteColor": "Blue" }' "https://localhost/people/123?name=William%20Boga" Result: { "Id": 123, "Name": "William Boga", "FavoriteColor": "Blue" } There are other advanced features. You can remove the [FromBody] decorator on your input and let MVC binding map the properties: [HttpPost("/test/{rootId}/echo/{id}"

Coin Change Problem Dynamic Programming Code Example

Example: coin change problem minimum number of coins dynamic programming class Main { // Function to find the minimum number of coins required // to get total of N from set S public static int findMinCoins(int[] S, int N) { // T[i] stores minimum number of coins needed to get total of i int[] T = new int[N + 1]; for (int i = 1; i <= N; i++) { // initialize minimum number of coins needed to infinity T[i] = Integer.MAX_VALUE; int res = Integer.MAX_VALUE; // do for each coin for (int c: S) { // check if index doesn't become negative by including // current coin c if (i - c >= 0) { res = T[i - c]; } // if total can be reached by including current coin c, // update minimum number of coins needed T[i] if (res != Integer.MAX_

AngularJS $http Response Header

Answer : You should use: headers('X-TotalPages') (Posting Wawy's answer so the question can be resolved.) For $http(url).then() syntax which replaced $http(url).success().error() in newer versions of AngularJS, I used this: $http(url).then(function(response){ response.headers("X-TotalPages"); }); Just using response.headers() will give all headers attached in response.

Border Radius Table Row Code Example

Example: border radius in table table { border-collapse: collapse; border-radius: 30px; border-style: hidden; /* hide standard table (collapsed) border */ box-shadow: 0 0 0 1px #666; /* this draws the table border */ } td { border: 1px solid #ccc; }

Bootstrap Carousel W3schools Code Example

Example: how to add carousel in javascript <! DOCTYPE html > < html > < head > < meta name = " viewport " content = " width=device-width, initial-scale=1 " > < style > * { box-sizing : border-box } body { font-family : Verdana , sans-serif ; margin : 0 } .mySlides { display : none } img { vertical-align : middle ; } /* Slideshow container */ .slideshow-container { max-width : 1000 px ; position : relative ; margin : auto ; } /* Next & previous buttons */ .prev , .next { cursor : pointer ; position : absolute ; top : 50 % ; width : auto ; padding : 16 px ; margin-top : -22 px ; color : white ; font-weight : bold ; font-size : 18 px ; transition : 0.6 s ease ; border-radius : 0 3 px 3 px 0 ; user-select : none ; } /* Position the "next button" to the right */ .next { right : 0 ; border-radius : 3 px 0 0 3 px ;

Arduino Millis Micros Code Example

Example 1: arduino millis() /*Description Returns the number of milliseconds passed since the Arduino board began running the current program. This number will overflow (go back to zero), after approximately 50 days. Syntax */ time = millis ( ) ; Example 2: arduino millis /*Description Returns the number of milliseconds passed since the Arduino board began running the current program. This number will overflow (go back to zero), after approximately 50 days. Syntax */ time = millis ( ) /* Returns Number of milliseconds passed since the program started. Return Data type: unsigned long. */

Certbot Download Certificate Code Example

Example 1: apt-get install certbot sudo apt-get update sudo apt-get install software-properties-common sudo apt-get install certbot sudo apt-get install python-certbot-apache # apache config sudo certbot --apache Example 2: use certbot to generate certificate # certbot certonly --standalone -d myminio.com --staple-ocsp -m test@yourdomain.io --agree-tos

Append Before Jquery Code Example

Example 1: append before jquery $( "h2" ).insertBefore( $( ".container" ) ); Example 2: append before parent jquery $('ElementBeforeYouWantToInsert').prepend(' < div > the element you want to insert </ div > '); Example 3: jquery append before Consider the following HTML: Html: --------------- < h2 > Greetings </ h2 > < div class = " container " > < div class = " inner " > Hello </ div > < div class = " inner " > Goodbye </ div > </ div > You can create content and insert it into several elements at once: jquery: -------------- $( ".inner" ).prepend( " < p > Test </ p > " ); Each < div class = " inner " > element gets this new content: Html Result: < h2 > Greetings </ h2 > < div class = " container " > < div class = " inner " > < p

Classmethod In Python Code Example

Example 1: class methods in python from datetime import date # random Person class Person : def __init__ ( self , name , age ) : self . name = name self . age = age @classmethod def fromBirthYear ( cls , name , birthYear ) : return cls ( name , date . today ( ) . year - birthYear ) def display ( self ) : print ( self . name + "'s age is: " + str ( self . age ) ) person = Person ( 'Adam' , 19 ) person . display ( ) person1 = Person . fromBirthYear ( 'John' , 1985 ) person1 . display ( ) Example 2: python: @classmethod class Float : def __init__ ( self , amount ) : self . amount = amount def __repr__ ( self ) : return f'<Float { self . amount : .3f } >' @classmethod def from_sum ( cls , value_1 , value_2 ) : return cls ( value_1 + value_2 ) class Dollar ( Float ) : def __init__ ( self

CanvasJS In Javascript Code Example

Example: javascript create canvas var canvas = document . createElement ( "canvas" ) ; //Create canvas document . body . appendChild ( canvas ) ; //Add it as a child of <body>

All Minecraft Bastion Types Code Example

Example 1: types of bastions minecraft lol no i'm a speedrunner Example 2: types of bastion minecraft hey, are you into modding or something?

Bash Add Pause Prompt In A Shell Script With Bash Pause Command Code Example

Example 1: Bash add pause prompt in a shell script with bash pause command read -p "Press [Enter] key to start backup..." read -p "Press any key to resume ..." ## Bash add pause prompt for 5 seconds ## read -t 5 -p "I am going to wait for 5 seconds only ..." Example 2: pause bash script function pause ( ) { read -s -n 1 -p "Press any key to continue . . ." echo "" } ## Pause it ## pause ## rest of script below

Bash For Loop One Line Code Example

Example 1: while bash one line while CONDITION_STATEMENT ; do SOME_CODE ; done Example 2: bash single line loop while true ; do foo ; sleep 2 ; done Example 3: linux for loop one line for i in { 1 .. 5 } ; do COMMAND-HERE ; done

Cloned Items In Owl Carousel

Answer : I had this issue - I found that setting the loop option to false resolved it for me. So, I've been banging my head over this cloning issue with passing click events to the cloned slide.... what finally solved it for me is to set these two config values: loop: false, rewind: true This will allow the carousel to still loop around but not duplicate slides. Get ready for Awesome solution of this problem: If you want to set loop:true in case of having more than particular number of items (in my case i am using 5 items on a screen, total scrollable items are 15) loop: ( $('.owl-carousel .items').length > 5 ) Above solution will not run loop in case of having less than 6 items while loop will be enabled automatically in case of having more than 5 items. This solved my problem, i hope, this will also help you. Thanks for asking this question and enjoy this code :)

AWS Elasticache Timeout From EC2

Image
Answer : I think the problem is about security groups of your instance. To the best of my knowledge you need to allow the traffic on the security group associated to your EC2 instance. If you are using memcached the port is 11211 if redis the port is 6379 Try to have a look to the AWS official documentation. http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/GettingStarted.AuthorizeAccess.html I hope this helps somehow. First, check the instance security group and check port 6379 is allowed in Inbound. After that, check your default VPC security group and add inbound rule Custom TCP Rule-6379-Anywhere and save. I hope this will fix the issue. Actually solution is to add security group to elasticache cluster, and this security group should allow 6379 port.