Skip to content

Instantly share code, notes, and snippets.

View MattSandy's full-sized avatar
💭
Hungry

Matt Sandy MattSandy

💭
Hungry
View GitHub Profile
@MattSandy
MattSandy / function_threading.php
Last active August 29, 2015 14:04
Threaded Downloads with Curl
<?php
function thread_download($file, $filename)
{
$url = $file;
$headers = get_headers($url,1);
//print_r($headers);
$bytes = $headers['Content-Length'][1];
//echo $bytes . "|";
for($i=0;$i<$bytes-1;$i+=204800)
{
@MattSandy
MattSandy / header.php
Last active August 29, 2015 14:05
Mobile Redirect
<?php
if(preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i',$useragent)||preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt
@MattSandy
MattSandy / quickstart.php
Last active May 26, 2020 17:57
Object Oriented Database Connection Quickstart
<?php
define('DB_NAME', 'zip');
/** MySQL database username */
define('DB_USER', '*****');
/** MySQL database password */
define('DB_PASSWORD', '*****');
/** MySQL hostname */
@MattSandy
MattSandy / gist:0b43f602e69e09e86aff
Last active August 29, 2015 14:09
Return Date Range Array
<?php
function createDateRangeArray($startDate,$endDate)
{
$range[0] = $startDate;
$startDateInt = preg_replace('/[^0-9]/', '', $startDate);
$endDateInt = preg_replace('/[^0-9]/', '', $endDate);
if($endDateInt>$startDateInt)
{
while($range[count($range)-1]!=$endDate)
@MattSandy
MattSandy / split.bash
Created April 28, 2015 15:58
Split CSV by Column Value
awk -F"," 'NR>1 {print $0 >> ($1 ".csv"); close($1 ".csv")}' file.csv
@MattSandy
MattSandy / match_inverval.R
Created July 7, 2015 02:04
Match repeated values in a vector based on a specified interval
vector <- c(10,1,0,10,0,0,10,0,0,10)
match_interval(vector,3))
match_interval <- function (vector, interval) {
matches <- c()
for(i in 1:interval) {
if(sd(vector[seq(i,length(vector),interval)])==0) {
matches[length(matches)+1] <- vector[i]
}
}
@MattSandy
MattSandy / find_patterns.R
Last active August 29, 2015 14:24
Find repeating patterns in an R vector from a vector of intervals to check.
vector <- c(10,1,0,10,0,0,10,0,0,10)
matches <- find_patterns(vector,seq(2,3))
find_patterns <- function (vector, intervals) {
matches <- matrix(c(NA, NA), nrow=1, ncol=2)
for(interval in intervals) {
for(i in 1:interval) {
if(sd(vector[seq(i,length(vector),interval)])==0) {
if(is.na(matches[1,1])) {
matches[1,] <- c(vector[i],interval)
@MattSandy
MattSandy / vector_break.R
Last active August 29, 2015 14:26
Breaks a vector into defined segment lengths
#Define the interval to cycle through
interval <- 30
#Replace sample_vector with your vector
sample_vector <- runif(100, 1, 10)
#Loop through each break in the sequence
for(i in seq(1,length(sample_vector),interval)) {
#Used to prevent the sequence from extending beyond the remainders
if(i+interval>=length(sample_vector)) {
#Vector access for this sequence is as follows:
print(sample_vector[i:length(sample_vector)])
#Route port 3000 to 80
sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000
#Search for running node.js processes
ps aux | grep node
#Kill process
kill -9 [id]
#Run node.js after closing shell
@MattSandy
MattSandy / dokku
Last active September 20, 2015 19:34
//server
sudo apt-get update
sudo apt-get install lxc wget bsdtar curl
sudo apt-get install linux-image-extra-$(uname -r)
sudo apt-get install gcc
wget -qO- https://raw.github.com/progrium/dokku/master/bootstrap.sh | sudo bash
//user