Skip to content

Instantly share code, notes, and snippets.

View nedf23's full-sized avatar

Ned Fenstermacher nedf23

  • State College, PA
View GitHub Profile
@nedf23
nedf23 / Preferences.txt
Last active December 17, 2015 04:39
My Sublime Text User Settings
{
"color_scheme": "Packages/Theme - Afterglow/Afterglow.tmTheme",
"draw_white_space": "all",
"enable_tab_scrolling": false,
"font_face": "Monoid",
"font_size": 14,
"highlight_line": true,
"ignored_packages":
[
"CSS",
@nedf23
nedf23 / function_key_trap.js
Created May 10, 2013 15:02
A CodePen by Ned Fenstermacher. Trap Function Keys
var funcKeys = {"114": "F3", "115": "F4", "116": "F5", "117": "F6", "118": "F7"};
$(document).keydown(function(e) {
if (e.keyCode == 114 ||
e.keyCode == 115 ||
e.keyCode == 116 ||
e.keyCode == 117 ||
e.keyCode == 118)
{
e.preventDefault();
event.returnValue = false;
@nedf23
nedf23 / multiple_statements.sql
Last active December 17, 2015 08:59
MySQL Triggers
DELIMITER $$
CREATE TRIGGER name_of_trigger
AFTER INSERT ON the_table_name
FOR EACH ROW
BEGIN
INSERT INTO the_other_table_name
(the_column, another_column)
VALUES
(1234, NOW());
@nedf23
nedf23 / temp_select.sql
Created June 19, 2013 14:24
MySQL Temporary Table From Select Statement
CREATE TEMPORARY TABLE table_name AS (
-- Your select
);
@nedf23
nedf23 / regex.txt
Created August 23, 2013 02:49
Get the containing contents of a tag with a positive lookbehind and positive lookahead.
(?<=href=").*(?=")
@nedf23
nedf23 / query.sql
Created November 6, 2013 12:50
Select Random Row
SELECT r.*
FROM random AS r
JOIN (SELECT RAND() * (SELECT MAX(id) FROM random) AS id) AS r2
WHERE r.id >= r2.id
LIMIT 1;
@nedf23
nedf23 / getFile.php
Created May 14, 2014 14:23
Access file that is in a non-public directory.
<?php
$file = '/location/to/the/file.pdf';
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
@nedf23
nedf23 / .bash_profile
Last active August 29, 2015 14:07
My Mac Profile Files
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/[\1]/'
}
txtblk='\e[0;30m' # Black - Regular
txtred='\e[0;31m' # Red
txtgrn='\e[0;32m' # Green
txtylw='\e[0;33m' # Yellow
txtblu='\e[0;34m' # Blue
txtpur='\e[0;35m' # Purple
@nedf23
nedf23 / remove_dups.sql
Created October 22, 2014 14:49
Remove duplicates from a table.
DROP TABLE IF EXISTS tmp_table;
CREATE TEMPORARY TABLE tmp_table (id INT);
INSERT tmp_table
SELECT id
FROM table_a t1
WHERE EXISTS (
SELECT *
FROM table_a t2
WHERE t2.some_id = t1.some_id
@nedf23
nedf23 / function.php
Last active August 29, 2015 14:08
Check a multidimensional array column for an unique value for the last specific number of elements.
<?php
function check_column_last_values_unique($arr, $column, $last)
{
$data = array_splice($arr, -$last);
$values = array_map(function($a) use ($column) { return $a[$column]; }, $data);
$unique = array_unique($values);
if (count($unique) == 1) {
return "true";