Skip to content

Instantly share code, notes, and snippets.

View pcnate's full-sized avatar

Nathan Baker pcnate

View GitHub Profile
@earthgecko
earthgecko / bash.generate.random.alphanumeric.string.sh
Last active June 21, 2024 07:34
shell/bash generate random alphanumeric string
#!/bin/bash
# bash generate random alphanumeric string
#
# bash generate random 32 character alphanumeric string (upper and lowercase) and
NEW_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
# bash generate random 32 character alphanumeric string (lowercase only)
cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 32 | head -n 1
@AmyStephen
AmyStephen / PHP Unit Testing with $_FILES and move_uploaded_file.php
Last active December 16, 2015 23:59
I ran into a couple of challenges for how to unit test my FileUpload package.: mocking $_FILES and PHP function "move_uploaded_file." What I ended up doing was establishing a property named $file_array in my upload class. In the constructor, I set that property to the value contained in $_FILES. Then, I allowed it to be overridden by the value i…
<?php
/**
* $files_array contains $_FILE superglobal
*
* Helps with Unit Testing
*
* @var array
*/
protected $file_array = array();
@croxton
croxton / leaflet_custom_zoom_levels.js
Last active May 20, 2022 16:13
Leaflet custom zoom levels
/*
Most map tile providers use 256px square tiles so Leaflet's basic zoom algorithm looks like this:
256 * Math.pow(2, zoom);
If you're working with vector layers you can extend one of leaflet's default CRSs
and make it return tile sizes in smaller increments. This can be very helpful when using
fitBounds() with layer groups, so the zoomed group fits better within the map bounds:
E.g., extending L.CRS.EPSG3857 (the default CRS):
@joshbeckman
joshbeckman / gist:7867934
Created December 9, 2013 06:00
Handle drag-n-drop JSON file upload and parsing with javascript.
if (window.File && window.FileReader && window.FileList && window.Blob) {
// Great success!
function handleJSONDrop(evt) {
evt.stopPropagation();
evt.preventDefault();
var files = evt.dataTransfer.files;
// Loop through the FileList and read
for (var i = 0, f; f = files[i]; i++) {
// Only process json files.
@mlynch
mlynch / autofocus.js
Last active August 24, 2022 15:03
AngularJS Autofocus directive
/**
* the HTML5 autofocus property can be finicky when it comes to dynamically loaded
* templates and such with AngularJS. Use this simple directive to
* tame this beast once and for all.
*
* Usage:
* <input type="text" autofocus>
*
* License: MIT
*/
function check(resolved) {
console.log(resolved);
var tag = resolved.split('/').pop(-1);
var latest = tag.slice(1);
var current = atom.getVersion();
if (latest != current) {
atom.notifications.addInfo('new version available: ' + resolved);
// TODO detect platform
// var filename = 'atom-amd64.deb'; // or 'atom.x86_64.rpm'
// var url = 'https://github.com/atom/atom/releases/download/' + tag + '/' + filename;
@zamicol
zamicol / post-receive
Last active July 22, 2022 21:47
Git push to prod
#!/bin/sh
# Use git to push to deploy (aka git push to prod)
# Use 'git push remote master' to push to deploy
# This script only deploys on pushes to master.
#
# HOWTO:
# On your server to deploy, create a bare git directory
# (somewhere like /var/git/<gitProject>)
# Your depoly directory (like /var/www) should be somewhere other than your git repo.
@magnetikonline
magnetikonline / README.md
Last active June 5, 2024 01:05
NSSM - the Non-Sucking Service Manager cheatsheet.
@NightOwlPrgmr
NightOwlPrgmr / User Defined Key Bindings.json
Last active June 4, 2016 06:21
Sublime Text User Keymap
[
{ "keys": ["alt+shift+up"], "command": "select_lines", "args": {"forward": false} },
{ "keys": ["alt+shift+down"], "command": "select_lines", "args": {"forward": true} },
{ "keys": ["alt+shift+o"], "command": "run_macro_file", "args": {"file": "Packages/User/output.sublime-macro"} },
{ "keys": ["alt+shift+c"], "command": "run_macro_file", "args": {"file": "Packages/User/console.sublime-macro"} },
{ "keys": ["ctrl+shift+t"], "command": "open_recent_file", "args": {"index": 0 } }
]
@cutaway
cutaway / bigip_decode_cookie.py
Created July 2, 2015 18:33
Deocde BigIP cookies to internal IP address and port number