Skip to content

Instantly share code, notes, and snippets.

View jose-roberto-abreu's full-sized avatar

José Roberto Abreu Báez jose-roberto-abreu

  • Homeappzz
  • Santo Domingo, Republica Dominicana
View GitHub Profile
@jose-roberto-abreu
jose-roberto-abreu / jwtRS256.sh
Created May 31, 2021 21:34 — forked from Holger-Will/jwtRS256.sh
generate public private key pair (RSA RS256) for use with koa-jwt jasonwebtoken etc.
# generate private key
openssl genrsa -out private.pem 2048
# extatract public key from it
openssl rsa -in private.pem -pubout > public.pem
func rotateLeft(arr:[Int], d:Int)->[Int] {
if arr.count == 0 {
return arr
}
let distanceToMove = d % arr.count
var index = 0
var tmpValue:Int? = arr[0]
var tmpArr = arr
for _ in 0..<tmpArr.count {
@jose-roberto-abreu
jose-roberto-abreu / MergeSortV2.swift
Created July 16, 2016 00:37
More Efficient, do not recreate the result Array
func mergeSort(var values:[Int])->[Int]{
if(values.count <= 1){
return values;
}
if(values.count == 2){
if(values[0] > values[1]){
swap(&values[0],&values[1])
}
func mergeSort(var values:[Int])->[Int]{
if(values.count <= 1){
return values;
}
if(values.count == 2){
if(values[0] > values[1]){
swap(&values[0],&values[1])
}
@jose-roberto-abreu
jose-roberto-abreu / RecursiveReverse.swift
Created July 2, 2016 23:35
Reverse a list of [Int] recursive
func reverseArr(arr:[Int])->[Int]{
return arr.count <= 0 ? [] : reverseArr(Array(arr[1..<arr.count])) + [arr[0]]
}
var otherValues:[Int] = [1,2,3,4,5,6,7,8,9,10]
reverseArr(otherValues) // Print: 10,9,8,7,6,5,4,3,2,1
@jose-roberto-abreu
jose-roberto-abreu / nn_basic_implementation.json
Created August 5, 2015 02:44
Implementation Neural Network
{"cells": [{"cell_type": "code", "metadata": {"trusted": true, "collapsed": false}, "execution_count": null, "outputs": [], "source": "import numpy as np\n\ndef loadDataSet():\n X = np.array([[1,1,1],[1,0,1],[1,1,0],[1,0,0]])\n y = np.array([[0],[1],[1],[0]])\n return X,y\n\ndef costError(w_1,w_2,currentIter):\n z_1 = X.dot(w_1.T)\n a_1 = np.hstack((np.ones((n_observations,1)),sigmoid(z_1)))\n \n z_2 = a_1.dot(w_2.T)\n a_2 = sigmoid(z_2)\n \n sumError = np.mean((y - a_2)**2)\n print(\"Error : %f , Iter: %d\"%(sumError,currentIter))\n \n \ndef sigmoid(z,derivate=False):\n if derivate:\n return sigmoid(z) * (1 - sigmoid(z))\n return 1 / (1 + np.e**-z)\n\ndef classify(w_1,w_2,input_test):\n z_1 = input_test.dot(w_1.T)\n a_1 = np.hstack((np.ones((1,1)),sigmoid(z_1)))\n \n z_2 = a_1.dot(w_2.T)\n a_2 = sigmoid(z_2)\n \n if a_2 >= 0.5:\n print(\"Classification : 1 , Prob: %f\"%a_2)\n else:\n print(\"Classification : 0 , Prob: %
This file has been truncated, but you can view the full file.
{"cells": [{"metadata": {"collapsed": false, "trusted": true}, "outputs": [{"name": "stdout", "text": "Error : 3.148222 , Iter: 0\nError : 2.533367 , Iter: 1\nError : 1.873753 , Iter: 2\nError : 1.500785 , Iter: 3\nError : 1.320264 , Iter: 4\nError : 1.222362 , Iter: 5\nError : 1.164071 , Iter: 6\nError : 1.127321 , Iter: 7\nError : 1.103377 , Iter: 8\nError : 1.087538 , Iter: 9\nError : 1.077074 , Iter: 10\nError : 1.070318 , Iter: 11\nError : 1.066217 , Iter: 12\nError : 1.064095 , Iter: 13\nError : 1.063520 , Iter: 14\nError : 1.064214 , Iter: 15\nError : 1.066006 , Iter: 16\nError : 1.068795 , Iter: 17\nError : 1.072520 , Iter: 18\nError : 1.077143 , Iter: 19\nError : 1.082633 , Iter: 20\nError : 1.088945 , Iter: 21\nError : 1.096019 , Iter: 22\nError : 1.103759 , Iter: 23\nError : 1.112039 , Iter: 24\nError : 1.120694 , Iter: 25\nError : 1.129532 , Iter: 26\nError : 1.138340 , Iter: 27\nError : 1.146906 , Iter: 28\nError : 1.155027 , Iter: 29\nError : 1.162531 , Iter: 30\nError : 1.169284 , Iter: 31\nErr
@jose-roberto-abreu
jose-roberto-abreu / .json
Created July 31, 2015 20:01
Percetron Simple Model
{"cells": [{"cell_type": "code", "execution_count": null, "source": "import numpy as np\nimport matplotlib.pyplot as plt\n\ndef loadDataSet():\n X = np.array([[1,1],[0,1],[1,0],[0,0]])\n y = np.array([1,-1,-1,-1])\n return X,y\n\nX,y = loadDataSet()\nn_observations,n_features = X.shape\nweights = np.zeros((1,n_features))\nbias = 0\n\nhasConverged = False\nwhile not hasConverged:\n hasConverged = True\n for n in range(n_observations):\n #activation\n a = X[n].dot(weights.T) + bias\n if y[n]*a <= 0:\n hasConverged = False\n #print(\"Classification error\")\n weights += y[n]*X[n]\n bias += y[n]\n \nprint(\"Weights : %s and Bias %d\" % (weights,bias))\n\n#Scatter Plot\nx_pos = X[y==1]\nx_neg = X[y==-1]\n\nplt.scatter(x_pos[:,0],x_pos[:,1],c=\"blue\")\nplt.scatter(x_neg[:,0],x_neg[:,1],c=\"red\")\n\n#show portion of decision boundary (2 dimension)\nX_line = np.linspace(-3,3,100)\nY_line = (-weights[0][0]/weights[0][1])*X_lin
@jose-roberto-abreu
jose-roberto-abreu / NN.json
Created July 28, 2015 14:47
NN Implementation
{"cells": [{"metadata": {"trusted": true, "collapsed": false}, "cell_type": "code", "source": "import numpy as np\n\n#Utility Functions\ndef loadDataSet():\n #Last column Target\n dataset = np.array([[1,1,1,1],\n [1,1,0,1],\n [1,0,1,1],\n [1,0,0,0]])\n return dataset\n\ndef sigmoid(z,derivate=False):\n if derivate:\n #Derivate Sigmoid Function\n return z * (1-z)\n #Simoidal Function\n return 1.0 / (1.0 + np.e**(-z))\n\ndef classify(Test_X):\n a_1 = sigmoid(np.dot(Test_X,weights_1.T))\n a_1 = np.hstack((np.ones((1,1)),a_1))\n a_2 = sigmoid(np.dot(a_1,weights_2.T))\n print(\"Prob Of Pos : %f\"%a_2)\n if a_2 >= 0.5:\n print(\"1\")\n else:\n print(\"0\")\n\n#Arquitecture\n'''\n 3 nodes input layer - include bias\n 3 nodes hidden layer - include bias\n 1 node output layer\n'''\n \n#Calc - HardCode for the arquitecture above\ndataset = loadDataSet()\nnumber_observation
{"nbformat": 4, "nbformat_minor": 0, "cells": [{"cell_type": "code", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Probability Of Pos : 0.122164\n0\n"}], "source": "import numpy as np\n\n#Utility Functions\ndef loadDataSet():\n dataset = np.array([[1,1,1],\n [1,1,0],\n [1,0,1],\n [1,0,0]])\n label = np.array([[1],[0],[0],[0]])\n return dataset,label\n\ndef sigmoid(z,derivate=False):\n if derivate:\n #Derivate Sigmoid Function\n return z * (1-z)\n #Simoidal Function\n return 1.0 / (1.0 + np.e**(-z))\n\ndef classify(value):\n print(\"Prob Of Pos : %f\"%value)\n if value >= 0.5:\n print(\"1\")\n else:\n print(\"0\")\n\n#Arquitecture\n'''\n 3 nodes input layer - include bias\n 3 nodes hidden layer - include bias\n 1 node output layer\n'''\n \n#Calc - HardCode for the arquitecture above\nX,y = loadDataSet()\nnumber_observations = X.shape[0]\nweights_1 = np.r