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
def hack1(n, k):
def f(s):
return s.count('1')
binaries = []
for x in range(2**n):
binaries.append(bin(x))
binaries.sort(key=f, reverse = True)
return binaries[k - 1]
def hack(n, k):
@luisfredgs
luisfredgs / projeto.wsgi
Created January 21, 2016 04:11 — forked from JuniorLima/projeto.wsgi
WSGI Kinghost
import os
import sys
import site
# Calculates the path based on location of WSGI script.
apache_configuration = os.path.realpath(os.path.dirname(__file__))
project = os.path.join(apache_configuration, 'nomedoproto')
sys.path.append(apache_configuration)
sys.path.append(project)
@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)
@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 / 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 / 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 / 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 / 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 / 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 / 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):