Skip to content

Instantly share code, notes, and snippets.

View emrehayirci's full-sized avatar
🤘

Emre Hayırcı emrehayirci

🤘
View GitHub Profile
@emrehayirci
emrehayirci / models.py
Created October 28, 2018 17:43
Django Student Profile Model Example
from django.db import models
from django.contrib.auth.models import AbstractUser
from django.contrib.auth.models import BaseUserManager
# This project uses Django Authentication System
# For more information visit: https://docs.djangoproject.com/en/1.11/topics/auth/default/
#referenced from https://medium.com/@ramykhuffash/django-authentication-with-just-an-email-and-password-no-username-required-33e47976b517
class MyUserManager(BaseUserManager):
"""
A custom user manager to deal with emails as unique identifiers for auth
@emrehayirci
emrehayirci / k-meansp2.R
Last active December 11, 2017 22:57 — forked from mahito-sugiyama/k-meansp2.R
k-means++ (written in R; with the Euclidean distance; distance computation is vectorized)
kmeansp2 <- function(x, k, iter.max = 10, nstart = 1, ...) {
n <- nrow(x) # number of data points
centers <- numeric(k) # IDs of centers
distances <- matrix(numeric(n * (k - 1)), ncol = k - 1) # distances[i, j]: The distance between x[i,] and x[centers[j],]
res.best <- list(tot.withinss = Inf) # the best result among <nstart> iterations
for (rep in 1:nstart) {
pr <- rep(1, n) # probability for sampling centers
for (i in 1:(k - 1)) {
centers[i] <- sample.int(n, 1, prob = pr) # Pick up the ith center
distances[1:length(distances)] <- colSums((t(x) - x[centers[i], ])^2) # Compute (the square of) distances to the center
@emrehayirci
emrehayirci / project.yml
Created July 12, 2017 15:07
Having issue of my lambda service unable to access dynamodb instance
service: my-service
provider:
name: aws
runtime: nodejs6.10
iamRoleStatements:
- Effect: "Allow"
Action:
- dynamodb:DescribeTable
- dynamodb:Query