Skip to content

Instantly share code, notes, and snippets.

View khanghoang's full-sized avatar
😬

Khang Hoang khanghoang

😬
  • Dropbox
  • San Jose, CA
  • 04:32 (UTC -07:00)
  • X @khanght
View GitHub Profile
!!! 5
%html
%head
%title= "Your Website"
%meta{ :content => "", :name => "description" }
%meta{ :content => "", :name => "author" }
%meta{ :content => "3 days", :name => "revisit-after" }
%link{ :href => "http://creativecommons.org/licenses/by/3.0/", :rel => "license", :title => "Creative Commons Attribution 3.0 Unported License" }
%link{ :href => "/feed", :rel => "alternate", :title => "Atom", :type => "application/atom+xml" }
%link{ :href => "/css/screen.css", :media => "screen", :rel => "stylesheet" }
/ A simplistic way of loading and rendering HAML partials (header.haml, footer.haml, nav.haml... you name it) without Rails
/ Useful when using tools like LiveReload http://livereload.com/
/ but don't want to configure a web server just to use PHP include/require constructs (discussion http://help.livereload.com/discussions/questions/22-haml-partials)
/ It could be improved/simplified using a helper http://stackoverflow.com/questions/5436769/partial-haml-templating-in-ruby-without-rails/5436973#5436973
/ Check out the Jade version https://gist.github.com/2593727
%html
%body
%header
= Haml::Engine.new(File.read('/path/to/your/partial.haml')).render
@implementation KZPropertyMapper (MyAppBoxing)
+ (NSDate *)boxValueAsDateSince1970:(id)value __used
{
if (value == nil) {
return nil;
}
AssertTrueOrReturnNil([value isKindOfClass:NSNumber.class]);
return [NSDate dateWithTimeIntervalSince1970:[value floatValue]];
}
@khanghoang
khanghoang / Sublime text go 5 lines in Vim mode.md
Last active August 29, 2015 14:01
Sublime text jumps 5 lines in Vim mode

Sublime Text 2\Packages\User\move_by_lines.py:

import sublime, sublime_plugin

class MoveByLinesCommand(sublime_plugin.TextCommand):
    def run(self, edit, extend = False, forward = True):
        # self.view.run_command("move_to", {"to": "hardbol", "extend": extend}) # to mimic TextPad's behaviour
        # pt = self.view.sel()[0].b
 if forward:
// Taken from the commercial iOS PDF framework http://pspdfkit.com.
// Copyright (c) 2013 Peter Steinberger. All rights reserved.
// Licensed under MIT (http://opensource.org/licenses/MIT)
//
// You should only use this in debug builds. It doesn't use private API, but I wouldn't ship it.
#import <objc/runtime.h>
#import <objc/message.h>
// Compile-time selector checks.

List of Block Declaration Syntaxes

Throughout, let

  • return_type be the type of object/primitive/etc. you'd like to return (commonly void)
  • blockName be the variable name of the block you're creating
  • var_type be the type object/primitive/etc. you'd like to pass as an argument (leave blank for no parameters)
  • varName be the variable name of the given parameter And remember that you can create as many parameters as you'd like.

Blocks as Variables

Possibly the most common for of declaration.

  1. Download [jshint.vim][jshint]

  2. Put it in ~/.vim/plugin/jshint.vim

  3. Edit your local vimrc file (I'm on macvim with janus, so it's at ~/.gvimrc.local) and add:

    au BufWritePost *.js :JSHint
  4. Read the [vim docs][vim] and particularly [auto commands][auto] I'm a newb and the neckbeards are probably laughing at me for even posting this.

@khanghoang
khanghoang / Sails-request-validation
Created December 4, 2014 16:16
Sails request validation
In SailsJS, I would like to validate request parameters using the same mechanism as when models are validated when model actions are performed.
So when you define a model you use the "attributes" option to specify your parameter properties, and they are then used for validation.
But what if you'd like to validate say a login form or email form on the server side, thus there is no model needed for it and you'd just like to validate the parameters?
So I'd like to be able to do something like this:
//login validation
req.validate({