Skip to content

Instantly share code, notes, and snippets.

@philiplambok
philiplambok / rails-object-style-guide.md
Created July 12, 2019 00:35
Rails object style guide

reserved

@philiplambok
philiplambok / query.md
Created July 25, 2019 02:46
history of improvement query.
 courses = Moodle::Course.taken_by(current_user)
 // Completed 200 OK in 161ms (Views: 0.2ms | ActiveRecord: 37.6ms
 // Completed 200 OK in 102ms (Views: 0.2ms | ActiveRecord: 31.1ms)
``

``rb
courses = Moodle::Course.includes(user_enrollments: [{ enrollments: [:courses] }]).taken_by(current_user)
// Completed 200 OK in 148ms (Views: 0.2ms | ActiveRecord: 37.4ms)
// Completed 200 OK in 109ms (Views: 0.1ms | ActiveRecord: 34.8ms)
@philiplambok
philiplambok / index.php
Created August 14, 2019 13:35
problem value not send to controller.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Add Remove Dynamic HTML Fields using JQuery Plugin in PHP</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ" crossorigin="anonymous"></script>
@philiplambok
philiplambok / improve-spec.md
Last active August 20, 2019 04:29
Improve system spec with rack_session_access

Before

$> time rspec
Finished in 6 minutes 54 seconds (files took 13.31 seconds to load)
823 examples, 0 failures

Coverage report generated for RSpec to /home/harukaedu/Codes/ruby/cms-corp-u/coverage. 2908 / 3003 LOC (96.84%) covered.
bundle exec rspec  151,89s user 21,29s system 39% cpu 7:14,58 total
@philiplambok
philiplambok / proposal.md
Last active September 4, 2019 04:22
proposal-refactor-csrf-token.md

Before

<template>....</template>

<script>
export default {
  data(){
    return {
      user: {
pipeline {
    agent any
    stages {
        stage('Preparation') {
            steps {
                git branch: '**', 
                credentialsId: '95ba7d88-78e8-429d-8d3a-bb51a6800c37', 
                url: '[email protected]:harukaedudev/ahmeng.git'
 }

SimpleBuilder

Make paramameter more cute than your waifu >//<

# app/builders/date.rb

class Date
  include SimpleBuilder
@philiplambok
philiplambok / presenter.md
Created December 13, 2019 02:46
Simple presenter/decorator/view-model/you-name-it <3
# Presenter

user = User.find_by(id: params[:id]) # <first_name='Nobu'; last_name='Boki'>
@user = UserPresenter.new(user)
@user.name # 'Nobu Boki'

# When use in collections
users = UserPresenter.to_collection(User.all)
users.first.class.name # UserPresenter
{
"editor.fontFamily": "Jetbrains Mono, Dank Mono, Menlo, Monaco, 'Courier New', monospace",
"workbench.colorTheme": "Dracula",
"workbench.iconTheme": "Monokai Pro Icons",
"window.zoomLevel": -1,
"editor.tabSize": 2,
"ruby.useLanguageServer": true,
"ruby.lint": {
"ruby": true
},

Before:

$> brakeman --only-files app/models/plugin_mokapos_setting.rb
Loading scanner...
Processing application in /Users/philiplambok/Codes/ruby/quickbook
Processing gems...
[Notice] Detected Rails 4 application
Processing configuration...
[Notice] Escaping HTML by default
Parsing files...