Skip to content

Instantly share code, notes, and snippets.

View freewayz's full-sized avatar
🏠
Working from home

Peter Edache freewayz

🏠
Working from home
View GitHub Profile
@freewayz
freewayz / django_model_deletable.py
Created September 27, 2016 14:43
Django check if model has related object before Deleting the model
#After looking for a way to check if a model instance can be deleted in django ,
#i came across many sample, but was not working as expected. Hope this solution can help.
#Let start by creating an Abstract model class which can be inherited by other model
class ModelIsDeletable(models.Model):
name = models.CharField(max_length=200, blank=True, null=True, unique=True)
description = models.CharField(max_length=200, blank=True, null=True)
date_modified = models.DateTimeField(auto_now_add=True)
@freewayz
freewayz / aws-boto-s3-download-directory.py
Created October 6, 2016 15:35
Download files and folder from amazon s3 using boto and pytho local system
#!/usr/bin/env python
import boto
import sys, os
from boto.s3.key import Key
from boto.exception import S3ResponseError
DOWNLOAD_LOCATION_PATH = os.path.expanduser("~") + "/s3-backup/"
if not os.path.exists(DOWNLOAD_LOCATION_PATH):
// number to string, pluginized from http://stackoverflow.com/questions/5529934/javascript-numbers-to-words
window.num2str = function (num) {
return window.num2str.convert(num);
}
window.num2str.ones=['','one','two','three','four','five','six','seven','eight','nine'];
window.num2str.tens=['','','twenty','thirty','forty','fifty','sixty','seventy','eighty','ninety'];
window.num2str.teens=['ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen'];
@freewayz
freewayz / simple-oop.js
Created January 4, 2016 18:43
Simple OOP concept in javascript
//how i started understanding my javascript oop concept based on ES5
//welcome comment and and
var Bank = function(name,acct_bal){
this.name = name; this.acct_bal = acct_bal;
}
Bank.prototype.deposit = function(amount){
this.acct_bal += amount;
console.log("Deposited =$" + amount + "\nYour balance is $" + this.acct_bal);
@freewayz
freewayz / boto-s3-upload-directory.py
Created August 12, 2016 10:35
How to use python and amazon boto to upload the Amazon s3
DIR_TO_UPLOAD = 'project-dist'
def upload_percent_cb(complete, total):
sys.stdout.write('-')
sys.stdout.flush()
def remove_root_dir_from_path(c):
s = c.split('/')
s.remove(DIR_TO_UPLOAD)
@freewayz
freewayz / admin.py
Created November 12, 2017 06:43 — forked from mattlong/admin.py
Add a custom admin page for a model and link to it from the detail page
from functools import update_wrapper
from django.contrib import admin
from django.contrib.admin import ModelAdmin
from django.contrib.admin.templatetags.admin_urls import add_preserved_filters
from django.core.exceptions import PermissionDenied
from django.shortcuts import render
from myapp.models import Widget
from myapp.forms import ManageWidgetForm
@freewayz
freewayz / annotations.swift
Created September 9, 2017 20:11
My first two hours on swift
var shouldStoreDouble: Double = 200.0 // we restrict this by adding an annotation
print("Double annotation ", shouldStoreDouble);
// let see when we say our computer should create
// a memory space for string but we try to store an integer
var onlyStringPlease: String = "John"
print("String annotation ", onlyStringPlease)
@freewayz
freewayz / GWT Compiler Options
Created April 8, 2017 01:32 — forked from abdennebi/GWT Compiler Options
GWT Compiler Options
Source : https://developers.google.com/web-toolkit/doc/latest/DevGuideCompilingAndDebugging
java -cp gwt-dev.jar com.google.gwt.dev.Compiler
Missing required argument 'module[s]'
Google Web Toolkit 2.3.0
Compiler [-logLevel level] [-workDir dir] [-gen dir] [-style style] [-ea] [-XdisableClassMetadata] [-XdisableCastChecking] [-validateOnly] [-draftCompile] [-optimize level] [-compileReport] [-strict] [-localWorkers count] [-war dir] [-deploy dir] [-extra dir] module[s]
where
-logLevel The level of logging detail: ERROR, WARN, INFO, TRACE, DEBUG, SPAM, or ALL
-workDir The compiler's working directory for internal use (must be writeable; defaults to a system temp dir)
@freewayz
freewayz / flatten_array.py
Created February 12, 2017 23:59
Python implementation of flatten an array
def flatten_array(arr):
output = []
for val in arr:
if type(val) == list: # is the current value we are looking at is also a list
output.extend(flatten_array(val)) # then recursive call itself to start from
# the beginning and use python list extend
else:
output.append(val) # ok this is not a list just append to the bottom
return output
@freewayz
freewayz / capitalize-obj.js
Created October 11, 2016 12:43
Iterating over array of object and capitailizing the first leter
var myResponse = {"start_date":["A valid integer is required."],
"end_date":["A valid integer is required."], "commite":["Require commite."]}
//iterate over the serializer error message
for (var prop in myResponse) {
var errorValue = myResponse[prop];
//test if the current prop has an _ in it string value
var _pattern = /_/;
if (_pattern.test(prop)) {