Skip to content

Instantly share code, notes, and snippets.

View martinthenext's full-sized avatar

Martin martinthenext

View GitHub Profile
@martinthenext
martinthenext / .tmux.conf
Created January 26, 2022 15:07
Latest tmux conf
# Smart pane switching with awareness of Vim splits.
# See: https://github.com/christoomey/vim-tmux-navigator
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
| grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
bind-key -n 'C-h' if-shell "$is_vim" 'send-keys C-h' 'select-pane -L'
bind-key -n 'C-j' if-shell "$is_vim" 'send-keys C-j' 'select-pane -D'
bind-key -n 'C-k' if-shell "$is_vim" 'send-keys C-k' 'select-pane -U'
bind-key -n 'C-l' if-shell "$is_vim" 'send-keys C-l' 'select-pane -R'
tmux_version='$(tmux -V | sed -En "s/^tmux ([0-9]+(.[0-9]+)?).*/\1/p")'
if-shell -b '[ "$(echo "$tmux_version < 3.0" | bc)" = 1 ]' \
@martinthenext
martinthenext / .vimrc
Last active September 9, 2022 14:02
recent vimrc
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
" The following are examples of different formats supported.
@martinthenext
martinthenext / daytobase3.py
Created May 26, 2021 00:29
Daytobase updated for Python3 and new telegram-bot API
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from telegram import Update
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackContext
import logging
from pymongo import MongoClient, TEXT, DESCENDING
from datetime import datetime, timedelta
import settings
import re
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
" The following are examples of different formats supported.
from sklearn.metrics.pairwise import cosine_similarity
similarity = cosine_similarity(question_repr, sentence_repr)
ranks = (-similarity).argsort(axis=None)
context_sentences[ranks[0]]
'During the middle of 2010, iPhone sales overtook those of the iPod.'
from sklearn.feature_extraction.text import TfidfVectorizer
sentences = [sentence
for datum in squad['data']
for paragraph in datum['paragraphs']
for sentence in paragraph['context'].split('. ')
]
tf_idf_vect = TfidfVectorizer(tokenizer=tokenize_and_stem)
tf_idf_vect.fit(sentences)
question = squad['data'][3]['paragraphs'][3]['qas'][3]['question']
tokenize_and_stem(question)
['In',
'what',
'year',
'did',
'iphon',
'sale',
'surpass',
squad['data'][3]['paragraphs'][3]['qas'][3]
{'question': 'In what year did iPhone sales surpass those of iPods?',
'id': '56ce73d1aab44d1400b887ac',
'answers': [{'text': '2010', 'answer_start': 444}],
'is_impossible': False}
import json
with open('data/train-v2.0.json') as squad_file:
squad = json.load(squad_file)
context = squad['data'][3]['paragraphs'][3]['context']
context
'''Before the release of iOS 5, the iPod branding was used for the media player
included with the iPhone and iPad, a combination of the Music and Videos apps on
@martinthenext
martinthenext / read_csv_to_dicts.py
Created July 31, 2018 19:40
Read CSV to dicts
def read_csv_to_dicts(filename):
with open(filename) as csvfile:
reader = csv.reader(csvfile, dialect='excel')
header = transform_header(next(reader))
if len(header) != len(set(header)):
raise ValueError("Duplicate column names in CSV.")
data = [{field: value for field, value in zip(header, row)}
for row in reader]