> 2021年11月25日信息消化 ### An Open-Source CMS on the Cloudflare Stack: Introductory Post origin: [An Open-Source CMS on the Cloudflare Stack: Introductory Post](https://blog.cloudflare.com/production-saas-intro/) With this in mind, we decided to do something unique to the industry: we are developing an example feature-complete SaaS application that will be built entirely on the Cloudflare stack. It is and will continue to be completely free, [open-sourced on GitHub](https://github.com/cloudflare/production-saas), and developed in public. This will be an incredible time as it can be used as a template for launching your own SaaS applications, too! In fact, you can clone the GitHub repository, update a few service tokens, and deploy the pre-built application to your own Cloudflare account within minutes! #### Application Overview Ultimately we decided to build an example content management system (CMS) which, as an application archetype, has also transformed over the years. Traditionally, a CMS operated on rented hardware, which was home to a long-lived server that handled incoming requests and queried an SQL-like database in order to retrieve the requested content, render it to an HTML page, and repeat the process over and over again. [WordPress](https://wordpress.org/) was — and still is — a very common example of this approach. Traditional CMS(Wordpress) → Stacic Site Generation → Headless CMD Today, in the serverless era, there are a number of “headless CMS” options available. These are made “headless” because they are not monolithic web servers that render HTML for each request. Instead, they offer API endpoints that will return the content as raw JSON data. The CMS application model is a great case study for our open-source example. One of the primary tenets of an edge-first design is that content should be made available as close as physically possible to the users asking for it. And the serverless architecture means that there’s no longer — or should not be — a single point of failure. These both directly benefit the CMS archetype and, when implemented, will yield clear performance gains. CMS 应用程序模型是我们开源示例的一个很好的案例研究。边缘优先设计的主要原则之一是,内容应该尽可能靠近要求它的用户。无服务器架构意味着不再存在或不应该存在单点故障。这些都直接有益于 CMS 原型,并且在实施时将产生明显的性能提升。 #### Github Milestones [cloudflare/production-saas/milestones](cloudflare/production-saas/milestones) #### Phase 1 ```markdown ## JSON API Build a JSON API that, on its own, is a feature-complete SaaS application. - Products - Workers - Workers KV - Cloudflare for SaaS (vanity domains) - Rate Limiting - Integrations - Stripe – (test mode) payments - SendGrid – transactional emails - Sentry – Error reporting ## GitHub CI/CD - Automatic Worker(s) deployments on main branch - Complete testing on every PR and all branches - Port all Secrets and ENV into new repo ## Miniflare 2.0 #7 Migrate to miniflare@2 (currently in rc) for: - local development - unit testing - e2e testing ## Test Suites #8 Complete coverage via: - unit - endpoints - mock 3rd party - mock cloudflare for saas Relies on #7 ## Input Validations ## Integration: Stripe #10 Dispatch calls to the Stripe API for full customer and billing needs. Note: The API calls will be real, but we'll always be using "test mode" Stripe tokens - Map User model changes to Stripe.Customer updates. - Map Space, Document, Schema, and Member limits to Stripe.Subscription updates ## Integration: SendGrid Send transaction emails to the "customer" for all account-related events: - welcome - email changed - password changed - password reset link ## Integration: Cloudflare for SaaS ## Model: Schema ``` ##### Phase 1 – JSON API The project must begin with some API endpoints to start managing and manipulating data. Using Workers and Workers KV, the work within this milestone will focus on building a robust JSON API that handles the core functionality that the rest of the application will need. There is no HTML, CSS, or client-side JavaScript involved in this phase. Instead, **work here should focus solely on the data: how it’s accessed, how models relate to one another, and how best to structure and store these relationships** within Workers KV. For example, individuals should be able to create and manage workspaces that belong to their personal user accounts or to the organization(s) that they belong to. A number of other features are planned — subscription management and invoicing through [Stripe](https://stripe.com/), sending transactional emails through [SendGrid](https://sendgrid.com/), and assigning vanity domains to workspaces through [Cloudflare for SaaS](http://blog.cloudflare.com/cloudflare-for-saas-for-all-now-generally-available/). Finally, of course, the standard house-keeping tasks will be set up. This includes continuous integration (CI) with API testing and automated, continuous deployments (CD). ![img](https://raw.githubusercontent.com/Phalacrocorax/memo-image-host/master/uPic/image2-20.png) #### Phase 2 ```markdown ## Dashboard UI - Integrate and migrate API code to Pages w/ Functions setup - Attach dashboard SPA for performing / managing all API capabilities ``` We will use [Svelte](https://svelte.dev/), a JavaScript framework for building user interfaces. While not everyone may enjoy or agree with this decision, the templating syntax resembles standard HTML markup, which will allow non-frontend developers to follow along and gauge what’s going on. Svelte will be paired with [Tailwind CSS](https://tailwindcss.com/) for the design system. Tailwind is a very popular, utility-first CSS framework that allows developers to compose styles through predefined, reusable HTML `”class”` names. The result will be a single-page application (SPA) and will be hosted on Cloudflare Pages. This means that, out of the box, the dashboard will be able to take advantage of [Access-protected preview deployments](https://developers.cloudflare.com/pages/platform/preview-deployments#customizing-preview-deployments-access), [instant rollbacks](https://developers.cloudflare.com/pages/platform/rollbacks), automated deployments, comprehensive analytics, and more. Finally, [now that Pages integrates with Workers directly](http://blog.cloudflare.com/cloudflare-pages-goes-full-stack/), the JSON API from **Phase 1** will migrate into a new repository structure. While this may seem like an innocent refactor, it actually unlocks an incredible set of features for the JSON API: [Access-protected preview deployments](https://developers.cloudflare.com/pages/platform/preview-deployments#customizing-preview-deployments-access), [instant rollbacks](https://developers.cloudflare.com/pages/platform/rollbacks), and automated deployments. Yes — these are the same Pages features mentioned above! This is amazing because it means that our API is continuously and atomically versioned, allowing its development to continue safely *alongside* the client dashboard that depends on it. In other words, there is zero risk of the API and the dashboard diverging, which would have allowed their expectations of one another to misalign. Instant rollbacks will also apply to the API since the *entire* application operates as a single Pages unit. ### 焦虑障碍,“前世今生” origin: [焦虑障碍,“前世今生”](https://mp.weixin.qq.com/s/GHAfWOXj-WuovULApkp_Mg) 最新的精神疾病诊断与统计手册DSM-5将焦虑症划分为以下几种类型:分离焦虑症、选择性缄默、广泛性焦虑症、社交焦虑(恐惧)症、惊恐障碍、惊恐发作、广场恐惧症、物质或药物使用引发的焦虑症、其他疾病引起的焦虑症及其他特指或非特指的焦虑症。 古希腊神话中的“潘(Pan)”神,是焦虑的指代,并且是“恐慌(panic)”一词的来源。潘是牧羊之神,长着山羊角和羊腿,这种半兽人的外表格外令人恐惧。他常常在希腊的山脉和道路上游走,总是突然出现并骚扰从他身边跑过的动物,喜欢音乐并时常演奏一种小簧管(潘笛)。 古希腊哲学家对焦虑进行了深入思考并提出了解决办法。在一些哲学家眼里,精神疾病的生物学模型“如孩童之语一般毫无意义”。柏拉图认为,医生只能治愈微小的疾病,而深层的情绪问题只有哲学家能够解决。**焦虑和其他心理问题并非来自生理上的不平衡,而是心灵的不和谐**。其中,斯多葛学派(Stoics)和伊壁鸠鲁学派(Epicureanism)尽管被视为相互竞争的流派,但他们对焦虑的本质及摆脱焦虑的方法提出了类似的见解。 斯多葛学派哲学家爱比克泰德认为“**错误认知**”是罪魁祸首,“**困扰人们的是不是事情本身,而是人们看待事物的方式**”。另一位斯多葛派哲学家塞内卡在《心灵的平静》(*De quietate animi*)一书中阐述,“对死亡的恐惧是阻止我们享受无忧无虑生活的主要认知”,“害怕死亡的人永远不会成为一个活人”。与之类似,在伊壁鸠鲁看来,“改变精神失调的一种途径是摆脱对过去的消极认知和对未来的恐惧,因为唯一存在的现实就是现在”。斯多葛学派和伊壁鸠鲁学派的见解预见了17-18世纪克尔凯郭尔、海德格尔和其他存在主义哲学家的观点,即人类意识到自己的存在是有限的,继而引发了根本焦虑(死亡焦虑)。同时,对焦虑本质的探讨,即**焦虑是错误认知引起的观点,也与当今认知行为疗法**(cognitive behavior therapy,CBT)**的观点相一致**,但比后者早了2000年。至于如何摆脱焦虑,哲学家们建议将注意力集中在当下而不是担心未来上。这种对当下的关注正是今天**正念冥想**等认知行为疗法的关键目标之一。 到了19世纪,美国神经病学家乔治·比尔德(George Beard)首次描述了**神经衰弱**(neurasthenia),而泛恐惧症是神经衰弱的众多表现之一。神经衰弱表现为疲劳、焦虑、头痛、阳痿、神经痛和抑郁情绪。1895年德国精神分析学家弗洛伊德(Sigmund Freud)首次在德语中使用了术语“**焦虑性神经症**”(angstneurose),将焦虑性神经症与神经衰弱区分开,并成为广泛性焦虑症和**惊恐障碍**(panic disorder)的前身。他举了以下例子:“例如,一名患有焦虑症的女性在丈夫每次感冒咳嗽时都会想到流感肺炎,在她的脑海里看到了他的葬礼”。根据弗洛伊德的说法,焦虑性神经症的症状比现在广泛性焦虑症的症状要广泛得多,包括普遍易怒、焦虑预期、恶心、腹泻(与神经衰弱的便秘相反)、感觉异常、风湿性疼痛等。 自20世纪50年代以来,美国研究报告中的焦虑量表评分不断增加。在1952年发布的DSM-I中,焦虑几乎是“精神障碍”的同义词。精神障碍中的“焦虑”被解释为人格的有意识部分发送和感知的危险信号,被认为是由来自人格内部的威胁产生。引起焦虑的被压抑的冲动可能会被各种症状表现释放或转移。 ##### 20世纪末到21世纪 ——独立出来的“焦虑症” 到了1980年,DSM-III则用单独章节描述焦虑症,涵盖了恐惧症(细分为广场恐惧症,社交恐惧症等)、惊恐障碍、广泛性焦虑症、强迫症和创伤后应激障碍(PTSD)。儿童或青春期焦虑症则包括分离焦虑症、童年或青春期回避障碍和过度焦虑症。在 DSM-IV(1994)中,加入了一个新类别——急性应激障碍(acute situational reaction)。除此,混合性焦虑抑郁障碍也被列入附录中。而近年使用的DSM-5基于神经生物学、遗传和心理特征,将焦虑障碍进行了重新归类。原来版本中的强迫症和创伤后应激障碍被分别单独分类。同样,国际疾病分类ICD-10(1992)也将广泛性焦虑症和神经衰弱分别描述。5年前发布的ICD-11保留了原有分类,并将焦虑症命名为“焦虑和恐惧相关障碍”谱系,并区别于“强迫症或相关障碍”和“与压力相关障碍”。 ##### 认知神经科学观点 对啮齿类动物、非人灵长类和人类被试者的研究表明,中央杏仁核(central amygdala,CeA)和终纹床核(bed nucleus of stria terminalis,BNST)在恐惧和焦虑状态中起着至关重要的作用。具体来说,海马体、BNST、杏仁核和内侧前额叶/扣带回皮层之间的连接可能构成“焦虑网络”,并由背外侧前额叶(dorsolateral prefrontal cortex,dlPFC)调节。而相应的,最新研究发现,利用实时神经反馈技术针对杏仁核-前额叶环路进行调控可降低焦虑。除此之外,焦虑症的治疗研究阐明了内侧前额叶和杏仁核活动可以预测患者对CBT的治疗反应。以上证据表明,对焦虑的大脑标记物进行干预可能是治疗焦虑障碍的潜在手段。 ![图片](https://raw.githubusercontent.com/Phalacrocorax/memo-image-host/master/uPic/640.jpg) ###### 结语 今天,焦虑障碍在世界范围内都是最常见的精神障碍。我国2019年的流行病学调查显示,焦虑障碍患病率远超于其他精神疾病(包括抑郁或双相情感障碍),成为最普遍的精神障碍。其发生发展是生物-心理-社会综合因素的结果,治疗也应当采用生物、心理、社会三位一体的原则。最后,引用压力研究者汉斯·塞利的话,“我不能也不应该消灭我的压力,而仅可以教会自己去享受它”。愿我们都能享受这充满焦虑的一生。 #### Daily Coding Problem: Problem #259 [Hard] This problem was asked by Two Sigma. Ghost is a two-person word game where players alternate appending letters to a word. The first person who spells out a word, or creates a prefix for which there is no possible continuation, loses. Here is a sample game: - Player 1: `g` - Player 2: `h` - Player 1: `o` - Player 2: `s` - Player 1: `t` [loses] Given a dictionary of words, determine the letters the first player should start with, such that with optimal play they cannot lose. For example, if the dictionary is `["cat", "calf", "dog", "bear"]`, the only winning start letter would be `b`. [Daily-Coding-Problem/Solution/Day-259.cpp](https://github.com/offamitkumar/Daily-Coding-Problem/blob/master/Solution/Day-259.cpp) ```cpp #include #include #include #include #include using namespace std; class Solution { public: vector getMove (vector&s) { map> f; for (auto&itr: s) { f[itr[0]].insert((int)itr.size()); } vectorgood; for (auto&itr:f) { if (none_of(itr.second.begin(), itr.second.end() , [](int x) { return x%2!=0; })) { good.push_back(itr.first); } } return good; } }; int main(void){ vectordict {"cat" , "calf" , "dog" , "bear"}; Solution s; vectorv = s.getMove(dict); for (auto&itr : v) { cout << itr << ' '; } return 0; } ``` ### Misc - Design your own **passive income** machine with a **job**, side hustle, and **financial assets**. That’s how you can make 6-figures of passive income to buy back your time and spend it however you want. | [I Built a 6-Figure Passive Income Machine — Here’s How to Do It Without Quitting Your Job](https://entrepreneurshandbook.co/i-built-a-6-figure-passive-income-machine-heres-how-to-do-it-without-quitting-your-job-4441e3a15486) - 感觉这里对应到了v2ex的一个帖子[分享下我对挣大钱的一些思考](https://www.v2ex.com/t/817584), 收入的三个来源, 劳动+产品+资产。 - [Feynman technique](https://click.convertkit-mail.com/0vumq8pg2xi9hpm0wxtl/x0hph3un92ge9ehg/aHR0cHM6Ly90d2l0dGVyLmNvbS9Qcm9mRmV5bm1hbi9zdGF0dXMvMTQ2MzU3MjA2MjA2OTM1MDQwMA==) “If you wanna master something, teach it.”