Skip to content

Instantly share code, notes, and snippets.

@Aaronlong31
Aaronlong31 / PBKDF2.groovy
Created April 27, 2015 12:47
为mosquitto-auth-plug提供的PBKDF2加密算法的JAVA版实现.
package com.oneclock.server.util
import org.apache.commons.codec.binary.Base64
import javax.crypto.SecretKeyFactory
import javax.crypto.spec.PBEKeySpec
import java.security.NoSuchAlgorithmException
import java.security.SecureRandom
import java.security.spec.InvalidKeySpecException
@Aaronlong31
Aaronlong31 / containerNoValidate.js
Created August 10, 2014 13:19
集装箱号验证
var cntrCodeMap = _.object('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(""), _.without(_.range(0, 39), 11, 22, 33));
$.validator.addMethod("cntrNo", function(value, element){
if (!value.match('^[A-Z]{4}[0-9]{7}$')) {
return false;
}
var chars = value.split("");
var checkNo = chars.splice(10, 1);
var sum = _.reduce(chars, function(check, char, index){
return check + cntrCodeMap[char] * Math.pow(2, index);
$.fn.serializeObject = function()
{
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name] !== undefined) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
@Aaronlong31
Aaronlong31 / 0_reuse_code.js
Created July 24, 2014 04:53
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@Aaronlong31
Aaronlong31 / .gitignore
Created February 25, 2014 08:42
java project .gitignore
*.class
*.jar
*.ear
*.war
*.iml
*.ipr
*.iws
.classpath
.project
rebel.xml
@Aaronlong31
Aaronlong31 / CorsFilter.groovy
Created December 29, 2013 10:45
在服务器端开启cors的支持。
package com.liba.core
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import org.springframework.web.filter.OncePerRequestFilter
import javax.servlet.FilterChain
import javax.servlet.ServletException
import javax.servlet.http.HttpServletRequest
// This hack works with com.android.tools.build:gradle:0.2, won't work in later version without modification
apply plugin: 'android'
targetCompatibility = 1.6
sourceCompatibility = 1.6
android {
target = 'android-14'
@Aaronlong31
Aaronlong31 / choose_share_intent.java
Created October 18, 2013 06:07
选择分享到指定的app
public Intent getShareIntent() {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, getShareContent());
List<ResolveInfo> resolveInfos = getPackageManager().queryIntentActivities(intent, 0);
List<Intent> targetedShareIntents = new ArrayList<Intent>();
if (!resolveInfos.isEmpty()) {
for (ResolveInfo resolveInfo : resolveInfos) {
Ln.d(resolveInfo.activityInfo.packageName + " : " + resolveInfo.activityInfo.name);
String packageName = resolveInfo.activityInfo.packageName;
@Aaronlong31
Aaronlong31 / CustomToastPosition.java
Created September 26, 2013 02:30
自定义Toast出现的位置
Toast toast = Toast.makeText(this, stringRes, Toast.LENGTH_SHORT);
toast.setGravity(Gravity.TOP | Gravity.CENTER, 0, 0);
toast.show();
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"3
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="1">
<Button