Skip to content

Instantly share code, notes, and snippets.

View macghriogair's full-sized avatar

Patrick macghriogair

  • Berlin
View GitHub Profile
@macghriogair
macghriogair / htpassword.rb
Created March 3, 2016 13:21
Create hash for a htpasswd auth file
#!/usr/bin/env ruby
unless ARGV.length == 2
puts "Dude, not the right number of arguments."
puts "Usage: ruby htpassword.rb username 'password'\n"
exit
end
username = ARGV[0]
passwd = ARGV[1]
@macghriogair
macghriogair / autoload.php
Last active November 23, 2021 07:21
basic autoload for php 5.2
<?php
/**
* A basic autoload implementation that should be compatible with PHP 5.2.
*
* @author pmg
*/
global $autoLoadFolders;
@macghriogair
macghriogair / AcmeDateTimeTest.php
Last active March 3, 2016 17:14
custom datetime class
<?php
namespace Acme;
class DateTimeTest extends \PHPUnit_Framework_TestCase
{
/** @test */
public function it_creates_from_unix_timestamp()
{
$unix = time();
@macghriogair
macghriogair / gist:7909f5c24f8c742ce2e6
Created March 20, 2016 14:23
stream csv file lumen
<?php
namespace App\Http\Controllers;
use App\Result;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\StreamedResponse;
class ExportController extends Controller
{
@macghriogair
macghriogair / ApiController.php
Created March 20, 2016 23:16
Lumen ApiController base
<?php
namespace App\Http\Controllers;
use Laravel\Lumen\Routing\Controller;
use Symfony\Component\HttpFoundation\StreamedResponse;
class ApiController extends Controller
{
/**
@macghriogair
macghriogair / Transformer.php
Last active March 20, 2016 23:18
basic transformer abstract
<?php
namespace App\Acme;
abstract class Transformer
{
public function transformCollection(array $items)
{
return array_map([$this, 'transform'], $items);
}
@macghriogair
macghriogair / test-class.sublime-snippet
Created February 12, 2017 16:23
sublime snippet phpunit test case
<snippet>
<content><![CDATA[
namespace Tests;
class ${TM_FILENAME/(.+)\..+|.*/$1/:name} extends \PHPUnit_Framework_TestCase
{
public function setUp()
{
}
@macghriogair
macghriogair / .babelrc
Last active August 23, 2017 07:45
Unit Test Vue + Webpack + Karma + Jasmine
{
"presets": [
[
"env",
{
"modules": false,
"targets": {
"browsers": [
"> 1%",
"last 2 versions",
@macghriogair
macghriogair / .eslintrc.json
Last active August 24, 2017 11:47
eslint config
{
"plugins": [
"jasmine",
"vue"
],
"env": {
"browser": true,
"es6": true,
"jasmine": true
},
@macghriogair
macghriogair / pollProgress.js
Created September 8, 2017 07:57
javascript polling w\ Promise
pollProgress(timeout, interval) {
let endTime = Number(new Date()) + (timeout || 3 * 1000 * 60)
interval = interval || 1000
let checkCondition = (resolve, reject) => {
this.fetchProgress(this.progressToken)
.then((response) => {
if (response.data.percentage >= 100) {
resolve(response)
} else if (Number(new Date()) < endTime) {
setTimeout(checkCondition, interval, resolve, reject)