Skip to content

Instantly share code, notes, and snippets.

Kaia Leahy tenebrousedge

View GitHub Profile
@tenebrousedge
tenebrousedge / protein_translation.cr
Created Feb 2, 2020
Iterable Example -- Exercism "Protein Translation" solution
View protein_translation.cr
require "string_scanner"
module ProteinTranslation
class Polypeptide
alias Codon = String
include Iterator(Codon)
CODONS = {
/AUG/ => "Methionine",
/UUU|UUC/ => "Phenylalanine",
@tenebrousedge
tenebrousedge / forth.cr
Created Oct 13, 2019
Forth Interpreter written in Crystal-lang
View forth.cr
module Forth
alias Stack = Array(Int32)
alias Operation = Proc(Stack, Stack)
end
module Forth
struct Statement
getter text : String
getter?(new_word : Bool) { text.starts_with?(":") }
forward_missing_to @text
@tenebrousedge
tenebrousedge / quads.rb
Created May 23, 2017
HackerRank - Beautiful Quadruples
View quads.rb
#!/bin/ruby
A = gets.strip.split(' ').map(&:to_i)
Array.class_eval do
def valid?
(0..3).all? {|i| 1 <= self[i] && self[i] <= A[i] }
end
end
@tenebrousedge
tenebrousedge / substring.rb
Created May 23, 2017
HackerRank Challenge - Special Substrings
View substring.rb
#!/bin/ruby
require 'pry-byebug'
require 'set'
# require 'trie'
# So this code works correctly, but it's horribly slow. Probably it needs a trie-based approach.
SPECIAL = {}
PREFIX = {}
View hangman.rb
#!/usr/bin/env ruby
def hangman
tries_left = 12
# only select words less than ten letters long
lines = File.readlines('/usr/share/dict/words').select { |e| e.length < 10 }
# grab a random word
word = lines[rand(lines.length)].chomp.chars
guessed = []
while tries_left > 0
@tenebrousedge
tenebrousedge / Category.php
Created Oct 19, 2013
Example of a Hierarchical Model Relation in CakePHP This is what you usually need instead of Tree Behavior
View Category.php
<?php
class Category extends Model {
public $name = 'Category';
public $hasMany = array('Children' => array(
'className' => 'Category',
'foreignKey' => 'parent_id'
));
@tenebrousedge
tenebrousedge / MultiMysql.php
Created Apr 13, 2013
CakePHP Mysql Database driver extension for inserting lots of rows at once. Depending on how your data is being generated, this is liable to be extremely memory-inefficient.
View MultiMysql.php
//Store it in App/Model/Datasource/Database/MultiMysql.php
<?php
App::uses('Mysql', 'Model/Datasource/Database');
class MultiMysql extends Mysql {
public function insertMulti($table, $fields, $values) {
$table = $this->fullTableName($table);
$holder = implode(',', array_fill(0, count($fields), '?'));
$fields = implode(', ', array_map(array(&$this, 'name'), $fields));
@tenebrousedge
tenebrousedge / example.php
Created Dec 5, 2012
Apis Configure information
View example.php
//database.php
var $apis = array(
'datasource' => 'Apis.ApisSource',
'login' => '',
'password' =>'',
'authMethod' => 'OAuthV2'
);
//some other config file
$config['Apis']['Cloudprint']['oauth'] = array(
You can’t perform that action at this time.