Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Nkansah Rexford seanmavley

🏠
Working from home
Block or report user

Report or block seanmavley

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View UserProfile.py
from django import forms
from django.contrib.auth.models import User
class UserProfileForm(forms.ModelForm):
class Meta:
model = User
fields = ['first_name', 'last_name', 'email']
@seanmavley
seanmavley / filterchips.dart
Last active Jun 27, 2018
Dynamic list for FilterChips
View filterchips.dart
class ActorFilterEntry<Widget> {
const ActorFilterEntry(this.id, this.name);
final String name;
final int id;
}
class InterestsFilterPage extends State<InterestPage> {
...
List<Widget> actorWidgets(interest) {
View CBV for Mulitple Inline formsets
# models.py
from django.db import models
class Recipe(models.Model):
title = models.CharField(max_length=255)
description = models.TextField()
class Ingredient(models.Model):
View logECG model functions.py
@classmethod
def get_total_hours(self):
'''Sum of all hours ever added'''
return GhanaECG.objects.all().aggregate(Sum('off_hours'))
@classmethod
def get_today_hours(self):
'''Sum of all hours submitted today'''
end_time = datetime.now()
start_time = datetime(end_time.year,end_time.month,end_time.day)
@seanmavley
seanmavley / freeradius_monit
Created Dec 22, 2016
Monitor freeradius with Monit
View freeradius_monit
check process freeradius with pidfile /var/run/freeradius/freeradius.pid
start program = "/etc/init.d/freeradius start"
stop program = "/etc/init.d/freeradius stop"
if failed host 127.0.0.1 port 1812 type udp protocol radius secret testing123 then alert
if failed host 127.0.0.1 port 1812 type udp protocol radius secret testing123 then alert
View start dev server on reboot
#!/bin/bash
clear
cd /path/to your/virtual environment #path to your virtual environment
. bin/activate #Activate your virtual environment
cd /path/to your/project directory #After that go to your project directory
python manage.py runserver #run django server
After that save this file with .sh extension. I have saved this file as script.sh in the following example.
Run following command in terminal for giving execution permission to your script
@seanmavley
seanmavley / gulpfile.js
Created Jun 20, 2016
Reset build folder before gulp build then restart browser
View gulpfile.js
var gulp = require('gulp');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var del = require('del'); // rm -rf
var browser = require('browser-sync').create();
var port = process.env.SERVER_PORT || 3000;
gulp.task('clean', function() {
@seanmavley
seanmavley / views_forms.py
Last active May 23, 2016
Allow user submit form once per day
View views_forms.py
# The problem:
# A user has to be able to submit a form only once per day
# The solution - my approach
# A hidden form (connected to a kinda Control Model) is embedded in the normal form the user submits.
# Hidden form when submitted, triggers a save on a model ForeignKey'ed
# to the request.user
# Upon re-rendering form, Control Model is checked. If an object exist relating to user in context,
# no form shows in template
View phpStrtime in javascript.js
// first day of the month
var firstDayThisMonth = moment(firstDayThisMonth).startOf('month').toDate();
Go back and forth using the subtract() and add() with the endOf() and startOf():
// last day of previous month
var yesterMonthLastDay = moment(yesterMonthLastDay).subtract(1,'months').endOf('month').toDate();
@seanmavley
seanmavley / network_available.js
Created Mar 29, 2016
check network connectivit
View network_available.js
// Register listeners
window.addEventListener("offline", function(){
$('#globalDiv').hide();
$("#message").html('WARNING: Internet connection has been lost.').show();
});
window.addEventListener("online", function(){
$("#message").empty().hide();
$('#globalDiv').show();
});
You can’t perform that action at this time.