Skip to content

Instantly share code, notes, and snippets.

View hoandang's full-sized avatar
👟
Roaming

Hoàn Đặng hoandang

👟
Roaming
  • Sydney, Australia
View GitHub Profile
@hoandang
hoandang / uninstall_homebrew.sh
Created August 17, 2012 07:49 — forked from mxcl/uninstall_homebrew.sh
Uninstall Homebrew
#!/bin/sh
# Just copy and paste the lines below (all at once, it won't work line by line!)
# MAKE SURE YOU ARE HAPPY WITH WHAT IT DOES FIRST! THERE IS NO WARRANTY!
function abort {
echo "$1"
exit 1
}
set -e
@hoandang
hoandang / email_regex
Created January 20, 2013 06:34
Validate email address
/\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
@hoandang
hoandang / ruby: user.rb
Created January 20, 2013 06:53
A typical user model in rails
# Gem 'bcrypt-ruby'
# Generate User model with password_digest field
class User < ActiveRecord::Base
has_secure_password
attr_accessible :email, :name, :password, :password_confirmation
before_save { self.email.downcase! }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true, uniqueness: {case_sensitive: false},
length: {maximum: 50}, format: { with: VALID_EMAIL_REGEX }
validates :name, presence: true, uniqueness: true
@hoandang
hoandang / mysql: next_auto_increment_id.sql
Created February 1, 2013 11:06
Return the next auto increment id in Mysql
SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='table_name'
@hoandang
hoandang / java: HasMap-Iterator.java
Last active December 13, 2015 19:09
Three ways to iterate a HashMap in Java
Map<String, Object> map = ...;
//If only interested in the keys, you can iterate through the keySet() of the map:
for (String key : map.keySet()) {
// ...
}
//If only need the values, use values():
for (Object value : map.values()) {
// ...
@hoandang
hoandang / javascript:custom_dialog.js
Created February 16, 2013 04:20
Create a custom dialog (there are two buttons OK and Cancel leverage twitter bootstrap)
document.addEventListener('DOMContentLoaded', function() {
document.getElementById("click").addEventListener("click", function(e){
var msg = 'Are you sure you want to delete action?';
customConfirm(msg);
//customConfirm(msg, function(){alert('id deleted')},function(){alert('user pressed Cancel button')});
e.preventDefault();
});
});
function customConfirm(message, true_func, false_func){
@hoandang
hoandang / jquery: combine_string_with_this.js
Created February 17, 2013 11:27
Combine selector with this in Jquery
$("selector", this)
@hoandang
hoandang / css: valign_table_row.css
Created February 17, 2013 11:28
Align middle table row
table tbody tr td
{
vertical-align: middle;
}
@hoandang
hoandang / java: JPAGetIdPersistedObj.java
Created February 23, 2013 15:48
Get Id from the persisted object JPA
import javax.persistence.GenerationType;
import javax.persistence.GeneratedValue;
@GeneratedValue(strategy=GenerationType.IDENTITY)
@hoandang
hoandang / struts2: pom.xml
Created February 25, 2013 15:50
pom.xml Struts2 REST + OpenJPA + Jetty Server
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.hoan</groupId>
<artifactId>Shop</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>Shop Maven Webapp</name>
<url>http://maven.apache.org</url>