Skip to content

Instantly share code, notes, and snippets.

@joequery
joequery / gist:3077833
Created July 9, 2012 17:43
Converting a simple website to Python Flask (backup gist!)

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.

@joequery
joequery / ordered_dict.py
Last active February 3, 2021 09:33
Python 3.5.0b1 OrderedDict implementation
# Located in Lib/collections/__init__.py
################################################################################
### OrderedDict
################################################################################
class _OrderedDictKeysView(KeysView):
def __reversed__(self):
yield from reversed(self._mapping)
@joequery
joequery / session_ex.php
Created November 4, 2015 09:07
PHP Session Example
<?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;
@joequery
joequery / gist:3421153
Created August 22, 2012 01:20
Postfix Calculator
// 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{
@joequery
joequery / gist:1607063
Created January 13, 2012 15:49
Convient bash functions for managing nginx and Unicorn
# Kill and restart nginx
function restart_nginx(){
pids=$(pidof nginx)
if [[ -n $pids ]];
then
sudo kill -9 $pids
sudo service nginx restart
fi
}
@joequery
joequery / gist:3418841
Created August 21, 2012 19:54
Vim Toggle Relative Line Numbers
" 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>
@joequery
joequery / sams.sql
Created November 30, 2015 17:04
Sams Teach Yourself SQL db dump
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 ,
@joequery
joequery / sombra_decrypt.php
Last active October 19, 2016 21:54
sombra decryption
<?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') {
@joequery
joequery / encrypt.php
Created October 19, 2016 21:12
sombra encrypt
<?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') {
@joequery
joequery / gist:1640945
Created January 19, 2012 16:19
Nginx individual site config for multiple rails apps with Unicorn
##############################################################
# 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 #