投稿時間:2021-06-03 02:26:38 RSSフィード2021-06-03 02:00 分まとめ(36件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
python Pythonタグが付けられた新着投稿 - Qiita XGBRegressor で WARNING: src/objective/regression_obj.cu:152: reg:linear is now deprecated in favor of reg:squarederror. https://qiita.com/tommarute/items/8702b16cc8d964502356 XGBRegressor で W A R N I N G s r c o b j e c t i v e r e g r e s s i o n o b j c u r e g l i n e a r i s n o w d e p r e c a t e d i n f a vorofregsquarederrorIssue タイトル の とおり 。 2021-06-03 01:21:27
Program [全てのタグ]の新着質問一覧|teratail(テラテイル) 文字列が同じでない場合のfor文 https://teratail.com/questions/341843?rss=all 文字列が同じでない場合のfor文前提・実現したいこと入力で与えられるn人の情報を構造体の配列で保存し、与えられた検索条件によって検索の結果を出力するプログラムです。 2021-06-03 02:00:02
Program [全てのタグ]の新着質問一覧|teratail(テラテイル) お知恵をお貸しください。スマホ閲覧時、フッター手前でボタンが止まる処理について https://teratail.com/questions/341842?rss=all お知恵をお貸しください。 2021-06-03 01:49:03
Program [全てのタグ]の新着質問一覧|teratail(テラテイル) SQL Server 結合時に条件ありで一番小さい1件のみデータを抽出したい。 https://teratail.com/questions/341841?rss=all SQLServer結合時に条件ありで一番小さい件のみデータを抽出したい。 2021-06-03 01:44:42
Program [全てのタグ]の新着質問一覧|teratail(テラテイル) バッチファイルにおける変数とgitコマンドの同時利用 https://teratail.com/questions/341840?rss=all バッチファイルにおける変数とgitコマンドの同時利用前提・実現したいこと変数とgitコマンドの同時利用が原因で下記エラーが発生します。 2021-06-03 01:43:49
Program [全てのタグ]の新着質問一覧|teratail(テラテイル) input typeを変えた時の配列連番処理 https://teratail.com/questions/341839?rss=all 2021-06-03 01:03:40
AWS AWSタグが付けられた新着投稿 - Qiita AWSのParalellClusterを使ってみた① https://qiita.com/all_green/items/7bfaa7931498f1c41b43 AWSのParalellClusterを使ってみた①はじめに概要ParallelClusterではクライアントPC上にクラスタ作成の設定等を行う環境を作成しクラスタの作成を行うクラスタを作成するとECの新しいインスタンスとしてMasterノードが作成されるMasterノードでジョブを実行するとジョブの規模に合わせてSlaveノードが作成されジョブが実行されるここではクライアントPCParallelClusterのインストール先にもローカルPCではなくAWSのインスタンスを使用しましたちなみにローカルPC上記のクライアントPCへの接続元の環境はmacOSCatalinaですつまりローカルPCmac→クライアントPCEC→クラスタMasterノードSlaveノードのような関係ですこの記事ではクラスタの作成Masterノードの作成を行うところまでをまとめておきますクライアントPCとしてのECインスタンス作成インスタンスの作成お試しなので一番小さいtnanomicroを選択するまたセキュリティグループの設定では自宅のPCから接続できるように公開範囲ソースをマイIPとしておくまたssh接続のためにキーペアを作成しておき公開鍵をダウンロードしsshkeysにでもコピーしておくインスタンスへ接続macの場合terminalから接続できるパブリックIPvアドレスまたはパブリックIPvDNSを確認し公開鍵を指定してssh接続するUbuntuの場合初期ユーザ名はubuntuであるRedHat系の場合初期ユーザ名はecuserであるterminalsshecuserecapnortheastcomputeamazonawscomisshkeyskeypairpem環境構築rootユーザのパスワードを変更するsudosupasswdパッケージ用リポジトリの追加sudodnfinstallysudoyumyinstallepelreleasepythonおよびpipのインストールなぜかpythonはリポジトリにないと言われたのでにしたcurlコマンドでpipをインストールするためのスクリプトを入手し実行yuminstallpythoncurlOpythongetpippyuserWhenyouusetheuserswitchpipinstallsAWSParallelClustertolocalbinとのことでパスを追加しておくbashprofileexportPATHlocalbinPATHリロードsourcebashprofileParallelClusterのインストールと設定ようやくparallelclusterをインストールpythonmpipinstallawsparallelclusterupgradeuserparallelclusterの設定をしようとpclusterconfigureとすると次のように怒られたrootipxxxxxxxxxxpclusterconfigureERRORYoumustspecifyaregionRunawsconfigureoraddtherltREGIONNAMEgtargtothecommandyouaretryingtorunorsettheAWSDEFAULTREGIONenvironmentvariableINFOConfigurationfilerootparallelclusterconfigwillbewrittenPressCTRLCtointerrupttheprocedureFailedwitherrorYoumustspecifyaregionERRORNooptionsfoundforAWSRegionIDAWSCLIを使用するためのIAMユーザの作成pclusterconfigureで怒られたメッセージを読むとYoumustspecifyaregionとあるregionの設定はAWSCLIAWSのコマンドラインツールを使用して行う必要があるがそのためには適切なアクセス権限ポリシーを持ったIAMユーザーが必要みたいですので以下のサイトを参考にIAMユーザを作成しましたawscliをインストールpipinstallawscliAWSCLIを使用する権限を持ったIAMユーザの作成マネジメントコンソールからIAMユーザを新規作成するアクセスの種類はとりあえず「プログラムによるアクセス」と「AWSマネジメントコンソールへのアクセス」の両方をONにしておいたけど後者はいらない気がする次に作成したIAMユーザにグループポリシーを適用するここでは新しくECuserというグループを作成しAmazonECFullAccessPowerUserAccessのつのポリシーを追加した参考サイトにはつ目しか載っていなかったのでつ目はいらないかも後ほど説明するがこの設定ではclusterの作成時に権限が足りなくてエラーが出たエラーを解消するにはAdministratorAccessのポリシーを追加する必要があったまたPowerUserAccessはいらなかったユーザの作成を完了し最終画面でアクセスキーやシークレットアクセスキーをメモるかcsvをダウンロードしておくAWSCLIの設定awsconfigureを実行しAWSCLIの環境設定を行うrootipxxxxxxxxxxawsconfigureAWSAccessKeyIDNone先程作成したユーザのAccessKeyAWSSecretAccessKeyNone先程作成したユーザのsecretAccessKeyDefaultregionnameNoneリージョンを選択します。 2021-06-03 01:26:34
海外TECH DEV Community How do web servers work? https://dev.to/endingwithali/how-do-web-servers-work-54ci How do web servers work Web Servers They re mystical things You just initialize one for your project and it handles the rest But what is actually going on under the hood I got curious so I asked my friend Jonathan Kingsley if he knew about em Turns out he s the kind of guy who read the HTTP paper for fun so we took to my stream and worked through building our own web server in Go Did I mention that the server is Mickey Mouse themed HTTPHTTP stands for Hypertext Transfer Protocol it was created as a part of the World Wide Web project in the early s Tim Berners Lee a British scientist invented the World Wide Web WWW in while working at CERN The web was originally conceived and developed to meet the demand for automated information sharing between scientists in universities and institutes around the world CERNThis project has become the basis of how the internet works it outlines the expectations of how to communicate data and information between servers Your computer knows how to interpret websites because of the work of the World Wide Web project What did we make We decided to make two iterations of a from scratch web server the first one outlined in this blog post handles get requests to endpoints that are hard coded In another blog post I ll walk through how we built a web server that can handle more dynamically implemented endpoints How does the server work Main ListeningAt the basic level a web server listens port err net Listen tcp We create a Listener object port that listens to a specific traffic port communication endpoint for incoming requests of a specific network protocol This line of code basically starts the server you can now receive incoming requests In this example we are expecting TCP style requests on port Mickey Mouse was created in therefore we chose to listen to port Great We re done Right Not exactly We can now receive requests but how do we handle and read them and how do we send back responses Acceptingconn err port Accept One of the generic functions that port has implemented is the Accept function Accept stalls blocks until a new incoming request is seen by port the incoming connection is returned as a Conn object While the server is running this function should be continually occurring meaning that in code it is placed in an infinite for loop Yeah you read that right a time where an infinite loop is encouraged Handlinggo handleConnection conn We create a new custom function called handleConnection this function is where we actually start going through interpreting and reading the data from the incoming connection Each time there is an incoming connection from another client aka any external connection since we are the server we accept it and spin off a new handleConnection to deal with that client We use the keyword go to spin off goroutines which enables multithreading asynchronisity for the server If we didn t use goroutines to enable concurrency incoming requests that block will block everything on that thread so you won t be able to serve as many incoming requests Code for main functionfunc main fmt Println Goofy hyuck booting up port err net Listen tcp if err nil failed to set up server fmt Println Mickey Oh no Goofy It looks like there was an error starting up the server fmt Println err Error return for conn err port Accept if err nil client failed to connect with server fmt Println err Error return go handleConnection conn fmt Println Welcome to the Mickey Mouse Web House Printing Twicefmt Println Welcome to the Mickey Mouse Web House When you run the code above this print may occur twice When browsers execute a request from a server they execute separate requests for both the favicon of the page and the contents of the page handleConnection Anatomy of an HTTP Request MessageAccording to the specifications of HTTP there s required information that must be passed in a specific order in order to be properly digested by the receiving side GET HTTP r nContent Type text plain charset UTF r nContent Length lt length gt r n r nHello World nNote each one of these lines end with r n when you re reading the incoming request this allows the buffer to know where each line of the protocol ends Basically it helps separate new lines GET HTTP r nYou can take this at face value It tells the server the type of request incoming the request target the endpoint trying to be reached and the HTTP version If you want to read more about the anatomy of HTTP Messages check out this blog post by the team at Mozilla I want to point out Content Type header up until I started working on this project it didn t hit home as to why setting and checking Content Type in HTTP requests was important But now I understand that each HTTP header acts almost like a basic if else check point Without setting the Content Type specifically the interpreting server won t know what to do or how to process the contents of the request Processing each kind of request is basically hard coded Basically always check your Content Type header if you re sending a request and if you re processing receiving a request be sure to specify the expected Content Type in your documentation to reduce frustration on both ends Anatomy of an HTTP Response MessageThis is what an HTTP response message is expected to look like HTTP OK r nContent Type text plain charset UTF r nContent Length lt length gt r n r nHello World nLet s break it down HTTP OK r nThis line tells us what version of HTTP we are using the status code and the text associated with the status codeContent Type text plain charset UTF r nThis header tells the receiving client the type of incoming content so it knows how to handle it Content Length lt length gt r n r nThe value for content length is important because it helps the receiving side know when the receiving message has been delivered in its entirety It ends with double r n the second one is a blank line used by request processors to note the start of the message body Hello World nThis is the message body Reading incoming requestsrequest err bufio NewReader connection ReadString n We read the information from the incoming requests using a bufio object based on the incoming connection To keep the server as simple as possible we re not even going to check what kind of request is coming in only what endpoint is being requested This allows us to only have to read the first line of the incoming HTTP request we don t care what the rest of the request says requestParts strings Split request We split the incoming request into parts and check if requestParts clubhouse which endpoint is being requested For this server we re only accepting one endpoint clubhouse message if goofy has a dog and goofy is a dog connection Write byte HTTP OK r n connection Write byte Content Type text plain charset UTF r n connection Write byte Content Length strconv Itoa len message r n r n connection Write byte message n returnTo send a response we use the Write function of the connection object but before we do that we need to send our required headers as outlined above and in the hypertext transfer protocol If the incoming request is not looking for clubhouse then we send back a error connection Write byte HTTP Not Found r n connection Write byte Content Type text plain charset UTF r n connection Write byte Content Length r n r n The final thing that happens before we finish the method is that we must close the connectiondefer connection Close In reality this was the first thing we did in our handleConnection function If you re new to Go defer is a keyword utilized to describe a function that should be executed when the main function completes no matter where it ends Code for handleConnection func handleConnection connection net Conn defer connection Close request err bufio NewReader connection ReadString n if err nil fmt Println err Error return requestParts strings Split request if requestParts clubhouse message If Goofy has a dog and Goofy is a dog connection Write byte HTTP OK r n connection Write byte Content Type text plain charset UTF r n connection Write byte Content Length strconv Itoa len message r n r n connection Write byte message n return connection Write byte HTTP Not Found r n connection Write byte Content Type text plain charset UTF r n connection Write byte Content Length r n r n Final code on Github Serving EndpointsI was surprised to learn that servers essentially just reading and parsing string After years of working with them I genuinely thought servers were way more complicated and that a simple example like this would be much more complex Right now our server can only handle one endpoint clubhouse which has a hardcoded response What about dynamically implemented endpoints Ones that are not defined directly in the server code don t worry we ve got that too Blog post coming soon BTW if you re curious if New Relic works with servers yes it does Click here to learn more Special thanks to Jonathan Kingsley for working on this project with me Having a mentor to help walk me through this process and has made it very digestible I am very grateful Wish you could have seen this learning live I stream coding and other fun tech things on Twitch almost every day Come hang out See y all soon Mickey MouseYeah while this doesn t use Mickey Mouse for any kind of analogy I ve been working on my Mickey Mouse impression and the entire time Jonathan and I streamed this project I kept doing my impression hence the use of Mickey Mouse 2021-06-02 16:35:08
海外TECH DEV Community Let's build a VDOM! https://dev.to/siddharthshyniben/let-s-build-a-vdom-56pa Let x s build a VDOM Please check out my previous post which explains what the VDOM is if you don t know what the VDOM is Alright now that we know what the VDOM is let s build it So we need to be able to do things Create a Virtual Node I ll just call it vnode Mount load a VDOMUnmount a VDOMPatch compare two vnodes and figure out the difference and then mount Alright let s go Creating a vnodeThis is basically just a utility functionfunction createVNode tag props children return tag props children In Vue and many other places this function is called h short for hyperscript But I choose to give it a better name Mounting a vnodeBy mounting I mean appending the vnode to any container like app or any other place it should be mounted This function will recursively walk through all of the nodes children and mount them to the respective containers Note that all the following code is to be placed in the mount function function mount vnode container Create a DOM Elementconst element vnode element document createElement vnode tag You may be thinking what vnode element is It s just a small property which is set internally so we can know which element is the parent of the vnodeSet all attributes from the props objectWe can just loop over themObject entries vnode props forEach key value gt element setAttribute key value Mount the children There are two cases to handle The children is just textThe children are an array of vnodesif typeof vnode children string element textContent vnode children else vnode children forEach child gt mount child element Recursively mount the children Finally we have to append the stuff to the DOMcontainer appendChild element Here is the final resultfunction mount vnode container const element vnode element document createElement vnode tag Object entries vnode props forEach key value gt element setAttribute key value if typeof vnode children string element textContent vnode children else vnode children forEach child gt mount child element Recursively mount the children container appendChild element Unmounting a vnodeUnmounting is as simple as removing an element from the DOM function unmount vnode vnode element parentNode removeChild vnode element Patching a vnodeThis is only comparatively the most complex function we have to write It basically find out the difference between two vnodes and only patch the changes This time I will put the explanation in the code comments so be sure to read through it Let s go function patch VNode VNode Assign the parent DOM element const element VNode element VNode element Now we have to check the difference between the two vnodes If the nodes are of different tags assume that the whole content has changed if VNode tag VNode tag Just unmount the old node and mount the new node mount VNode element parentNode unmount Vnode else Nodes have same tags So we have two checks remaining Props Children I am not going to check the props for now because it would just lengthen the post and miss the point I might write a third article which contains the full implementation Checking the children If the new node has a string for children if typeof VNode children string If the two children are strictly different if VNode children VNode children element textContent VNode children else If the new node has an array of children The length of children is the same The old node has more children than the new one The new node has more children than the old one Find out the lengths const children VNode children const children VNode children const commonLen Math min children length children length Recursively call patch for all the common children for let i i lt commonLen i patch children i children i If the new node has fewer children if children length gt children length children slice children length forEach child gt unmount child If the new node has more children if children length gt children length children slice children length forEach child gt mount child element And that s it This is a really basic version of a vdom implementation just so you can grasp the concept There s a few more stuff left to do including checking the props and some more speed improvements For now let s render a VDOM Let s go back to out really old generateList example For our vdom implementation we could do something like this function generateList list let children list map child gt createVNode li null child return createVNode ul class fruits ul children mount generateList apple banana orange document querySelector app any selector Here is a pen 2021-06-02 16:09:11
海外TECH DEV Community Tina Cloud is in public alpha https://dev.to/tinacms/tina-cloud-is-in-public-alpha-2ied Tina Cloud is in public alphaThe team at Tina is pleased to announce that Tina Cloud is officially in public Alpha Everyone is encouraged to register a free account on our headless GitHub backed CMS and start committing We have been working incredibly hard behind the scenes to get our vision in the hands of developers and content teams Tina Cloud brings the power of Tina s open source content editor with a GraphQL API that allows you to interact with your Markdown files stored in your repository Also with Tina Cloud you can allow any team member to edit content ーeven if they don t have a GitHub account When we launched TinaCMS it was mainly an open source Javascript UI for editing your site visually At that time TinaCMS was a month old open source project and we relied on developers to roll their own solution for user management authentication roles content storage and more But we quickly learned that developers need more out of the box to get their teams successful With Tina Cloud we re staying true to our vision of Git backed content management but with a batteries included experience What to Expect with the Tina Cloud Alpha Tina cloud is still being actively developed and is in a place we believe you can have a great experience with it You may run into issues we didn t encounter yet or be required to update to the latest version because we have improved our API Tina cloud isn t complete yet some key features are currently being shaped up Media Management SolutionMulti branch workflowsRead only tokens for our GraphQL API That means it s only used when you are editing content What tech stack should be used with Tina CloudNext js Next js is a perfect match for Tina and is the default choice for our team GitHub GitHub is required as it is the only Git provider we support on Tina Cloud currently Let us know if you want us to support other Git providers Static file based builds When you go to build our Tina Cloud product collects your filesystem content in the future you will be able to fetch data from our Cloud API during build times How can I get started The first thing to do is to signup for Tina Cloud once you re in we have a few ways for you to get started and get up and running in minutes Tina Cloud Starter A basic implementation of Tina Cloud aimed at getting your up and running in a few minutes Tina Cloud Next js blog starter A guide to add Tina Cloud on top of the default Next js blog starter and work directly through our CMS You can also check out the video to get started with Tina Cloud in under minutes it gives you an overview of our Tina Cloud starter and gives you some tips on how to run Tina Cloud locally Where can I give feedback or get help We have a few channels open for you to reach out provide feedback or get help with any challenges you may have Dig into the new Tina Cloud documentation that covers implementations Join our Discord Email us if would like to schedule a call with our team and share more about your context Get support through your Tina Cloud dashboard there s a chat widget at the bottom of the screen on the left side What about pricing We are still deciding out what we believe will be fair pricing for people who decided to use Tina Cloud During the Alpha Tina Cloud is at no cost for small teams and we will contact you if we believe your use case may eventually fit within our post beta paid plans Please reach outThe whole team is truly excited to enter a public Alpha phase and hope you will check it out and give us honest feedback We wanna hear about your projects let us know how Tina Cloud can help your team make progress To keep up to date with Tina goings on make sure to follow tina cms and james r perkins on Twitter Stay tuned for further improvements features community built projects and more 2021-06-02 16:03:55
海外TECH DEV Community How to Dynamically Update Twitter Cover Image to Show Latest Followers Using PHP GD and TwitterOAuth https://dev.to/erikaheidi/how-to-dynamically-update-twitter-cover-image-to-show-latest-followers-using-php-gd-and-twitteroauth-62n How to Dynamically Update Twitter Cover Image to Show Latest Followers Using PHP GD and TwitterOAuthA week ago I came across this tweet that made me so intrigued Tony Dinh tdinh me I have done it My profile banner now shows my latest followers Update every secs Nope unfollow and follow again won t work sorry PM May It made me remember a couple other times in my career where I was very excited and actually almost obsessed to figure out how something was made The first time long ago that happened was when I saw this magazine cover tool where you uploaded a photo and generated a magazine cover That led me to a whole world of discoveries and my first successful project that allowed me to leave the job I had at the time to live off Google Adsense Yes it was a fake magazine cover generator online made with PHP and GD The other occasion when I felt as motivated to find out how they did something was when I found this tool to keep track of who unfollowed you on Twitter Again that led me to a whole world of discoveries open source contributions and lots of digging in the Twitter API So when I saw that tweet from Tony I realized this would be basically the cover generator Twitter API tinkering combined I got very excited to implement it Took about a week couple hours each day because I had small chunks of code here and there that I could reuse and repurpose This is the final result you can also check it out live What makes me excited about this little project is that the possibilities are ENDLESS You can showcase whatever you want that has a dynamic output and can be programmatically obtained like via an API The same approach can be used to tinker with your profile image Ok enough talk Let s get to work Before Getting StartedBefore moving along make sure you have the following available to you A registered application on dev twitter com with read and write access Obtain the following tokens from the application settings page Consumer API Token App token Consumer API Secret App secret Access Key User token Access Secret User secret A working PHP development environment in the command line with the following dependencies installed php cli ext gdext jsonext curlComposerA PNG image to serve as cover This will be pasted on top of all layers The image must be x and have transparent placeholders for the avatar images like this one that you can use as base to create your own You ll also need the exact coordinates for each location where the avatar images will be placed You are encouraged to use a source code editor such as Visual Studio Code to facilitate working within a PHP project For this demo we ll create a command line application using Minicli a minimalist framework for command line applications in PHP We ll use the TwitterOAuth library to communicate with the Twitter API If you d prefer to follow along with the code from an existing repository or if you just want to try this demo out you can check erikaheidi dynacover on GitHub Bootstrapping the ApplicationStart by bootstrapping a small command line app using Minicli Here we ll call it dynacover composer create project prefer dist minicli application dynacoverCreating a minicli application project at dynacover Installing minicli application Installing minicli application Extracting archiveCreated project in home erika Projects dynacoverLoading composer repositories with package informationUpdating dependenciesLock file operations install updates removals Locking minicli minicli Writing lock fileInstalling dependencies from lock file including require dev Package operations install updates removals Installing minicli minicli Extracting archiveGenerating autoload files package you are using is looking for funding Use the composer fund command to find out more This will bootstrap de application Enter the new directory and have a look at the files Here s a quick overview of the directory structure in a new Minicli app cd dynacover ├ーapp│  └ーCommand├ーcomposer json├ーcomposer lock├ーLICENSE├ーminicli├ーREADME md└ーvendor ├ーautoload php ├ーcomposer └ーminicliThe app Command directory is where all commands are defined We ll work on that in the next step Next include abraham twitteroauth as dependency via Composer composer require abraham twitteroauthYou can also rename your script to match the application name mv minicli dynacoverTo test that everything works as expected run php dynacover helpYou should see the following output Available Commandshelp└ーtable└ーtestThese commands are implemented at the app Command Help directory as example commands that you may want to check out In the next step we ll start creating new commands Obtaining New Followers with TwitterOAuth LibraryBefore writing the code that will dynamically generate the image first make sure you can obtain your latest followers using the TwitterOAuth library and your application user keys We ll create a simple command to list your latest followers First however we need to set up the Twitter tokens in such a way that you can obtain them from the command controllers The easiest way to do so is to create a separate file with the credentials and import them into the app s configuration You should also make sure this file is included within your gitignore in case you are using version control so that it is not committed along with the application code Storing Twitter Credentials SafelyCreate a new file named credentials php in the root of the application folder This file should return an array with the application s sensitive data Copy the following content to your credentials php file and replace all the keys with your own Twitter credentials credentials php lt phpreturn twitter consumer key gt APP CONSUMER KEY twitter consumer secret gt APP CONSUMER SECRET twitter user token gt USER ACCESS TOKEN twitter token secret gt USER ACCESS TOKEN SECRET To make sure this file isn t included within version control you should add a line to your gitignore file You can do this with the following command which will append a new line to that file echo credentials php gt gt gitignoreThen edit the dynacover script to merge this data into the main config This is how you can do it dynacover usr bin php lt phpif php sapi name cli exit require DIR vendor autoload php use Minicli App config app path gt DIR app Command if is file DIR credentials php config array merge config include DIR credentials php app new App config app gt runCommand argv Now you should be able to obtain these credentials from any command controller Creating New Command to Fetch FollowersWith the credentials in place you can start working with the Twitter API Create a new directory within app Command called Fetch mkdir app Command FetchCreate a new file at app Command Fetch FollowersController php using your preferred code editor This is a class that needs to extend from the Minicli Command CommandController and implement a method named handle which will handle the command when it s invoked from the prompt From the handle mehtod you ll obtain the needed credentials from the this gt getApp gt config object accessible as magic properties api token this gt getApp gt config gt twitter consumer key api secret this gt getApp gt config gt twitter consumer secret access token this gt getApp gt config gt twitter user token token secret this gt getApp gt config gt twitter token secret Then using the TwitterOAuth library you can create a request to obtain your latest followers client new TwitterOAuth api token api secret access token token secret followers client gt get followers list skip status gt true count gt The following code contains the full implementation also listing the results as output at the end app Command Fetch FollowersController php lt phpnamespace App Command Fetch use Minicli Command CommandController use Abraham TwitterOAuth TwitterOAuth class FollowersController extends CommandController public function handle api token this gt getApp gt config gt twitter consumer key api secret this gt getApp gt config gt twitter consumer secret access token this gt getApp gt config gt twitter user token token secret this gt getApp gt config gt twitter token secret client new TwitterOAuth api token api secret access token token secret followers client gt get followers list skip status gt true count gt this gt getPrinter gt info Latest Followers true foreach followers gt users as follower this gt getPrinter gt info follower gt screen name this gt getPrinter gt info Finished return You can now run this command with php dynacover fetch followersIf everything worked as expected you should see a list with your most recent new followers like this With this data we can start building the dynamic cover image Generating a Cover with User AvatarsYou ll now build a new command to generate the cover image We ll need the base image that will be pasted on top of the avatar images to give the best effect I used Canva to create mine but you can use any image photo editor able to work with PNGs and transparency For this demo we ll use this example image After creating this on Canva I opened the image on Gimp and used the circle selection tool to select where I want the profile images to go then hit delete to delete that portion of the image and make it transparent For this demo you can download the example cover which already contains the transparent placeholders Our coordinates will be based on that image Setting Up the Example Cover ImageCreate a new folder inside the app directory called Resources to place this cover image mkdir app Resourcescp Downloads twitter cover png app Resources twitter cover png Creating A Cover Generate Commandmkdir app Command CoverCreate a new command controller in that folder named GenerateController so it will be reachable as dynacover cover generate later on You can place the following bootstrap code in it lt phpnamespace App Command Cover use Minicli Command CommandController class GenerateController extends CommandController public function handle TODO Implement handle method Here are the things we ll need to do now Get Latest Followers Download their avatars to a temporary location Create a new GD image resource using imagecreatetruecolor sized x Loop through an array with the right coordinates to paste the avatar images and use imagecopyresampled to place those images in the blank GD resource Finalize with the PNG image on top Write the image to a fixed location that we can use later on to upload to Twitter If you want to try and implement that on your own as a challenge go ahead I encourage you to try If you just want to see it working then you can copy the following controller code to your own GenerateController php file app Command Cover GenerateController php lt phpnamespace App Command Cover use Abraham TwitterOAuth TwitterOAuth use Minicli Command CommandController class GenerateController extends CommandController public function handle api token this gt getApp gt config gt twitter consumer key api secret this gt getApp gt config gt twitter consumer secret access token this gt getApp gt config gt twitter user token token secret this gt getApp gt config gt twitter token secret client new TwitterOAuth api token api secret access token token secret followers client gt get followers list skip status gt true count gt if isset followers gt users this gt getPrinter gt error An error occurred return users followers gt users placeholders this gt getPlaceholders cover final imagecreatetruecolor foreach placeholders as key gt placeholder follower users key this gt getPrinter gt info Adding user to banner follower gt screen name path this gt downloadAvatar follower gt profile image url resource this gt getResource path info getimagesize path if resource imagecopyresampled cover final resource placeholder pos x placeholder pos y placeholder width placeholder height info info now finish with the cover image on top cover imagecreatefrompng DIR Resources cover template png if cover imagecopyresized cover final cover save path DIR latest header png imagepng cover final save path this gt getPrinter gt info Finished generating cover at save path return public function getPlaceholders array return pos x gt pos y gt width gt height gt pos x gt pos y gt width gt height gt pos x gt pos y gt width gt height gt pos x gt pos y gt width gt height gt pos x gt pos y gt width gt height gt public function getResource path info getimagesize path extension image type to extension info if strtolower extension png return imagecreatefrompng path if strtolower extension jpeg OR strtolower extension jpg return imagecreatefromjpeg path return null public function downloadAvatar url string file contents file get contents url file path tmp basename url image fopen file path w fwrite image file contents fclose image return file path You can run the command with php dynacover cover generateOnce it s finished check the root of the application to see the resulting image It should look similar to this Naturally you should feel free to customize the image and the position of the placeholders Just remember to adjust the coordinates accordingly Once you are happy with the generated cover you can go ahead and implement a command to update your twitter cover Programmatically Updating Twitter Cover ImageThe only thing missing now is the part where we actually update the cover image within our Twitter profile using the API Create a new command controller inside app Command Cover called UpdateController The following controller will Call the dynacover cover generate command to make sure we have an updated image to upload Post the new image to Twitter using the TwitterOAuth library and the account update profile banner endpoint app Command Cover UpdateController lt phpnamespace App Command Cover use Abraham TwitterOAuth TwitterOAuth use Minicli Command CommandController class UpdateController extends CommandController public function handle banner path DIR latest header png this gt getPrinter gt info Generating new cover this gt getApp gt runCommand dynacover cover generate api token this gt getApp gt config gt twitter consumer key api secret this gt getApp gt config gt twitter consumer secret access token this gt getApp gt config gt twitter user token token secret this gt getApp gt config gt twitter token secret client new TwitterOAuth api token api secret access token token secret post width gt height gt offset top gt offset left gt banner gt base encode file get contents banner path this gt getPrinter gt info Uploading cover to Twitter client gt post account update profile banner post this gt getPrinter gt info Finished uploading new banner return Once you get this controller set up you can run php dynacover cover updateThen check your Twitter profile to verify that the new cover was uploaded Include Script on Crontab Optional The last stap to automate your cover generation is to include the update script in Crontab or equivalent to run at a certain fixed interval every or minutes for instance I have set mine with Crontab to run every minutes and this is how I ve done it crontab eThis will open a text editor with the crontab for your user The following line will execute the specified command every minutes and throw the output to dev null usr bin php home erika dynacover dynacover cover update gt dev null gt amp Once you save and quit the new crontab will be installed Please notice that this should be set on a remote live server and using your local machine to run the scheduled script won t be as reliable Always use full paths for both the php executable and your dynacover script ConclusionIn this tutorial we saw how it is possible to programmatically generate Twitter cover header images and upload them to your profile so that you may show your latest followers Although the subject of this guide was Twitter followers and the Twitter profile header image the same principles apply to generate images for other networks and using other APIs The PHP GD library is very powerful and this is just scratching the surface of fun things we can build with it I hope you have enjoyed this tutorial and please share your profiles once you have implemented it 2021-06-02 16:03:07
Apple AppleInsider - Frontpage News App Store commerce grew 24% year-over-year to $643B in 2020 https://appleinsider.com/articles/21/06/02/app-store-commerce-grew-24-year-over-year-to-643b-in-2020?utm_medium=rss App Store commerce grew year over year to B in The App Store ecosystem facilitated billion in billings and sales throughout according to an independent study highlighted by Apple Credit AppleCompared to the billion in commerce generated in the results represent a increase year over year Additionally a study by the Analysis Group indicates that developers grew their businesses in while reaching new customers Read more 2021-06-02 17:00:09
Apple AppleInsider - Frontpage News Save $100 on the LG UltraFine 5K Display for MacBook Pro, MacBook Air, Mac mini https://appleinsider.com/articles/21/06/02/save-100-on-the-lg-ultrafine-5k-display-for-macbook-pro-macbook-air-mac-mini?utm_medium=rss Save on the LG UltraFine K Display for MacBook Pro MacBook Air Mac miniAppleInsider readers this week can save on the LG MDKL B inch UltraFine K display with macOS compatibility Grab the lowest price on the high res monitor to use with your MacBook Pro MacBook Air or Mac mini LG UltraFine K monitor discountUsing this activation link with promo code APINSIDER knocks off the inch high resolution display at LG Authorized Online Dealer Adorama dropping the price down to the lowest price available from an LG Authorized Dealer Read more 2021-06-02 16:52:33
Apple AppleInsider - Frontpage News New job ad suggests Apple launching 'homeOS' [u] https://appleinsider.com/articles/21/06/02/new-job-ad-suggests-apple-launching-homeos?utm_medium=rss New job ad suggests Apple launching x homeOS x u An Apple Music job posting initially referred to a previously unknown homeOS in its listing of Apple s mobile platforms Apple may be about to reveal a new OSA previously unannounced additional homeOS platform was been mentioned in the job description for a software engineer working in Apple Music Originally spotted by Twitter users and now confirmed by AppleInsider the listing made two references to the new OS Read more 2021-06-02 16:21:11
海外TECH Engadget Microsoft will unveil the next version of Windows on June 24th https://www.engadget.com/microsoft-windows-next-generation-june-24-162309239.html?src=rss_b2c Microsoft will unveil the next version of Windows on June thAfter teasing the next generation of Windows during Build last week Microsoft announced that it ll be officially unveiling the new version of its operating system on June th at AM Eastern 2021-06-02 16:23:09
海外TECH Engadget DICE Awards organizer's new festival will honor video game art https://www.engadget.com/dice-awards-game-makers-sketchbook-160047098.html?src=rss_b2c festival 2021-06-02 16:00:47
海外TECH Network World Could antiferromagnetic chips replace silicon? https://www.networkworld.com/article/3620438/could-antiferromagnetic-chips-replace-silicon.html#tk.rss_all Could antiferromagnetic chips replace silicon We probably wouldn t have a Digital Age without silicon The second most abundant element in the Earth s crust oxygen is No silicon is cheap and has the ability to conduct electricity and or act as an insulator Converted into silicon wafers it powers the computers smartphones and other electronic devices we use to work and importantly to avoid work So clearly silicon is indispensable Or maybe not Our insatiable demand for more and more data along with the need to store it is pushing the limits of what silicon can deliver in terms of speed density and security In a bid to find a worthy successor to silicon based memory devices MIT physicists are zeroing in something called antiferromagnets To read this article in full please click here 2021-06-02 16:23:00
Cisco Cisco Blog Accelerate and Simplify – Guiding Principles in the Design of New Software Image Upgrade and Patching Solutions https://blogs.cisco.com/networking/accelerate-and-simplify-guiding-principles-in-the-design-of-new-software-image-upgrade-and-patching-solutions Accelerate and Simplify Guiding Principles in the Design of New Software Image Upgrade and Patching SolutionsHow the Cisco IOS XE team of developers is changing the paradigm of how enterprise networking image upgrades are done  It has huge cost time productivity and security implications for Cisco customers around the globe and the functionality and safety of their wide array of network devices 2021-06-02 16:58:18
Cisco Cisco Blog Overcoming the next hurdle to get to 800G pluggable optics: Cisco Optics Podcast Episode 5 notes https://blogs.cisco.com/sp/overcoming-the-next-hurdle-to-get-to-800g-pluggable-optics-cisco-optics-podcast-episode-5-notes Overcoming the next hurdle to get to G pluggable optics Cisco Optics Podcast Episode notesJoin us for Episode of the Cisco Optics Podcast where we start a new conversation with my esteemed colleague Dr Mark Nowell Cisco Fellow 2021-06-02 16:26:38
海外科学 NYT > Science Here Are America’s Top Methane Emitters. Some Will Surprise You. https://www.nytimes.com/2021/06/02/climate/biggest-methane-emitters.html public 2021-06-02 16:33:33
金融 金融庁ホームページ 「令和2年金融商品販売法等改正に係る政令・内閣府令案等」に関する パブリックコメントの結果等について公表しました。 https://www.fsa.go.jp/news/r2/sonota/20210602/20210602.html 内閣府令 2021-06-02 17:00:00
ニュース ジェトロ ビジネスニュース(通商弘報) 第1四半期GDP成長率は前期比マイナス1.8%、5月の景況感は高水準で今後の回復に期待 https://www.jetro.go.jp/biznews/2021/06/bdc8c42b5de691d5.html 高水準 2021-06-02 16:40:00
ニュース ジェトロ ビジネスニュース(通商弘報) 新型コロナ対策、海上輸送の乱れ、コンテナ不足が在ロシア日系企業に打撃 https://www.jetro.go.jp/biznews/2021/06/0ad5052f2ae1a143.html 日系企業 2021-06-02 16:30:00
ニュース ジェトロ ビジネスニュース(通商弘報) 湖北省とEUの貿易額、14.8%を鉄道輸送が占める https://www.jetro.go.jp/biznews/2021/06/0a6218ee3497541b.html 鉄道輸送 2021-06-02 16:20:00
ニュース ジェトロ ビジネスニュース(通商弘報) ラオスからの中国向け農産物の大規模輸出協力で覚書 https://www.jetro.go.jp/biznews/2021/06/6109ddf944fda094.html 農産物 2021-06-02 16:10:00
ニュース BBC News - Home Covid-19: Lack of queue jumping helped vaccine drive, says Matt Hancock https://www.bbc.co.uk/news/uk-57336316 public 2021-06-02 16:50:06
ニュース BBC News - Home Dalian Atkinson: PC's fear 'through the roof' during arrest https://www.bbc.co.uk/news/uk-england-shropshire-57331711 benjamin 2021-06-02 16:33:39
ニュース BBC News - Home UK records hottest day of the year for third day in row https://www.bbc.co.uk/news/uk-57333711 london 2021-06-02 16:44:24
ニュース BBC News - Home Kingstanding stabbing: Killed teen named as Dea-John Reid https://www.bbc.co.uk/news/uk-england-birmingham-57334647 birmingham 2021-06-02 16:02:45
ニュース BBC News - Home Pension scandal: 'I've lost 14 years of payments' https://www.bbc.co.uk/news/business-57314686 elderly 2021-06-02 16:02:05
ニュース BBC News - Home Tottenham make contact with ex-Chelsea boss Conte https://www.bbc.co.uk/sport/football/57332318 manager 2021-06-02 16:04:01
ニュース BBC News - Home Everton: Nuno Espirito Santo and David Moyes emerge as candidates for Toffees job https://www.bbc.co.uk/sport/football/57336509 everton 2021-06-02 16:30:33
ニュース BBC News - Home Covid-19 in the UK: How many coronavirus cases are there in my area? https://www.bbc.co.uk/news/uk-51768274 cases 2021-06-02 16:41:25
ニュース BBC News - Home Covid: What's the roadmap for lifting lockdown? https://www.bbc.co.uk/news/explainers-52530518 covid 2021-06-02 16:07:27
ニュース BBC News - Home Travel guide to Spain, Portugal, France and more holiday hotspots https://www.bbc.co.uk/news/explainers-56997931 greece 2021-06-02 16:37:51
Azure Azure の更新情報 General availability: Azure API Management Premium tier price reduction for incremental purchased units https://azure.microsoft.com/ja-jp/updates/azure-api-management-premium-tier-price-reduction-for-incremental-purchased-units/ General availability Azure API Management Premium tier price reduction for incremental purchased unitsAfter the first purchased unit a price reduction of will be applied on all subsequent units purchased 2021-06-02 16:34:59

コメント

このブログの人気の投稿

投稿時間:2021-06-17 22:08:45 RSSフィード2021-06-17 22:00 分まとめ(2089件)

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

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