Skip to content

Instantly share code, notes, and snippets.

View makoru-hikage's full-sized avatar
🐮
Perhaps

Kurt Ma. Coll makoru-hikage

🐮
Perhaps
View GitHub Profile
@makoru-hikage
makoru-hikage / repeater.perl
Created August 3, 2016 06:14
Because I do not know `sed` and `awk` back in 2014
#!/usr/bin/perl
open(INFILE1, "<list_of_classes.txt") or die "Couldn't open file, $!";
@listOfClasses = <INFILE1>;
@items = ();
#Split all the items of the list which might be
@makoru-hikage
makoru-hikage / ClassGenerator.perl
Last active April 1, 2017 05:55
Just like Repeater.perl but this is the original one I created
#!/usr/bin/perl
#The original one I wrote back in 2014 because I don't know sed and awk.
open(INFILE1, "<list_of_classes.txt") or die "Couldn't open file, $!";
@listOfClasses = <INFILE1>;
@items = ();
@makoru-hikage
makoru-hikage / altIDsnippet.php
Created October 21, 2016 06:14
The use of alternative ID system.
<?php
/**
* This is a simple search function by ID. An alternate ID(AID) key is a candidate key that
* is UNIQUE and is a natural key. This is used when surrogate keys are applied but a
* user want to search by a unique identifying name. Whilst primary keys(PK) called 'id'
* are UNSIGNED INT, the AID keys are usually VARCHAR. Such an example is a User entity.
* A user entity has 'id' as PK and 'username' as its AID. When someone wants to search
* by 'username'.
@makoru-hikage
makoru-hikage / Denote School Year.sql
Last active January 9, 2017 10:50
This is an SQL query for extraction of semesters and any other terms under a school year.
-- Assuming the the table design is like this
--
-- Table Name: school_calendar
-- Columns
-- id - INT NOT NULL PRIMARY KEY
-- semester - VARCHAR (255) NOT NULL
-- date_start - DATE
-- date_end - DATE
--
-- The data will be as follows
@makoru-hikage
makoru-hikage / SchoolCalendar.php
Created December 3, 2016 21:11
"Denote School Year.sql"'s Eloquent implementation
<?php
namespace DeltaX\Models;
use Illuminate\Database\Eloquent\Model;
use Carbon\Carbon;
class SchoolCalendar extends Model {
protected $guarded = ['created_at', 'updated_at', 'is_deleted'];
protected $hidden = ['created_at', 'updated_at', 'is_deleted'];
@makoru-hikage
makoru-hikage / ErraticEloquentQuery.php
Last active December 4, 2016 15:46
This shows "Fatal error: Maximum function nesting level of '256' reached, aborting!"
<?php
public function getAcademicYearAttribute(){
$year_start = Carbon::parse($this->date_start)->year;
$year_end = Carbon::parse($this->date_end)->year;
$academic_year =
self::select(['date_start','date_end', 'semester'])
->whereYear('date_start', $year_start)
->where(function($q) use ($year_end){
@makoru-hikage
makoru-hikage / DeterminePrecedingNsters.php
Last active December 9, 2016 07:34
This function determines the subsequent and preceding semesters, trimesters, or quarters by month
<?php
//With enough logic and math, one adept programmer can use this to determine what school year a semester belongs to.
//Using only the declared arguments of this lone user-defined function.
//Tested using PHP Fiddle (http://phpfiddle.org/)
define ('INTO_SEMESTERS', 2);
define ('INTO_TRIMESTERS', 4);
define ('INTO_QUARTERS', 3);
function getNsterOfYear($division, $date, $monthStart){
$month = date_parse_from_format('Y-n-d', $date)['month'];
@makoru-hikage
makoru-hikage / studentBySection.sql
Last active February 1, 2017 07:43
Groups all the students in the same section in a given academic term
/**
* INVOLVED TABLES
*
* TABLE: students
* id
* user_id
* degree_id
* ...
*
* TABLE: degrees
@makoru-hikage
makoru-hikage / NullIsArray.php
Last active February 18, 2017 01:01
It seems that a `null` value is treated as an array()
<?php
$dummy= [
'Alpha' => null,
'Beta' => null,
'Charlie' => null
];
switch ($dummy['Alpha']) {
case is_array($dummy['Alpha']) :
@makoru-hikage
makoru-hikage / SwitchCaseVarTypeTest.php
Last active February 18, 2017 01:45
The correct use of switch case to test a variable's type. Correction for NullIsArray.php
<?php
$dummy= [
'Alpha' => null,
'Beta' => null,
'Charlie' => null
];
switch (gettype($dummy['Alpha'])) {
case 'array' :
echo 'Alpha, according to this switch statement, is Array';