Skip to content

Instantly share code, notes, and snippets.

@omirobarcelo
omirobarcelo / py_downloader.py
Last active September 29, 2018 16:55
Script to download and organize all the pages of a chapter in MangaTown
import sys
import os
import urllib2
if len(sys.argv) < 3:
print 'usage: python py_mangatown_download.py <url_of_chapter_first_img> <dest_folder>'
exit()
dirs = sys.argv[2].split('/')
for dir in dirs:
@omirobarcelo
omirobarcelo / alpine-ttt.html
Created April 21, 2020 13:50
Tic-Tac-Toe made with AlpineJS
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine@v2.x.x/dist/alpine.min.js" defer></script>
<title>Alpine Tic-Tac-Toe</title>
@omirobarcelo
omirobarcelo / catch_decorator_method.ts
Created May 12, 2020 10:54
A Catch decorator for methods
type HandlerFunction = (error: Error, ctx: any) => void;
export const Catch = (errorType: any, handler: HandlerFunction): any => {
return (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
// Save a reference to the original method
const originalMethod = descriptor.value;
// Rewrite original method with try/catch wrapper
descriptor.value = function (...args: any[]) {
try {
@omirobarcelo
omirobarcelo / catch_decorator_class_excerpt.ts
Created May 12, 2020 12:12
Excerpt of the Catch decorator for classes and methods
// Decorator factory function
export const Catch = (errorType: any, handler: HandlerFunction): any => {
return (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
// Method decorator
if (descriptor) {
return _generateDescriptor(descriptor, errorType, handler);
}
// Class decorator
else {
// Iterate over class properties except constructor
@omirobarcelo
omirobarcelo / alosaur_hello_world.ts
Created June 9, 2020 16:05
Hello World Alosaur application
import { Controller, Get, Area, App } from 'https://deno.land/x/alosaur/mod.ts';
@Controller('/home')
export class HomeController {
@Get('/text')
text() {
return 'Hello world';
}
@Get('/json')
json() {
@omirobarcelo
omirobarcelo / deps.ts
Last active June 9, 2020 17:19
deps.ts file (v1) for 'Creating your own blog with Deno' article
export { Controller, Get, Area, App } from 'https://deno.land/x/alosaur/src/mod.ts';
// We import it as
// import { Controller, Get, Area, App } from 'deps.ts';
@omirobarcelo
omirobarcelo / post_list.json
Created June 9, 2020 17:30
Example of post_list.json for 'Creating your own blog with Deno' article
[
{
"id": "1fa7dfa9",
"title": "How to Use the Environment for Specific HTTP Services",
"coverUrl": "https://blog-backend-deno.herokuapp.com/post-covers/data-service-article.png",
"labels": ["Angular", "TypeScript", "Programming", "Web Development"]
},
{
"id": "e6308bab",
"title": "A Try/Catch Decorator to Stylize Your Code",
@omirobarcelo
omirobarcelo / post_loc.json
Created June 9, 2020 17:32
Example locations for 'Create your own blog with Deno' article
{
"1fa7dfa9": "./posts/specific-data-service.html",
"e6308bab": "./posts/try-catch-decorator.html"
}
@omirobarcelo
omirobarcelo / posts.service.ts
Created June 9, 2020 17:33
Service for serving posts
import { join, normalize } from '../../../deps.ts';
import { readJson } from '../../../deps.ts';
import { Request, Response, serveFile } from '../../../deps.ts';
import { Post } from './interfaces/post.interface.ts';
export class PostsService {
private CWD = '.';
constructor() {
this.CWD = Deno.cwd();
@omirobarcelo
omirobarcelo / posts.controller.ts
Created June 10, 2020 15:27
Controller for requesting posts
import { Controller, Get, Param, Req, Request } from '../../../deps.ts';
import { PostsService } from './posts.service.ts';
import { Post } from './interfaces/post.interface.ts';
@Controller('/posts')
export class PostsController {
constructor(private _service: PostsService) {}
@Get()
async list(): Promise<Post[]> {