Skip to content

Instantly share code, notes, and snippets.

View xeoncross's full-sized avatar

David Pennington xeoncross

View GitHub Profile
@kylekrall
kylekrall / gist:8946831
Last active August 29, 2015 13:56
Logstash + Kibana + Nginx + Google_Auth_Proxy - Authentication w/ Google OAuth2 using bit.ly's google_auth_proxy - Restrict dashboard editing to specific users
location ~ ^/kibana-int/dashboard/.*$ {
set $privs NA; # by default, no privs needed
proxy_read_timeout 90;
if ( $request_method ~ (PUT|DELETE) ) {
set $privs M; # M for modify
}
if ( $remote_user ~ (admin1|admin2|admin3|admin4) ) {
set $privs "${privs}Y"; # Y for admin
}
@mchamplain
mchamplain / gist:9105581
Created February 20, 2014 01:56
Regex to parse a youtube URL and extract the video id
<?php
public static function getYoutubeVideoIdFromUrl($url)
{
// Check for a valid youtube url
$rx = '~ # Using ~ to avoid LTS (http://en.wikipedia.org/wiki/Leaning_toothpick_syndrome)
^http(?:s)?:// # Mandatory protocol (optional ssl)
(?:www\.)? # Optional subdomain
(?:youtube\.com/watch(?:/)?\?v=|youtu\.be/) # mandatory domain & path for youtube or shortlink for youtu.be
([^?&]+) # video id as capture group 1
~x';
@pandauxstudio
pandauxstudio / gist:9101728
Created February 19, 2014 21:14
Timezone-Adjusted Timestamp
// Source: http://stackoverflow.com/questions/2834353/php-how-do-i-convert-a-server-timestamp-to-the-users-timezone
$timestamp = time();
echo 'Unix timestamp: ' . $timestamp;
$dt = DateTime::createFromFormat('U', $timestamp);
$dt->setTimeZone(new DateTimeZone($timezone));
$adjusted_timestamp = $dt->format('U') + $dt->getOffset();
echo ' Timestamp adjusted for: ' . $timezone . $adjusted_timestamp;
@sich
sich / gist:9178007
Last active August 29, 2015 13:56
Perfectly balanced tree
function tree(&$tree, $num_nodes)
{
if($num_nodes == 0)
return null;
$left = (int)($num_nodes / 2);
$right = $num_nodes - $left -1;
$tree[]['value'] = (int)(mt_rand( 1, 50) / $num_nodes+1);
$last = count($tree)-1;
@tegansnyder
tegansnyder / translation-helpers.sh
Created March 10, 2014 15:34
Find extensions that include translation helpers
echo "Community Namespace"
echo "------------------------------------------"
cd app/code/community
for i in $(ls -d */)
do
echo ${i%%/} && fgrep -Rho --include='*.php' '__(' ${i%%/} | wc -l
done
echo
echo "Local Namespace"
echo "------------------------------------------"
@wgbartley
wgbartley / doorbell2SMS.cpp
Last active August 29, 2015 13:57
Doorbell-to-SMS
/**
* This is a simple "sketch" that calls a web page when a button is pressed. It is a proof-of-concept
* for my boss and hastily written in about 2 hours. The remote URL is a PHP script that handles
* making the API calls to a remote SMS-messaging service.
*
* I'm sure it could make use of interrupts somehow, but I'm not sure how off the top of my head.
*
* It uses the onboard RGB LED as status display:
* - Red = Waiting to be pressed
* - Green = Making HTTP request
<?php
/**
* A class for validating and filtering user input
*
* This class acts as a wrapper for the filter functions in >= PHP 5.2 or PECL.
* If an optional array of required items is passed to the class constructor,
* the Pos_Validator object generates an array of missing items.
*
* The first argument for each validation method is the name of the input
* field or URL variable, which is always required. Many methods accept
@lastguest
lastguest / call_closure.php
Last active August 29, 2015 13:57
Javascript like scope heritage
<?php
function foobarbaz(){
// Extract environment object to local scope (not mandatory, you can access the parent scope via $this. Ex. $this->foo )
extract((array)$this);
var_dump($foo, $bar, $baz);
}
<?PHP
class F {
public static function curry($f) {
return new F($f);
}
private function __construct($f, $args = []) {
$this->f = $f;
$this->args = $args;
@bobbydeveaux
bobbydeveaux / bubble.php
Created March 13, 2014 21:26
PHP Bubble Sort
<?php
function main() {
for ($c=0;$c<1000000;$c++) {
bubble();
}
}
function bubble() {
$array = array(3,4,1,3,5,1,92,2,4124,424,52,12);