Skip to content

Instantly share code, notes, and snippets.

View GMadorell's full-sized avatar
🏗️
Building stuff

Gerard Madorell GMadorell

🏗️
Building stuff
View GitHub Profile
@GMadorell
GMadorell / pelican-steps.md
Created March 28, 2014 23:46
Pelican steps

##Installing pelican Remeber to use a virtual env ;).

pip install pelican  
pip install Markdown  
pip install Fabric
pip install beautifulsoup4
@GMadorell
GMadorell / SendToKindle.sh
Created March 6, 2014 20:44
Send file via email to kindle.
#! /bin/bash
# Depends on package sendemail (apt-get install sendemail).
# Add this script to /home/$USER/.local/share/nautilus/scripts/
# Remember giving the script permission to be run as an executable.
sendemail -f EMAIL@gmail.com -t KINDLE_USERNAME@kindle.com -u "Convert" -m "Sent automatically by sendemail." -s smtp.gmail.com:587 -xu EMAIL@gmail.com -xp EMAILPASSWORD -a "$1"
@GMadorell
GMadorell / text_to_numeric.py
Created February 17, 2014 15:49
Simple method to translate text to numbers giving a different number to every different text.
def text_to_number(text_array):
"""
@param text_array: Numpy array of strings.
@return: Numpy array of integers. Each different input string will be
assigned a different incremental number.
"""
vectorizer = CountVectorizer()
X = vectorizer.fit_transform(text_array).toarray()
return X.argmax(1)
@GMadorell
GMadorell / sqrt.scala
Last active December 28, 2015 19:59
A implementation of Newton's method for calculating the sqrt() of a number.
def isGoodEnough(guess: Double, x: Double) = {
math.abs(guess * guess - x) / x < 0.0001
}
def improve(guess: Double, x: Double): Double = {
(guess + x / guess) / 2
}
def sqrtIter(guess: Double, x: Double): Double = {
if (isGoodEnough(guess, x)) guess
else sqrtIter(improve(guess, x), x)
@GMadorell
GMadorell / IntervalScale.java
Last active February 1, 2018 14:03
Scale an interval to another interval. Translate intervals.
public static float scaleInterval(
float value,
float minActualInterval, float maxActualInterval,
float minDesiredInterval, float maxDesiredInterval) {
return ((value - minActualInterval) / (maxActualInterval - minActualInterval))
* (maxDesiredInterval - minDesiredInterval) + minDesiredInterval;
}
@GMadorell
GMadorell / IsNumber.java
Created October 23, 2013 14:10
Regex for finding whether a string is a number.
public static boolean isNumber(String string) {
return string.matches("-?\\d+(\\.\\d+)?");
}
@GMadorell
GMadorell / SplitStringInSymbols.java
Created October 22, 2013 14:31
Split a string into the given symbols. This was hard because some symbols can be tracted as a regex if they aren't scaped.
public static String[] splitString(String objective, String symbols) {
return objective.split(Pattern.quote(symbols));
}
@GMadorell
GMadorell / ParenthesisParse.java
Created October 22, 2013 13:24
Get values inside parenthesis in a String.
// http://stackoverflow.com/questions/14584018/how-can-i-get-inside-parentheses-value-in-a-string
String example = "United Arab Emirates Dirham (AED)";
Matcher m = Pattern.compile("\\(([^)]+)\\)").matcher(example);
while(m.find()) {
System.out.println(m.group(1));
}
@GMadorell
GMadorell / Gitfiz no layout used implementation (LibGDX).
Created August 1, 2013 11:18
Shows how to implement Gitfiz SDK without using an external layout XML file, useful for the LibGDX framework.
/**
* Extends AndroidApplication incorporating a view for the Gitfiz sdk, which is just a bottom left button.
*/
public class AdmobApplication
extends AndroidApplication
// Giftiz interfaces.
implements ButtonNeedsUpdateDelegate {
private ImageView giftizButtonView;