Skip to content

Instantly share code, notes, and snippets.

View spencerdeinum's full-sized avatar

Spencer Deinum spencerdeinum

View GitHub Profile
@spencerdeinum
spencerdeinum / sql_injection.php
Created September 7, 2015 18:09
Example of sql injection in PDO
<?php
$dbh = new PDO('mysql:host=localhost;dbname=injection', 'root');
if(isset($_GET['id'])) {
// Example of injectable sql query
foreach($dbh->query('select * from users where id = ' . $_GET['id'] . ' LIMIT 1') as $query) {
$user = $query;
}
}
@spencerdeinum
spencerdeinum / thumbs.sh
Last active August 29, 2015 14:25
Grab some youtube thumbs
#!/usr/bin/env bash
if [ $# -eq 0 ]; then
echo "Usage: thumbs.sh <youtube-video-id> ..."
exit 1
fi
function getThumbs() {
for i in {0..3}; do
wget http://img.youtube.com/vi/"$1"/"$i".jpg -O "$1"-"$i".jpg
@spencerdeinum
spencerdeinum / array.cpp
Created December 30, 2013 22:50
std::array
#include <array>
#include <iostream>
using namespace std;
template<class T, size_t Size>
T sum(array<T, Size> a)
{
T total = 0;
@spencerdeinum
spencerdeinum / for.cpp
Created December 30, 2013 19:41
c++ iteration
#include <vector>
#include <algorithm>
#include <iostream>
int main()
{
std::vector<int> vec = { 1, 2, 3, 4, 5 };
std::cout << "For loop, with auto" << std::endl;
for(auto iter = vec.begin(); iter != vec.end(); ++iter)
@spencerdeinum
spencerdeinum / reversemigration.php
Created August 2, 2013 17:22
Really terrible code, seriously just awful
<?php
class ReverseMigration_Task
{
function __construct()
{
$this->sql_types = array(
'int' => 'integer',
'varchar' => 'string',
@spencerdeinum
spencerdeinum / local.conf
Created June 17, 2013 15:11
/etc/fonts/local.conf
<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
<match target="font" >
<edit mode="assign" name="autohint"> <bool>true</bool></edit>
<edit mode="assign" name="hinting"> <bool>false</bool></edit>
<edit mode="assign" name="lcdfilter"> <const>lcddefault</const></edit>
<edit mode="assign" name="hintstyle"> <const>hintslight</const></edit>
<edit mode="assign" name="antialias"> <bool>true</bool></edit>
<edit mode="assign" name="rgba"> <const>rgb</const></edit>
@spencerdeinum
spencerdeinum / moment.js
Last active December 18, 2015 12:39
Moment js is awesome
$(function() {
$('#patient_age').on('change', function() {
var birth_year = moment().subtract('years', $(this).val());
birth_year.startOf('year');
$('#date_of_birth').val(birth_year.format('YYYY-MM-DD'));
});
_.contains(['name', 'type', 'mode_of_administration'], 'name') // => true
<?php
Route::secure('GET', 'patient/(:num)/prescriptions/(:num)/druglist',
array('as' => 'druglist-index', 'uses' => 'patient.prescriptions.druglist@index'));
Route::secure('POST', 'patient/(:num)/prescriptions/(:num)/druglist',
array('as' => 'druglist-create', 'uses' => 'patient.prescriptions.druglist@create'));
Route::secure('PUT', 'patient/(:num)/prescriptions/(:num)/druglist/(:num)',
array('as' => 'druglist-update', 'uses' => 'patient.prescriptions.druglist@update'));
➜ healthie git:(site/pcs) ✗ git add .
warning: You ran 'git add' with neither '-A (--all)' or '--ignore-removal',
whose behaviour will change in Git 2.0 with respect to paths you removed.
Paths like 'application/migrations/2013_05_21_171759_add_missing_fields_to_prescriptions.php' that are
removed from your working tree are ignored with this version of Git.
* 'git add --ignore-removal <pathspec>', which is the current default,
ignores paths you removed from your working tree.
* 'git add --all <pathspec>' will let you also record the removals.