This file contains 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 perl | |
use Scalar::Util qw(weaken refaddr); | |
my $c = Test->load("child"); | |
my $test; | |
{ | |
my $p = Test->load("parent"); | |
$test = $p; | |
weaken($test); | |
This file contains 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
(defmethod dbm-put ((db kc-dbm) key value &key mode (overwrite-if-exists T)) | |
(if overwrite-if-exists | |
(kcdbset (ptr-of db) | |
(convert-to-foreign key :string) (convert-to-foreign (length key) :unsigned-long) | |
(convert-to-foreign value :string) (convert-to-foreign (length value) :unsigned-long)) | |
(kcdbadd (ptr-of db) | |
(convert-to-foreign key :string) (convert-to-foreign (length key) :unsigned-long) | |
(convert-to-foreign value :string) (convert-to-foreign (length value) :unsigned-long))) |
This file contains 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
(defgeneric put-method-for (mode) | |
(:method ((mode (eql :replace))) #'kcdbset) | |
(:method ((mode (eql :keep))) #'kcdbadd) | |
(:method ((mode (eql :concat))) #'kcdbappend)) | |
(defun put (key value &key (mode :replace)) | |
(funcall (put-method-for mode) key value)) | |
;; definitions of methods for kcdbset, kcdbadd, and kcdbappend define methods | |
;; that store key/value pairs with different behaviors based on whether |
This file contains 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
(defclass kc-dbm () | |
() | |
(:documentation "A KC database.")) | |
(defclass kc-bdb (kc-dbm) | |
() | |
(:documentation "A KC B+ tree database.")) | |
(defclass kc-hdb (kc-dbm) | |
() |
This file contains 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
import java.util.*; | |
public class ChainDemo { | |
static interface Command { | |
void execute(Map<String, Object> ctx); | |
} | |
static class Chain { | |
private List<Command> commands = new ArrayList<Command>(); |
This file contains 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
-- Product function | |
product' [] = 1 | |
product' (x:xs) = | |
do putStrLn "testing" | |
return ((product' xs) * x) | |
-- quicksort function using where clause | |
qsort [] = [] | |
qsort (x:xs) = qsort smaller ++ [x] ++ qsort larger | |
where |
This file contains 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
class CreateAssets < ActiveRecord::Migration | |
def self.up | |
create_table :assets do |t| | |
t.date :manufacturing_date | |
..... |
This file contains 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 'chronic' | |
class DateValidator < ActiveModel::EachValidator | |
def validate_each(record, attribute, value) | |
valid = true | |
begin | |
y = Chronic.parse(value) | |
valid = false unless y | |
rescue |
This file contains 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
class RawEachValidator < ActiveModel::EachValidator | |
def validate(record) | |
attributes.each do |attribute| | |
raw_value = record.send("#{attribute}_before_type_cast") || record.read_attribute_for_validation(attribute) | |
self.validate_each(record, attribute, raw_value) | |
end | |
end | |
end |
This file contains 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 'chronic' | |
class DateValidator < ActiveModel::EachValidator | |
def validate_each(record, attribute, value) | |
valid = true | |
begin | |
y = Chronic.parse(value) | |
valid = false unless y | |
rescue |
OlderNewer