投稿時間:2022-06-20 03:10:43 RSSフィード2022-06-20 03:00 分まとめ(13件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
python Pythonタグが付けられた新着投稿 - Qiita scikit-learnのデータセットfetch_lfw_people https://qiita.com/rucolarucola/items/1b2d552dbd6caf803c78 arndatasetsimportfetchlf 2022-06-20 02:49:13
海外TECH MakeUseOf How to Fix the “Not Enough Memory to Run Microsoft Excel” Error on Windows https://www.makeuseof.com/windows-excel-not-enough-memory-error/ windows 2022-06-19 17:15:14
海外TECH DEV Community How Template Literal Types work in TypeScript https://dev.to/smpnjn/how-template-literal-types-work-in-typescript-mdi How Template Literal Types work in TypeScriptTemplate Literals are common in Javascript they let us easily combine variables and strings in Javascript TypeScript also introduces the concept of Template Literal Types where we can enforce types on the inputs for Template literals That gives us controls to ensure that text is in a certain format Let s look at how they work Template Literal Types in TypeScriptA perfect example of when a template literal type might be useful is for creating IDs of certain formats For example let s say we have an ID which starts with ga or ua followed by a string or number We can define a new type using type literals for that like so type startOfId ga ua type ID startOfId string number That means that the first part of type ID needs to conform to type startOfId while the second bit can be a string or number The entire type ID must be a string since a template literal implies a string type Now we can use our type on variables we want to conform to this pattern For example type startOfId ga ua type ID startOfId string number let newId ID ga abc Combining with Generic TypesIf you want to get even fancier you can combine template literal types with generic types Below we have two types genericType and user type genericType lt Type gt name string amp keyof Type object property type user name string age number description string let myObject genericType lt user gt name age object property Since genericType accepts another type as an argument we can pass in user so now the name property in myObject can only be age object property name object property or description object property 2022-06-19 17:11:49
海外TECH DEV Community Making your own Express Middleware https://dev.to/smpnjn/making-your-own-express-middleware-3a2 Making your own Express MiddlewareExpress is a common way to display static routes to a user It is even more commonly used to create APIs for Node JS In Express it s easy to define a URL and what will happen at that URL We can also define middleware which runs before the final request is returned This can let us to alter the request and do it in a standard way across many routes If you ve used Express you may have already used pre built middlewares like bodyParser or jsonParser In this guide let s look at how you can create your own custom middleware Creating a middleware in ExpressA middleware is simply something which data passes through on its way to its actual end location Consider you have a route like this import express from express const app express app get home req res next gt if req getRoute true res status send Hello world else res status send Goodbye world In this example if the request or req has the property getRoute set to true we will show a different set of text By default HTTP requests do not have a property called getRoute Of course it would be easy to set it within home itself but imagine you had multiple requests all depending on this one getRoute property import express from express const app express app get home req res next gt if req getRoute true res status send Hello world else res status send Goodbye world app get home article req res next gt if req getRoute false res status send This is my article else res status send ERROR OCCURRED Now we have a situation where a middleware might make sense There are two ways to define a middleware with use or via a function Let s look at use first use as a middlewareConsidering our previous example we can use use to write a function that runs on every route This is therefore a general middleware which will run any time the user goes to any valid route on your server Here is an example where we define getRoute within a use middleware app use req res next gt Add getRoute to our request object req getRoute true Next tells express to now go to the next valid function next app get home req res next gt if req getRoute true res status send Hello world else res status send Goodbye world app get home article req res next gt if req getRoute false res status send This is my article else res status send ERROR OCCURRED Using this middleware we can add getRoute to our request and it ll now be available to home and home article It ll also be available to any other route on your server When we call next it tells Express to go onto the next valid route For example if the user went to home then first our middleware would be called and then since we called next within it Express would go to the home route as we have it defined Use case API VerificationA trick I often use for generalised middlewares is to split functionality that applies to certain HTTP methods For example if I wanted to apply an API verification function to all POST requests I can easily do that in a standard middleware used by the entire app import apiVerification from util js app use async req res next gt Here apiVerification is a function that returns true if the right request is sent We only want to apply it to POST methods though so lets add that to our middleware if req method POST let verifyCredentials await apiVerification req if verifyCredentials next else res status send ERROR OCCURRED else For everything else like GET go to next valid route next This is a perfect way to add a standard verification method to all your POST routes without having to redefine and recall apiVerification every time If apiVerification fails the user is given an error message instead For other methods like GET this apiVerification step is skipped is skipped Specific MiddlewaresSometimes you only want a middleware to apply to specific routes rather than generally to everything For that we need to define them in a function Using our previous example we can create a function for req getRoute and apply it to only the routes we want to let setGetRoute req res next gt req getRoute true app get home setGetRoute req res next gt if req getRoute true res status send Hello world else res status send Goodbye world app get home article req res next gt if req getRoute undefined res status send This is my article else res status send ERROR OCCURRED Now req getRoute will only be available to app get home since we only added that function to that route app get home setGetRoute For home article req getRoute will not be available This is quite useful when we only want to provide certain functionality in specific situations ConclusionMiddlewares are a powerful part of Express and let us process requests differently or apply certain functions to all requests I hope you ve enjoyed this article To learn more about Javascript click here 2022-06-19 17:10:50
海外TECH DEV Community Creating a Reusable Tab Component in Vue https://dev.to/smpnjn/creating-a-reusable-tab-component-in-vue-2ni5 Creating a Reusable Tab Component in VueOne of the most frequently used UX elements on the web or on personal devices are tabs In this guide let s look at how you can make a reusable tabs component using the Vue Composition API This set of tabs can be imported used and styled easily in any project you like and means you never have to think twice when you want to implement your own set of tabs You can find the source code for Vue Tabs on GitHub via this link If you re new to Vue I d suggest checking out my guide on getting started and making your first Vue app before reading this guide Creating a Reusable Vue Tabs ComponentTabs essentially consist of two parts the tab itself and a container which houses all the tabs Therefore to get started I m going to make two files in our Vue file structure Tab vue and Tabs vue Our basic file structure for this component is going to look like this src App vue main js components Tabs vue Tab vue index html README md package jsonSo let s start by creating our Tab vue file We are using the composition API to make these tabs so our code is a little simpler than if we used the Options API You can learn the difference between the Composition and Options API here Tab vue lt script setup gt import ref onMounted from vue const props defineProps active lt script gt lt template gt lt div class tab class active true active gt lt slot gt lt slot gt lt div gt lt template gt lt style gt tab display none tab active display block lt style gt The code for a single tab is relatively simple Our tabs are going to have one property active This property will define whether a tab should show or not Inside our tab we put a slot This is so we can define custom content for our Tab whenever we get round to defining it Finally we have some CSS to show or hide tabs based on if they are active or not Now that we have a Tab let s try making a container for multiple tabs which I ve put in the Tabs vue file Tabs vueLet s start by defining our script The interesting problem we need to solve here is tabs consist of the tabs themselves and then the tab which you click on to access that particular tab Therefore we need to pull our child tabs up and create headers for each Let s start by defining our script to do that lt script setup gt import ref onMounted from vue const props defineProps customClass Defining our reactive data properties let tabContainer ref null let tabHeaders ref null let tabs ref null let activeTabIndex ref onMounted gt tabs value tabContainer value querySelectorAll tab for let x of tabs value if x classList contains active activeTabIndex tabs value indexOf x lt script gt In essence we have to gather our tabs from the tab container through a reference We ll attach that ref to our template tag later For now let s just define the variable Then we ll need someway to get all the different tab headers so let s define that variable now We ll also need somewhere to store our tabs which will be in tabs Finally we need a way to track which tab is active which will be our activeTabIndex In the composition API we use ref If you re familiar with the Options API most of these variables would ve gone in the data function instead When we mount our component we run onMounted and query all tabs This lets us do two things We can now get access to all of our tabs in one simple variable We can figure out which tab is currently active and set the variable correctly Changing tabsWe ll also need one additional function for when the user changes tabs This function just hides all the currently active elements and then adds active classes to the headers and tabs which are active const changeTab index gt Set activeTabIndex item to the index of the element clicked activeTabIndex index Remove any active classes for let x of tabs value tabHeaders value x classList remove active Add active classes where appropriate to the active elements tabs value activeTabIndex classList add active tabHeaders value activeTabIndex classList add active Putting it in our templateNow that we have our script setup let s make our template and style Since we ve gathered all of our tabs into the tabs variable we ll loop over it using a v for We ll also append on the click event to each of those tab headers Note this is also where we add our references So our variable tabContainer is now tied to tabs container since we added the ref tabContainer to it The same goes for tabHeaders lt template gt lt div id tabs container class customClass ref tabContainer gt lt div id tab headers gt lt ul gt lt this shows all of the titles gt lt li v for tab index in tabs key index class activeTabIndex index active click changeTab index ref tabHeaders gt tab title lt li gt lt ul gt lt div gt lt this is where the tabs go in this slot gt lt div id active tab gt lt slot gt lt slot gt lt div gt lt div gt lt template gt lt style gt tab headers ul margin padding display flex border bottom px solid ddd tab headers ul li list style none padding rem rem position relative cursor pointer tab headers ul li active color font weight bold tab headers ul li active after content position absolute bottom px left height px width background active tab tab headers width active tab padding rem lt style gt Pulling it all together into a single viewNow that we have our two components we can implement our tabs anywhere we like by importing both and using them We need to give every Tab a header attribute which will act as the title for the tab that you click on Adding tabs to your site then looks like this lt script setup gt import Tabs from components Tabs vue import Tab from components Tab vue lt script gt lt template gt lt Tabs gt lt Tab active true title First Tab gt Lorem ipsum dolor sit amet consectetur adipiscing elit Fusce gravida purus vitae vulputate commodo lt Tab gt lt Tab title Second Tab gt Cras scelerisque dolor vitae suscipit efficitur risus orci sagittis velit ac molestie nulla tortor id augue lt Tab gt lt Tab title Third Tab gt Morbi posuere mauris eu vehicula tempor nibh orci consectetur tortor id eleifend dolor sapien ut augue lt Tab gt lt Tab title Fourth Tab gt Aenean varius dui eget ante finibus sit amet finibus nisi facilisis Nunc pellentesque risus et pretium hendrerit lt Tab gt lt Tabs gt lt template gt And just like that we have tabs we can use anywhere You can view the demo below Conclusion and Source CodeImplementing Vue tabs is pretty straightforward and by importing these two components into any project you ll have instantly functional tabs You can find the source code for Vue Tabs on GitHub via this link I hope you ve enjoyed this guide If you want more you can find my other Vue tutorials and guides here 2022-06-19 17:09:25
海外TECH DEV Community How to get the Full URL in Express on Node.js https://dev.to/smpnjn/how-to-get-the-full-url-in-express-on-nodejs-2h23 How to get the Full URL in Express on Node jsIn Express running on Node js we have access to the request object and also we can send a response back to the user via the response object However we don t have access to a simple way of getting the full URL from the request Fortunately it is quite easy to build the full URL from the request object in Express Let s look at how it works Getting the full URL of a Request in ExpressIn express we can display certain content on certain routes like so app get page req res next gt Show some content to the user Within a route we can use the req object to get the full URL The full URL is composed of a few different pieces the protocol of the current URLthe host of the URL i e the domain name and the page you are on i e pageTo combine all of these from our request we can run the following let fullUrl req protocol req get host req originalUrl Note it is better to use req get host since it will include the port So if you re running on localhost then will be included req hostname only returns the domain or localhost which may cause issues for you in the future Therefore a full URL can be found for any page our route using the following code app get page req res next gt Show some content to the user let fullUrl req protocol req get host req originalUrl 2022-06-19 17:07:21
海外TECH DEV Community How to make a Symbolic Link on Linux https://dev.to/smpnjn/how-to-make-a-symolic-link-on-linux-5hco How to make a Symbolic Link on LinuxSymbolic links are a link on Linux systems which point another file or folder It means that navigating to one of these files may run a file that exists somewhere else or it may bring you to a folder somewhere completely differently based on how it is defined For example a symbolic link called etc link may be defined to bring you to var www httpdocs Types of symbolic links on Linux and MacThere are two types of symbolic links on Linux systems hard links and soft links Hard links are similar to another name for the same file or directory They can only exist for files or directories on the same file system Symbolic Soft links are like shortcuts to files or directories rather than direct mappings to them They can point to files or directories on different file systems The type of symbolic link you make can affect how other commands work on linux on those files or folders For example hard links can be useful if we want to easily delete the reference when using commands like rm For many basic uses a symbolic or soft link works Let s look at how to create them How to create symbolic links on Linux and MacCreating symbolic links on Linux is relatively straightforward to do it we use the ln command By default this command only makes hard links To create a symbolic or soft link we use the s command For example the below code will make a soft link to var name txt from etc name txt ln s var name txt etc name txtIf the file etc name txt already exists this function will throw an error Instead if you still want to make the file use the f option to overwrite name txt ln sf var name txt etc name txtSymbolic links to directories also work in exactly the same way ln sf var etc fakevar Removing symbolic linksIf you find yourself needing to remove an already created symbolic link just use the unlink command For example in our above code we linked to var name txt from etc name txt To remove this symbolic link we could write unlink etc name txtThis command will actually remove the symbolic link entirely so it won t appear in your directory system anymore So you can also just simply remove the file using the rm command rm etc name txt ConclusionSymbolic links are useful shortcuts to other files or directories They differ from hard links in that hard links refer directly to the same file and share the same permissions and owners Symbolic links on the other hand may differ from the file or folder they link to 2022-06-19 17:06:31
海外TECH DEV Community How to send events from a child to parent in Svelte https://dev.to/smpnjn/how-to-send-events-from-a-child-to-parent-in-svelte-3lo9 How to send events from a child to parent in SvelteSvelte events are the way we add interactivity to components in Svelte A common issue with Svelte events is adding arguments to functions called within them For example suppose we have a basic counter which increases any time the user clicks on it lt script gt we write export let to say that this is a property that means we can change it later let x const addToCounter function x lt script gt lt button id counter on click addToCounter gt x lt button gt This works fine but let s say we want to change it so that we increase the counter by a certain amount whenever it is clicked We might try changing the code to something like this lt script gt we write export let to say that this is a property that means we can change it later let x const addToCounter function amount x amount lt script gt lt button id counter on click addToCounter gt x lt button gt But this WONT work instead we need to change our event to contain a function instead To add arguments to our addToCounter function we have to do something like this instead lt button id counter on click gt addToCounter gt x lt button gt Here we call a function which returns the value produced by addToCounter This also works for events so if you want to pass the event or e object to your function you could do something like this lt button id counter on click e gt addToCounter e gt x lt button gt 2022-06-19 17:05:33
海外TECH DEV Community How Intrinsic Type Manipulations work in TypeScript https://dev.to/smpnjn/how-intrinsic-type-manipulations-work-in-typescript-869 How Intrinsic Type Manipulations work in TypeScriptDid you know that TypeScript comes with a bunch of built in string manipulator types That means we can easily transform a string type into uppercase lowercase or capitalized versions of itself When might this be useful In lots of situations where you have a fixed set of string values for example whenever you have a set of strings from an object using something like keyof To transform a string into a different version by defining a new type along with one of the type manipulators For example below we transform myType into the capitalized version type myType hi there type capitalizedMyType Capitalize lt myType gt let myVar capitalizedMyType Hi there In the above example hi there would throw an error only Hi there will work with a Capitalize type Similarly we can uncapitalize a string using Uncapitalize type myType HI THERE type uncapitalizedMyType Uncapitalize lt myType gt let myVar uncapitalizedMyType hI THERE Above only hI THERE will work Any other case will fail the check Uppercase and Lowercase Intrinsic Type ManipulationAlong with Capitalize we also have Uppercase and Lowercase They both do exactly what you think they d do one changes all characters to uppercase and the other to lowercase type myType this long sentence type bigMyType Uppercase lt myType gt let myVar bigMyType THIS LONG SENTENCE Lowercase intrinsic type manipulationAbove we ve created a type which is the uppercase version of myType Here is the same example but in the other direction making the lowercase version type myType THIS LONG SENTENCE type smallMyType Lowercase lt myType gt let myVar smallMyType this long sentence Using with template literalsThese types become very useful when working with template literals where we can enforce a string literal to use a lowercase version for example for an ID Here is a version where we have a set number of strings and we only want to use the lowercase version in the ID as part of the versionId type type versions DEV PROD STAGING type versionPrefix gold beta alpha type versionId versionPrefix Lowercase lt versions gt let currentVersion versionId gold dev Above we have two sets of union types and we combine them into one versionId Here we only accept lowercase letters but version is uppercase We can transform it with Lowercase so gold dev is valid Using with keyof objectsIn a similar way we may receive an object from an API or elsewhere which has odd or uneven casing To normalise this we can use intrinsic type manipulations Below I am using keyof to get all the keys in myObject and making them all lowercase too type myObject firstName string Age number Lastname string type keys Lowercase lt keyof myObject gt let getObjectKey keys firstname keys only has the following valid values firstname age lastname In this example using intrinsic string manipulation like this can be an easy way to create clean types when the data we have at our disposal has issues 2022-06-19 17:04:31
海外TECH DEV Community How to convert a String to a Number in TypeScript https://dev.to/smpnjn/how-to-convert-a-string-to-a-number-in-typescript-4ei4 How to convert a String to a Number in TypeScriptTypeScript is a strongly typed language which means we have to give things a little more thought when converting between them Fortunately converting a string to a number is pretty easy in TypeScript Converting a String to a Number in TypeScriptIf we re using integers the easiest way to convert a string into a number is to simply use the unary operator Here is an example using a simple integer let someString string let myNumber number someString Returns console log myNumber We can also just use or parseInt for number like integer strings let someString string let myNumber number parseInt someString Returns console log myNumber Converting DecimalsUnfortunately this method won t work very well for decimals as and parseInt deal only with integers If we want to convert a decimal like string to a number in TypeScript we can use parseFloat just like normal Javascript let someString string let myNumber number parseFloat someString Returns console log myNumber Number functionWe can also use the Number function to convert number like strings into numbers This will work with both integers and decimals let someString string let myNumber number Number someString Returns console log myNumber 2022-06-19 17:03:26
海外TECH DEV Community 5 Hard Truths about Engineering leadership https://dev.to/jaredniervas/5-hard-truths-about-engineering-leadership-4gl0 Hard Truths about Engineering leadershipOverall becoming an engineer leader is great All routes to seniority lead away from programming But once you make it up that ladder based on hard work and your engineering excellence did you ever think you might not be as prepared to lead as you d like One of your most important talents as a leader will be delegating You must know who is capable of doing what and who is willing to take on additional responsibility People must be pushed without being drowned If you can delegate everything you ll be ready to take on greater responsibilities in the future Big Tech does a superb job at putting together teams The two pizza team is the most effective Take the model and use it It is not always a good idea to experiment with organizational structures When it comes to managing engineers what can non technical leaders do Many developers find it difficult to report to non technical bosses It s why with a few exceptions for CEOs all Engineering Managers in Tech Driven companies are examined for technical skills during interviews As soon as possible place qualified technical individuals in the middle between them and the teams If this will take time promote and assign tech leads to be your right hand in the short term and then pay attention to them Engineers have a problem with empathy at times Just because they ve worked as an engineer before doesn t mean they re qualified to manage people s careers People who lack empathy should not manage engineers just as non technical MBAs should not manage engineers No amount of Management training can teach you to care about people You have to find it in yourself Don t juggle the roles of Engineering Manager and Senior IC Performing both jobs for an extended period of time is a bad idea It will stifle your growth in the long run You re not going to get very good at either of these things It s also a disservice to your employees product and clients Corporations have a pressing need for trans formative leaders who drive innovation in today s complex rapidly evolving global markets This is true of many technical disciplines but incredibly true for software engineering To become one of these highly prized leaders technical professionals must transcend their silos and broaden their perspectives Leverage the expertise of peers and mentors Search through and save resources interesting to you through a safe space for engineering leaders to connect and learn Join Lohika Community curated to bring together Engineering leaders to share insights explore trends attend events and empower leadership and career growth 2022-06-19 17:00:35
Apple AppleInsider - Frontpage News Lifetime Microsoft Office for Mac Home & Business 2021 license now $49.99 https://appleinsider.com/articles/22/06/17/new-price-drop-lifetime-microsoft-office-for-mac-home-business-2021-license-now-3999?utm_medium=rss Lifetime Microsoft Office for Mac Home amp Business license now A price drop is in effect on a lifetime Microsoft Office for Mac license delivering in savings at a low price Microsoft Office for Mac Home Business lifetime license now offUpdate at p m ET on June The deal has since reverted back to off Read more 2022-06-19 17:21:19
海外TECH WIRED 30 Last-Minute Father’s Day Deals https://www.wired.com/story/last-minute-fathers-day-deals-2022-3/ headphones 2022-06-19 17:30:00

コメント

このブログの人気の投稿

投稿時間:2021-06-17 05:05:34 RSSフィード2021-06-17 05:00 分まとめ(1274件)

投稿時間:2021-06-20 02:06:12 RSSフィード2021-06-20 02:00 分まとめ(3871件)

投稿時間:2020-12-01 09:41:49 RSSフィード2020-12-01 09:00 分まとめ(69件)