Skip to content

Instantly share code, notes, and snippets.

View ahmadarif's full-sized avatar
🎯
Focusing

Ahmad Arif ahmadarif

🎯
Focusing
View GitHub Profile
if (err is HttpException) {
val code = err.response().code()
Log.d("HttpException", "code $code")
val body = retrofit.converter<ErrorResponse>(err)
Log.d("HttpException", "body ${body.message}")
}
data class ErrorResponse(val message: String)
@ahmadarif
ahmadarif / api.php
Created September 23, 2017 16:03
Sample Array Paginate
Route::get('test', function () {
$arr = [];
for ($i=0; $i<1000; $i++) {
$arr[] = $i+1;
}
return response(paginate($arr));
});
@ahmadarif
ahmadarif / adonis_medium_1_coding_style.js
Last active February 10, 2018 01:03
Penjelasan penulisan kode AdonisJS
// callback style
Users.all((err, users) => {
users.posts().fetch((err, bicycles) => {
res.send({ users, bicycles })
})
})
// promise style
let users = null
@ahmadarif
ahmadarif / adonis_medium_2_database_support.csv
Created February 9, 2018 23:46
Database Support Adonis
Database Npm driver
PostgreSQL npm i pg
MySQL npm i mysql or npm i mysql2
MariaDB npm i mariasql
SQLite3 npm i sqlite3
Oracle npm i oracledb or npm i strong-oracle
MSSQL npm i mssql
'use strict'
const Schema = use('Schema')
class UserSchema extends Schema {
up () {
this.create('users', table => {
table.increments()
table.string('username', 80).notNullable().unique()
table.string('email', 254).notNullable().unique()
'use strict'
const Schema = use('Schema')
class NewsSchema extends Schema {
up () {
this.create('news', (table) => {
table.increments()
table.string('title', 100)
table.text('content')
'use strict'
const Factory = use('Factory')
const Hash = use('Hash')
Factory.blueprint('App/Models/User', async (faker) => {
return {
username: faker.username(),
email: faker.email({ domain: "example.com"}),
password: await Hash.make(faker.password())
'use strict'
/*
|--------------------------------------------------------------------------
| UserSeeder
|--------------------------------------------------------------------------
|
| Make use of the Factory instance to seed database with dummy data or
| make use of Lucid models directly.
|
// fungsi select
const users = await Database.from('users').where('id', 1)await Database.select('*').from('users')
// fungsi select kolom tertentu
const users = await Database.from('users').where('id', 1)await Database.select('id', 'username').from('users')
// fungsi where clause
const users = await Database.from('users').where('id', 1)await Database.from('users').where('id', 1)
// fungsi join tabel
'use strict'
const Model = use('Model')
class News extends Model {
}
module.exports = News