Skip to content

Instantly share code, notes, and snippets.

View daifu's full-sized avatar

Daifu Richard Ye daifu

View GitHub Profile
@daifu
daifu / juggernaut_heroku.md
Created July 8, 2012 19:43 — forked from maccman/juggernaut_heroku.md
Juggernaut on Heroku

Clone repo:

git clone git://github.com/maccman/juggernaut.git
cd juggernaut

Create Heroku app:

heroku create myapp --stack cedar
heroku addons:add redistogo:nano

git push heroku master

@daifu
daifu / orm.js
Created July 8, 2012 19:45 — forked from maccman/orm.js
orm.js
if (typeof Object.create !== "function")
Object.create = function(o) {
function F() {}
F.prototype = o;
return new F();
};
var Model = {
init: function(){ },
@daifu
daifu / test.html
Created July 13, 2012 16:18
Javascript Web Application BindingModelsUser
<script id="userTmpl" type="text/x-jquery-tmpl">
<li>${name}</li>
</script>
<ul id="users"> </ul>
@daifu
daifu / _snippet.html
Created July 16, 2012 23:46 — forked from elijahmanor/_snippet.html
Differences Between jQuery .bind() vs .live() vs .delegate() vs .on() Methods
<ul id="members" data-role="listview" data-filter="true">
<!-- ... more list items ... -->
<li>
<a href="detail.html?id=10">
<h3>John Resig</h3>
<p><strong>jQuery Core Lead</strong></p>
<p>Boston, United States</p>
</a>
</li>
<!-- ... more list items ... -->
@daifu
daifu / LICENSE.txt
Created July 24, 2012 02:06 — forked from eliperelman/LICENSE.txt
String.prototype.trim polyfill for 140byt.es
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Eli Perelman http://eliperelman.com
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@daifu
daifu / hasOwnProperty.js
Created July 24, 2012 02:07
javascript hasOwnProperty for object
if ( !Object.prototype.hasOwnProperty ) {
Object.prototype.hasOwnProperty = function(prop) {
var proto = obj.__proto__ || obj.constructor.prototype;
return (prop in this) && (!(prop in proto) || proto[prop] !== this[prop]);
};
}
var cached = {};
function factorial(num) {
if (num === 1)
return 1;
else if (cached[num] !== undefined) {
return cached[num];
}
else {
return num * factorial(num - 1);
}
@daifu
daifu / StampVendingMachine.java
Last active December 11, 2015 11:18
Find the minmum stamps based on the request.
/*
Stamp Vending Machine
It is for dispensing the minimum stamps based on the available stamps in the machine.
How to use:
1. Compile: javac StampVendingMachine.java
2. Run: java StampVendingMachine
3. > 32
output: 2
ctrl + c to terminate
@daifu
daifu / isPalindrome.java
Created January 26, 2013 08:40
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example, "A man, a plan, a canal: Panama" is a palindrome. "race a car" is not a palindrome.
public class Solution {
public boolean isPalindrome(String s) {
// Start typing your Java solution below
// DO NOT write main() function
int size = s.length();
String lcs = s.toLowerCase();
int left = 0;
int right = size - 1;
while(right >= left) {
if(lcs.charAt(right) == lcs.charAt(left)) {
@daifu
daifu / minimumTotal.java
Last active February 21, 2023 18:20
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.
/*
For example, given the following triangle
[
[2],
[3,4],
[6,5,7],
[4,1,8,3]
]
The minimum path sum from top to bottom is 11 (i.e., 2 + 3 + 5 + 1 = 11).