Skip to content

Instantly share code, notes, and snippets.

View ldmarz's full-sized avatar
💯
Dandolo todo mientras me divierto

Lenin martinez ldmarz

💯
Dandolo todo mientras me divierto
View GitHub Profile
@ldmarz
ldmarz / main.go
Created January 10, 2022 15:09
Fomatting numbers with golang.org/x/text/
package main
import (
"golang.org/x/text/language"
"golang.org/x/text/message"
)
func main() {
p := message.NewPrinter(language.English)
p.Printf("%d\n", 1000)
@ldmarz
ldmarz / raw-queries.swift
Created November 19, 2018 17:38
executing raw queries vapor3 with fluent
import Foundation
import FluentPostgreSQL
import Vapor
struct RemoveHashColumn: Migration {
typealias Database = PostgreSQLDatabase
static func prepare( on connection: PostgreSQLConnection ) -> Future<Void> {
return Database.update(Files.self, on: connection) { builder in
connection.raw("ALTER TABLE oldName RENAME TO newName;")
extension User: Migration {
static func prepare(on connection: PostgreSQLConnection) -> Future<void> {
return Database.create(self, on: connection) { builder in
builder.field(for: \.id, type: .int, isIdentifier: true)
builder.field(for: \.email, type: .string, .notNull)
builder.field(for: \.lifeStory, type: .text)
builder.field(for: \.iq, type: .int, .default(.literal("123456")))
builder.field(for: \.companyID, type: .int)
builder.reference(from: \.companyID, to: \Company.id)
builder.unique(on: \.email)
@ldmarz
ldmarz / migration-new-field.swift
Created November 13, 2018 12:09
Adding new field on vapor 3
import Foundation
import Vapor
import FluentPostgreSQL
struct AddUserPassword: Migration {
typealias Database = PostgreSQLDatabase
static func prepare( on connection: PostgreSQLConnection ) -> Future<Void> {
return Database.update(User.self, on: connection) { builder in
builder.field(for: \.password)
vapor build && vapor run revert // To revert the last migration
vapor build && vapor run revert --all // To revert all migration
var commands = CommandConfig.default()
commands.useFluentCommands()
services.register(commands)
import FluentPostgreSQL
import Vapor
struct AddFieldMock: Migration {
typealias Database = PostgreSQLDatabase
static func prepare( on connection: PostgreSQLConnection ) -> Future<Void> {
return Database.update(Acronym.self, on: connection) { builder in
builder.field(for: \.someFIeld)
}
var commands = CommandConfig.default()
commands.useFluentCommands()
services.register(commands)
@ldmarz
ldmarz / main.java
Created October 9, 2018 15:43
Get arbitrary resources from a .war file JAVA
// Get string path from some resource
getClass().getResource('Some name resource').getPath()
// Get the resource can be as stream
getClass().getResource('some resource')
// Print where is the resource folder inside .war package
getClass().getResource('').getPath()
const query = 'old man || the lock artist > scalzi';
const result = fuseWithOperators(query, mockData);
// → [{"title": "Old Man's War", "author": {"firstName": "John", "lastName": "Scalzi"}}]