We need to generate secret key for development environment.
mix phoenix.gen.secret
# ednkXywWll1d2svDEpbA39R5kfkc9l96j0+u7A8MgKM+pbwbeDsuYB8MP2WUW1hfLet's generate User model and controller.
| interface MyProgramDSL<T> { | |
| read: () => Promise<string>; | |
| write: (value: string) => Promise<void> | |
| done: (value: T) => Promise<T> | |
| } | |
| const MyProgram = async ({ read, write, done }: MyProgramDSL<string>) => { | |
| await write("Hello, what is your name?"); | |
| const name = await read(); |
| type Program<T> = Read<T> | Write<T> | Done<T>; | |
| interface Read<T> { | |
| kind: "Read"; | |
| next: (data: T) => Program<T>; | |
| } | |
| interface Write<T> { | |
| kind: "Write"; | |
| valToWrite: string; |
| // DONT FORGET TO `yarn add esbuild-loader` !!! | |
| // config/webpacker/environment.js | |
| const { environment } = require('@rails/webpacker') | |
| const { ESBuildPlugin } = require('esbuild-loader') | |
| const esBuildUse = [ | |
| { | |
| loader: require.resolve('esbuild-loader'), | |
| // What you want to compile to, in this case, ES7 |
| /** | |
| * Typescript dynamic class method example | |
| * | |
| * REFERENCES: | |
| * @see https://www.typescriptlang.org/docs/handbook/declaration-merging.html | |
| * @see https://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/Mixins.md | |
| * @see http://blog.brillskills.com/2013/09/exploring-javascript-prototypes-via-typescripts-class-pattern | |
| * @see https://github.com/Microsoft/TypeScript/wiki/%27this%27-in-TypeScript | |
| * | |
| * For this example, using IONIC 2/3 Toast component to override a method |
| import { Module } from '@nestjs/common'; | |
| import { MyLibModule } from './my-lib.module'; | |
| @Module({ | |
| imports: [ | |
| MyLibModule.register({ name: 'Enzo' }), | |
| ] | |
| }) | |
| export class ImportingModule {} |
| require 'net/http' | |
| def working_url?(url_str) | |
| url = URI.parse(url_str) | |
| Net::HTTP.start(url.host, url.port) do |http| | |
| http.head(url.request_uri).code == '200' | |
| end | |
| rescue | |
| false | |
| end |
| function logClass(target: any) { | |
| // save a reference to the original constructor | |
| var original = target; | |
| // a utility function to generate instances of a class | |
| function construct(constructor, args) { | |
| var c : any = function () { | |
| return constructor.apply(this, args); | |
| } |
| /** | |
| * Creates a dynamic instance of a specific class/prototype. | |
| * Minor changes from initial solution shared by **Steve Fenton** | |
| * | |
| * WARNING: This solution don't works on Angular applications, | |
| * using JIT (because the webpack don't compiles classes into window object) | |
| * or AOT (js minification for production build) compilation. | |
| * | |
| * @see https://www.stevefenton.co.uk/2014/07/creating-typescript-classes-dynamically/ | |
| */ |
| # config/routes.rb | |
| Rails.application.routes.draw do | |
| mount ActionCable.server, at: '/cable' | |
| end | |
| # app/channels/chat_channel.rb | |
| class ChatChannel < ApplicationCable::Channel | |
| def subscribed | |
| stream_from "chat_channel" | |
| end |