python |
Pythonタグが付けられた新着投稿 - Qiita |
Blenderで2つのオブジェクトの頂点の差分を調べる |
https://qiita.com/SaitoTsutomu/items/8b40d349511e63f64081
|
blender |
2022-05-08 20:17:53 |
python |
Pythonタグが付けられた新着投稿 - Qiita |
基本的な出力層の活性化関数と損失関数の組み合わせまとめ(TF2.0) |
https://qiita.com/pocokhc/items/d67b63ec9ca74b453093
|
binarycrossentropy |
2022-05-08 20:06:07 |
js |
JavaScriptタグが付けられた新着投稿 - Qiita |
【JavaScript】for of文の使い方(foreachの代わり) |
https://qiita.com/poipoi_PHPer/items/b0f33fd4dda340e265d7
|
letarrayvaluevaluevalueva |
2022-05-08 20:52:19 |
js |
JavaScriptタグが付けられた新着投稿 - Qiita |
Heroku scheduler addonの画面でUTCではなく日本時間を表示する |
https://qiita.com/kanaxx/items/3c9cdbd0129308eac235
|
herokuscheduler |
2022-05-08 20:25:47 |
AWS |
AWSタグが付けられた新着投稿 - Qiita |
AWSリソースの自動起動停止について |
https://qiita.com/ys1/items/b5ea8bff2729aa7b2bcf
|
自動起動 |
2022-05-08 20:57:00 |
Git |
Gitタグが付けられた新着投稿 - Qiita |
メモ: GitHubへの commit と push で使うアカウントが違う? (Windows) |
https://qiita.com/Icy9ptcl/items/746440337ee95e112ebb
|
commit |
2022-05-08 20:19:44 |
Ruby |
Railsタグが付けられた新着投稿 - Qiita |
【Rails】deviseでログイン機能実装 |
https://qiita.com/zoukun97/items/c2d52a881f69e65dcb51
|
railsgenera |
2022-05-08 20:08:15 |
技術ブログ |
Developers.IO |
NLBのターゲットにALBを登録する構成で、HTTPからHTTPSへのリダイレクトをさせる |
https://dev.classmethod.jp/articles/nlb-target-alb-http-https-redirect/
|
bapplicationloadbalancer |
2022-05-08 11:29:45 |
技術ブログ |
Developers.IO |
Issue EventによりGitHub Actionsを実行してFile/Branch/Pull Requestを作成する |
https://dev.classmethod.jp/articles/creating-a-file-branch-pull-request-from-github-actions-by-issue-event/
|
filebranchpullrequest |
2022-05-08 11:26:46 |
海外TECH |
Ars Technica |
Corals convert sunscreen chemical into a toxin that kills them |
https://arstechnica.com/?p=1852873
|
alters |
2022-05-08 11:00:37 |
海外TECH |
MakeUseOf |
YouTube Go Is Shutting Down: Here's Everything You Need to Know |
https://www.makeuseof.com/youtube-go-is-shutting-down-what-to-know/
|
YouTube Go Is Shutting Down Here x s Everything You Need to KnowYouTube Go is going away but YouTube promises improvements to the main app so everyone can use it Here s what you need to know |
2022-05-08 11:15:14 |
海外TECH |
DEV Community |
The ABCs of NestJS: A Beginner’s guide with MongoDB(Mongoose). |
https://dev.to/davidekete/the-abcs-of-nestjs-a-beginners-guide-with-mongodbmongoose-2ln
|
The ABCs of NestJS A Beginner s guide with MongoDB Mongoose What is NestJS NestJS is a modern NodeJS framework that makes use of popular NodeJS frameworks such as Express and Fastify under the hood NestJS was largely inspired by Angular and as a result it employs an Angular style module system NestJS is written in TypeScript although it also supports native JavaScript PrerequisitesTo follow this tutorial you must meet the following requirementsCompetence in PostMan or any other API testing tool Basic Knowledge of NodeJS and Express apps Basic knowledge of TypeScript Competence in MongoDB Mongoose The following should be installed on your system NodeJS v and above Visual Studio Code Recommended or any other IDE PostMan or any other API testing Tool Common Terminologies used in NestJS Here are some of the most regularly used terms in NestJS that you ll encounter a lot in this article InterfacesAn interface is a type definition As a result it is utilized as a type checker enforcer in functions classes etc interface humanInterface name string gender string age number const kevin humanInterface name Kevin Sunders gender Male age The humanInterface above performs strict type checking on the kevin object Typescript would throw an error if you added another field or changed the type of any of the object properties ControllersControllers are in charge of receiving incoming requests and responding to the client A controller collaborates with its associated service ServicesA service is a provider that stores and retrieves data and is used with its corresponding controller DecoratorsA decorator is a function returning expression that accepts a target name and property descriptor as optional arguments Decorators are written as decorator name They are usually attached to class declarations methods and parameters Get getAll Model return this testService getAll The Get decorator above marks the code block below it as a GET request More about that later on ModuleA module is a part of a program that handles a particular task A module in NestJS is marked by annotating a class annotated with the Module decorator Nest uses the metadata provided by the Module decorator to organize the application structure Installing the CLITo get started you ll have to install the NestJS CLI with npm You can skip this step if you already have the NestJS CLI installed on your system npm i g nestjs cliThis code block above will install the nest CLI globally on your system Creating a new projectTo generate a new project run nest new followed by your desired project name For this article we ll be writing a simple blog API with CRUD functionality while adhering to RESTful standards nest new Blog ApiThis command will prompt you to select a package manager choose npm This will then scaffold the entire project structure with a test API endpoint whose port is set to by default You can test it at http localhost http localhost after running the npm run start dev command which will start the server in watch mode similar to what nodemon does in express apps After testing the endpoint you ll need to delete some of the default files because you won t be needing them anymore To do this open the src folder and inside delete app controller spec ts delete app controller ts delete app service ts Open app module ts Remove the reference to AppController in the controllers array and the imports Remove the reference to AppService in the providers array and the imports You might also need to change the README md to meet your specifications Your app module ts file should look like this app module tsimport Module from nestjs common Module imports controllers providers export class AppModule Environmental VariablesAs good practice some sensitive information in your code shouldn t be made public For example your PORT and your MongoDB URI Let s fix this in your code On your terminal runnpm i dotenvThen create a env file in your directory and add it to your gitignore file Store your PORT variable you will also have to store your MongoDB URI later in the same place Now replace the exposed PORT in your main ts file To do this import the dotenv package and call the config method on it import as dotenv from dotenv dotenv config This should be your main ts file after you follow the steps above main tsimport NestFactory from nestjs core import AppModule from app module import as dotenv from dotenv dotenv config async function bootstrap const app await NestFactory create AppModule await app listen process env PORT bootstrap Generating ModulesTo generate a NestJS module using the NestJS CLI run the code snippet below nest generate module blogsThis command creates a blogs folder that contains a blogs module ts file and registers BlogsModule in your app module ts file Generating InterfacesLet s generate an interface using the NestJS CLI to do the type checking for the object that will represent your blog posts To achieve this you have to first cd into the blogs folder because it is recommended that they be stored near the domain objects to which they are associated cd src blogsThen run the code snippet below to generate the interface nest generate interface blogsthis creates a blogs interface ts file This is where we will define our interface we ll name the interface BlogsInterface export interface BlogsInterface title string body string category string dateCreated Date before running any more commands on your terminal remember to cd out of the src folder and back into your root folder by runningcd Generating Services amp ControllersYou ll need to generate a service class to store and retrieve data and handle all the logic and a controller class to handle all incoming requests and outgoing responses ServiceTo generate a service run the command below nest generate service blogsThis command creates two files the blogs service spec ts and the blogs service ts and registers the service in the providers array in the blogs module ts ControllerTo generate a controller run the command below nest generate controller blogsThis command creates two files the blogs controller spec ts and the blogs controller ts and registers the controller in the controllers array in the blogs module ts With these your blogs structure is almost complete you just need to make the BlogsService accessible to other parts of your program You can achieve this by creating an exports array in the blogs module ts file and registering the BlogsService in that array blogs module tsimport Module from nestjs common import BlogsService from blogs service import BlogsController from blogs controller Module providers BlogsService controllers BlogsController exports BlogsService export class BlogsModule MongoDB Mongoose Install mongoose by running npm install save nestjs mongoose mongooseAfter the installation import MongooseModule from nestjs mongoose into your app module ts file Then grab your MongoDB URI and store it in your env file Repeat the steps to import dotenv in the app module ts file Then in the imports array call the forRoot method which takes your MongoDB URI as an argument on the MongooseModule Similar to the mongoose connect in regular express apps Module imports BlogsModule MongooseModule forRoot process env MONGODB URI Creating a Schema Let s create a schema to define the shape of the blogs in our collection To do this Create a folder inside your blogs folder name it schemas Inside the schemas folder create a file and call it blogs schema ts Then Firstly you ll have to Import the prop decorator the Schema decorator and the SchemaFactory from nestjs mongoose Create a class Blog and export it Turn the class into a Schema by placing the Schema decorator above the class Create a constant BlogSchema assign the return value of calling the createForClass Blog with the name of your class as an argument on SchemaFactory that you imported earlier blogs schema tsimport Prop Schema SchemaFactory from nestjs mongoose Schema export class Blog export const BlogSchema SchemaFactory createForClass Blog Then you ll need to define the properties of the Schema To define a property in the schema you ll need to mark each of them with the prop decorator The prop decorator accepts an options object or a complex type declaration The complex type declarations could be arrays and nested object type declarations blogs schema tsimport Prop Schema SchemaFactory from nestjs mongoose Schema export class Blog Prop required true title string Prop required true body string Prop required true category string Prop required true dateCreated Date export const BlogSchema SchemaFactory createForClass Blog Next import Document from mongoose Then create a union type with the Schema class and the imported Document Like so blogs schema tsimport Document from mongoose export type BlogDocument Blog amp Document Your final blogs schema ts file should look like this import Prop Schema SchemaFactory from nestjs mongoose import Document from mongoose export type BlogDocument Blog amp Document Schema export class Blog Prop required true title string Prop required true body string Prop required true category string Prop required true dateCreated Date export const BlogSchema SchemaFactory createForClass Blog Registering SchemaYou ll need to import everything into your blogs module ts file To achieve this you ll need to Import MongooseModule from nestjs mongoose Import Blog BlogSchema from schemas blogs schema Create an imports array inside the module decoratorCall the forFeature method on the MongooseModule This takes in an array containing an object that defines a name and a schema property which should be set to your Blog name and your BlogSchema respectively Module imports MongooseModule forFeature name Blog name schema BlogSchema Injecting SchemaYou ll need to inject the Blog model into the blogs service ts using the InjectModel decorator To achieve this you ll have toimport Model from mongoose import InjectModel from nestjs mongoose Import Blog BlogSchema from schemas blogs schema Create a constructor inside the BlogsService class Declare a private variable and call it blogModel and assign a type of Model lt BlogDocument gt to it All mongoose methods will be called on this variable Recall that BlogDocument is the union type of the Blog class and the Mongoose Model that you created earlier It is used as the generic type for your variable Decorate blogModel with InjectModel and pass Blog name as an argument constructor InjectModel Blog name private blogModel Model lt BlogDocument gt How Routing WorksBy now you must have noticed that the Controller decorator has the string blogs passed into it This means that the controller will send all responses and handle all requests made on http localhost blogs Next up you ll implement the service and controller logic Service and Controller Logic It s finally time to implement your CRUD functionality Before we get started you ll need to set up your controller Start by importing some HTTP method decorators into your controller blogs controller tsimport Controller Body Delete Get Post Put Param from nestjs common Then you ll need to import the service and register it so you can be able to access it and import the interface for type checking blogs controller tsimport BlogsInterface from blogs interface import BlogsService from blogs service To register your service create a constructor inside the BlogsController class and declare a private readonly variable service and set its type to BlogsService constructor private readonly service BlogsService Now that you re all set up let s get started CreateService LogicImport BlogsInterface from blogs interface and add an async function to the BlogsService class called createBlog which will take one parameter blog with its type as BlogInterface and its return type as a Promise with a generic lt Blog gt type async createBlog blog BlogsInterface Promise lt Blog gt return await new this blogModel blog dateCreated new Date save Controller LogicIn your BlogsController class add an async function to the class Call it createBlog and mark it with the Post decorator which defines it as a POST request createBlog takes one parameter blog with its type as BlogInterface Mark the parameter with Body decorator which extracts the entire body object from the req object and populates the decorated parameter with the value of body Post async createBlog Body blog BlogsInterface return await this service createBlog blog ReadAdd two async methods One to return a single blog post and the second to return all the blog posts Service Logicasync getAllBlogs Promise lt Blog gt return await this blogModel find exec async getBlog id string Promise lt Blog gt return await this blogModel findById id Controller Logic Get async getAllBlogs return await this service getAllBlogs Get id async getBlog Param id id string return await this service getBlog id The async functions are marked with the Get decorator which defines it as a GET request The second async function s decorator has an argument id Which is what you ll pass into the Param decorator The parameter is marked with the Param id which extracts the params property from the req object and populates the decorated parameter with the value of params UpdateLet s implement the logic for the PUT request Service Logicasync updateBlog id string body BlogsInterface Promise lt Blog gt return await this blogModel findByIdAndUpdate id body Controller Logic Put id async updateBlog Param id id string Body blog BlogsInterface return await this service updateBlog id blog The async function s second parameter is marked with the Body decorator which extracts the entire body object from the req object and populates the decorated parameter with the value of body DeleteLet s implement the logic for delete requests Service Logicasync deleteBlog id string Promise lt void gt return await this blogModel findByIdAndDelete id The Promise generic type is void because a Delete request returns an empty promise Controller Logic Delete id async deleteBlog Param id id string return await this service deleteBlog id Testing the APITo test this API you should use an API testing tool For this article I ll be using a popular API testing tool called Postman I ll be using random data about popular topics to test CreateMake a POST request to http localhost blogs with the following JSON objects this will add all the data to your database title jeen yuhs body The life of superstar rapper Kanye West is currently streaming on Netflix and according to our jeen yuhs review it s a fascinating watch credit Radio Times category Music title Why You Should Always Wash Your Hands body Germs from unwashed hands can be transferred to other objects like handrails tabletops or toys and then transferred to another person s hands credit cdc gov category Health title Why You Should Follow me on Twitter body Well Because I asked nicely category Random You should get a response and the created blog with a date and an id added ReadMake a GET request to http localhost blogs This should return a response with an array of all the data you previously added Copy the id property of one of the array objects Make another GET request to http localhost blogs id with the previously copied id This should return a response with the data of the object whose id was used to make the request UpdateMake a PUT request to http localhost blogs id with the data below The id should be replaced with the one you copied earlier This should return a response and updates the object bearing the id behind the scenes if you run another GET request you should get the updated object title why you Should Cut your Nails body It s important to trim your nails regularly Nail trimming together with manicures makes your nails look well groomed neat and tidy credit WebMD category Health DeleteMake a DELETE request to http localhost blogs id This should return a response and deletes the object bearing the id behind the scenes if you run another GET request you won t see the deleted object ConclusionSo we re finally at the end of this article Let s recap what you ve covered What NestJS is Terminologies in NestJS Creating a NestJS app Integrating MongoDB into a NestJS app Manipulating and NestJS app That s quite a lot congratulations on making it this far You can find the code on github Good luck on your NestJS journey |
2022-05-08 11:36:06 |
海外TECH |
DEV Community |
Deploy WordPress App to Amazon Lightsail |
https://dev.to/aws-builders/deploy-wordpress-app-to-amazon-lightsail-48i
|
Deploy WordPress App to Amazon Lightsail IntroductionAWS Lightsail can be the easiest entry to the AWS Cloud It has fixed monthly pricing unlike most other services so you don t have to worry about a huge monthly bill Lightsail is really great for small to medium apps It has out of the box support for WordPress Magento Joomla Prestashop Drupal Ghost and Django apps It provides pre configured stacks like LAMP NGINX MEAN and Node js You can also launch pre configured Plesk WHM amp cPanel in just a few clicks But that s not all You can launch any Linux based and Windows OS instance My personal favorites are Ubuntu and Amazon Linux PrerequisitesNeed a valid AWS account to deploy the WP app If you don t have one just create one from here Before starting to deploy your app read about Amazon Lightsail Pricing and Free Tier Don t worry I will try to keep everything within the free tier At this time of writing you can run a Lightsail instance for free for months Install WordPress AppLogin to your AWS account if not already Go to Lightsail homepage You should see a page like this Are you seeing this Let s go ️ Create InstanceNow click on the big Create Instance button If you don t see one follow this Let s choose Instance location platform and blueprint A Click the link to change location and availability zone AZ if not what you want I recommend selecting a location closer to your customers B Choose the Linux Unix platform C Select the Apps OS from the blueprint D Now choose WordPress from the app list Not the multisite one Now scroll down to Choose your instance plan section I chose a free tier plan and only one instance Here is my setup Finally scroll to the bottom of the page and click the Create instance button Wait for the status to become Running Congratulations your instance has launched Assign a Static IP optional AWS Lightsail Instance comes with public and private IP Which changes every time Stop and Start the instance My Public IP was this when I launched the instance After Stop and Start the instance it got a new Public IP address We have to fix that So let s create and assign a Static IP Click on your application instance name to see the details of your instance Click on Create static IP from here Add a meaningful name and click Create gt ️Warning You are allowed to assign static IPs for free You will be charged for static IP that is not attached to a running instance Connect to the instance using SSHYou can connect to an instance in two ways Using browserThat s the easiest Go to the Connect tab and click Connect using SSH Using SSH ClientDownload the SSH key from here If you are using PuTTY you can follow this tutorial If you are using a terminal in macOS or Linux run this command on where you downloaded the SSH key Run for the first time to fix the permissionchmod lt path to your lightsail ssh key gt pem Connect to your Lightsail instance Username and Public IP can be found in Connect tabssh i lt path to your lightsail key gt pem lt username gt lt public ip gt Get Admin Username and PasswordYou can get the username from the Connect tab The username is user for this stack To get the password log in to SSH and run this commandcat bitnami application passwordNow open a browser tab and go to http lt public ip gt wp admin Enter username and password above You should see the WP Admin dashboard like me Add a DomainGo to the Home page Click on the Networking tab and then hit Create DNS zone buttonAdd your domain name Scroll to the bottom and click the Create DNS zone buttonAdd these name server records in your domain control panel ex Namecheap GoDaddy You might have different records than mineNow to the good part Click Add Record button Add your instance and click on tick icon to save gt ️It may take few minutes to days to propagate DNS records Now update the domain name in siteurl and home rows of wp options table Import Existing App Import DatabaseYou may have an existing database You can import your database to the Lightsail instance You can use a Database client app like TablePlus MySQL Workbench or even just the terminal Your database credentials exist in wp config php file Connect to your instance via SSH and run this command cat stack wordpress wp config phpUse DB credentials to connect to DB and replace localhost with the instance s public IP Connect to your DB via SSH recommended or add the port here ️Don t forget to change the domain name in siteurl and home rows of wp options table Import existing filesApplication folder located in stack wordpress You can upload files in two ways SFTP Client You can use SFTP clients like FileZilla or Transmit to upload files Use the same SSH credential to upload files Git Connect to your instance via SSH Install git by using this command sudo apt get install gitNow pull your files from git using the git clone pull command ConclusionThis is just the first step toward deploying your WordPress app to Amazon Lightsail instance There are lot more you can do You are welcome to ask your questions give me feedback or any improvement request |
2022-05-08 11:02:48 |
Apple |
AppleInsider - Frontpage News |
Crime blotter: Capitol riot defendant who feared iCloud exposure pleads guilty |
https://appleinsider.com/articles/22/05/08/crime-blotter-capitol-riot-defendant-who-feared-icloud-exposure-pleads-guilty?utm_medium=rss
|
Crime blotter Capitol riot defendant who feared iCloud exposure pleads guiltyIn the latest Apple Crime Blotter siblings in a Stanford MacBook theft ring plead guilty a man pulls a knife while stealing a MacBook and iCloud evidence is used in meth prosecution The latest in an occasional AppleInsider series looking at the world of Apple related crime Capitol riot defendant who threw iPhone in the ocean pleads guilty Read more |
2022-05-08 11:45:37 |
海外TECH |
CodeProject Latest Articles |
Generate Variable Substitution-Boxes Starting from a Key |
https://www.codeproject.com/Articles/5331410/Generate-Variable-Substitution-Boxes-Starting-from
|
cipher |
2022-05-08 11:40:00 |
ニュース |
BBC News - Home |
NI election results 2022: Governments urge parties to reform executive |
https://www.bbc.co.uk/news/uk-northern-ireland-61367403?at_medium=RSS&at_campaign=KARANGA
|
border |
2022-05-08 11:38:05 |
ニュース |
BBC News - Home |
Ncuti Gatwa: BBC names actor as next Doctor Who |
https://www.bbc.co.uk/news/uk-61371123?at_medium=RSS&at_campaign=KARANGA
|
fiction |
2022-05-08 11:51:08 |
北海道 |
北海道新聞 |
国内で4万2538人感染 前週から1万5千人増 |
https://www.hokkaido-np.co.jp/article/678208/
|
新型コロナウイルス |
2022-05-08 20:34:00 |
コメント
コメントを投稿