9.17学习笔记 java和python交互,java8位UUID,mac闪电接口高清线导购

史经业
2023-12-01

jython实现java与python交互

import org.python.util.PythonInterpreter; 
import org.python.core.*; 
public class SimpleEmbedded { 
public static void main(String []args)throws PyException
{ 
PythonInterpreter interp =
new PythonInterpreter();

System.out.println("Hello, brave new world");
interp.exec("import sys");
interp.exec("print sys");

interp.set("a", new PyInteger(42));
interp.exec("print a");//42
interp.exec("x = 2+2");
PyObject x = interp.get("x");

System.out.println("x: "+x);//2
System.out.println("Goodbye, cruel world");
}

http://blog.csdn.net/carolzhang8406/article/details/23706771

java生成8位UUID:

public static String[] chars = new String[] { "a", "b", "c", "d", "e", "f",
            "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
            "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5",
            "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I",
            "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V",
            "W", "X", "Y", "Z" };


public static String generateShortUuid() {
    StringBuffer shortBuffer = new StringBuffer();
    String uuid = UUID.randomUUID().toString().replace("-", "");
    for (int i = 0; i < 8; i++) {
        String str = uuid.substring(i * 4, i * 4 + 4);
        int x = Integer.parseInt(str, 16);
        shortBuffer.append(chars[x % 0x3E]);
    }
    return shortBuffer.toString();
}

http://www.oschina.net/code/snippet_1431757_50945

省份证检验:

ID=input('请输入十八位身份证号码: ')
if len(ID)!=18:
    print("错误的身份证号码")
else:
    print("你的身份证号码是 "+ID)

    ID_check=ID[17]
    W=[7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2]
    ID_num=[18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2]
    ID_CHECK=['1','0','X','9','8','7','6','5','4','3','2']
    ID_aXw=0
    for i in range(len(W)):

        ID_aXw=ID_aXw+int(ID[i])*W[i]

    ID_Check=ID_aXw%11
    if ID_check!=ID_CHECK[ID_Check]:
        print('错误的身份证号码')
    else:
        print('正确的身份证号码')

        ID_add=ID[0:6]
        ID_birth=ID[6:14]
        ID_sex=ID[14:17]


        #ID_add是身份证中的区域代码,如果有一个行政区划代码字典,就可以用获取大致地址#

        year=ID_birth[0:4]
        month=ID_birth[4:6]
        day=ID_birth[6:8]
        print("生日: "+year+'年'+month+'月'+day+'日')

        if int(ID_sex)%2==0:
            print('性别:女')
        else:
            print('性别:男')

http://www.oschina.net/code/snippet_139783_50597

java读取T的类名:

public class RawDao<T> {
    Class<T> entityClass = null;
    public RawDao() {
        entityClass = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
    }

    public Class<T> getEntityClass() {
        return entityClass;
    }

}

class RawDao1 extends RawDao<Test> {
    public RawDao1() {

    }

    public static void main(String[] args) {
        System.out.println(new RawDao1().getEntityClass());
    }
}

google翻墙host设置:
http://www.360kb.com/kb/2_150.html

python生成随机中文验证码:

# -*- coding: utf-8 -*-
import Image,ImageDraw,ImageFont
import random
import math, string  

class RandomChar():
  """用于随机生成汉字"""
  @staticmethod
  def Unicode():
    val = random.randint(0x4E00, 0x9FBF)
    return unichr(val)  

  @staticmethod
  def GB2312():
    head = random.randint(0xB0, 0xCF)
    body = random.randint(0xA, 0xF)
    tail = random.randint(0, 0xF)
    val = ( head << 8 ) | (body << 4) | tail
    str = "%x" % val
    return str.decode('hex').decode('gb2312')  

class ImageChar():
  def __init__(self, fontColor = (0, 0, 0),
                     size = (100, 40),
                     fontPath = 'wqy.ttc',
                     bgColor = (255, 255, 255),
                     fontSize = 20):
    self.size = size
    self.fontPath = fontPath
    self.bgColor = bgColor
    self.fontSize = fontSize
    self.fontColor = fontColor
    self.font = ImageFont.truetype(self.fontPath, self.fontSize)
    self.image = Image.new('RGB', size, bgColor)  

  def rotate(self):
    self.image.rotate(random.randint(0, 30), expand=0)  

  def drawText(self, pos, txt, fill):
    draw = ImageDraw.Draw(self.image)
    draw.text(pos, txt, font=self.font, fill=fill)
    del draw  

  def randRGB(self):
    return (random.randint(0, 255),
           random.randint(0, 255),
           random.randint(0, 255))  

  def randPoint(self):
    (width, height) = self.size
    return (random.randint(0, width), random.randint(0, height))  

  def randLine(self, num):
    draw = ImageDraw.Draw(self.image)
    for i in range(0, num):
      draw.line([self.randPoint(), self.randPoint()], self.randRGB())
    del draw  

  def randChinese(self, num):
    gap = 5
    start = 0
    for i in range(0, num):
      char = RandomChar().GB2312()
      x = start + self.fontSize * i + random.randint(0, gap) + gap * i
      self.drawText((x, random.randint(-5, 5)), RandomChar().GB2312(), self.randRGB())
      self.rotate()
    self.randLine(18)  

  def save(self, path):
    self.image.save(path)

#使用方法
ic = ImageChar(fontColor=(100,211, 90))
ic.randChinese(4)
ic.save("1.jpeg")

http://www.oschina.net/code/snippet_12_325

检测mysql是否挂了:
‘/usr/bin/mysqladmin ping’
http://www.oschina.net/code/snippet_12_47861

mac带闪电接口,可以连接显示器,如果macpro有高清接口,若要接显示器,直接购买hdmi接口比较划算!我买的时候竟然不知道我的mac有hdmi接口,浪费了几十块~

fragmentManager.getFragments();里面的fragment顺序不一定是按照add的顺序,为了制作自定义返回上一个fragment,使用自定义的算法:

//super.onBackPressed();
                FragmentManager fragmentManager = getSupportFragmentManager();
                List<Fragment> fragmentlist = fragmentManager.getFragments();
                Logutil.showlog("list:" + fragmentlist);
                for (int i = fragmentlist.size()-1; i >= 0 ; i--) {
                    Fragment fragment = fragmentlist.get(i);
                    if (!(fragment == null || !fragment.isVisible())) {//可视的
                        String fragmentName = fragment.getClass().getSimpleName();
Fragment backFragment = null;
                            Logutil.showlog("tag:" + fragment.getTag());
                            int fragIndex = StringUtil.string2int(fragment.getTag())-1;
                            Looper:
                            while (fragIndex >= 0) {
                                backFragment = fragmentManager.findFragmentByTag(String.valueOf(fragIndex));
                                Logutil.showlog("backFragment:" + backFragment);
                                if (backFragment != null) {
                                    Logutil.showlog("backFragment add?:" + backFragment.isAdded());
                                    Logutil.showlog("backFragment removing?:" + backFragment.isRemoving());
                                }
                                if (backFragment == null || !backFragment.isAdded() || backFragment.isRemoving()) {
                                    --fragIndex;
                                } else {
                                    break Looper;
                                }
                            }
                            Logutil.showlog("currFragment:" + fragmentName);
                            Logutil.showlog("backFragment:" + backFragment);

                            if (backFragment != null) {
                                FragmentTransaction mFragmentTransaction = fragmentManager.beginTransaction();
                                mFragmentTransaction.remove(fragment);
                                mFragmentTransaction.show(backFragment);//IndexOutOfBoundsException
                                mFragmentTransaction.commitAllowingStateLoss();




//add fragment的时候,将index设置进入tag
 mFragmentTransaction.add(R.id.content, tagfragment, String.valueOf(fragmentIndex++));

版本控制快速入门(hg,Bazaar,git)
http://www.oschina.net/question/12_7502

 类似资料: