Posts

Showing posts from January, 2015

Associate A Private Key With The X509Certificate2 Class In .net

Answer : You can save yourself the hassle of copy-pasting all that code and store the private key next to the certificate in a pfx / pkcs#12 file: openssl pkcs12 -export -in my.cer -inkey my.key -out mycert.pfx You'll have to supply a password, which you have to pass to the constructor of X509Certificate2 : X509Certificate2 cert = new X509Certificate2("mycert.pfx","password"); For everyone else with the same problem, I found a neat little piece of code that let's you do exactly that: http://www.codeproject.com/Articles/162194/Certificates-to-DB-and-Back byte[] certBuffer = Helpers.GetBytesFromPEM(publicCert, PemStringType.Certificate); byte[] keyBuffer = Helpers.GetBytesFromPEM(privateKey, PemStringType.RsaPrivateKey); X509Certificate2 certificate = new X509Certificate2(certBuffer, password); RSACryptoServiceProvider prov = Crypto.DecodeRsaPrivateKey(keyBuffer); certificate.PrivateKey = prov; EDIT: The code for the Helper method (which ot

Switch Case Range Arduino Code Example

Example: arduino switch case switch ( var ) { case label1 : // statements break ; case label2 : // statements break ; default : // statements break ; }

Archive Artifacts In Jenkins

Answer : You cannot remove the 'prefix' of a path using just the archive artifacts setting. (Some of the upload extensions do support this - the Publish over FTP plugin for example) If you really need this a simple solution is to add an extra build step that copies your Debug folder to the root of the project workspace. A cleaner way might be to have a stage dedicated to producing artifacts, set up with the appropriate working directory: stage('Release') { steps { dir('MyApp1/MyApp1/bin/Debug') { archiveArtifacts artifacts: '**', fingerprint: true } } }

Cannot Open Source File "iostream.h"C/C++ Code Example

Example: cannot open source file "iostream" //include paths gcc -v -E -x c++ -

Angular: Scroll Dynamic Element Into View Knowing Only Its ID

Answer : You want the id to be on the actual item that the ng-for creates, not the ng-for itself. That would eliminate the need for any extra logic when passing data to the list from the component. // inside ngAfterViewInit() to make sure the list items render or inside ngAfterViewChecked() if you are anticipating live data using @Inputs const itemToScrollTo = document.getElementById('item-' + id); // null check to ensure that the element actually exists if (itemToScrollTo) { itemToScrollTo.scrollIntoView(true); } <div class="list" *ngFor="let item of functionThatGetsItems(); let i = index"> <div class="list-item" id="item-{{i}}"> <div class="title"> {{ item.title }} </div> <div class="content"> {{ item.content }} </div> </div> </div> This is not strictly angular, but you could do document.querySelector('#MyList31'

BigDecimal In JavaScript

Answer : I like using accounting.js for number, money and currency formatting. Homepage - https://openexchangerates.github.io/accounting.js/ Github - https://github.com/openexchangerates/accounting.js

Cmd Sleep Command Code Example

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

Bootstrap Textarea Form Whole Row Code Example

Example 1: bootstrap form < form > < div class = " form-group " > < label for = " exampleInputEmail1 " > Email address </ label > < input type = " email " class = " form-control " id = " exampleInputEmail1 " aria-describedby = " emailHelp " placeholder = " Enter email " > < small id = " emailHelp " class = " form-text text-muted " > We'll never share your email with anyone else. </ small > </ div > < div class = " form-group " > < label for = " exampleInputPassword1 " > Password </ label > < input type = " password " class = " form-control " id = " exampleInputPassword1 " placeholder = " Password " > </ div > < div class = " form-group form-check " > < input type = " ch

#1191 - Can't Find Fulltext Index Matching The Column List Code Example

Example: Can't find FULLTEXT index ALTER TABLE `items` ADD FULLTEXT(`item_title`,`item_description`); SELECT * FROM items WHERE MATCH (item_title,item_description) AGAINST ('dog');

Android Notification Icon Is A White Circle

Image
Answer : You must use a notification icon with no background. Android will add the circle background. You can set background color with .setColor(context.getResources().getColor(R.color.colorPrimary)) to match your app indentity. Icon inside will remain white and circle will get the color you defined. If your compileSDKversion is above 20 then notification icon should be a white-on-transparent background image. Otherwise the image will be rendered as a white colored image. Please go through the below link too for guidelines to create the icon https://www.google.com/design/spec/patterns/notifications.html and also the notification icon generator. https://romannurik.github.io/AndroidAssetStudio/icons-notification.html#source.space.trim=1&source.space.pad=0&name=ic_stat_example It seems to be a problem of cache during compilation ... The first image I was using was bad (fully colored), so I think my compilator created somekind of cache on the filename. I

Add Onclick Event Handler To Button Using Jquery Code Example

Example 1: on click jquery $ ( " #target " ) .click ( function ( ) { alert ( "Handler for .click() called." ) ; } ) ; Example 2: set onclick jquery $ ( elem ) . click ( myFunc ( ) ) ;

Android Button With Rounded Corners, Ripple Effect And No Shadow

Answer : I finally solved it with below code. This achieve rounded corners for button. Also, for Android Version >= V21, it uses ripple effect. For earlier Android version, button color changes when it is clicked, based on android:state_pressed, android:state_focused , etc. In layout xml file: <Button style="?android:attr/borderlessButtonStyle" android:id="@+id/buy_button" android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent" android:gravity="center" android:background="@drawable/green_trading_button_effect" android:textColor="@android:color/white" android:text="BUY" /> For button onclick ripple effect (Android >= v21) : drawable-v21/green_trading_button_effect.xml <?xml version="1.0" encoding="utf-8"?> <ripple xmlns:android="http://schemas.android.com/apk/res/android

Arduino Mapping Function Code Example

Example 1: map arduino Syntax map ( value , fromLow , fromHigh , toLow , toHigh ) Parameters value : the number to map . fromLow : the lower bound of the value’s current range . fromHigh : the upper bound of the value’s current range . toLow : the lower bound of the value’s target range . toHigh : the upper bound of the value’s target range . Example : map ( val , 0 , 255 , 0 , 1023 ) ; Example 2: arduino map function long map ( long x , long in_min , long in_max , long out_min , long out_max ) { return ( x - in_min ) * ( out_max - out_min ) / ( in_max - in_min ) + out_min ; }

Yt Mp3 Converter Online Code Example

Example: yt to mp3 Youtube - DL works great . Download from https : //youtube-dl.org/. To use, type youtube-dl <url> --audio-format mp3

Android.support.design.widget.TextInputLayout Could Not Be Instantiated

Answer : replace android.support.design.widget.TextInputLayout with com.google.android.material.textfield.TextInputLayout If you uses AndroidStudio, you should not include android-support-design.jar. Instead, write like below in your build.gradle: dependencies { ... compile 'com.android.support:design:24.0.0' ... } Edit : If this doesn't work you are probably using a different version. In Windows, go to: [android-sdk]\extras\android\m2repository\com\android\support\design On Mac: sdk/extras/android/m2repository/com/android/support/design This directory holds a number of version folders. Use the latest version on your build.gradle. add in the build.gradle following this line: implementation 'com.android.support:design:28.0.0' and use in the xml file: <com.google.android.material.textfield.TextInputLayout android:id="@+id/inputLayoutMobile" android:layout_width="ma

"apt-get Update" Fails? (Kali Linux With Virtual Box)

Answer : The solution is to change mirror in sources.list file. For some reason the default mirror is not working. There are several mirrors of the Kali Linux repository server, all of which are spread over the world. Each time you interact with the repository, by default it will automatically use the mirror that is closest to you based on your geoip location (idea being, this will give you the best speed due to less latency). However, you can manually force kali to use a certain/different mirror rather than the one that is nearest you. Go to http://http.kali.org/README.mirrorlist where you will have a list of mirrors to chose from. First backup your current source file mv /etc/apt/sources.list /etc/apt/sources.list.backup Then create a new sources.list file vim /etc/apt/sources.list and enter new mirror. For example, old sources.list file was deb http://http.kali.org/kali kali-rolling main contrib non-free The new sources.list file can be deb http://archiv

Android Studio Background Color Codes Code Example

Example: android studio set background color YourView.setBackgroundColor(Color.argb(255, 255, 255, 255));

Android : Control Smooth Scroll Over Recycler View

Answer : It's unclear what you mean when you say " smoothScroll ". You could be referring to the automatic " smoothScrollToPosition " which will automatically scroll to a specified position, you could be talking about manual scrolling and you could be talking about flinging. For the sake of prosperity, I will attempt to answer all of these issues now. 1. Automatic smooth scrolling. Inside your layout manager, you need to implement the smoothScrollToPosition method: @Override public void smoothScrollToPosition(RecyclerView recyclerView, State state, int position) { // A good idea would be to create this instance in some initialization method, and just set the target position in this method. LinearSmoothScroller smoothScroller = new LinearSmoothScroller(getContext()) { @Override public PointF computeScrollVectorForPosition(int targetPosition) { int yDelta = calculateC

Are There Any Big Spring-boot Open Source Projects?

Answer : Here are some non pet store but a real world , non trivial , and open source application that use Spring Boot 2. Thingsboard which is an IoT platform with the microservice architecture using Spring Boot 2 Flowable is a business process engines that are based on Spring and have already upgrade to support Spring Boot 2.0 Spring Initializr is the backend web API that can quickly generate a sample spring-boot project. It is exactly the backend API that powered the famous start.spring.io. Kafdrop is the web client that managing Kafka. Built with Spring Boot, Spring MVC, Freemarker etc. Kafkawize is another web client that managing Kafka. Built with Spring Boot, Spring MVC, Spring Security,Spring Data JPA and Thymeleaf etc. The backend of the Corona-Warn-App which is an app that helps trace infection chains of COVID-19 in Germany.Built with Spring Boot, Spring MVC, Spring Security,Spring Data JPA, Bean Validation etc. CloudFoundry User Account and Authentication (UA

Add Arraylist Java Code Example

Example 1: java insert into arraylist ArrayList < Integer > str = new ArrayList < Integer > ( ) ; str . add ( 0 ) ; str . add ( 1 ) ; // Result = [0, 1] str . add ( 1 , 11 ) ; // Result = [0, 11, 1] Example 2: insert element into arraylist java ArrayList < String > arrayList = new ArrayList < > ( ) ; // Adds element at the back of the list arrayList . add ( "foo" ) ; arrayList . add ( "bar" ) ; // Result = ["foo", "bar"] // Adds element at the specified index arrayList . add ( 1 , "baz" ) ; // Result = ["foo", "baz", "bar"] Example 3: how to add to an arraylist java import java . util . ArrayList ; public class Details { public static void main ( String [ ] args ) { //ArrayList<String> Declaration ArrayList < String > al = new ArrayList < String > ( ) ; //add method for String ArrayList

Change Status Bar Text Color Android Programmatically Code Example

Example 1: change status bar text color android programmatically WindowInsetsControllerCompat( < window > , < view > ).isAppearanceLightStatusBars = Boolean Window window = Activity.getWindow(); View view = window.getDecorView(); // You need androidx.core for this Example 2: change status bar color android programmatically public void statuscolor(){ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(Color.parseColor(getPreferences().getString(Constant.SECONDARY_COLOR, Constant.SECONDARY_COLOR))); } } Example 3: change status bar color android // for my fellow react-native developers // add this in styles.xml < resources > <!-- Base application theme. --> < style name = " AppTheme " parent = " Theme.AppCompat.DayNight.NoAction

Priority Cpu Scheduling Program In Java Code Example

Example: preemptive priority scheduling implementation in c # include <iostream> # include <algorithm> # include <iomanip> # include <string.h> using namespace std ; struct process { int pid ; int arrival_time ; int burst_time ; int priority ; int start_time ; int completion_time ; int turnaround_time ; int waiting_time ; int response_time ; } ; int main ( ) { int n ; struct process p [ 100 ] ; float avg_turnaround_time ; float avg_waiting_time ; float avg_response_time ; float cpu_utilisation ; int total_turnaround_time = 0 ; int total_waiting_time = 0 ; int total_response_time = 0 ; int total_idle_time = 0 ; float throughput ; int burst_remaining [ 100 ] ; int is_completed [ 100 ] ; memset ( is_completed , 0 , sizeof ( is_completed ) ) ; cout << setprecision ( 2 ) << fixed ;