Skip to content

Instantly share code, notes, and snippets.

View alairock's full-sized avatar

Skyler Lewis alairock

View GitHub Profile
@alairock
alairock / RecurseTreeCrawl.sql
Last active February 3, 2017 19:30
Recursive tree crawling in Postgres.
WITH RECURSIVE file_depth
AS (
SELECT
id,
parent_folder_id,
1 AS depth
FROM files
WHERE files.parent_folder_id = '0'
UNION
@alairock
alairock / rsa.py
Last active July 2, 2022 05:15
Simplify RSA encode and decode messages with the python rsa library.
import base64
import os
import rsa
def load_priv_key(path):
path = os.path.join(os.path.dirname(__file__), path)
with open(path, mode='rb') as privatefile:
keydata = privatefile.read()
return rsa.PrivateKey.load_pkcs1(keydata)

Keybase proof

I hereby claim:

  • I am alairock on github.
  • I am alairock (https://keybase.io/alairock) on keybase.
  • I have a public key ASBhALIeRnQkHI9MccUghiVQ9kCz14yoViFb1wNaXWrA-go

To claim this, I am signing this object:

@alairock
alairock / generator.php
Last active February 3, 2017 19:31
Using a Generator in PHP. Helpful when you need to work on hundreds....thousands....millions of records. Don't load them all into memory all at once. Work on them one at a time!
<?php
$usersQuery = \App\User::query();
$usersQuery->where('type', '=', 'client');
foreach(generate($usersQuery) as $user) {
// Do something with that user
}
@alairock
alairock / Stripe.php
Last active August 29, 2020 19:37
Get a Stripe token in PHP/Laravel. Helpful when testing.
<?php
Route::get('/stripetoken', function()
{
$client = new \GuzzleHttp\Client();
$pubKey = 'pk_test_xxxxxxxxxxxxx';
$cardNumber = "4242424242424242";
$cvc = "123";
$expMonth = "11";
$expYear = "2018";
@alairock
alairock / background.js
Created October 30, 2015 16:10 — forked from danharper/background.js
Bare minimum Chrome extension to inject a JS file into the given page when you click on the browser action icon. The script then inserts a new div into the DOM.
// this is the background code...
// listen for our browerAction to be clicked
chrome.browserAction.onClicked.addListener(function (tab) {
// for the current tab, inject the "inject.js" file & execute it
chrome.tabs.executeScript(tab.ib, {
file: 'inject.js'
});
});
@alairock
alairock / styles.less
Last active October 3, 2019 15:49
Atom.io custom styling.
/*
* Your Stylesheet
*
* This stylesheet is loaded when Atom starts up and is reloaded automatically
* when it is changed.
*
* If you are unfamiliar with LESS, you can read more about it here:
* http://www.lesscss.org
*/

PHPUnit API reference

  • version 3.6

TODO

Check those constraints:

$this-&gt;anything()
@alairock
alairock / funky-fresh.js
Last active February 3, 2017 19:24
Custom parallax effect
/**
* Main JS file for Casper behaviours
*/
$(document).ready(function(){
var lastScrollTop = 0;
$(window).scroll(function(event){
var st = $(this).scrollTop();
var scrolli = st/1.5;
scrollicious = $(".cover-image > img").css({"top": scrolli + "px"});
if (st > lastScrollTop){
@alairock
alairock / GeoCaching API
Last active December 19, 2015 11:09
GeoCaching via CakePHP. Shows how to use connect via Oauth, get the token, and use the token to process a post request.
<?php
//Place the following line above the class:
//App::import('Vendor', 'OAuth/OAuthClient');
//OAuth component found here: http://code.42dh.com/oauth/
public function index() {
$data = array(
'AccessToken' => $this->Session->read('access_token'),
'Usernames' => array('alairock'),