Skip to content

Instantly share code, notes, and snippets.

Avatar
😎
The wise are guided by reason

Laban Labohkip81

😎
The wise are guided by reason
View GitHub Profile
@Labohkip81
Labohkip81 / gist:e7ad366d3a83ab618f25dfdaf51f0ed9
Created Aug 8, 2021
Return username and token in django rest framework
View gist:e7ad366d3a83ab618f25dfdaf51f0ed9
from rest_framework.authtoken.views import ObtainAuthToken
class CustomAuthToken(ObtainAuthToken):
def post(self, request, *args, **kwargs):
serializer = self.serializer_class(
data=request.data, context={"request": request}
)
serializer.is_valid(raise_exception=True)
user = serializer.validated_data["user"]
View Cheza Footer
View remove-all-from-docker.sh
# Stop all containers
docker stop `docker ps -qa`
# Remove all containers
docker rm `docker ps -qa`
# Remove all images
docker rmi -f `docker images -qa `
# Remove all volumes
View sendtext.py
import africastalking
username = "africa username" # use 'sandbox' for development in the test environment
# use your sandbox app API key for development in the test environment
api_key = "africa's talking api key"
africastalking.initialize(username, api_key)
# # Use the service synchronously
@Labohkip81
Labohkip81 / admin.py
Last active Sep 24, 2019 — forked from wsvincent/admin.py
Django Custom User Model for any new project
View admin.py
# users/admin.py
from django.contrib import admin
from django.contrib.auth import get_user_model
from django.contrib.auth.admin import UserAdmin
from .forms import CustomUserCreationForm, CustomUserChangeForm
from .models import CustomUser
class CustomUserAdmin(UserAdmin):
add_form = CustomUserCreationForm
@Labohkip81
Labohkip81 / main.kt
Created Aug 12, 2018
AdvancedThreadbareDemo created by Labohkip81 - https://repl.it/@Labohkip81/AdvancedThreadbareDemo
View main.kt
class Shape {
var numberOfSides = 0
fun simpleDescription() =
"A shape with $numberOfSides sides."
}
var shape = Shape()
shape.numberOfSides = 7
println(shape.simpleDescription())
@Labohkip81
Labohkip81 / main.kt
Created Aug 12, 2018
AdvancedThreadbareDemo created by Labohkip81 - https://repl.it/@Labohkip81/AdvancedThreadbareDemo
View main.kt
Empty file
@Labohkip81
Labohkip81 / Readln function.kt
Created Aug 11, 2018
This program expounds on the usage of the readln function in kotlin
View Readln function.kt
//the readline function reads data input by the user into the keyboard
//this is similar to the scanner class in java.
fun main(args :Array<String>){
print("Enter a number")
val dataInput = readLine()
println()
print("Enter the second number")
val secondNumber = readLine()
println(dataInput)
@Labohkip81
Labohkip81 / Packt book projects_.idea_kotlinc.xml
Created Aug 8, 2018
Kotlin practice files.Codes are well commented thus can be used for revision
View Packt book projects_.idea_kotlinc.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Kotlin2JvmCompilerArguments">
<option name="jvmTarget" value="1.8" />
</component>
<component name="KotlinCommonCompilerArguments">
<option name="apiVersion" value="1.2" />
<option name="languageVersion" value="1.2" />
</component>
</project>