Skip to content

Instantly share code, notes, and snippets.

View dfucci's full-sized avatar

Davide Fucci dfucci

View GitHub Profile
@dfucci
dfucci / app.js
Created March 22, 2012 12:29
Mongoose embedded docs
var mongoose = require('mongoose')
, Schema = mongoose.Schema;
mongoose.connect('mongodb://localhost/blog');
var Comments = new Schema({
title : String
, body : String
, date : Date
});
@dfucci
dfucci / querystring.js
Created April 27, 2012 12:27
Querystring key-val #js
// Read a page's GET URL variables and return them as an associative array.
function getUrlVars()
{
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
@dfucci
dfucci / ggprplots.R
Last active August 29, 2015 14:01 — forked from masverba/ggprplots.R
# Component+residual plots with ggplot2, with support for interaction terms.
# Modeled after function "prplot" in package "faraway".
#
# Example usage:
# > print(ggprplots(lm(prestige~income+education, data=Prestige)))
library(ggplot2)
@dfucci
dfucci / computeDistance
Created October 21, 2014 06:36
Possible solution for MusicPhone's first task
public static Double computeDistance(GeoPoint p1, GeoPoint p2, String units){
double distance = 0.0;
final double EarthRadiusMI = 3958.76;
final double EarthRadiusKM = 6371.01;
if(p1==null) throw new IllegalArgumentException("p1");
if(p2==null) throw new IllegalArgumentException("p2");
if(units == null) throw new IllegalArgumentException("units");
units = units.toLowerCase().trim();
if(!units.equalsIgnoreCase("km") && !units.equalsIgnoreCase("mi")) throw new IllegalArgumentException("Invalid value: " + units);
@dfucci
dfucci / sentiment.py
Created June 28, 2015 03:21
Sentiment book analysis
from __future__ import print_function
from alchemyapi import AlchemyAPI
import json
import re
txt = open("book.txt")
book_txt = txt.read()
book_chaps = book_txt.split('\n== ')
result = {}
@dfucci
dfucci / Grid.java
Last active September 8, 2015 08:46
package oulu.fsecure.tdd.day2;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Grid {
private int xSize;
private int ySize;
@dfucci
dfucci / vimrc
Last active July 10, 2016 10:30
set encoding=utf-8
execute pathogen#infect()
syntax on
filetype plugin on
filetype indent on
""
"" Customisations
""
highlight Pmenu ctermbg=238 gui=bold
###########################
# Configuration
###########################
# use 256 term for pretty colors
set -g default-terminal "screen-256color"
# increase scroll-back history
set -g history-limit 5000
DEBUG=True
CSRF_COOKIE_SECURE=False
SESSION_COOKIE_SECURE=False
SECRET_KEY=s3cr3t
DATABASE_URL=sqlite:////tmp/db.sqlite3
ALLOWED_HOSTS=*
EMAIL_BACKEND=django.core.mail.backends.filebased.EmailBackend
EMAIL_HOST=email_host
EMAIL_PORT=587
EMAIL_HOST_USER=host_user
# ~/.tmuxinator/rails-dev.yml
name: rails-dev
root: ~/Projects/galileo
# Optional tmux socket
# socket_name: foo
# Runs before everything. Use it to start daemons etc.
# pre: sudo /etc/rc.d/mysqld start