A Coder

Coding My Dream!

0%

在运行vagrant provision时经常会出现default:stdin:is not a tty的错误信息,但是对于运行结果没有影响,每次看到这个信息有点郁闷。

解决办法也很简单,只要在配置文件中增加一下内容就可以了

config.ssh.shell = "bash -c 'BASH_ENV=/etc/profile exec bash'"

在idea中编译时发生如下的错误

Information:Using javac 1.7.0_75 to compile java sources
Information:java:javacTask:源发行版 1.6 需要目标发行版 1.6
Information:java:Errors occurred while compiling module ‘kulong’
Information:15/3/26 13:22 - Compilation completed with 1 error and 0 warnings in 5s 771ms
Error:java:Compilation failed:internal java compiler error


阅读全文 »

技术站点
—-

Hacker News:非常棒的针对编程的链接聚合网站
Programming reddit:同上
MSDN:微软相关的官方技术集中地,主要是文档类
infoq:企业级应用,关注软件开发领域
OSChina:开源技术社区,开源方面做的不错哦
cnblogs,51cto,csdn:常见的技术社区,各有专长
stackoverflow:IT技术问答网站
GitHub:全球最大的源代码管理平台,很多知名开源项目都在上面,如Linux内核,
OpenStack等免费的it电子书:http://it-ebooks.info/
DevStore:开发者服务商店


阅读全文 »

昨天做项目时遇到一个问题,我在页面上定义的js方法,方法定义如下

<script type="application/javascript">
    function callback(data){
       alert(data);
    }
</script>

然后在这个页面引入的js中调用此方法

callback("haha");

问题是在IE9及chrome 等高级浏览器下都能正常的工作,但是在IE8及以下浏览器下都提示未定义callback这个方法。折腾的好久,最后请教了同事,他说把type="application/javascript" 改成 type="text/javascript" 试试。结果还真的可以了……

好吧,百度了一下为什么,得到的原因大致如下:
type="text/javascript" 是比较过时的写法,IETF 推荐的是 type="application/javascript",而比较古老的浏览器不认type="application/javascript",从而导致js不生效。
如果为了更好的兼容低端浏览器推荐使用type="text/javascript"

> 最近项目碰到一个业务场景,需要将数据分别保存到两个数据库,并查询两个数据库的内容,同时还需要保证数据的一致性。下面要说的就是我的折腾历程。

###配置两个数据源###
将不同数据库的mapper和xml文件分开放在两个文件夹中如 mainpay

####Main数据库配置如下:####















<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="sqlSessionFactoryBeanName" value="mainSqlSessionFactory"/>
    <!-- Mapper接口所在包名,Spring会自动查找其下的Mapper -->
    <property name="basePackage" value="com.loftor.mapper.main"/>
</bean>
阅读全文 »

完整代码在:http://git.loftor.com/study/c.git/

hash算法采用最简单的求余。

/hash算法/
int hash(char key, int size){
int rect = 0;
while (
key != ‘\0’)
{
rect += key;
key++;
}
return rect%size;
}

解决冲突使用的是 链表

###头文件 Hashtable.h###

typedef struct HashNode{
char
key;
char value;
HashNode
next; //相同hash取下一个节点
} HashNode;


typedef struct Hashtable{
int size;
int item_size;
HashNode head;
} Hashtable;


/
初始化/
Hashtable
hashtable_init(int size);

/添加一个/
void hashtable_put(Hashtable hashtable, char key, char value);

/
获取一个/
char
hashtable_get(Hashtable hashtable, char key);

/删除一个/
void hashtable_remove(Hashtable hashtable, char key);

/销毁/
void hashtable_destroy(Hashtable hashtable);

/
打印/
void hashtable_print(Hashtable
hashtable);

/hash算法/
int hash(char* key, int size);


阅读全文 »

对于java的传参有些了解,今天正好在重温C语言的传值和传址,顺便一起研究下java

##基本数据类型##
对于基本数据类型,如 int long bool 等 是值传递,传递时将值复制一份给形参,如下:

package com.loftor;

public class Argument {
public static void main(String[] args) {
int value = 1;
change(value);
System.out.print(value); //输出结果为1
}

public static void change(int value){
value=2;
}
}


阅读全文 »

根据记忆实现了C的链表基本操作
代码在:http://git.loftor.com/study/c.git/tree/List/List.cpp

// List.c: 主项目文件。
#include <stdio.h>
#include <stdlib.h>

/*双向节点定义*/
typedef struct Node
{
  int value;
  Node * next;
  Node * prev;
} Node;

/*初始化链表*/
Node * createList(int first){
  Node * node = (Node *)malloc(sizeof(Node));
  node->value = first;
  node->next = NULL;
  node->prev = NULL;
  return node;
}

bool isEmptyList(Node **pNode){
  return (*pNode) == NULL;
}


/*指针重置到List头部*/
void resetHead(Node **pNode){
  if (isEmptyList(pNode)){
    (*pNode) = NULL;
  }
  else{
    while ((*pNode)->prev != NULL)
    {
      (*pNode) = (*pNode)->prev;
    }
  }
}

/*指针重置到List头部*/
void resetTail(Node **pNode){
  if (isEmptyList(pNode)){
    (*pNode) = NULL;
  }
  else{
    while ((*pNode)->next != NULL)
    {
      (*pNode) = (*pNode)->next;
    }
  }
}


/*返回List长度*/
int lengthList(Node **pNode){
  resetHead(pNode);
  int length = 0;
  if (isEmptyList(pNode)){
    return length;
  }
  while ((*pNode)->next != NULL)
  {
    length++;
    (*pNode) = (*pNode)->next;
  }
  resetHead(pNode);
  return length;
}

/*打印链表*/
void printfList(Node *pNode){
  if (!isEmptyList(&pNode))
  {
    printf("%d\t", pNode->value);
    while (pNode->next != NULL){
      pNode = pNode->next;
      printf("%d\t", pNode->value);
    }
  }
  printf("\n");
}

/*左边压入一个*/
void leftPush(Node **pNode, int value){
  Node * newNode = (Node *)malloc(sizeof(Node));
  resetHead(pNode);
  newNode->prev = NULL;
  newNode->next = *pNode;
  newNode->value = value;
  if (!isEmptyList(pNode))
  {
    (*pNode)->prev = newNode;
  }
  *pNode = newNode;
}

/*右边压入一个*/
void rightPush(Node **pNode, int value){
  Node * newNode = (Node *)malloc(sizeof(Node));
  resetTail(pNode);
  newNode->next = NULL;
  newNode->prev = *pNode;
  newNode->value = value;

  if (!isEmptyList(pNode))
  {
    (*pNode)->next = newNode;
  }
  else{
    *pNode = newNode;
  }
  resetHead(pNode);
}



/*从左边出一个*/
int leftPop(Node **pNode){
  resetHead(pNode);
  Node *tempNode = *pNode;
  int value = tempNode->value;
  (*pNode) = tempNode->next;
  (*pNode)->prev = NULL;
  free(tempNode);
  return value;
}

/*从右边出一个*/
int rightPop(Node **pNode){
  resetTail(pNode);
  Node *tempNode = *pNode;
  int value = tempNode->value;
  (*pNode) = tempNode->prev;
  (*pNode)->next = NULL;
  resetHead(pNode);
  free(tempNode);
  return value;
}

/*删除指定节点*/
bool removeNode(Node **pNode, int index){
  int length = lengthList(pNode);
  if (length<index) //节点不存在
  {
    return false;
  }
  Node * tempNode = *pNode;
  for (int i = 0; i < index; i++)
  {
    tempNode = tempNode->next;
  }
  if (tempNode->prev != NULL)
  {
    tempNode->prev->next = tempNode->next;
  }
  if (tempNode->next != NULL)
  {
    tempNode->next->prev = tempNode->prev;
  }
  free(tempNode);
  return true;
}

/*销毁List*/
bool destroyList(Node **pNode){
  resetHead(pNode);
  if (pNode==NULL)
  {
    return true;
  }
  Node *head = (*pNode);
  if (head->next == NULL)
  {
    free(head);
    return true;
  }

  while ((*pNode)->next != NULL)
  {
    (*pNode) = (*pNode)->next;
    free((*pNode)->prev);
  }
  *pNode = NULL;
  return true;
}



int main()
{
  //Node * list = createList(1);
  Node * list = NULL;

  rightPush(&list, 2);
  rightPush(&list, 3);
  rightPush(&list, 4);
  rightPush(&list, 5);
  rightPush(&list, 6);
  rightPush(&list, 7);
  leftPush(&list, 1);
  removeNode(&list, 4);
  printf("链表长度为:%d\n", lengthList(&list));

  int value = leftPop(&list);
  value = rightPop(&list);

  printf("链表长度为:%d\n", lengthList(&list));
  printfList(list);
  destroyList(&list);
  return 0;
}

在windows下面安装了git后,没有使用 git bash 去生成key时,可能会出现以下错误

Microsoft Windows [版本 6.3.9600]
(c) 2013 Microsoft Corporation。保留所有权利。

C:\Users\Loftor>ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (//.ssh/id_rsa):
Could not create directory '//.ssh': No such file or directory
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
open //.ssh/id_rsa failed: No such host or network path.
Saving the key failed: //.ssh/id_rsa.

C:\Users\Loftor>

这个错误的原因是我们没有配置环境变量HOME目录,从而找不到目录。

所以我们只要在环境变量中增加HOME就能解决问题了!~

环境变量HOME配置.png

C:\Users\Loftor>ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Loftor/.ssh/id_rsa):
Created directory '/c/Users/Loftor/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/Loftor/.ssh/id_rsa.
Your public key has been saved in /c/Users/Loftor/.ssh/id_rsa.pub.
The key fingerprint is:
04:14:6f:66:3f:f5:71:d0:d7:36:82:c6:09:94:fe:45 Loftor@LOFTOR-PC
The key's randomart image is:
+--[ RSA 2048]----+
|     .+..o+ o ...|
|       o . = E o=|
|        B . o o.+|
|       = o . o o |
|        S + . .  |
|           o     |
|                 |
|                 |
|                 |
+-----------------+

C:\Users\Loftor>

###复制表结构及数据到新表###

CREATE TABLE 新表 SELECT FROM 旧表

这种方法会将oldtable中所有的内容都拷贝过来,当然我们可以用delete from newtable;来删除。
不过这种方法的一个最不好的地方就是新表中没有了旧表的primary key、Extra(auto_increment)等属性。需要自己用alter添加,而且容易搞错。

###只复制表结构到新表###

CREATE TABLE 新表 SELECT
FROM 旧表 WHERE 1=2

CREATE TABLE 新表 LIKE 旧表

###复制旧表的数据到新表(假设两个表结构一样)###

INSERT INTO 新表 SELECT * FROM 旧表

###复制旧表的数据到新表(假设两个表结构不一样)###

INSERT INTO 新表 (字段1,字段2,…….) SELECT 字段1,字段2,…… FROM 旧表




阅读全文 »