Skip to content

Instantly share code, notes, and snippets.

View patrickpissurno's full-sized avatar
🚀

Patrick Pissurno patrickpissurno

🚀
View GitHub Profile
@patrickpissurno
patrickpissurno / linear_regression.sql
Last active April 26, 2024 08:39
Simple linear regression and prediction in PL/pgSQL (PostgreSQL)
-- This code is based on my other Gist "Simple linear regression in Javascript" (https://gist.github.com/patrickpissurno/ea0dc4039f075fbaf398619761bd9044)
-- There might be a more efficient way to do this in SQL
-- This function is resposible for computing the weights for the ax + b equation
CREATE OR REPLACE FUNCTION linear_regression(x_array decimal(15,2)[], y_array decimal(15,2)[]) RETURNS decimal(15,2)[] AS $$
DECLARE
slope decimal(15,2);
intercept decimal(15,2);
n integer;
@patrickpissurno
patrickpissurno / linear_regression.js
Last active May 6, 2019 01:36
Simple linear regression in Javascript
function linear_regression(x_array, y_array){
var slope;
var intercept;
var n = y_array.length;
var sum_x = 0;
var sum_y = 0;
var sum_xy = 0;
var sum_xx = 0;
var sum_yy = 0;
@patrickpissurno
patrickpissurno / is-mobile.js
Last active July 19, 2017 03:24
Simple javascript to check if device is mobile or not. Just load the script and call IsMobile()
//Work derived from https://github.com/sebarmeli/JS-Redirection-Mobile-Site
function IsMobile()
{
// Helper function for adding time to the current date -> used by cookie
var addTimeToDate = function(msec)
{
var exdate = new Date();
exdate.setTime(exdate.getTime() + msec);
return exdate;
};
@patrickpissurno
patrickpissurno / brazil-cities.xml
Last active May 11, 2021 11:52
Cidades do Brasil em Android Resource String-Array (Brazil's Cities in Android String-Array Resource format)
<!--
Conteúdo derivado de https://gist.github.com/letanure/3012978
Cidades do Brasil em Android Resource String-Array
Brazil's Cities in Android String-Array Resource format
Free for use, no attribution required
-->
<resources>
<string-array name="cities_array">
<item>Abadia de Goiás</item>