Skip to content

Instantly share code, notes, and snippets.

View chrisza4's full-sized avatar

Chakrit Likitkhajorn chrisza4

  • ThoughtWorks
  • Thailand
View GitHub Profile
@chrisza4
chrisza4 / cleanup.js
Last active May 18, 2019 07:06
connectionCleanup.js
// ถ้าเกิดว่าเรามีงานที่ต้องต่อ Connection กับฐานข้อมูลหรือระบบภายนอก และมีคำสั่ง Connect/Disconnect
// ทั้งสองคำสั่งเป็น Async
function createConnectionForSocket(socketId) {
let connection = null
async function connectToSomeSystem () {
connection = await someSystem.connect('url')
return
}
async function disconnectFromSomeSystem () {
(defn tennis [winner {:keys [score advantage] :as game-state}]
"kata from http://codingdojo.org/kata/Tennis/
take winner and game state, return updated game state"
;;The scoring system is rather simple:
(let [is-deuce (= (vals score) [40 40])]
(cond
;;, the winner of a ball will have advantage and game ball.
(and is-deuce (nil? advantage))
(assoc game-state :advantage winner)
;; b. If the player with advantage wins the ball he wins the game
class GreeterControler {
Hello(): ActionResult {
return authorizedEndpoint(() => {
return Content("Hello there");
});
}
}
function authorizedEndpoint(src: () => ActionResult):() => ActionResult {
// Authorization logic here
class GreeterControler
{
[Authorized]
public ActionResult Hello()
{
return Content("Hello there");
}
}
@chrisza4
chrisza4 / m.js
Created February 19, 2019 15:25
้Not Like this
function doSomething() {
// Some kind of ceremony (Factory, Initiate classes, Design patterns stuff, etc.)
// Some kind of ceremony (Factory, Initiate classes, Design patterns stuff, etc.)
// Some kind of ceremony (Factory, Initiate classes, Design patterns stuff, etc.)
// Real business logic #1
// Some kind of ceremony (Factory, Initiate classes, Design patterns stuff, etc.)
// Some kind of ceremony (Factory, Initiate classes, Design patterns stuff, etc.)
// Some kind of ceremony (Factory, Initiate classes, Design patterns stuff, etc.)
// Some kind of ceremony (Factory, Initiate classes, Design patterns stuff, etc.)
// Real business logic #2
@chrisza4
chrisza4 / hatethis.cs
Created February 19, 2019 15:07
Hate this
public class MyClass
{
public void MyFunction()
{
// Some kind of ceremony (Factory, Initiate classes, Design patterns stuff, etc.)
// Some kind of ceremony (Factory, Initiate classes, Design patterns stuff, etc.)
// Some kind of ceremony (Factory, Initiate classes, Design patterns stuff, etc.)
// Real business logic #1
// Some kind of ceremony (Factory, Initiate classes, Design patterns stuff, etc.)
// Some kind of ceremony (Factory, Initiate classes, Design patterns stuff, etc.)
// ตอนแรกเรามีแบบนี้
public interface ITaskService
{
List<Task> getTasksByProject(string projectId);
}
class TaskStats {
public TaskStats(ITaskService taskService)
{
(defmethod restructure-param :current-user
[_ binding acc]
(update-in acc [:letks] into [binding `(:identity ~'+compojure-api-request+)]))
(ns acemotion.core.alerts.schemas
(:require [schema.core :as s]
[acemotion.core.utils.utils :as utils]))
(def alert-type
{:warning 0
:danger 1})
(def alert
{:id s/Uuid
(ns acemotion.test.core.groups.services_test
(:require [acemotion.config :refer [env]]
[acemotion.db.core :refer [*db*] :as db]
[acemotion.test.helpers :as test-helpers]
[acemotion.core.groups.services :as groups-services]
[clojure.test :refer :all]
[luminus-migrations.core :as migrations]
[mount.core :as mount]))
(def chris (test-helpers/generate-test-user "chris@user.com"))