Skip to content

Instantly share code, notes, and snippets.

View schmkr's full-sized avatar

Alwin Schoemaker schmkr

View GitHub Profile
@gunnarlium
gunnarlium / JsonErrorHandler.php
Last active September 20, 2018 12:47
Exmple JsonErrorHandler for Silex (or any other app implementing HttpKernel)
<?php
namespace Aptoma;
use Silex\Application;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\HttpException;
/**
* JsonErrorHandler is able to capture exceptions and do smart stuff with them.
@Integralist
Integralist / 1. Custom Grunt Tasks - Gruntfile.js
Last active October 20, 2017 07:39
Example of how to structure your Grunt files
module.exports = function (grunt) {
// Project configuration.
grunt.initConfig({
// Store your Package file so you can reference its specific data whenever necessary
pkg: grunt.file.readJSON('package.json')
// ...tasks...
@schmkr
schmkr / Readme.md
Last active December 22, 2015 17:39
Example of Composer Satis with a deep SVN structure

Example of output when running:

bin/satis build satis.json ./web -vvv

Current output

Executing command (CWD): git describe --exact-match --tags
Executing command (CWD): git branch --no-color --no-abbrev -v
Executing command (CWD): hg branch
Scanning packages
@clouddueling
clouddueling / MainCtrl.js
Last active November 3, 2022 13:26
How to authenticate using AngularJS
controllers.controller('MainCtrl', function($scope, $location, Facebook, $rootScope, $http, $location, Upload, Auth, User, Question, Category, Serie, Record, Location, Popup, Process, Card, Question) {
$scope.$on('authLoaded', function() {
$scope.isExpert($scope.main.serieId);
$scope.isMember($scope.main.serieId);
});
$scope.loadAuth = function() {
Auth.load().success(function(data) {
$scope.main.user = data.user;
$scope.$broadcast("authLoaded");
@jed
jed / how-to-set-up-stress-free-ssl-on-os-x.md
Last active February 27, 2025 16:31
How to set up stress-free SSL on an OS X development machine

How to set up stress-free SSL on an OS X development machine

One of the best ways to reduce complexity (read: stress) in web development is to minimize the differences between your development and production environments. After being frustrated by attempts to unify the approach to SSL on my local machine and in production, I searched for a workflow that would make the protocol invisible to me between all environments.

Most workflows make the following compromises:

  • Use HTTPS in production but HTTP locally. This is annoying because it makes the environments inconsistent, and the protocol choices leak up into the stack. For example, your web application needs to understand the underlying protocol when using the secure flag for cookies. If you don't get this right, your HTTP development server won't be able to read the cookies it writes, or worse, your HTTPS production server could pass sensitive cookies over an insecure connection.

  • Use production SSL certificates locally. This is annoying

@kvz
kvz / exponential_backoff.php
Last active December 20, 2015 06:58
Tries your function several times with a bigger & bigger interval, until it does not throw an exception. Useful if you want to gracefully handle external services not being available, without actually building retries into your code. Works via Hollywood principle: Don't call us, we'll call you.
<?php
Class SomeClass() {
public function retry ($cb, $intervals = array(2, 4, 8, 16)) {
while ($intervals) {
if (!is_a($results = $cb(), 'Exception')) {
// good results, return them
return $results;
}
// failed, sleep for a larger & larger interval
$backoff = array_shift($intervals);
@lyrixx
lyrixx / post-checkout
Created June 26, 2013 13:37
Git post checkout
#!/bin/bash
# Put this file at: .git/hooks/post-checkout
# and make it executable
# You can install it system wide too, see http://stackoverflow.com/a/2293578/685587
PREV_COMMIT=$1
POST_COMMIT=$2
NOCOLOR='\e[0m'
@AMeijerNL
AMeijerNL / Base64 encode images (Mac terminal)
Created June 12, 2013 07:59
No installs required, just change the filename and you're all set! Even better: First compress / minify your images (using a tool like ImageOptim). Uncompressed .png file (200x70 pixels) outputs as 4764 characters The same file, compressed: outputs as 1749 characters! Which is only 36% of the original size!
$ openssl enc -base64 -in YOUR_FILE.png | tr -d '\n'
<?php
class Bundles implements ResponseClassInterface
{
protected $bundles = array();
public function addBundle($bundle)
{
$this->bundles[] = $bundle;
}
@desandro
desandro / require-js-discussion.md
Created January 31, 2013 20:26
Can you help me understand the benefit of require.js?

I'm having trouble understanding the benefit of require.js. Can you help me out? I imagine other developers have a similar interest.

From Require.js - Why AMD:

The AMD format comes from wanting a module format that was better than today's "write a bunch of script tags with implicit dependencies that you have to manually order"

I don't quite understand why this methodology is so bad. The difficult part is that you have to manually order dependencies. But the benefit is that you don't have an additional layer of abstraction.