Skip to content

Instantly share code, notes, and snippets.

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

Harminder Virk thetutlage

🏠
Working from home
View GitHub Profile
@thetutlage
thetutlage / master.html
Created February 10, 2016 07:00
Master view for adonis tweedle application
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>Tweedle</title>
<meta name="description" content="">
<meta name="author" content="">
<link href='https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,200,300,600,700,900' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="/style.css">
@thetutlage
thetutlage / list.html
Created February 10, 2016 08:18
Stories list view for tweedle app
{% extends '../partials/master' %}
{% block content %}
<div class="__band">
<div class="__text">
<p><b>Tweedle</b> is a place to share your tech stories in 140 characters. It is built on top of <a href="http://adonisjs.com/"> AdonisJs </a></p>
</div>
<div class="button__area">
<a href="/signup" class="__button">Join us</a>
@thetutlage
thetutlage / toSentence.js
Created January 18, 2017 08:18
Function to be used with tagged ES2015 template literals
function toSentence (strings, ...values) {
const nouns = values[0] || ''
const noun = values[1] || ''
const verb = values[2] instanceof Array === true ? (nouns.length ? values[2][1] : values[2][0]) : ''
const mappedString = strings.map((char, index) => {
if (index === 0 && !nouns) {
return `${char}${noun}`
} else if (index === 1 && !nouns) {
return ''
@thetutlage
thetutlage / JsonAPISerializer.js
Created April 26, 2018 18:06
Adonis JSONAPI serializer
'use strict'
const _ = use('lodash')
/**
* JSONAPI serializer for lucid models.
*
* NOTE: The implementation is not complete yet.
*
* @class JsonAPISerializer
@thetutlage
thetutlage / index.js
Created May 8, 2018 06:41
Mailgun messages.mime returning 400 with content length header
'use strict'
const nodemailer = require('nodemailer')
const got = require('got')
const FormData = require('form-data')
class MailGunTransporter {
send (mail, callback) {
const form = new FormData()
form.append('to', '<TO_EMAIL>')
@thetutlage
thetutlage / index.html
Last active June 9, 2018 04:24
Html file for adonis antl demo
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css">
</head>
<body>
<nav class="navbar navbar-expand navbar-light bg-light">
<a class="navbar-brand" href="#">AdonisJs</a>
@thetutlage
thetutlage / routes.js
Created June 27, 2018 08:53
Import Adonis Database provider
const Database = use('Database')
@thetutlage
thetutlage / routes.js
Created June 27, 2018 08:56
Adonis Database query builder select queries
// All users
await Database.from('users').select('*')
// Get admin users
await Database.from('users').where('role', 'admin')
// Inactive users
await Database
.from('users')
.where('status', 'inactive')
@thetutlage
thetutlage / routes.js
Created June 27, 2018 09:00
Adonis database insert queries
await Database
.table('users')
.insert({ username: 'virk', role: 'admin', password: 'secret' })
// Bulk inserts
await Database
.table('users')
.insert([
{ username: 'virk', role: 'admin', password: 'secret' },
{ username: 'nikk', role: 'guest', password: 'secret' }
@thetutlage
thetutlage / routes.js
Created June 27, 2018 09:43
AdonisJs blog queries via query builder
// Display categories in the blog header
const categories = await Database.table('categories').select('*')
// Fetch posts for a category where category_id = 1
const posts = await Database
.table('posts')
.innerJoin('category_posts', 'posts.id', 'category_posts.post_id')
.where('category_posts.category_id', categoryId)
// Select author for a given post