Posts

Showing posts from November, 2012

Python Math.abs Code Example

Example 1: python absolute value >> > abs ( - 15 ) 15 Example 2: math abs python variableName = - 4 print ( abs ( variableName ) ) # output is 4

Add Comments In Batch File Code Example

Example 1: comment lines in batch file :: This is a comment line Example 2: batch comment :: This is a comment REM This is also a comment

Build Python Script To Executable File For Windows/MacOS/Linux

Answer : This tutorial will show you how to convert Python to exe using PyInstaller. Make sure you have Python installed # The first thing is, of course, you have to install Python. Please don't forget to add Python to your PATH environment. Install Pyinstaller # Open your command promt/terminal and execute the command to install PyInstaller pip install Pyinstaller Build Python script to executable binary file # Let say we have a very simple Python script that just print the Hello world text to the console. This file name is "test.py" test.py : print ( "Hello world" ) To build that Python to exe we can use Pyinstaller which was installed in previous step pyinstaller --onefi

Can You "compile" PHP Code And Upload A Binary-ish File, Which Will Just Be Run By The Byte Code Interpreter?

Answer : After this question was asked, Facebook launched HipHop for PHP which is probably the best-tested PHP compiler to date (seeing as it ran one of the world’s 10 biggest websites). However, Facebook discontinued it in favour of HHVM, which is a virtual machine, not a compiler. Beyond that, googling PHP compiler turns up a number of 3rd party solutions. PeachPie PeachPie GitHub compiles PHP to .NET and .NET Core can be compiled into self-contained binary file runs on Mac, Linux, Windows, Windows Core, ARM, ... Phalanger GitHub (download), Wikipedia compiles to .NET (CIL) looks discontinued from July 2017 and doesn't seem to support PHP 7. phc compiles to native binaries not very active now (February 2014) – last version in 2011, last change in summer 2013 Roadsend PHP Compiler GitHub, GitHub of a rewrite free, open source implementation of PHP with compiler compiles to native binaries (Windows, Linux) discontinued since 2010 till contribut

Chrome Console Send Post Request Code Example

Example 1: how to send a post by console chrome fetch('https://www.hackthebox.eu/api/invite/generate', { method: 'POST', body: JSON.stringify({ title: 'foo', body: 'bar', userId: 1 }), headers: { 'Content-type': 'application/json; charset=UTF-8' } }) .then(res => res.json()) .then(console.log) Example 2: chrome developer tools send get request fetch('https://jsonplaceholder.typicode.com/posts/1') .then(res => res.json()) .then(console.log) Example 3: chrome developer tools send get request fetch('https://jsonplaceholder.typicode.com/posts', { method: 'POST', body: JSON.stringify({ title: 'foo', body: 'bar', userId: 1 }), headers: { 'Content-type': 'application/json; charset=UTF-8' } }) .then(res => res.json()) .then(console.log)

Angular 5 Scroll To Top On Every Route Click

Answer : There are some solutions, make sure to check them all :) The router outlet will emit the activate event any time a new component is being instantiated, so we could use (activate) to scroll (for example) to the top: app.component.html <router-outlet (activate)="onActivate($event)" ></router-outlet> app.component.ts onActivate(event) { window.scroll(0,0); //or document.body.scrollTop = 0; //or document.querySelector('body').scrollTo(0,0) ... } Use, for exemple, this solution for a smooth scroll: onActivate(event) { let scrollToTop = window.setInterval(() => { let pos = window.pageYOffset; if (pos > 0) { window.scrollTo(0, pos - 20); // how far to scroll on each step } else { window.clearInterval(scrollToTop); } }, 16); } If you wish to be selective, say not every component should trigger the scrolling, you can

Authenticate Jenkins CI For Github Private Repository

Answer : Perhaps GitHub's support for deploy keys is what you're looking for? To quote that page: When should I use a deploy key? Simple, when you have a server that needs pull access to a single private repo. This key is attached directly to the repository instead of to a personal user account. If that's what you're already trying and it doesn't work, you might want to update your question with more details of the URLs being used, the names and location of the key files, etc. Now for the technical part: How to use your SSH key with Jenkins? If you have, say, a jenkins unix user, you can store your deploy key in ~/.ssh/id_rsa . When Jenkins tries to clone the repo via ssh, it will try to use that key. In some setups, you cannot run Jenkins as an own user account, and possibly also cannot use the default ssh key location ~/.ssh/id_rsa . In such cases, you can create a key in a different location, e.g. ~/.ssh/deploy_key , and configure ssh

Angular 2 Iframe On Website

Answer : You could run an angular app and load it into iframe. In your app, you should create a route where only one component will be visible. Then you can load it into iframe in the other website. Example: your component would be available at http://localhost:4200/components/card and then on your website, you can load it like this: <iframe src="http://localhost:4200/components/card></iframe>

Aria-current= Page Bootstrap Code Example

Example 1: bootstrap breadcrumb < nav aria-label = " breadcrumb " > < ol class = " breadcrumb " > < li class = " breadcrumb-item " > < a href = " # " > Home </ a > </ li > < li class = " breadcrumb-item " > < a href = " # " > Library </ a > </ li > < li class = " breadcrumb-item active " > Data </ li > </ ol > </ nav > Example 2: bootstrap Breadcrumb Indicate the current page’s location within a navigational hierarchy that automatically adds separators via CSS. < nav aria-label = " breadcrumb " > < ol class = " breadcrumb " > < li class = " breadcrumb-item active " aria-current = " page " > Home </ li > </ ol > </ nav > < nav aria-label = " breadcrumb " > < ol class = " breadcru

Line Break In Markdown Code Example

Example 1: line break in code in markdown // Add two spaces at the end of the line This is my first line . ( < -- two spaces ) This is my second line . Example 2: Markdown new line Hello ( < -- two spaces ) World Example 3: markdown break line rstudio blablabla [ 2 x Space , 1 x return ] is equivalent to < br / > next line . . .

Axios See Plain Headers Code Example

Example 1: pass header in axios const headers = { 'Content-Type': 'application/json', 'Authorization': 'JWT fefege...' } axios.post(Helper.getUserAPI(), data, { headers: headers }) .then((response) => { dispatch({ type: FOUND_USER, data: response.data[0] }) }) .catch((error) => { dispatch({ type: ERROR_FINDING_USER }) }) Example 2: axios defaults headers common var instance = axios.create({ baseURL: 'https://some-domain.com/api/', timeout: 1000, headers: {'X-Custom-Header': 'foobar'} });

Colorama Download Python Code Example

Example 1: colorama from colorama import Fore, Back, Style print ( Fore.RED + 'some red text' ) print ( Back.GREEN + 'and with a green background' ) print ( Style.DIM + 'and in dim text' ) print ( Style.RESET_ALL ) print ( 'back to normal now' ) Example 2: how to install colorama Installing with pip is almost always the way to go. It will handle downloading the package for you, as well as any dependencies. If you do not have pip, see http://www.pip-installer.org/en/latest/installing.html. Then pip install colorama or sudo pip install colorama Ba-boom ! Done. Source https://stackoverflow.com/questions/9846683/how-to-install-colorama-python

Cannot Connect To X Server GOOGLE COLAB

Answer : An X server is a program in the X Window System that runs on local machines (i.e. the computers used directly by users) and handles all access to the graphics cards, display screens and input devices (typically a keyboard and mouse) on those computers. With that said Colab runs as a terminal instance in the server, if you are using GPU runtime, then the problem is not with X server accessing your Graphics card, neither with Input devices, generally this occurs when you try to parse some data that should be displayed as separate window on your desktop, commands like cv2.imshow() , there can be other similar functions that can cause this problem, if you have to use graphical ouput you might want to look into %matplotlib notebook and displaying the data in the interactable matplot plots. If this is not your issue, just post a link to your modified code and I might be able to help more. I had the same problem in Colab for a simple OpenCV program to track a tennis ball in

Angular JS Break ForEach

Image
Answer : The angular.forEach loop can't break on a condition match. My personal advice is to use a NATIVE FOR loop instead of angular.forEach . The NATIVE FOR loop is around 90% faster then other for loops. USE FOR loop IN ANGULAR: var numbers = [0, 1, 2, 3, 4, 5]; for (var i = 0, len = numbers.length; i < len; i++) { if (numbers[i] === 1) { console.log('Loop is going to break.'); break; } console.log('Loop will continue.'); } There's no way to do this. See https://github.com/angular/angular.js/issues/263. Depending on what you're doing you can use a boolean to just not going into the body of the loop. Something like: var keepGoing = true; angular.forEach([0,1,2], function(count){ if(keepGoing) { if(count == 1){ keepGoing = false; } } }); please use some or every instances of ForEach, Array.prototype.some: some is much the same as forEach but it break when the callback returns true Array.prototype.e

Best Python Formatter Vscode Extension Code Example

Example 1: python code formatter vs code "python.formatting.provider" : "autopep8" Example 2: python code formatter vs code pip install pep8 pip install - - upgrade autopep8

ActionController::InvalidAuthenticityToken Rails 5 / Devise / Audited / PaperTrail Gem

Answer : As it turns out, Devise documentation is quite revealing with regard to this error: For Rails 5 , note that protect_from_forgery is no longer prepended to the before_action chain, so if you have set authenticate_user before protect_from_forgery , your request will result in " Can't verify CSRF token authenticity. " To resolve this, either change the order in which you call them, or use protect_from_forgery prepend: true . The fix was to change code in my application controller from this: protect_from_forgery with: :exception To this: protect_from_forgery prepend: true This issue did not manifest itself until I attempted adding Audited or Paper Trail gems.

Cannot Use ReadMavenPom In Jenkinsfile

Answer : I needed to install the pipeline-utility-steps plugin.

Bootstrap 3 Font Awesome Cheat Sheet Code Example

Example: https://fontawesome.com TABLES < i class = " fa fa-table " aria-hidden = " true " > </ i >