Skip to content

Instantly share code, notes, and snippets.

View therealklanni's full-sized avatar
👨‍💻
Learning Rust

Kevin Lanni therealklanni

👨‍💻
Learning Rust
View GitHub Profile
@therealklanni
therealklanni / RESTRequest.php
Created August 23, 2012 18:45
RESTRequest is a PHP class for handling cURL requests, specifically for use with RESTful web services. Supports session states.
<?php
class RESTRequest
{
public $response;
public $code;
private $handle;
private $session;
private $curlopts;
@therealklanni
therealklanni / clean_modules.sh
Last active October 17, 2020 22:32
Automatically remove stale modules (based on last-modified date)
# Remove stale modules directories, fast!
#
# Paste or source this file in your shell rc file (should work with Bash and ZSH)
#
# Optionally provide a path as first arg, and optionally a duration in days as second arg (default=30)
# e.g. clean_modules ~/github 60
# Remove the "-exec du" line for faster operation (i.e. do not print sizes, which can be slow)
PROJECT_DIR=~/Projects
# If `bfs` is installed, use that for faster searching
function asyncQuicksort(xs = []) {
// get the "head" and "tail" of the array
let [h, ...t] = xs
// create the initial Promise
return new Promise((res, rej) => {
// resolve immediately if "head" was undefined
if (!h) return res([])
// recurse for the "left" half of the partition
asyncQuicksort(t.filter(a => a <= h)).then(a => {
// recurse for the "right" half of the partition
@therealklanni
therealklanni / README.md
Last active January 27, 2020 17:07
Infinitely repeating arrays in JavaScript ... kind of

repeat(a) -> [a]

Inspired by Haskell, I wanted to see if I could replicate, using ES6 features, the repeat function:

repeat :: a -> [a]

So as you can see in repeat.js, I have done exactly that. However there are some caveats.

@therealklanni
therealklanni / ES6.sublime-build
Last active July 10, 2019 18:09
ES6 REPL in Sublime Text
{
"cmd": ["/usr/local/bin/babel-node $file"],
"shell": true,
"selector": "*.js"
}
@therealklanni
therealklanni / fixed-spec.js
Created January 28, 2019 00:43
Sudoku Checker
import { sudokuVerifier } from '../src/sudoku_verifier'
import problems, { sudoku } from '../problems'
function assertValid(problem, solution) {
expect(
sudokuVerifier({ problem, solution })
).toEqual({ status: 'valid', invalidIndexes: [ ] })
}
function assertIncomplete(problem, solution) {
@therealklanni
therealklanni / proxy.php
Created November 22, 2011 04:53
Stupidly simple PHP proxy
<?php
// Stupidly simple PHP proxy for AJAX (HTTP GET) requests. Written by Kevin Lanni.
$dest = ''; // Set to the remote script URL (i.e. http://remotehost.com/some.php)
$a = array();
foreach ($_GET as $k=>$v) {
$a[] = "{$k}={$v}";
}

Keybase proof

I hereby claim:

  • I am therealklanni on github.
  • I am therealklanni (https://keybase.io/therealklanni) on keybase.
  • I have a public key ASBtBpAqGlRXLoRQ-cZhbgTarUvu5VJIqMslZcPK0W6Bpgo

To claim this, I am signing this object:

@therealklanni
therealklanni / using-git-guppy.md
Last active September 5, 2017 09:02
Supercharge your git hooks with gulp — Introducing git-guppy

Supercharge your git hooks with gulp

Introducing git-guppy

Automate your developer workflow with git-guppy. git-guppy allows you to add git-hooks to your project repository that are automatically installed when users clone and install your repository, so you won't have to worry about developers skipping essential workflow steps and bypassing your project guidelines.

Getting Started

So let's use a unit test scenario to illustrate an example. We're going to run unit tests before every commit (pre-commit hook) and reject the commit if the tests fail (giving the developer a chance to fix their tests before committing broken code).

@therealklanni
therealklanni / JSONP_Example.php
Created November 23, 2011 23:42
Simple public Web API in PHP using JSONP
<?php
/* JSONP_Example.php
* Author: Kevin Lanni
* Description: Demonstrates how to create a simple public Web API using JSONP responses
* This is useful for opening Web APIs for public use without the need for proxying or other SOP work-arounds.
* This example does not demonstrate API keys or any other method of authentication.
*/
// Supply a header to set the proper expectation for the client browser
header('Content-Type: application/json');