Skip to content

Instantly share code, notes, and snippets.

View luisfredgs's full-sized avatar
🎯
Focusing

Luís Gonçalves luisfredgs

🎯
Focusing
View GitHub Profile
@luisfredgs
luisfredgs / pandas_csv_to_json.py
Last active September 27, 2022 14:39
Convert pandas dataframe from CSV to JSON
import pandas as pd
data = pd.read_csv("file.csv", sep=",")
print(data.head(2))
with open('file.json', 'w') as f:
f.write(data.to_json(orient='records', lines=True))
# check
data = pd.read_json("file.json", lines=True)
print(data.head(2))
@luisfredgs
luisfredgs / kcca.py
Created January 4, 2019 12:55 — forked from yuyay/kcca.py
kernel canonical correlation analysis in python
#! encoding=UTF-8
"""
kernel canonical correlation analysis
"""
import numpy as np
from scipy.linalg import svd
from sklearn.metrics.pairwise import pairwise_kernels, euclidean_distances
class KCCA(object):
@luisfredgs
luisfredgs / AttentionWithContext.py
Created September 9, 2018 20:27 — forked from rmdort/AttentionWithContext.py
Keras Layer that implements an Attention mechanism, with a context/query vector, for temporal data. Supports Masking. Follows the work of Yang et al. [https://www.cs.cmu.edu/~diyiy/docs/naacl16.pdf] "Hierarchical Attention Networks for Document Classification"
class AttentionWithContext(Layer):
"""
Attention operation, with a context/query vector, for temporal data.
Supports Masking.
Follows the work of Yang et al. [https://www.cs.cmu.edu/~diyiy/docs/naacl16.pdf]
"Hierarchical Attention Networks for Document Classification"
by using a context vector to assist the attention
# Input shape
3D tensor with shape: `(samples, steps, features)`.
# Output shape
@luisfredgs
luisfredgs / gist:8cb3dbcc4ba0f82e3c488c2f662f943c
Created April 24, 2017 15:10 — forked from Atem18/gist:4696071
Tutorial to seting up a django website in production.

Set up Django, Nginx and Gunicorn in a Virtualenv controled by Supervisor

Steps with explanations to set up a server using:

  • Virtualenv
  • Virtualenvwrapper
  • Django
  • Gunicorn
@luisfredgs
luisfredgs / README
Created October 3, 2016 19:49 — forked from larsmans/README
Sentiment analysis with scikit-learn
Sentiment analysis experiment using scikit-learn
================================================
The script sentiment.py reproduces the sentiment analysis approach from Pang,
Lee and Vaithyanathan (2002), who tried to classify movie reviews as positive
or negative, with three differences:
* tf-idf weighting is applied to terms
* the three-fold cross validation split is different
* regularization is tuned by cross validation
@luisfredgs
luisfredgs / Contact.java
Last active May 19, 2016 02:55 — forked from rogerhu/Contact.java
Endless scrolling with RecyclerVIew
package codepath.com.recyclerviewfun;
import java.util.ArrayList;
import java.util.List;
public class Contact {
private String mName;
private boolean mOnline;
public Contact(String name, boolean online) {
@luisfredgs
luisfredgs / imagick-3.4.0-PHP7-forge.sh
Created May 5, 2016 17:34 — forked from pascalbaljet/imagick-3.4.0-PHP7-forge.sh
Install Imagick 3.4.0 on PHP 7.0 server (Laravel Forge)
#!/bin/bash
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
apt-get install pkg-config libmagickwand-dev -y
cd /tmp
wget https://pecl.php.net/get/imagick-3.4.0.tgz
tar xvzf imagick-3.4.0.tgz
@luisfredgs
luisfredgs / UrlImageParser.java
Last active May 5, 2016 13:20 — forked from Antarix/UrlImageParser.java
Parser para carregar imagens presentes em conteúdo HTML <img/> em TextView no android.
package br.com.toptarget.topvagas.helper;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.text.Html;
import android.util.Log;
import android.view.View;
import org.apache.http.HttpResponse;
@luisfredgs
luisfredgs / intro.markdown
Created March 17, 2016 15:27 — forked from tillsanders/intro.markdown
Laravel: drag-and-drop repositioning with auto-save of DB entries

Laravel: drag-and-drop repositioning with auto-save of DB entries

Use case: Database entries are represented in a table. By grabbing and moving a row up or down the table, you can change the entries' order/position. The changes are submitted automatically via ajax.

  • Uses jQueryUI (custom download: sortable is needed)
  • newly created elements are added to the top (see route /jobs/create)
@luisfredgs
luisfredgs / wsgi.py
Created March 10, 2016 02:10 — forked from LeZuse/wsgi.py
WSGI script with virtualenv activation with Flask
import os
import sys
# Install venv by `virtualenv --distribute venv`
# Then install depedencies: `source venv/bin/active`
# `pip install -r requirements.txt`
activate_this = '/var/www/apache/csshat.com/csshat.com/venv/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
path = os.path.join(os.path.dirname(__file__), os.pardir)