Skip to content

Instantly share code, notes, and snippets.

View vigack's full-sized avatar

vigack

  • Hangzhou. China
View GitHub Profile
@vigack
vigack / test.c
Created August 1, 2017 01:34
判断两个int类型数符号是否相反
int x, y;
bool f = ((x^y)<0); // true表示两数符号相反
@vigack
vigack / insert-node.c
Last active August 1, 2017 01:48
向指定list的尾部插入一个节点(无首节点)
Node* insert(Node *head,int data)
{
Node *tail;
Node *tmp;
tail = (Node *)malloc(sizeof(struct Node));
tail->data = data;
if(head == NULL){
head = tail;
}else{
tmp = head;
@vigack
vigack / BFS.c
Created August 2, 2017 03:07
广度优先搜索
/* 基本的实现思路:维护一个Queue,push根节点。当Queue非空,开始循环,POP->取值->PUSH LEFT节点->PUSH RIGHT节点 */
@vigack
vigack / gcd_lcm.c
Created August 2, 2017 08:21
最大公因数、最小公倍数相关
int gcd(int a, int b){
int rmd; // remainder
if(a<b) // insure a>b
return gcd(b,a);
while((rmd=a%b)!=0){
a = b;
b = rmd;
} // loop down, b is the gcd
return b;
}
@vigack
vigack / LomutoQuickSort.c
Last active August 3, 2017 08:36
QuickSort-Lomuto's Version
void swap(int *a, int *b){
int tmp;
tmp = *a;
*a = *b;
*b = tmp;
}
void quickSort(int left, int right, int *arr){
// base
if(left>=right)
@vigack
vigack / test.rb
Created September 7, 2017 03:22
connnect oracle databse use oci8
require 'oci8'
conn = OCI8.new('username', 'password', 'host:port/service')
table = conn.describe_table('tableName')
table.columns
@vigack
vigack / test.java
Created September 7, 2017 06:19
奇妙BUG记录
private Table getTable(String scheme, String tableName){
Connection connection = null;
Table table = new Table();
table.setTableName(tableName);
try {
List<Column> columns = new ArrayList<>();
connection = getConnection(scheme);
ResultSet resultSet =
connection.getMetaData().getColumns(null, null,tableName,null);
while(resultSet.next()){
@vigack
vigack / fkcracker.sh
Last active September 20, 2017 04:10
查找/var/log/secure中试图暴力登陆的ip
# 原型,打印出所有ip,但是会重复,且ip之间没有换行
perl -ne 'print $1 if(/Failed password.+(\d+.\d+.\d+.\d+)/)' /var/log/secure*
# 发现上面那个命令没有打印全ip,改为下面的,这样就会获得完整ip并且ip之间换行了
perl -ne 'print "$1\n" if(/Failed password\D+(\d+\.\d+\.\d+\.\d+)/)' /var/log/secure*
# 使用{3}来缩减代码量
perl -ne 'print "$1\n" if(/Failed password\D+((\d+\.){3}\d+)/)' /var/log/secure*
# 去重,这个感觉比较麻烦,因为如果用数组或者哈希的话,就不能用-n来去掉外面那层while(<>){...}了
@vigack
vigack / creepy.md
Last active September 22, 2017 06:04
spring的multipart/formdata 仅支持post请求

初次尝试REST规范,在使用PATCH,PUT的时候出现了问题,无法通过@RequestParam获取参数值 阅读源码,发现对于multipart/formdata形式的请求,spring都会做如下判断

public static final boolean isMultipartContent(
            HttpServletRequest request) {
        if (!POST_METHOD.equalsIgnoreCase(request.getMethod())) {
            return false;
        }
 return FileUploadBase.isMultipartContent(new ServletRequestContext(request));
@vigack
vigack / ProxyDemo.java
Created November 22, 2017 01:41
Java中使用网络代理
public class ProxyDemo {
@Test
public void test() throws IOException {
// 如果是http代理
//System.setProperty("http.proxyHost", sProxyHost);
//System.setProperty("http.proxyPort", sProxyPort)
System.setProperty("socksProxyHost", "127.0.0.1");
System.setProperty("socksProxyPort", "1080");
OkHttpClient client = new OkHttpClient();