Flask is a Python web framework that's steadily increasing in popularity within the webdev world. After reading so many great things about Flask, I decided to try it out myself. I personally find testing out a new framework difficult, because you must find a project complex enough to reveal the framework's quirks, but not so daunting as to take the fun out of the project. Luckily, my PHP/Wordpress powered website filled this role quite nicely - the website simply consists of static content, a contact page, and a blog. If I could not convert such a simple site over to Flask, I would immediately know that Flask and I would not make a good team.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Located in Lib/collections/__init__.py | |
################################################################################ | |
### OrderedDict | |
################################################################################ | |
class _OrderedDictKeysView(KeysView): | |
def __reversed__(self): | |
yield from reversed(self._mapping) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
$num_visits = $_SESSION['page_load_count']; | |
if(isset($_GET['reset']) || !isset($num_visits)){ | |
$num_visits = 0; | |
} | |
$num_visits++; | |
$_SESSION['page_load_count'] = $num_visits; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Implement a post-fix calculator using a stack. | |
#include<stdio.h> | |
#include<stdlib.h> | |
#include<stdbool.h> | |
#include<string.h> | |
#define MAX_ELEMENTS 100 | |
#define ROGUE_VALUE -99999 | |
typedef int stackdata_t; | |
typedef struct{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Kill and restart nginx | |
function restart_nginx(){ | |
pids=$(pidof nginx) | |
if [[ -n $pids ]]; | |
then | |
sudo kill -9 $pids | |
sudo service nginx restart | |
fi | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" use Ctrl+L to toggle the line number counting method | |
function! g:ToggleNuMode() | |
if &nu == 1 | |
set rnu | |
else | |
set nu | |
endif | |
endfunction | |
nnoremap <silent><C-L> :call g:ToggleNuMode()<cr> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE Customers | |
( | |
cust_id char(10) NOT NULL , | |
cust_name char(50) NOT NULL , | |
cust_address char(50) NULL , | |
cust_city char(50) NULL , | |
cust_state char(5) NULL , | |
cust_zip char(10) NULL , | |
cust_country char(50) NULL , | |
cust_contact char(50) NULL , |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function str_rot($s, $n = 13) { | |
static $letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; | |
$n = (int)$n % 26; | |
if (!$n) return $s; | |
if ($n == 13) return str_rot13($s); | |
for ($i = 0, $l = strlen($s); $i < $l; $i++) { | |
$c = $s[$i]; | |
if ($c >= 'a' && $c <= 'z') { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function str_rot($s, $n = 13) { | |
static $letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; | |
$n = (int)$n % 26; | |
if (!$n) return $s; | |
if ($n == 13) return str_rot13($s); | |
for ($i = 0, $l = strlen($s); $i < $l; $i++) { | |
$c = $s[$i]; | |
if ($c >= 'a' && $c <= 'z') { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################## | |
# Upstream must have unique name and unique socket. # | |
# The socket must match what is in the app's unicorn.rb file # | |
############################################################## | |
upstream railsapp1_server { | |
server unix:/tmp/railsapp1.sock fail_timeout=0; | |
} | |
############################## | |
# Rewrite www to non-www # |
NewerOlder