Skip to content

Instantly share code, notes, and snippets.

View encodes1's full-sized avatar

Mark Tooth encodes1

  • SG World
  • Stoke-on-Trent
View GitHub Profile
@encodes1
encodes1 / gist:5686112
Created May 31, 2013 16:21
check allowed extensions flask / python returns true if in allowed list and false if not . (to find ext) and not in allowed list
def allowed_file(filename):
allowed = app.config['ALLOWED_EXTENSIONS']
return '.' in filename and filename.rsplit('.', 1)[1] in allowed
ZSH_THEME_GIT_PROMPT_PREFIX="%{$reset_color%}%{$fg[cyan]%}["
ZSH_THEME_GIT_PROMPT_SUFFIX="]%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}*%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN=""
#Customized git status, oh-my-zsh currently does not allow render dirty status before branch
git_custom_status() {
local cb=$(current_branch)
if [ -n "$cb" ]; then
echo "$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_PREFIX$(current_branch)$ZSH_THEME_GIT_PROMPT_SUFFIX"
@encodes1
encodes1 / prime2.c
Created May 10, 2013 12:48
Week 1 - Challenge 1 - solution 2
#include<stdio.h>
#include<math.h>
int main()
{
int n, i = 3, x, c;
char prime;
printf("Enter the number of prime numbers required\n");
scanf("%d",&c);
printf("Enter the last number\n");
@encodes1
encodes1 / prime.c
Created May 10, 2013 12:29
Week 1 - Challenge 1
#include<stdio.h>
int main()
{
int n, i = 3, x, c;
printf("Enter the start number\n");
scanf("%d",&c);
printf("Enter the last number\n");
scanf("%d",&n);
@encodes1
encodes1 / squares_in_a_grid.py
Created May 9, 2013 13:02
Week 1 - Challenge 2 - solution
# 3 x 3 grid, has 1 3*3, 4 2*2, 9 1*1
# the easy way to calculate this is to subtract the number you need from the width
# so 2 x 2 in a 3 x 3 grid would be (3 -(2-1)) * (3 -(2-1)) = 4
gridSize = 9
total = 0
# first we start with the smallest square and go up to the widest square
for x in range(1,gridSize+1):
if x ==1:
total = total + (gridSize * gridSize)
@encodes1
encodes1 / Week 1 - Challenge 5 - Solution.rb
Created May 9, 2013 10:09
Week 1 - Challenge 4 - Solution. This is a basic attempt at this solution. It does not take into account brackets. allthough i'm working on finding a nice solution to that. First time i've used ruby as well. some nice language features :)
nums = [100, 13.2, 92.123, 0.124, 12]
ops = ['+','/','-','*']
highest = 0
eq = ''
highesteq = ''
perms = nums.to_a.permutation.map()
perm2 = ops.to_a.permutation.map()
perms.each{ | n |
perm2.each { | o |
eq = ''
@encodes1
encodes1 / .htaccess
Created September 18, 2012 12:57
.htaccess performace / speed tweaks
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
@encodes1
encodes1 / mark.zsh-theme
Created August 17, 2012 15:17
zsh theme
ZSH_THEME_GIT_PROMPT_PREFIX="[%{$fg_bold[green]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}]"
ZSH_THEME_GIT_PROMPT_DIRTY=" %{$fg[red]%}*"
ZSH_THEME_GIT_PROMPT_CLEAN=""
function prompt_char {
if [ $UID -eq 0 ]; then echo "%{$fg[red]%}#%{$reset_color%}"; else echo $; fi
}
PROMPT='%(?, ,%{$fg[red]%}FAIL: $?%{$reset_color%}