Posts

Showing posts from August, 2020

Android Project, Change Firebase Account

Answer : Follow the below steps, to switch firebase account Go to your firebase console, and select the project you want to shift Select the icon besides the project name on top right. Select Permissions from the flyout. You've reached the IAM & Admin page of firebase. Click on +Add button on top. Enter the email ID of the account to transfer the project to. In the dropdown, Select a role > Project > Owner. Click add Check mail in the email added above. Accept the invite, and go to IAM & Admin page of the transferred project. Use remove button to delete the previous user Hope this helps. 1- Yes, it's possible and you can follow this tutorial to do so. 2- If you want to simply switch projects, generate a new JSON on the console and remove the old one. If you want to migrate your database, it's possible, just check this question. 3- Both answers are "yes" so, try them out.

Change The Default Base Url For Axios

Answer : Instead of this.$axios.get('items') use this.$axios({ url: 'items', baseURL: 'http://new-url.com' }) If you don't pass method: 'XXX' then by default, it will send via get method. Request Config: https://github.com/axios/axios#request-config Putting my two cents here. I wanted to do the same without hardcoding the URL for my specific request. So i came up with this solution. To append 'api' to my baseURL, I have my default baseURL set as, axios.defaults.baseURL = '/api/'; Then in my specific request, after explicitly setting the method and url, i set the baseURL to '/' axios({ method:'post', url:'logout', baseURL: '/', }) .then(response => { window.location.reload(); }) .catch(error => { console.log(error); }); Create .env.development , .env.production files if not exists and add there your API endpoint, for example: VUE_APP_

An Example Of Encrypting An Xml File In Java Using Bouncy Castle

Answer : What type of encryption do you want to perform? Password-based (PBE), symmetric, asymmetric? Its all in how you configure the Cipher. You shouldn't have to use any BouncyCastle specific APIs, just the algorithms it provides. Here is an example that uses the BouncyCastle PBE cipher to encrypt a String: import java.security.SecureRandom; import java.security.Security; import javax.crypto.Cipher; import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.PBEKeySpec; import org.bouncycastle.jce.provider.BouncyCastleProvider; public class PBE { private static final String salt = "A long, but constant phrase that will be used each time as the salt."; private static final int iterations = 2000; private static final int keyLength = 256; private static final SecureRandom random = new SecureRandom(); public static void main(String [] args) throws Exception {

Androidx.test.InstrumentationRegistry Is Deprecated

Answer : You can use InstrumentationRegistry.getInstrumentation().getTargetContext() in the most cases from androidx.test.platform.app.InstrumentationRegistry . If you need the Application, you can use ApplicationProvider.getApplicationContext<MyAppClass>() . If you haven't already, I think you can also use the new test dependency: androidTestImplementation 'androidx.test:core:1.0.0-beta02' . When you're using Android X you need to make sure you have the following in your app's build.gradle file androidTestImplementation 'androidx.test:core:1.1.0' androidTestImplementation 'androidx.test.ext:junit:1.1.0' The second one is to make sure you have the correct AndroidJUnit4 to use in your tests. Make sure you import both of these. import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 Now instead of using val context = InstrumentationRegistry.getContext() you can use the lin

#333 Color Code Example

Example: #333 color < div > style="background-color:#0000FF">Background Color </ div > "

Change Linear Layout Top Margin Programmatically Android

Answer : layout = (LinearLayout) findViewById(R.id.layoutbtnlinear_aboutme); LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)layout.getLayoutParams(); params.setMargins(0, 50, 0, 0); layout.setLayoutParams(params); LayaoutParams usually create confusion while setting margin because of their parent layout... So this MarginLayoutParams is very useful which works with all layouts. Java Code MarginLayoutParams params = (MarginLayoutParams) view.getLayoutParams(); params.width = 200; //Ths value 200 is in px... Please convert in DP params.leftMargin = 100; params.topMargin = 200; Kotlin code val params: MarginLayoutParams = view!!.layoutParams as MarginLayoutParams params.width = 200 params.leftMargin = 100 params.topMargin = 200 This updates the top margin without the need to update the other margin values. LinearLayout layout = (LinearLayout) findViewById(R.id.your_linear_layout); LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)

Bootstrap Table Responsive In Mobile View Code Example

Example 1: responsive table bootstrap 4 < div class = " table-responsive-sm " > < table class = " table " > ... </ table > </ div > Example 2: responsive bootstrap table < table class = " table " > < thead > < tr > < th scope = " col " > # </ th > < th scope = " col " > First </ th > < th scope = " col " > Last </ th > < th scope = " col " > Handle </ th > </ tr > </ thead > < tbody > < tr > < th scope = " row " > 1 </ th > < td > Mark </ td > < td > Otto </ td > < td > @mdo </ td > </ tr > < tr > < th scope = " row " > 2 </ th > < td > Jacob </ td > < td > Thorn

Youtube Mp3 Playlist Downloader Code Example

Example: youtube dl download playlist mp3 youtube - dl -- extract - audio -- audio - format mp3 - o "%(title)s.%(ext)s" < url to playlist >

BackgroundImage: `url("${src}") Code Example

Example 1: how to set background image for button in css div#submitForm input { background : url ( "../images/buttonbg.png" ) no - repeat scroll 0 0 transparent ; color : # 000000 ; cursor : pointer ; font - weight : bold ; height : 20 px ; padding - bottom : 2 px ; width : 75 px ; } Example 2: adding background image css /* Answer to: "adding background image css" */ /* The background-image property sets one or more background images for an element. By default, a background-image is placed at the top-left corner of an element, and repeated both vertically and horizontally. Tip: The background of an element is the total size of the element, including padding and border (but not the margin). Tip: Always set a background-color to be used if the image is unavailable. */ /* Set a background-image for the <body> element: */ body { background - image : url ( "paper.gif" ) ; background - co

Can I Run Two Ongoing Npm Commands In 1 Terminal

Answer : You could run one process in the background with & (one ampersand, not two) but that would require you to manage it manually, which would be rather tedious. For details see What does ampersand mean at the end of a shell script line?. For that use-case someone built concurrently , which makes it simple to run processes in parallel and keep track of their output. npm install --save-dev concurrently And your start script becomes: "start": "concurrently 'npm run webpack' 'npm run server'" If you want to make the output a little prettier you can give the processes names with -n and colours with -c , for example: "start": "concurrently -n 'webpack,server' -c 'bgBlue.bold,bgGreen.bold' 'npm run webpack' 'npm run server'"

Build HashSet From A Vector In Rust

Answer : Because the operation does not need to consume the vector¹, I think it should not consume it. That only leads to extra copying somewhere else in the program: use std::collections::HashSet; use std::iter::FromIterator; fn hashset(data: &[u8]) -> HashSet<u8> { HashSet::from_iter(data.iter().cloned()) } Call it like hashset(&v) where v is a Vec<u8> or other thing that coerces to a slice. There are of course more ways to write this, to be generic and all that, but this answer sticks to just introducing the thing I wanted to focus on. ¹This is based on that the element type u8 is Copy , i.e. it does not have ownership semantics. The following should work nicely; it fulfills your requirements: use std::collections::HashSet; use std::iter::FromIterator; fn vec_to_set(vec: Vec<u8>) -> HashSet<u8> { HashSet::from_iter(vec) } from_iter() works on types implementing IntoIterator , so a Vec argument is sufficient. Ad

Aggregation With Update In MongoDB

Answer : After a lot of trouble, experimenting mongo shell I've finally got a solution to my question. Psudocode: # To get the list of customer whose score is greater than 2000 cust_to_clear=db.col.aggregate( {$match:{$or:[{status:'A'},{status:'B'}]}}, {$group:{_id:'$cust_id',total:{$sum:'$score'}}}, {$match:{total:{$gt:500}}}) # To loop through the result fetched from above code and update the clear cust_to_clear.result.forEach ( function(x) { db.col.update({cust_id:x._id},{$set:{clear:'Yes'}},{multi:true}); } ) Please comment, if you have any different solution for the same question. With Mongo 4.2 it is now possible to do this using update with aggregation pipeline. The example 2 has example how you do conditional updates: db.runCommand( { update: "students", updates: [ { q: { }, u: [ { $set: { average : { $avg: "$tests&qu

Bot Telegram Python Tutorial Code Example

Example: telegram bot python import telepot from telepot . loop import MessageLoop def handle ( msg ) : content_type , chat_type , chat_id = telepot . glance ( msg ) print ( content_type , chat_type , chat_id ) bot = telepot . Bot ( "INSERT TOKEN HERE" ) bot . message_loop ( handle )

Codeigniter 4 Hmvc Code Example

Example: codeigniter composer create-project codeigniter4/appstarter --no-dev

Closing A Userform With Unload Me Doesn't Work

Answer : As specified by the top answer, I used the following in the code behind the button control. Private Sub btnClose_Click() Unload Me End Sub In doing so, it will not attempt to unload a control, but rather will unload the user form where the button control resides. The "Me" keyword refers to the user form object even when called from a control on the user form. If you are getting errors with this technique, there are a couple of possible reasons. You could be entering the code in the wrong place (such as a separate module) You might be using an older version of Office. I'm using Office 2013. I've noticed that VBA changes over time. From my experience, the use of the the DoCmd.... method is more specific to the macro features in MS Access, but not commonly used in Excel VBA. Under normal (out of the box) conditions, the code above should work just fine. Without seeing your full code, this is impossible to answer with any certainty. The error

Bootstrap Select2 Height Code Example

Example: .select2-selection__arrow { height: 34px !important; } .select2-selection__rendered { line-height: 31px !important; } .select2-container .select2-selection--single { height: 35px !important; } .select2-selection__arrow { height: 34px !important; }

Breaking Up Long Strings On Multiple Lines In Ruby Without Stripping Newlines

Answer : Maybe this is what you're looking for? string = "line #1"\ "line #2"\ "line #3" p string # => "line #1line #2line #3" You can use \ to indicate that any line of Ruby continues on the next line. This works with strings too: string = "this is a \ string that spans lines" puts string.inspect will output "this is a string that spans lines" Three years later, there is now a solution in Ruby 2.3: The squiggly heredoc. class Subscription def warning_message <<~HEREDOC Subscription expiring soon! Your free trial will expire in #{days_until_expiration} days. Please update your billing information. HEREDOC end end Blog post link: https://infinum.co/the-capsized-eight/articles/multiline-strings-ruby-2-3-0-the-squiggly-heredoc The indentation of the least-indented line will be removed from each line of the content.

180 Degrees In Radians Code Example

Example 1: degrees to radians radians = degrees * pi / 180; Example 2: degrees to radians double radians = Math.toRadians(degrees);

Access Google Spreadsheet API Without Oauth Token

Answer : API key is not enough. You're trying to use spreadsheets.values.append which requires OAuth authorization: Authorization Requires one of the following OAuth scopes: https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/spreadsheets For more information, see the [Auth Guide](https://developers.google.com/identity/protocols/OAuth2). Note it says OAuth. You could use the format as below: https://docs.google.com/spreadsheets/d/{sheetID}/export?format=csv Make a URLConnection to this URL, after replacing the sheetID with your public sheet and read the csv file as you would normally do in your programming language of choice. Please note that this is only true for Readable Public Google spreadsheets, and is a bit of a hack when you don't necessarily need to do the Credentials jig and jive In my case I need to publish content from a Google Spreadsheet to a web page. My workaround consists in u