Skip to content

Instantly share code, notes, and snippets.

View coderek's full-sized avatar
👽

Derek Zeng coderek

👽
View GitHub Profile
class Solution:
# @param board, a 2D array
# Capture all regions by modifying the input board in-place.
# Do not return any value.
def solve(self, b):
if len(b) == 0:
return []
board = [list(x) for x in b]
allEntrances = self.findAllEntrances(board)
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC0Gws3wF4N6Yzm6nAXg4ub7InIpYqUm4j/1N1HOIcxfblr2kS9NZ8dHUdZMVhCjHvkrEpExH9OdFjTVzbfYtMNvX8XOCOglosdTrGXwJrO3vg5Emz9ntu6DXgA26SxMi7dQnKjZKPxi6e7+Tx82BC62pAmr/nrVQTOM6fa+682KwEmk4ONXXcc8WObiC3Lk8AEbDS9WTB+ejcKTwRH4lMX5OFyZ1aEux8PL35Iu4hIU7fwSn8zspnuCLyEyhLElPAg3e7k2wxd/9rySPPKntYzZ4YnhUNC+E6JTEhhRlbXpWL8O54xph+bs8GG5kjyGDzZK3vUU7ue/c+Fh8Kr4nAZ [email protected]
_, seq = STDIN.read.scan(/(\n>THREE[^\n]*\n)([^>]*)\n/).flatten
p _, seq
# you can run this file as `ruby scan.rb < test`, where test contains the text to match
# it matches something like this, note the new line at beginning
#
String.prototype.hashCode = function() {
var hash = 0, i, chr, len;
if (this.length == 0) return hash;
for (i = 0, len = this.length; i < len; i++) {
chr = this.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0; // Convert to 32bit integer
}
return hash;
};
@coderek
coderek / mraid.html
Created July 31, 2014 01:12
mraid sample
<script src="mraid.js"></script>
<!--april 1--><head>
<meta name="viewport" content="width=device-width, user-scalable=no">
</head>
<script>if (!window.mraid) { document.write('<script src="http://cdn.engagefront.com/mraid-basic.js"><\/script>'); }</script>
<script>
!function(a){a.setTimeout(function(){var b=a.document,c="engagefront",d="/EngageMetrics/v1/",e="script",f=b.getElementsByTagName(e)[0],g=b.createElement(e),h=b.location,i=h.protocol;g.src="https:"===i?"https://"+c+"-a.akamaihd.net"+d:"http://cdn."+c+".com"+d,f.parentNode.insertBefore(g,f)},0)}(window);
</script>
<style>
@coderek
coderek / MiddlewarePattern.js
Created July 25, 2014 02:02 — forked from tastywheat/taskQueue.js
simple demonstration. this pattern is used by connect to stack middlewares
//process n number of async functions in order. used when promises aren't viable e.g. cross file or service calls.
var MiddlewareService = function(){
var stack = [],
isProcessingStack = false,
commonState = { task: 0 };
function push(fn){
stack.push(fn);
@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
@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 / 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)->

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.