Skip to content

Instantly share code, notes, and snippets.

View coderek's full-sized avatar
👽

Derek Zeng coderek

👽
View GitHub Profile
<html>
<head>
<title>Text Search</title>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js"></script>
<link rel="stylesheet" type="text/css" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
</head>
<body>
@coderek
coderek / game.css
Created February 13, 2014 22:22
Game of Life JavaScript Implementation
.grid {
}
.cell {
background: black;
float: left;
box-shadow: inset 0 0 1px 0 white;
}
.cell.live {
background: seagreen;
}
<!DOCTYPE html>
<html>
<head></head>
<body>
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.0/backbone-min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="main.js"></script>
</body>
</html>

What Backbone offers

Backbone provides us with a foundation to build the application. What it offers include:

  1. models and collections
    They encapsulate the business logic of the app and are in charge of the communication with the server.

  2. views
    They can be regarded as the controller in MVC architecture which manages display, user interaction and change of model's state. This is where data binding is happening between view and model.

  3. events

Web Performance

DOM

  1. use events delegation, instead of direct binding e.g. a table with 1000 rows, $("table").on("click", "tr", fn);

  2. reduce reflow when changing DOM node 1. hide it first, then change, then display

  3. clone it then change, then replace

/**
* Copyright 2012 Akseli Palén.
* Created 2012-07-15.
* Licensed under the MIT license.
*
* <license>
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,

Jonathan Ive

And just as Steve loved ideas, and loved making stuff, he treated the process of creativity with a rare and a wonderful reverence. You see, I think he better than anyone understood that while ideas ultimately can be so powerful, they begin as fragile, barely formed thoughts, so easily missed, so easily compromised, so easily just squished.

@coderek
coderek / calculator.coffee
Last active December 16, 2022 22:08
calculator string parser
# Expr ::= Term ('+' Term | '-' Term)*
# Term ::= Factor ('*' Factor | '/' Factor)*
# Factor ::= ['-'] (Number | '(' Expr ')')
# Number ::= Digit+
log = console.log.bind(console)
tokenize = (str)->
@coderek
coderek / top_engineer.md
Created June 8, 2014 13:32
How do top programmers work?

from, Rose Wiegley, Owner of Parkside Software, LLC http://www.quora.com/Software-Engineering/How-do-top-programmers-work

First, they do NOT do a lot of things:

  • They do NOT reinvent a wheel. There's lots of new stuff to do and no time to waste redoing what others have done well. If there are libraries, gems, code snippets, examples, etc they will happily use the tools available and spend their time on the new stuff.
  • They do NOT write code for features they do not need. In other words they keep it simple. When writing something it's common to think "Well some day we may want to do X so I'll go ahead and add Y and Z to this feature in case we need to support it ..." If a good programmer doesn't need something now they do not add it. You never know what you will really need in the future. Stuff changes and writing stuff takes time now and support time later.

They also do a lot of things:

  • They have a mental map/design of the project in their head. Before a drop of code hits the computer a top programmer
@coderek
coderek / sort-views.coffee
Created July 25, 2014 01:55
add view sorting to marionette collection view version < 2.0
d = [{a: 34}, {a: 32}, {a: 7}]
Item = Marionette.ItemView.extend
template: _.template "<%= a %>"
c = new Backbone.Collection(d)
CV = Marionette.CollectionView.extend