This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "string_scanner" | |
module ProteinTranslation | |
class Polypeptide | |
alias Codon = String | |
include Iterator(Codon) | |
CODONS = { | |
/AUG/ => "Methionine", | |
/UUU|UUC/ => "Phenylalanine", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 = {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Category extends Model { | |
public $name = 'Category'; | |
public $hasMany = array('Children' => array( | |
'className' => 'Category', | |
'foreignKey' => 'parent_id' | |
)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//database.php | |
var $apis = array( | |
'datasource' => 'Apis.ApisSource', | |
'login' => '', | |
'password' =>'', | |
'authMethod' => 'OAuthV2' | |
); | |
//some other config file | |
$config['Apis']['Cloudprint']['oauth'] = array( |