Skip to content

Instantly share code, notes, and snippets.

View duongphuhiep's full-sized avatar

DUONG Phu-Hiep duongphuhiep

  • lemonway.fr
  • Paris, France
View GitHub Profile
@duongphuhiep
duongphuhiep / PerfWatcher.java
Created September 21, 2014 20:53
Performance log ellapsed time
package dh.tool.common;
import com.google.common.base.Stopwatch;
import com.google.common.base.Strings;
import org.slf4j.Logger;
import java.security.InvalidParameterException;
import java.util.concurrent.TimeUnit;
/**
@duongphuhiep
duongphuhiep / MockHttpRequest.html
Last active August 27, 2015 21:32
Simulate responses from external ajax RESTful services by mocking XMLHttpRequest. http://stackoverflow.com/questions/32254959/test-front-end-application-without-back-end
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Try MockHttpRequest</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<!--you must to download this script to your local and replace it here-->
<script src="https://raw.githubusercontent.com/philikon/MockHttpRequest/master/lib/mock.js"></script>
</head>
@duongphuhiep
duongphuhiep / fake-backend.js
Created August 28, 2015 20:26
Use sinon.js to create a fake RESTful Server, and simulate ajax response for some specifics XMLHttpRequest
var sinon = require("sinon");
var utils = require('../lib/utils');
var xhr = sinon.useFakeXMLHttpRequest(); //in fact xhr === sinon.FakeXMLHttpRequest
xhr.useFilters = true;
xhr.addFilter(function(method, url, async, username, password) {
console.log('check filter on', method, url, async, username, password);
var parsedUrl= utils.parseUri(url);
@duongphuhiep
duongphuhiep / tabs.html
Last active September 16, 2015 22:52
tabs panel in pure CSS thanks to http://csscience.com/css3-tabs/
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<style type="text/css" media="screen">
* {
box-sizing: border-box;
}
@duongphuhiep
duongphuhiep / tabs2-reponsive.html
Created September 17, 2015 11:06
Two panels Left-Right transform to two Tabs panels on narrow mobile screen with pure CSS
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<style type="text/css" media="screen">
* {
box-sizing: border-box;
}
input {
@duongphuhiep
duongphuhiep / iron-ajax-demo.html
Created September 22, 2015 17:36
iron-ajax element basic usage
<dom-module id="post-collection">
<template>
<iron-ajax
auto
method="POST",
url="/backend/admin.php"
body='{"ignoreTemp":"true"}'
handle-as="json"
last-response="{{postsCollection}}"
on-response="handleResponse"
@duongphuhiep
duongphuhiep / post-collection.html
Created September 23, 2015 00:22
Polymer dom-repeat: use currentTarget to references to the item itself, not the sub-child
<template is="dom-repeat" items={{postsCollection}}>
<file-item content-type="post-folder" file-name={{item}} on-tap="clickHandle"></file-item>
</template>
<script>
clickHandle: function(e) {
e.currentTarget refers to <file-item>
e.target refers to the div inside <file-item>
}
<script/>
@duongphuhiep
duongphuhiep / Form.cs
Last active January 19, 2016 17:09
WinForm: Display BusyForm then run Long Operation on background
private void compareBtn_Click(object sender, EventArgs e)
{
try
{
var busyForm = new BusyForm();
busyForm.Shown += async (sd, args) =>
{
try
{
public static class UriExtensions
{
public static void GetUsernamePassword(this Uri uri, out string userName, out string password)
{
userName = string.Empty;
password = string.Empty;
if (uri == null || string.IsNullOrWhiteSpace(uri.UserInfo))
return;
var items = uri.UserInfo.Split(new[] { ':' });
[user]
name = duong
email = duongphuhiep@gmail.com
[core]
autocrlf = input
[alias]
unstage = reset -q HEAD --
discard = checkout --
nevermind = !git reset --hard HEAD && git clean -d -f
uncommit = reset --mixed HEAD~