Skip to content

Instantly share code, notes, and snippets.

View shangoyanyi's full-sized avatar

chih-kuang,wu shangoyanyi

View GitHub Profile
@shangoyanyi
shangoyanyi / servletTester.java
Last active November 2, 2015 05:45
Mockito - A Simple Servlet Tester
/**
* this work's fine on mockito 1.9.5
*/
@Test
public void testServlet() throws Exception {
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
when(request.getParameter("username")).thenReturn("me");
when(request.getParameter("password")).thenReturn("secret");
@shangoyanyi
shangoyanyi / defer.js
Last active November 2, 2015 05:45
Angular - do Parse Query in Angular
/**
* get recipe object from parse
* Object from parse query is not controlled by $scope, so using defer to pass it to $scope
*/
// call $q.defer()
var RecipeDfd = $q.defer();
// call parse query and resolve it
var Recipe = Parse.Object.extend("Recipe");
@shangoyanyi
shangoyanyi / $sce.trustAsResourceUrl.js
Last active November 2, 2015 05:44
Angular - fix the security issue of iframe src
/**
* use $sce.trustAsResourceUrl(SOME_URL) to fix the security issue
*/
$scope.videoUrl = $sce.trustAsResourceUrl(recipe.get("video").url);
@shangoyanyi
shangoyanyi / GRANT_PRIVILEGE_TO_ALL.SQL
Last active November 2, 2015 05:43
Oracle - grant privilege to all tables
-- thanks to all in this article
-- https://community.oracle.com/thread/618903
--
FOR x IN (SELECT * FROM user_tables)
LOOP
EXECUTE IMMEDIATE 'GRANT SELECT ON ' || x.table_name || ' TO <<someone>>';
END LOOP;
@shangoyanyi
shangoyanyi / stopPropagation.js
Last active November 2, 2015 05:42
Angular - solve the conflict between ng-route and bootstrap
/*
* bootstrap can use <a href='#' class='some-class' >link</a> as a button,
* and angular catches <a>link</a> click event to do the route.
* this is how to prevent the routing being triggered when user click the button.
*/
$scope.doThings = function($event){
$event.stopPropagation(); //prevent event propagation
public String copyString(String input){
if (input == null){
return null;
}
try{
StringBuildersb = newStringBuilder();
for (inti=0;i<input.codePointCount(0,input.length());i++){
sb.appendCodePoint(input.codePointAt(i));
//MD5
import java.security.MessageDigest;
public class MD5 {
public static String hash(String plainText) {
MessageDigest cry = null;
try {
cry = MessageDigest.getInstance("MD5");
} catch (Exception e) {
public static <T, E> Set<T> getKeysByValue(Map<T, E> map, E value) {
Set<T> keys = new HashSet<T>();
for (Entry<T, E> entry : map.entrySet()) {
if (entry.getValue().equals(value)) {
keys.add(entry.getKey());
}
}
return keys;
}
@shangoyanyi
shangoyanyi / spotify-oauth-in-react.js
Last active June 16, 2017 17:31
React - do spotify oauth with React
var React = require("react");
module.exports = React.createClass({
...,
// open new spotify oauth window
handleLoginRequest: function(){
var url = 'https://accounts.spotify.com/authorize' +
'?client_id=' + this.props.clientId +
'&redirect_uri=' + encodeURIComponent(this.props.redirectUri) +
'&scope=' + encodeURIComponent(this.props.scope) +
@shangoyanyi
shangoyanyi / chocolatey install guide
Last active May 17, 2016 09:29
chocolatey install guide
chocolatey install guide