Skip to content

Instantly share code, notes, and snippets.

Ryan Rampersad ryanmr

View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am ryanmr on github.
  • I am ryanmr (https://keybase.io/ryanmr) on keybase.
  • I have a public key ASCn_b5Lvo--MjFb3wtRVQ3lbpaXc__Ivkw35xm3bLVQ4wo

To claim this, I am signing this object:

View chapters.py
import sys
from mutagen.id3 import ID3, CTOC, CHAP, TIT2, CTOCFlags
from mutagen import File
def main():
print "hi"
# target_file = "ns61-ian.mp3"
target_file = "pk43.mp3"
print_tags(target_file)
View Cards.scala
def split():(Deck, Deck) = {
val s = size()
val h = s / 2
val d1 = new Deck()
val d2 = new Deck()
for (i <- 1 to s) {
getCard() match {
case Some(card) => {
if (i < h) {
d1.addCard(card)
View evan-you-effect.js
document.addEventListener('touchmove', function (e) {
e.preventDefault()
})
var c = document.getElementsByTagName('canvas')[0],
x = c.getContext('2d'),
pr = window.devicePixelRatio || 1,
w = window.innerWidth,
h = window.innerHeight,
f = 90,
q,
View FeedsController.php
<?php
namespace App\Http\Controllers\Frontend;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use \Carbon\Carbon;
View query.txt
array:2 [▼
0 => array:3 [▼
"query" => "select * from `episodes` where (`hidden` = ? and `unlisted` = ? and `state` = ? and exists (select * from `series` where `episodes`.`series_id` = `series`.`id` and `slug` = ?) or exists (select * from `episodes_relations` as `self_a536d4a0691c58055cceecc94fd32e35` where `self_a536d4a0691c58055cceecc94fd32e35`.`episode_id` = `episodes`.`id` and `type` = ? and exists (select * from `series` where `episodes`.`series_id` = `series`.`id` and `slug` = ?) and `episodes`.`deleted_at` is null)) and `episodes`.`deleted_at` is null order by `published_at` desc, `created_at` desc"
"bindings" => array:6 [▼
0 => false
1 => false
2 => "published"
3 => "pk"
4 => "parent"
5 => "pk"
View episode-series-special.php
/*
Schema:
episodes (id, series_id, ...etc)
episode_relations (id, episode_id, episode_related_id)
series (id, slug, ...etc)
Some episodes are related to each other by the episodes_relations pivot table.
Goal:
get all of the episodes of the `specified-slug` series, and all of the episodes of `special-slug` that have a related parent episode that is in the `specified-slug` series
View episode_feed.php
$episodes = App\Episode::with(['related'])
->visible()
->recent()
->withSlug('pk')
->orWhere(function($query){
$query->withSlug('tf')->
whereHas('related', function($query){
$query->where('type', '=', 'parent')
->whereHas('related.series', function($query){
$query->where('slug', '=', 'pk');
View EpisodeWasCreated-ApplyEpisodeDefaults.md

A short story about a six month bug

I've been tinkering with Laravel for at least six months ago with a realistic goal of finishing a custom Nexus CMS before I expire of old age. A few months ago, I came around to adding the functionality for Episode events, specifically, applying default hosts and album art to an episode of none were specified when it was initally created -- short of a shortcut feature.

I will be addressing some classes (an Event, and a Listener, and below, a tiny fraction of the Episode model) from this gist published earlier. There might be some minor changes between this and production code, but it suffices.

    public function store(Request $request)
    {
View ApplyEpisodeDefaults.php
<?php
namespace App\Listeners;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
// use Log;
use App\Episode;
You can’t perform that action at this time.