Skip to content

Instantly share code, notes, and snippets.

View kenjipm's full-sized avatar

Kenji Prahyudi Mudjono kenjipm

View GitHub Profile
@kenjipm
kenjipm / workers.sql
Last active November 23, 2021 10:47
The following data definition defines an organization's employee hierarchy. An employee is a manager if any other employee has their managerId set to the first employees id. An employee who is a manager may or may not also have a manager. TABLE employees id INTEGER NOT NULL PRIMARY KEY managerId INTEGER REFERENCES employees(id) name VARCHAR(30) …
SELECT name FROM employees
WHERE id NOT IN (SELECT managerId FROM employees WHERE managerId IS NOT NULL);
@kenjipm
kenjipm / students.sql
Last active April 17, 2022 10:36
Given the following data definition, write a query that returns the number of students whose first name is John. TABLE students id INTEGER PRIMARY KEY, firstName VARCHAR(30) NOT NULL, lastName VARCHAR(30) NOT NULL
SELECT COUNT(*) FROM students WHERE firstName = "John";
@kenjipm
kenjipm / make_pipeline.php
Last active January 2, 2019 07:10
As part of a data processing pipeline, complete the implementation of the make_pipeline method: The method should accept a variable number of functions, and it should return a new function that accepts one parameter $arg. The returned function should call the first function in the make_pipeline with the parameter $arg, and call the second functi…
<?php
class Pipeline
{
public static function make_pipeline(...$funcs)
{
return function($arg) use ($funcs)
{
foreach ($funcs as $func)
{
$arg = $func($arg);
@kenjipm
kenjipm / isPalindrome.php
Last active June 8, 2019 15:41
A palindrome is a word that reads the same backward or forward.
<?php
class Palindrome
{
public static function isPalindrome($word)
{
$word = strtolower($word);
$length = strlen($word);
for($i = 0; $i < $length; $i++)
{