Skip to content

Instantly share code, notes, and snippets.

@heygema
heygema / package.json
Last active March 28, 2017 23:26
My webpack default config setup for django project.
{
"name": "myApp",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
@heygema
heygema / user_accounts.py
Last active March 25, 2017 04:50
The example of one file of custom account in django to rule them all !
from django.contrib.auth.models import BaseUserManager
class MyUserManager(BaseUserManager):
def create_user(self, email, password=None, **kwargs):
if email is None:
raise TypeError('user must have an email')
user = self.model(email=self.normalize_email(email))
user.set_password(password)
user.save(using=self._db)
return user
@heygema
heygema / backend.py
Last active March 26, 2017 15:51
MyCustomAuthBackend for Django
# settings file:
AUTH_USER_MODEL = 'accounts.User'
AUTHENTICATION_BACKENDS = ('accounts.backend.MyBackend', )
# backend.py in usercp (APP) folder
from models import Customer
from django.contrib.auth.hashers import check_password
# Taken from http://www.djangorocks.com/tutorials/creating-a-custom-authentication-backend/creating-a-simple-authentication-backend.html
class MyAuth:
@heygema
heygema / bfs.py
Created April 3, 2017 20:40
Simple Python Implementing Breadth First Search Algorithm., enlightenment from here https://pythoninwonderland.wordpress.com/2017/03/18/how-to-implement-breadth-first-search-in-python/
graph = {
'A': ['B', 'C', 'E'],
'B': ['A', 'D', 'E'],
'C': ['A', 'F', 'G'],
'D': ['B'],
'E': ['A', 'B', 'D'],
'F': ['C'],
'G': ['C']
}
@heygema
heygema / webpack.config.js
Created September 1, 2017 17:23
Webpack config for static html site
var debug = process.env.NODE_ENV !== "production";
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var HtmlWebpackPluginConfig = new HtmlWebpackPlugin({
template: __dirname + '/app/index.html',
filename: 'index.html',
inject: 'body'
})
module.exports = {
@heygema
heygema / App.js
Last active January 30, 2018 06:27
RadioGroup and RadioItem
// @flow
import React from 'react';
import {RadioItem, RadioGroup} from './Radio';
type P = {};
type S = {};
class App extends React.Component<P, S> {
render() {
return (
@heygema
heygema / .eslintignore
Last active February 8, 2018 05:50
Eslint Setup
/node_modules
/coverage
/flow-typed/npm
/src/registerServiceWorker.js
*.json
@heygema
heygema / challenge.js
Last active April 4, 2018 04:53
KF coding challenge
// 1. getAverage;
let getAverage = array => array.reduce((a, b) => a + b, 0) / array.length
// 2. DigitsExplode
let explode = s => s.replace(/[0-9]/g, d => d.repeat(d));
// 3. Parse string to key value pairs
function wordsToObject(input) {
let arr = input.split(" ");
const L = arr.length;
type action =
| AddTodo
| DeleteTodo(int)
| CheckTodo(int)
| CheckAll
| HandleInput(string)
| ShowCompleted
| ShowDoing
| ShowAll;
@heygema
heygema / StringUtils.re
Last active May 29, 2018 10:44
my utils for string in ReasonML.
let split = (string) => {
let rec toList = (l, i) =>
switch (i) {
| 0 => l
| num => toList([string.[num - 1], ...l], num - 1)
};
toList([], string |> String.length)
};