Skip to content

Instantly share code, notes, and snippets.

View kieraneglin's full-sized avatar
😎

Kieran kieraneglin

😎
  • British Columbia, Canada
View GitHub Profile
@kieraneglin
kieraneglin / router_syntax.php
Last active February 20, 2018 20:18
PHP Router Syntax Example
<?php
$router = new Router();
// Traditional routes
$router->route('POST', '/posts', 'posts#create'); // This looks for PostsController with a method named `create`
$router->route('GET', '/posts', 'posts#index');
$router->route('GET', '/posts/{:id}', 'posts#show'); // This will pass a param with a key of `id` and a value of whatever is in the URL
$router->route('PATCH', '/posts/{:id}', 'posts#update');
$router->route('GET', '/me', 'users#show'); // It's worth noting that the lack of a trailing slash is important. `/me/` will not match `/me` and vice-versa
<?php
class PostsController {
public function show($params) { // Note that you have to accept an argument here to get param information
$post = Post.find($params['id']); // This param comes from the identifier we set in the route. Note that the `Post.find` is a fictional method
include 'views/posts/show.php';
}
public function index($params) {
<?php
class Router {
private $routes = [];
public function get($pattern, $controller_method) {
$this->route('get', $pattern, $controller_method);
}
public function post($pattern, $controller_method) {
<?php
include 'router.php';
foreach (glob('controllers'.DIRECTORY_SEPARATOR.'*_controller.php') as $filename) {
// Include all php files that end with `_controller.php` in the `controllers` directory
// Note that this does not recursively include files
include $filename;
}
$router = new Router();
extern crate rand;
use rand::Rng;
use std::time::Instant;
fn merge(l1: &Vec<i32>, s: usize, m: usize, e: usize, l2: &mut Vec<i32>) {
let mut ptr1 = s;
let mut ptr2 = m;
for i in s..e {
if (ptr1 < m) && (ptr2 >= e || l1[ptr1] <= l1[ptr2]) {
@kieraneglin
kieraneglin / islander_problem.ex
Last active April 5, 2019 21:36
B99 islander problem in Elixir
defmodule IslanderProblem do
@total_islanders 12
@group_size 4
# Weighs islanders 3 times, finding which islander is the outlier
#
# Returns an integer representing the weight of the outlier
def start(islanders) when is_list(islanders) do
if length(islanders) != @total_islanders do
raise ArgumentError, "There must be exactly #{@total_islanders} islanders"
@kieraneglin
kieraneglin / LICENSE.txt
Last active March 30, 2021 15:06
Elixir module for interfacing with DRV8825 via Nerves
_My_ portion of this code is licensed under the very permissive DWYW License (https://github.com/thornjad/DWYW).
If you are unable to recognize DWYW as a valid license, _my_ portion of this code is then licensed under MIT.
TL;DR: I don't care what you do with this, just don't get mad at me if a stepper breaks itself/something else when using this module. Liability = no. When I say "my code", I mean everything that isn't Circuits.GPIO.
The Circuits.GPIO library is licenced as such: https://github.com/elixir-circuits/circuits_gpio/blob/main/LICENSE
@kieraneglin
kieraneglin / lyrics.csv
Created May 16, 2021 23:00
Lyrics training dataset
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
lyrics
"Fuck this world
I'm so sick of your temporary bullshit
I want the light at the end
And I know how to get it
If it takes my life then I will gladly die
Open your mind
Realise we are slaves
Forced Draconian mind-state
Open your eyes
@kieraneglin
kieraneglin / example_live_test.exs
Last active November 11, 2024 19:15
Pow sessions with LiveView (including tests)
defmodule MyAppWeb.ExampleLiveTest do
# `LiveviewCase` is a custom test helper - pretty much the same as ConnCase but with
# import Phoenix.LiveViewTest
# import MyApp.Support.AuthHelpers
use MyAppWeb.LiveviewCase, async: false
import MyApp.Factory
alias MyApp.Repo
alias MyAppWeb.ExampleLive
@kieraneglin
kieraneglin / onelogin_instructions.md
Last active June 28, 2023 16:18
OneLogin SAML setup

1. Add SAML app in OneLogin

  1. Log in to the OneLogin Dashboard, and click Apps > Add Apps
  2. Search for SAML, and select SAML Test Connector (IdP)
  3. Set the Display Name to Percent Pledge
  4. Set the Rectangular Icon to our logo which you can find here
  5. Click Save

Screenshot 2023-04-26 at 8 55 38 AM