Skip to content

Instantly share code, notes, and snippets.

@fleepgeek
fleepgeek / apps.py
Last active September 10, 2024 20:50
A Django Middleware to prevent multiple sessions for the same user. It automatically logs out the previous session and replaces it with the new session.
from django.apps import AppConfig
class ForumConfig(AppConfig):
name = 'forum'
# This function is the only new thing in this file
# it just imports the signal file when the app is ready
def ready(self):
import your_app_name.signals
@fleepgeek
fleepgeek / clear.txt
Created August 1, 2018 12:54 — forked from EQuimper/clear.txt
React-Native clear Watchman + Cache
watchman watch-del-all && rm -rf node_modules/ && yarn cache clean && yarn install && yarn start -- --reset-cache
@fleepgeek
fleepgeek / daily-ui.txt
Created August 15, 2018 16:39 — forked from Pustur/daily-ui.md
DailyUI – A list of design challenges
Sign Up
Credit Card Checkout
Landing Page (above the fold)
Calculator
App Icon
User Profile
Settings
404 page
Music Player
Social Share
@fleepgeek
fleepgeek / JSON_Encode_Decode.dart
Created November 14, 2018 22:12 — forked from Vloz/JSON_Encode_Decode.dart
Example of use of reviver and toEncodable functions, to encode and decode a JSON with a List of Object in dart
class MyListClass{
String value;
List<MyItemClass> items;
MyListClass(){}
MyListClass.fromRaw(Map value){
value = JSON.decode(value['value']);
items = JSON.decode(value['items'],reviver:(k,v){
@fleepgeek
fleepgeek / objects_and_arrays.js
Created January 28, 2019 10:36
A simple gist to show how to use JavaScript objects and arrays
/*
Objects are containers for named values called properties or methods.
Objects are mutable ie its values can be changed other js variables are immutable
Objects are passed/called by reference not value
eg var obj = {name: "John"};
var x = obj;
x.name = "Mike"; This would also change the value of obj.name to "Mike"
Primitive data types (number, boolean, string) are passed by value
Date, Math, Array, RegExp, etc are all objects
NB: Math does not inherit from Object.prototype because it is a global object
@fleepgeek
fleepgeek / isArmstrong.js
Last active January 29, 2019 15:43
A JavaScript function to check if a given number is an Armstrong number
function isArmstrong(num){
var numStr = num.toString();
var isArmstrongNum = false;
var sum = 0;
if(numStr.length === 3){
for(var i=0; i < numStr.length; i++) {
var n = parseInt(numStr.charAt(i));
sum += Math.pow(n, 3);
}
if(sum === num) {
@fleepgeek
fleepgeek / dom.js
Created January 30, 2019 11:08
A simple JavaScript file to show basic DOM operations.
/*The DOM is a hierachy your browser creates for every webpage
<head> and <body> are on the same level (3rd level)
*/
// var body = document.getElementsByTagName('body');
// body[0].bgColor = 'blue';
// console.log(body);
// var container = document.querySelector('.container');
// container.innerHTML = '<h1>Hello</h1>';
// console.log(container);
// var btnShow = document.querySelector(".btn-show");
// var box = document.querySelector(".box");
// btnShow.addEventListener("click", () => {
// box.classList.toggle("show");
// });
// var allows reassignment which could be harmful if unintentionally did it.
// var name = "John";
// var name = "Mike";
document.addEventListener('DOMContentLoaded', () => {
// setTimeout(() => {
// console.log("Hello");
// }, 2000);
// console.log("World");
// setInterval(() => {
// console.log("hi");
// }, 1000)
// console.log("World");
/*
ABOUT FUNCTIONS
---------------
While coding, we could notice there are some similar tasks we
do over and over again. An example would be looping.
Most of the time, we do the same thing:
- declare a counter variable
- check if is is less than the array length
- increment the counter until the condition is false
This tasks above is pretty much the same thing.