Skip to content

Instantly share code, notes, and snippets.

View neuromaancer's full-sized avatar
🎯
Focusing

Alafate neuromaancer

🎯
Focusing
View GitHub Profile
@neuromaancer
neuromaancer / oveleaf_vim_keybinds.js
Last active August 28, 2023 05:54
Overleaf Editor Custom VIM Keybindings
// ==UserScript==
// @name Overleaf Editor Custom VIM Keybindings
// @namespace http://tampermonkey.net/
// @version 0.1
// @match https://www.overleaf.com/project/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
@neuromaancer
neuromaancer / utils.py
Last active September 26, 2022 14:16
utils
"""
@Created Date: Friday February 4th 2022
@Author: Alafate Abulimiti
@Company: INRIA
@Lab: CoML/Articulab
@School: PSL/ENS
@Description: Save the frequent useful functions
--------------
@HISTORY:
Date By Comments
# Verify conda is installed, check version number
conda info

# Update conda to the current version
conda update conda

# conda install PACKAGENAME 
Install a package included in Anaconda
import os
libs = {
"pillow",
"sklearn",
"numpy",
"pandas",
"jupyterlab",
"scikit-learn",
"torch torchvision",
@neuromaancer
neuromaancer / tree.md
Last active September 6, 2019 13:43 — forked from upsuper/tree.md
一行 Python 实现树

一行 Python 实现树

使用 Python 内置的 defaultdict,我们可以很容易的定义一个树形数据结构:

def tree(): return defaultdict(tree)

就是这样!

@neuromaancer
neuromaancer / df_operations.py
Last active April 30, 2022 13:50
DF_operations
# add row
scores = list()
for row in df.itemrows():
df.loc[len(df)] = scores
def get_data(data, features):
"""
Data is an array each row being a tuple with possibily several features.
Keep only those features whose indices appear in the 'features' vector
"""
@neuromaancer
neuromaancer / dict_operations.py
Last active April 30, 2022 13:50
dict_operations
# 合并两个dict 同keys, values 相加
def get(compe_list, text_list):
span_score = calcul_span_score.calcul_span_score(text_list, compe_list)
fre_score = calcul_fre_score.calcul_fre_score(text_list, compe_list)
span_score_counter = Counter(span_score)
fre_score_counter = Counter(fre_score)
scores_dict = dict(span_score_counter + fre_score_counter)
return scores_dict
@neuromaancer
neuromaancer / genereate_vocabs_from_list.py
Last active April 30, 2022 13:50
genereate vocabs from list
# docs is 2 dims
vocabs = set(itertools.chain.from_iterable(docs))
return vocabs
@neuromaancer
neuromaancer / decorators.py
Last active April 30, 2022 13:46
python-decorator
# 这是装饰器函数,参数 func 是被装饰的函数
def logger(func):
def wrapper(*args, **kw):
print('主人,我准备开始执行:{} 函数了:'.format(func.__name__))
# 真正执行的是这行。
func(*args, **kw)
print('主人,我执行完啦。')
return wrapper
@neuromaancer
neuromaancer / pythonic.py
Last active August 25, 2019 11:55
pythonic_code
# 列表对象(list)是一个查询效率高于更新操作的数据结构,比如删除一个元素和插入一个元素时执行效率就非常低,因为还要对剩下的元素进行移动
names = ['raymond', 'rachel', 'matthew', 'roger',
'betty', 'melissa', 'judith', 'charlie']
names.pop(0)
names.insert(0, 'mark')
## pythonic
from collections import deque
names = deque(['raymond', 'rachel', 'matthew', 'roger',
'betty', 'melissa', 'judith', 'charlie'])