Skip to content

Instantly share code, notes, and snippets.

View alekpopovic's full-sized avatar
🏠
Working from home

Aleksandar Popovic alekpopovic

🏠
Working from home
View GitHub Profile
@alekpopovic
alekpopovic / dsl.ts
Created February 16, 2021 23:56 — forked from freddi301/dsl.ts
Typescript example DSL
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();
@alekpopovic
alekpopovic / DSL.ts
Created February 16, 2021 23:56 — forked from ulve/DSL.ts
Sample DSL with interpreter in TypeScript
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;
@alekpopovic
alekpopovic / environment.js
Created February 7, 2021 00:01 — forked from KonnorRogers/environment.js
ESBuild with Webpacker < 6 in Rails. Bye Babel <3
// 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
@alekpopovic
alekpopovic / dynamic-method.ts
Created January 1, 2021 16:58 — forked from mfdeveloper/dynamic-method.ts
This is a example of a dynamic class method on Typescript. Until here, is not possible access class properties inside the overrided/new method
/**
* 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
@alekpopovic
alekpopovic / importing.module.ts
Created December 10, 2020 18:07 — forked from evolkmann/importing.module.ts
Create Nest.js modules with custom config
import { Module } from '@nestjs/common';
import { MyLibModule } from './my-lib.module';
@Module({
imports: [
MyLibModule.register({ name: 'Enzo' }),
]
})
export class ImportingModule {}
@alekpopovic
alekpopovic / working_url.rb
Created December 1, 2020 19:53 — forked from tb/working_url.rb
Check if URL exists in Ruby
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
@alekpopovic
alekpopovic / class_decorator.ts
Created November 28, 2020 22:16 — forked from remojansen/class_decorator.ts
TypeScript Decorators Examples
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);
}
@alekpopovic
alekpopovic / instance-loader.ts
Created November 21, 2020 20:30 — forked from mfdeveloper/instance-loader.ts
Creating TypeScript Classes Dynamically - Totally based on Steve Fenton solution
/**
* 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/
*/
@alekpopovic
alekpopovic / Guardian JWT.md
Created November 13, 2020 20:46 — forked from nikneroz/Guardian JWT.md
Elixir + Phoenix Framework + Guardian + JWT. This is tutorial and step by step installation guide.

Elixir + Phoenix Framework + Guardian + JWT + Comeonin

Preparing environment

We need to generate secret key for development environment.

mix phoenix.gen.secret
# ednkXywWll1d2svDEpbA39R5kfkc9l96j0+u7A8MgKM+pbwbeDsuYB8MP2WUW1hf

Let's generate User model and controller.

@alekpopovic
alekpopovic / Rails Code
Created November 8, 2020 17:45 — forked from jevin/Rails Code
Using ActionCable in Expo/React Native
# 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