Skip to content

Instantly share code, notes, and snippets.

View vu3jej's full-sized avatar
🌴
On vacation

vu3jej

🌴
On vacation
View GitHub Profile
@archatas
archatas / processing_with_progress.py
Last active February 6, 2023 04:17
Progress bar useful for django management commands and scripts that require user interaction
from tqdm import tqdm
from myapp.models import MyModel
progress_bar = tqdm(desc="Processing", total=MyModel.objects.count())
for obj in MyModel.objects.all():
obj.process() # do something time consuming
progress_bar.update(1)
progress_bar.close()

Oh my zsh.

Install with curl

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

Enabling Plugins (zsh-autosuggestions & zsh-syntax-highlighting)

  • Download zsh-autosuggestions by

Getting Stanford NLP and MaltParser to work in NLTK for Windows Users

Firstly, I strongly think that if you're working with NLP/ML/AI related tools, getting things to work on Linux and Mac OS is much easier and save you quite a lot of time.

Disclaimer: I am not affiliated with Continuum (conda), Git, Java, Windows OS or Stanford NLP or MaltParser group. And the steps presented below is how I, IMHO, would setup a Windows computer if I own one.

Please please please understand the solution don't just copy and paste!!! We're not monkeys typing Shakespeare ;P


@subfuzion
subfuzion / curl.md
Last active May 31, 2024 09:45
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@karambir
karambir / factory.md
Created February 15, 2016 14:43
Factory Boy with Many to Many Fields

Many-to-many relation with a ‘through’

If only one link is required, this can be simply performed with a RelatedFactory. If more links are needed, simply add more RelatedFactory declarations:

# models.py

class User(models.Model):
    name = models.CharField()
@elleryq
elleryq / changepassword.sh.j2
Last active June 13, 2023 13:24
Create Django super user in ansible
#!/usr/bin/expect
set timeout -1;
spawn {{django_dir}}/venv/bin/python manage.py changepassword {{admin_user}};
expect {
"Password:" { exp_send "{{admin_pass}}\r" ; exp_continue }
"Password (again):" { exp_send "{{admin_pass}}\r" ; exp_continue }
eof
}

NLTK API to Stanford NLP Tools compiled on 2015-12-09

Stanford NER

With NLTK version 3.1 and Stanford NER tool 2015-12-09, it is possible to hack the StanfordNERTagger._stanford_jar to include other .jar files that are necessary for the new tagger.

First set up the environment variables as per instructed at https://github.com/nltk/nltk/wiki/Installing-Third-Party-Software

@duhaime
duhaime / gist:9330473f9a4e288f00af
Created September 13, 2015 00:35
Cluster vectors with K-Means
from __future__ import division
from sklearn.cluster import KMeans
from numbers import Number
from pandas import DataFrame
import sys, codecs, numpy
class autovivify_list(dict):
'''Pickleable class to replicate the functionality of collections.defaultdict'''
def __missing__(self, key):
value = self[key] = []
@Kmaschta
Kmaschta / DRF-dynamic-fields.py
Last active September 5, 2020 10:31
Django Rest Framework - Dynamic Fields
# How to display only interesting fields for a Django Rest Framework API
# /?fields=field1,field2,field3
from rest_framework import serializers, pagination
class DynamicFieldsModelSerializer(serializers.ModelSerializer):
"""
A ModelSerializer that takes an additional `fields` argument that
controls which fields should be displayed.
@tgarc
tgarc / save_user_variables.md
Last active December 20, 2021 08:25
automatically save ipython sessions

I often like to start my ipython session from where I last left off - similar to saving a firefox browsing session. IPython already automatically saves your input history so that you can look up commands in your history, but it doesn't save your variables. Here are the steps to save the state of your variables on exit and have them loaded on startup:

  1. Add the save_user_variables.py script below to your ipython folder (by default $HOME/.ipython). This script takes care of saving user variables on exit.

  2. Add this line to your profile's ipython startup script (e.g., $HOME/.ipython/profile_default/startup/startup.py):
    get_ipython().ex("import save_user_variables;del save_user_variables")

  3. In your ipython profile config file (by default $HOME/.ipython/profile_default/ipython_config.py) find the following line:
    # c.StoreMagics.autorestore = False
    Uncomment it and set it to true. This automatically reloads stored variables on startup. Alternatively you can use reload the last session manually us