Skip to content

Instantly share code, notes, and snippets.

@hguochen
hguochen / Bootstrap 101 Template
Created December 26, 2013 06:09
Basic Bootstrap HTML Template
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap 101 Template</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
@hguochen
hguochen / Python Class
Created December 26, 2013 06:23
Python class template
class PythonClass:
def __init__(self):
"""Constructor"""
def method(self):
return "Hello World!"
anInstance = PythonClass()
@hguochen
hguochen / HTML5 Bootstrap Template
Last active January 2, 2016 06:59
HTML 5 Bootstrap Template
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
# Outputs the reading time
# Read this in “about 4 minutes”
# Put into your _plugins dir in your Jekyll site
# Usage: Read this in about {{ page.content | reading_time }}
module ReadingTimeFilter
def reading_time( input )
words_per_minute = 180
@hguochen
hguochen / Jekyll reading time plugin
Created January 7, 2014 06:36
Jekyll plugin - word_count minute read
{% capture words %}
{{ post.content | number_of_words | divided_by:180 }}
{% endcapture %}
{% assign word_count = words | times: 1 %}
{% if word_count != 0 %}
<span>{{ word_count }} minute read</span>
{% else %}
<span>less than {{ word_count | plus: 1 }} minute read</span>
{% endif %}
@hguochen
hguochen / styles.css
Created January 31, 2014 13:29
CSS Style Architecture
/******* BASE *******/
/* Section for normalize, layout, typography styles */
/******* END BASE *******/
/******* COMPONENTS *******/
/* Section for alerts, buttons, forms, list, nav, tables styles */
/******* END COMPONENTS *******/
/******* MODULES *******/
/* Section for aside, footer, header styles */
/******* END MODULES *******/
@hguochen
hguochen / Django form logic
Last active August 29, 2015 13:56
Django form logic
def contact(request):
if request.method == 'POST': # If the form has been submitted...
form = ContactForm(request.POST) # A form bound to the POST data
if form.is_valid(): # All validation rules pass
# Process the data in form.cleaned_data
# ...
return HttpResponseRedirect('/thanks/') # Redirect after POST
else:
form = ContactForm() # An unbound form
@hguochen
hguochen / Django formset with AJAX
Last active January 15, 2018 08:23
Django formset with ajax
<h3>My Services</h3>
{{ serviceFormset.management_form }}
{% for form in serviceFormset.forms %}
<div class='table'>
<table class='no_error'>
{{ form.as_table }}
</table>
</div>
{% endfor %}
<input type="button" value="Add More" id="add_more">
import models
class PersonManager(models.Manager):
@models.querymethod
def male(query):
return query.filter(gender='m')
@models.querymethod
-module(merge_sort).
-export([merge_sort/1]).
% bottom-up merge sort
merge_sort([]) ->
[];
merge_sort(L) ->
iterate([[X] || X <- L]).
iterate([Xs]) ->