Posts

Showing posts from December, 2010

Calculating SHA 3 Hash In Java

Answer : The common Java reference implementation for crypto and crypto support is probably BouncyCastle. It can be a big library to bring in, which is why we often reach into sun.security (rightly or wrongly.) Anyway, BouncyCastle seems to offer org.bouncycastle.jcajce.provider.digest.SHA3.DigestSHA3 Thanks to @jdv for his answer. I'm adding more information to have a quick start and an example. First, add the BouncyCastle maven dependency, or get it on Maven Central : <dependency> <groupId>org.bouncycastle</groupId> <artifactId>bcpkix-jdk15on</artifactId> <version>1.56</version> </dependency> Then we can test it : import org.bouncycastle.jcajce.provider.digest.SHA3; import org.bouncycastle.util.encoders.Hex; import org.junit.Test; @Test public void testSha3() throws Exception { String input = "Hello world !"; SHA3.DigestSHA3 digestSHA3 = new SHA3.Digest512(); byte[

Battery Indicator Has Disappeared From Gnome Panel

Image
Answer : Note: Try steps 4/5 first, it may be fixed with 1st hit. Below the extended instruction to debug the problem with the indicator. Check if indicator-power-service is running: ps ax | grep indicator-power If it's running, try reset its settings then restart it: dconf reset -f /com/canonical/indicator/power/ pkill -f indicator-power-service No success, locate it then try it from terminal (looking for any errors in output): sudo updatedb; locate -r indicator-power-service$ My system is 64bit, So: /usr/lib/x86_64-linux-gnu/indicator-power/indicator-power-service If it works with command, then some thing wrong with its autostart. As it was checked, it isn't running on start up. Verify the existence of: /usr/share/upstart/sessions/indicator-power.conf description "Indicator Power Backend" # Want to move to indicator-services-[start|end], but that's not all # there yet. Use the signals that exist today for now. start on indicators-

504 Gateway Timeout - Two EC2 Instances With Load Balancer

Answer : What web server are you using? I had a very similar issue with nginx and AWS load balancing. I added keepalive_timeout 75s; to the http block in my nginx config file and haven't see the issue since. Make sure you restart nginx after you add and save that line (on ubuntu sudo service nginx restart . On redhat stop nginx /path/to/nginx/executable -s stop then /path/to/nginx/executable to start up nginx) This fix was recommended by AWS on their help page AWS Load balancer troubleshooting First, what is the Idle Timeout for your ELB set to? You'll find it at the very bottom of the "Description" tab for your load balancer. You can read more about the idle timeout here in the ELB documentation. The default is 60 seconds. You should also consider setting or increasing Keep-alive in your web server. How you do that will depend on what web server you are using. Second, if you think it's due to the client being switched from one instance to the ot

1/2inch = Cm Code Example

Example: inch to cm 1 inch = 2.54 cm

Angular 4 Reactive Form Email Validation By Regular Expression Fail

Answer : The pattern is not correct as a string. In deed you are inside a string so to escape '.' you need to use double backslash like: emailRegEx = '^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,4}$' Or if you want to avoid doing so i suggest to use: emailRegEx = /^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$/ Edit: Keep in mind that this is a simple pattern that exclude a lot of valid email address (see RFC 5322 (sections 3.2.3 and 3.4.1) and RFC 5321). For example the angular build in email validator use the following pattern /^(?=.{1,254}$)(?=.{1,64}@)[-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+(\.[-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+)*@[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?(\.[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?)*$/

Code Html Online Code Example

Example 1: online html compiler #I recommmend https://codepen.io/pen/ Example 2: online html editor <!-- Answer to: "online html editor" --> <!-- A common good "online editor" would be: https://jsfiddle.net/ However, for an online editor focusing specifically on html this one is pretty good: https://html-online.com/editor/ --> Example 3: html online editor <!-- Good HTML Online Editors --> <!-- Links --> https://repl.it https://codeply.com https://jsfiddle.net https://codepen.io Example 4: html online editor // Use the w3schools tryit editor //for example below address https://www.w3schools.com/html/tryit.asp?filename=tryhtml_default Example 5: online html editor <!-- Use CodePen --> https://codepen.io/ Example 6: online html editor <!-- Use the w3schools tryit editor -->

A Way To Output Pyunit Test Name In Setup()

Answer : You can use self._testMethodName . This is inherited from the unittest.TestCase parent class. def setUp(): print "In method", self._testMethodName self.id().split('.')[-1] You can find the Documentation at: http://docs.python.org/library/unittest.html#unittest.TestCase.id edit: For 2.7 users, https://docs.python.org/2.7/library/unittest.html#unittest.TestCase.id You can use str(self.id()).split()[4] . It could be found here http://docs.python.org/library/unittest.html#unittest.TestCase.id

Print Bottom View Of Binary Tree Code Example

Example: gfg bottom view of tree /* This is not the entire code. It's just the function which implements bottom view. You need to write required code. */ // Obj class is used to store node with it's distance from parent. class Obj { public : Node * root ; int dis ; Obj ( Node * node , int dist ) { root = node ; dis = dist ; } } ; // bottom view logic below. void bottomView ( Node * root ) { queue < Obj * > q ; q . push ( new Obj ( root , 0 ) ) ; map < int , int > m ; while ( ! q . empty ( ) ) { Obj * ob = q . front ( ) ; q . pop ( ) ; m [ ob -> dis ] = ob -> root -> data ; if ( ob -> root -> left != NULL ) q . push ( new Obj ( ob -> root -> left , ob -> dis - 1 ) ) ; if ( ob -> root -> right != NULL ) q . push ( new Obj ( ob -&

AWS ELB Apache2 503 Service Unavailable: Back-end Server Is At Capacity

Answer : Solution 1: You will get a "Back-end server is at capacity" when the ELB load balancer performs its health checks and receives a "page not found" (or other simple error) due to a mis-configuration (typically with the NameVirtual host). Try grepping the log files folder using the "ELB-HealthChecker" user agent. e.g. grep ELB-HealthChecker /var/log/httpd/* This will typically give you a 4x or 5x error which is easily fixed. e.g. Flooding, MaxClients etc is giving the problem way too much credit. FYI Amazon: Why not show the returned response from request? Even a status code would help. Solution 2: I just ran into this issue myself. The Amazon ELB will return this error if there are no healthy instances. Our sites were misconfigured, so the ELB healthcheck was failing, which caused the ELB to take the two servers out of rotation. With zero healthy sites, the ELB returned 503 Service Unavailable: Back-end server is at capacity. Solu

Building The Profile Page Of An App In Flutter With Firebase\ Code Example

Example: firebase user profile flutter class StartUpViewModel extends BaseModel {}

Can I Rename Files In A Directory With Vim?

Answer : Yes, it can't be done like that. That "file-browser-type interface" is provided by a built-in plugin called netrw. It is read-only so yeah, you can't modify it. You are supposed to hit R to rename the file under the cursor or the marked files. See :help netrw , :help netrw-browse-maps and more specifically :help netrw-R . If you want to batch-rename files using Vim you should try qmv from the renameutils package or vidir from the moreutils package (thanks to Dmitry for the heads up). Check out the renamer.vim - Use the power of vim to rename groups of files plugin (now purely maintained on GitHub). Like netrw , it presents the directory contents in a scratch buffer, and then lets you edit that buffer, and finally apply the edits to the underlying files.

Best Bollywood Songs Download Code Example

Example: best songs of 2019 bollywood Tujhe Kitna Chahne Lage Hum

Sqrt -32 Code Example

Example: sqrt cpp # include <math.h> //get square root of a number "b" int main ( ) { int a = 2 ; //declare number you want to take square root of int sqrtNum = sqrt ( a ) ; //assign the sqrt value to a variable cout << sqrtNum << endl ; return 0 ; }

App Bar Bootstrap Code Example

Example: bootstrap header //an example of a bootstrap nav bar which you can use as a boilerplate code < nav class = " navbar navbar-expand-lg navbar-light bg-light " > < a class = " navbar-brand " href = " # " > Navbar </ a > < button class = " navbar-toggler " type = " button " data-toggle = " collapse " data-target = " #navbarSupportedContent " aria-controls = " navbarSupportedContent " aria-expanded = " false " aria-label = " Toggle navigation " > < span class = " navbar-toggler-icon " > </ span > </ button > < div class = " collapse navbar-collapse " id = " navbarSupportedContent " > < ul class = " navbar-nav mr-auto " > < li class = " nav-item active " > < a class = " nav-link " href = " # "

Angular V8 - @ViewChild Static True Or False

Answer : Use { static: true } when you want to access the ViewChild in ngOnInit . Use { static: false } will be accessible only in ngAfterViewInit . This is also what you want to do for when you have a structural directive ( *ngIf etc.) in your template. In most cases { static: false } will work. import { Component, OnInit, AfterViewInit, ViewChild, ElementRef } from '@angular/core'; @Component({ selector: 'example', templateUrl: './example.component.html', styleUrls: ['./example.component.scss'] }) export class ExampleComponent implements OnInit, AfterViewInit { @ViewChild('elementA', { static: true }) elementStatic: ElementRef<HTMLElement>; @ViewChild('elementB', { static: false }) elementDynamic: ElementRef<HTMLElement>; public ngOnInit(): void { this.elementStatic.nativeElement; // Ok this.elementDynamic.nativeElement; // ERROR TypeError: Cannot read property 'nativeElement&

Cohen Sutherland Line Clipping Algorithm With Example

Example: Cohen Sutherland Line Clipping Algorithm: In the algorithm, first of all, it is detected whether line lies inside the screen or it is outside the screen. All lines come under any one of the following categories: Visible Not Visible Clipping Case Cohen Sutherland Line Clipping Algorithm: In the algorithm, first of all, it is detected whether line lies inside the screen or it is outside the screen. All lines come under any one of the following categories: Visible Not Visible Clipping Case

C Helloworld Code Example

Example 1: c hello world # include <stdio.h> int main ( ) { printf ( "Hello, world!" ) ; return 0 ; } Example 2: hello word c # include <stdio.h> int main ( ) { // printf() displays the string inside quotation printf ( "Hello, World!" ) ; return 0 ; }

Bootstrap Cdn File W3schools Code Example

Example: bootstrap javascript cdn < script src = " https://code.jquery.com/jquery-3.4.1.slim.min.js " integrity = " sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n " crossorigin = " anonymous " > </ script > < script src = " https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js " integrity = " sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo " crossorigin = " anonymous " > </ script > < script src = " https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js " integrity = " sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6 " crossorigin = " anonymous " > </ script >

Am I Reading Bott - Tu Right?

Answer : It is definitely for someone who already knows the subject and is looking for a different perspective. It is not advanced and it is not introductory, more a supplement. It is also sloppy and very hard to follow for someone who does not know the subject. The praises are from people who know the subject and like the presentation and a few things not easily found elsewhere. Overall, it is not a good book in my opinion. I think Differential Forms in Algebraic Topology is well written. However, it is written in a way a master teaches a student: There are no loss of detail, no fancy language, and explicit examples are everywhere. The student is supposed to emulate Bott's proof writing style, to criticize it, to tease it and understand every detail of it. When I read it I often find questions I would ask myself was discussed by him in very detail. But I am also aware that this is my second or third time reading the book; when I read it the first time my feeling was quite

Change Working Directory In Shell With A Python Script

Answer : Others have pointed out that you can't change the working directory of a parent from a child. But there is a way you can achieve your goal -- if you cd from a shell function, it can change the working dir. Add this to your ~/.bashrc: go() { cd "$(python /path/to/cd.py "$1")" } Your script should print the path to the directory that you want to change to. For example, this could be your cd.py: #!/usr/bin/python import sys, os.path if sys.argv[1] == 'tdi': print(os.path.expanduser('~/long/tedious/path/to/tdi')) elif sys.argv[1] == 'xyz': print(os.path.expanduser('~/long/tedious/path/to/xyz')) Then you can do: tdi@bayes:/home/$> go tdi tdi@bayes:/home/tdi$> go tdi That is not going to be possible. Your script runs in a sub-shell spawned by the parent shell where the command was issued. Any cd ing done in the sub-shell does not affect the parent shell.

Animate CSS Background-position With Smooth Results (sub-pixel Animation)

Answer : Checkout this example: #content { height: 300px; text-align: center; font-size: 26px; color: #000; position:relative; } .bg{ position: absolute; left: 0; right: 0; top: 0; bottom: 0; z-index: -1; background: url(http://www.gstatic.com/webp/gallery/1.jpg) 0% 0% repeat; animation-name: MOVE-BG; animation-duration: 100s; animation-timing-function: linear; animation-iteration-count: infinite; } @keyframes MOVE-BG { from { transform: translateX(0); } to { transform: translateX(-187%); } } <div id="content">Foreground content <div class="bg"></div> </div> http://jsfiddle.net/5pVr4/4/ Animating background-position will cause some performance issues. Browsers will animate transform properties much cheaply, including translate. Here is an example using translate for an infinite slide animation (without prefixes): http://jsfiddle.net/brunomuller/5pVr4/504/ @-webkit-ke