天道酬勤,学无止境

问答

Ruby: How to parse a string to pull something out and assign it to a variable

I have a string that looks something like this: "my name is: andrew" I'd like to parse the string, pull out the name from the string, and assign it to a variable. How would I do this with Ruby? Update: The string I used as an example was only an example. The strings that I will be working with can change formats, so you can't rely on the colon being in the actual example. Here are a few examples that I'm working with: "/nick andrew" # command: nick, value: "andrew" "/join developers" # command: join, value: "developers" "/leave" # command: leave, value: nil I'd like to use some sort of regular

2022-05-03 09:03:27   ruby

Trouble loading local modules only with AWS Lambda

app structure: . ├── Makefile ├── Pipfile ├── Pipfile.lock ├── README.md ├── template.yaml ├── tests │ ├── __init__.py │ └── unit │ └── lambda_application │ ├── test_handler.py │ └── test_parent_child_class.py └── lambda_application ├── __init__.py ├── first_child_class.py ├── lambda_function.py ├── second_child_class.py ├── requirements.txt └── parent_class.py 4 directories, 14 files Code sample from lambda_function.py: import os import json from hashlib import sha256 import boto3 from requests import Session from .first_child_class import FirstChildClass def lambda_handler(event, context): #

2022-05-03 09:03:22   python   python-3.x   amazon-web-services   aws-lambda

How to get SHA1 code in new version of android studio 4.2?

Before this update we can get SHA1 code from Gradle but now it's look like it's changed.

2022-05-03 09:03:17   java   android   sha1   android-studio-4.2

Is it possible to find the number of triangles that can be formed from a list of lengths in better than (n choose 3) time?

This relates to a larger problem I'm working on. For example, let's say we're given a list 9 5 6 1 The possible triangles would have sides of length (9,5,6) (9,6,1) (9,5,1) (5,6,1) and the ones that are valid (by the triangle inequality) are (9,5,6) (5,6,1) Is it possible to find those valid ones in better-than-O(n choose 3) time?

2022-05-03 09:02:46   algorithm   language-agnostic   time-complexity   complexity-theory

Get timezone offset from timezone name using Javascript

I found many solution that gives Timezone name from offset value. But I have Timezone name and I want offset value for that. I tried setTimezone('Asia/Kolkata'), but I think their is no method like setTimezone. example: Asia/Kolkata should give me -330 ( offset )

2022-05-03 09:02:42   javascript   jquery   timezone   timezone-offset

Left-justify geom_text layer with ggplot2

ggplot2 automatically centers the text in a geom_text layer. For example: library(ggplot2) library(tidyverse) df <- data_frame(text = c("A short sentence.", "A slightly longer sentence.", "This sentence is the longest of the sentences."), y = row_number(text) - 1, x = 1) ggplot(df, aes(x = x, y = y)) + geom_text(aes(label = text), nudge_x = nchar(text)/2) Produces: ggplot: However, I want to left-justify the text in a neat column. I'm essentially asking how to provide an xmin to the text. Do I need to perform a mathematical operation on the x variable that scales x accordingly? Or is there a

2022-05-03 09:02:37   r   ggplot2   geom-text

Problems setting PATH in Makefile

I'm new to make and Makefiles, but I'm trying to create one for my next project and I'm running into PATH issues. I keep getting the error: "No such file or directory" I've created a simple target called test that runs all my tests using mocha. Mocha is installed as a local node module, so its executable can be found at ./node_modules/.bin/mocha. I'm altering my PATH as described in this make tutorial so I can refer to it as mocha instead of typing the full path, but something doesn't seem to be working. Here's what I have so far: export PATH := node_modules/.bin:$(PATH) test: which mocha

2022-05-03 09:02:27   makefile

Flutter onPressed() vs onTap()

I've been using Flutter for about 8 weeks. It's awesome, no question. However, there has been something bugging me since I've started, and that is, why do some widgets have an onTap method whilst others have onPressed? Google has not been able to give me any answers. If this is not relevant or on-topic enough for Stack Overflow, sorry about that, please point me to the right community to ask.

2022-05-03 09:02:21   flutter

Pycharm code reformatting: align lines by operator

In Jetbrains Pycharm (Professional, 2016.1), is there a way (built in or third-party) to modify the code style in python to align consecutive lines by an operator, particularly an assignment one? For example, I would like var1 = 5 variable2 = 10 varbl3 = 15 to be reformatted to var1 = 5 variable2 = 10 varbl3 = 15 I am aware of several packages that let me do this manually with an external command (I am currently using Front-End Alignment, but String Manupulation also works decently), but it precludes me from also using code reformatting (which I otherwise find very useful) on the same piece of

2022-05-03 09:02:17   python   alignment   pycharm   text-alignment

Get the URL generated from a form on submit with JavaScript

Is it possible to catch the URL generated from a form when firing its 'submit' event? I know I can generate the URL from data I'm not talking about form's action URL I mean the ?field=value&other-input-name=value& ... part Scenario: We have a form and a JavaScript script which sends an Ajax request to a PHP script. I usually do like this: Register for the form's submit event Prevent the default behavior Construct a URL from data Open an HTTP request with the constructed URL Now, I was wondering, when firing 'submit' normally (on non-Ajax requests) the URL gets constructed by the form, which

2022-05-03 09:01:56   javascript   ajax   form-submit   dom-events   onsubmit