Python Simple Dates

Feb15

Simple Dates for Python

simpledates is a library that was born out of the frustration of never being able to remember the Python datetime api. It’s goal is to simplify working with date / datetime and to provide a simple API that’s easy to remember.

Getting Started

Here’s a simple example of the API.

from simpledates import SimpleDate
from datetime import datetime

sd = SimpleDate('Aug 2nd 2012')
sd2 = SimpleDate(datetime.now())

print sd == sd2
print sd2 - sd
print sd2.past(days=15)
print sd2.future(months=2)
print sd2.is_it().weekday()
print sd2.is_it().monday()
print sd2.past(days=27).is_it().first_of_month()
print sd2.past(weeks=12).ago()

Get the source on Github

 

YUI3 port of the jQuery Validation Plugin

Jan26

A YUI3 widget that’s modeled after the famousjquery-validation plugin

How To

new Y.YUI3Validation({
    formName: "#myForm",
    errorClass: 'my-error-class', #optional
    handleSubmit: mySubmitFun, #optional
    debug: false #optional
}).render();

Add one of these classes to your html form fields.

  • required
  • email
  • url
  • date
  • dateISO
  • number
  • digits

Optional Params

  • errorClass – default: ‘nv_error’ (the class that gets applied to all error messages)
  • handleSubmit – default: null (a function that handles the form submit action)
  • debug – default: false (adds some console logs)

Get the source on Github

 

YUI3 Sugar Methods

Jan01

YUI3 doesn’t ship with a lot sugar methods like some other frameworks. At my day job we use YUI3, so I decided to write some sugar methods to help me save some time.

How To

Adding it to your application

    YUI({
        modules: {
            'yui3-sugar': {
                    fullpath: 'yui3-sugar.js',
                    requires: [ 'node', 'transition' ]
            }
        }
    }).use('node', 'yui3-sugar', function(Y) {
        /* ... */
    });

Using the methods


Y.one('#my-node').slideUp(0.7, callback);
Y.one('#my-node').slideDown(0.5, callback);
Y.one('#my-node').slideToggle(0.2, callback);
Y.one('#my-node').fadeToggle(0.7);
Y.one('#my-node').fadeTo(0.7, 0.5, callback);
Y.one('#my-node').fadeToColor(0.7, '#FF0000', callback);

function callback() {
   Y.log('callback hit');
}

List of Methods

-  toggle()
-  slideUp(int duration, func callback)
-  slideDown(int duration, func callback)
-  slideToggle(int duration, func callback)
-  fadeToggle(int duration) *not totally working correctly yet
-  fadeTo(int duration, string opacity, func callback)
-  fadeToColor(int duration, string color, callback)

Get the source on Github

 

Sidebar