Skip to content

Instantly share code, notes, and snippets.

View isterin's full-sized avatar

Ilya Sterin isterin

View GitHub Profile
#!/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);
(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)))
(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
(defclass kc-dbm ()
()
(:documentation "A KC database."))
(defclass kc-bdb (kc-dbm)
()
(:documentation "A KC B+ tree database."))
(defclass kc-hdb (kc-dbm)
()
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>();
-- 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
class CreateAssets < ActiveRecord::Migration
def self.up
create_table :assets do |t|
t.date :manufacturing_date
.....
require 'chronic'
class DateValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
valid = true
begin
y = Chronic.parse(value)
valid = false unless y
rescue
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
require 'chronic'
class DateValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
valid = true
begin
y = Chronic.parse(value)
valid = false unless y
rescue