Skip to content

Instantly share code, notes, and snippets.

View teguhpratama's full-sized avatar

Teguh Pratama teguhpratama

  • Indonesia
View GitHub Profile
@teguhpratama
teguhpratama / employees_who_are_not_managers.sql
Created January 19, 2019 10:57
A query that selects the names of employees who are not managers.
SELECT t1.`name` FROM `employees` AS t1 WHERE `managerId` IS NOT NULL
AND t1.`id` NOT IN (SELECT `managerId` FROM `employees` WHERE `managerId` IS NOT NULL)
UNION
SELECT t1.`name` FROM `employees` AS t1 WHERE `managerId` IS NULL
AND t1.`id` NOT IN (SELECT `managerId` FROM `employees` WHERE `managerId` IS NOT NULL);
@teguhpratama
teguhpratama / number_of_students.sql
Created January 19, 2019 10:54
Get the number of students whose first name is John.
SELECT COUNT(*) FROM `students` WHERE `firstname` = "John";
@teguhpratama
teguhpratama / pipeline.php
Created January 19, 2019 10:52
The Pipeline Pattern.
<?php
class Pipeline
{
public static function make_pipeline(...$funcs)
{
return function($arg) use ($funcs)
{
$result = $arg;
foreach ($funcs as $func) {
$result = $func($arg);
@teguhpratama
teguhpratama / palindrome.php
Created January 19, 2019 10:45
A palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward, such as madam or racecar or the number 10801.
<?php
class Palindrome
{
public static function isPalindrome($word)
{
$word = strtolower($word);
if ( $word == strrev($word) ) {
return true;
}
return false;