Skip to content

Instantly share code, notes, and snippets.

View leoluyi's full-sized avatar
🎯
Focusing

Leo Lu leoluyi

🎯
Focusing
View GitHub Profile
@leoluyi
leoluyi / url_shortener.py
Created March 6, 2018 05:18 — forked from aster1sk/url_shortener.py
Minimalistic URL shortener (Python/Flask/Mongo)
"""
Install : pip install pymongo flask
Minimalistic url shortener : use with curl -sd "url=http://example.com/" http://this-app.com/shorten
"""
from flask import Flask, request, redirect, abort
from pymongo import MongoClient
import base64, md5, re
con = MongoClient()
col = con.shortener.entries
# encoding: utf-8
"""
@author: BrikerMan
@contact: eliyar917@gmail.com
@blog: https://eliyar.biz
@version: 1.0
@license: Apache Licence
@file: w2v_visualizer.py
@time: 2017/7/30 上午9:37
"""
@leoluyi
leoluyi / Dictconfig example
Created February 27, 2018 05:59 — forked from kien-truong/Dictconfig example
Example log dictionary config in pure python
logconfig = {
"version": 1,
"disable_existing_loggers": 0,
"root": {
"level": "DEBUG",
"handlers": [
"console",
"file",
"debugfile"
]
@leoluyi
leoluyi / vis_hackthon.R
Created February 10, 2018 16:40
vis_hackthon
library(data.table)
library(dplyr)
library(dtplyr)
library(abroadplayr)
library(GGally)
library(stringr)
library(ggplot2)
library(wordcloud2)
reports <- as.data.table(reports)
@leoluyi
leoluyi / convert-encoding.sh
Created January 30, 2018 03:57 — forked from arpith20/convert-encoding.sh
Shell script to convert encoding of files to utf-8.
#!/bin/bash
if [ $# -lt 1 ]
then
echo "Usage: "$0" <file_name>"
echo "Convert files to utf-8"
exit
fi
for i in $*
do
@leoluyi
leoluyi / OpenWithSublimeText3.bat
Created December 5, 2017 07:44 — forked from roundand/OpenWithSublimeText3.bat
Open folders and files with Sublime Text 3 from windows explorer context menu (tested in Windows 7)
@echo off
SET st3Path=C:\Program Files\Sublime Text 3\sublime_text.exe
rem add it for all file types
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 3" /t REG_SZ /v "" /d "Open with Sublime Text 3" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 3" /t REG_EXPAND_SZ /v "Icon" /d "%st3Path%,0" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 3\command" /t REG_SZ /v "" /d "%st3Path% \"%%1\"" /f
rem add it for folders
@reg add "HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text 3" /t REG_SZ /v "" /d "Open with Sublime Text 3" /f
@leoluyi
leoluyi / adaboost.py
Created November 13, 2017 16:12 — forked from tristanwietsma/adaboost.py
AdaBoost Python implementation of the AdaBoost (Adaptive Boosting) classification algorithm.
from __future__ import division
from numpy import *
class AdaBoost:
def __init__(self, training_set):
self.training_set = training_set
self.N = len(self.training_set)
self.weights = ones(self.N)/self.N
self.RULES = []

解决 Git 在 windows 下中文乱码的问题

原因

中文乱码的根源在于 windows 基于一些历史原因无法全面支持 utf-8 编码格式,并且也无法通过有效手段令其全面支持。

解决方案

  1. 安装
@leoluyi
leoluyi / xgboost.R
Last active August 14, 2017 09:36
xgboost with caret
library(caret)
library(xgboost)
#-------------------------------------------------------
# (1) caret + xgboost: xgbTree, auto-tuning
#-------------------------------------------------------
# create training sample and test sample
index = createDataPartition(iris$Species, p = 0.9, list = FALSE)
iris.Train = iris[index, ]
iris.Test = iris[-index, ]
@leoluyi
leoluyi / url_regex.py
Last active August 28, 2017 09:25
Testing url regular expression
import re
url = '快來好康大放送http://www.test.com/dir/zxczxc/filename.jpg?zxc=zxxc&var1=foo#bar刷台新卡'
url_regex1 = 'http[s]?:\/\/(?:[a-zA-Z0-9$-_@.&+!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+(?:#[-A-z0-9]+)?'
# url_regex2 = '(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?'
urls = re.findall(url_regex1, url)
print(urls)