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 / mp4-strem-laravel.php
Created February 12, 2016 18:31
Pseudo Stream of MP4 files on Laravel
<?php
Route::get('mp4-stream/{filename}', function($filename){
$contentType = "video/mp4";
$path = $filename;
$fullsize = filesize($path);
$size = $fullsize;
$stream = fopen($path, "r");
$response_code = 200;
$headers = array("Content-type" => $contentType);
@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 / 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 / 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