Skip to content

Instantly share code, notes, and snippets.

View koenpunt's full-sized avatar
:octocat:
...

Koen Punt koenpunt

:octocat:
...
View GitHub Profile
# Basic regex + Ruby method to strip textile formatting.
# Handles all test cases at http://hobix.com/textile/ down to "Phrase Attributes."
def strip_textile(text)
text.gsub(/\b[_+^*~@%\-]{1,2}|[_+^*~@%\-]{1,2}\b|\b\?\?|\?\?\b|h\d\.\s|bq.\s|fn\d\.\s|\D\{.*\}\.\s?|\{.*\}\.\s?|\%\{.*\}|\D\(.*\)\.\s?|\{%.*\%\}\s|<.*?>/, "")
end
@koenpunt
koenpunt / UIImageView+imageDimensions.swift
Created September 3, 2015 14:44
UIImageView extension for calculated UIImageSize
//
// UIImageView+imageFrame.swift
// Tindex
//
// Created by Koen Punt on 24-08-15.
// Copyright (c) 2015 Koen Punt. All rights reserved.
//
import UIKit
require 'active_support/inflector'
guard 'rspec', :version => 2 do
# ...
# entries auto-generated after running "guard init rspec"
# ...
watch(%r{^spec/factories/(.+)\.rb$}) do |m|
%W[
spec/models/#{m[1].singularize}_spec.rb
spec/controllers/#{m[1]}_controller_spec.rb
@Kalyse
Kalyse / compile.js
Created March 12, 2012 14:26
Node Less Compiler
var fs = require('fs'), // file system access
path = require('path'),
less = require('less'); // less processor
var options = {
compress: true,
optimization: 1,
silent: false
};
@metakeule
metakeule / monitrc
Created March 14, 2012 13:21
node app as daemon with nvm, upstart and monit
# /etc/monit/monitrc (excerpt)
check process node-app with pidfile /var/run/node-app.pid
start program = "/sbin/start node-app" with timeout 5 seconds
stop program = "/sbin/stop node-app"
if failed port 3000 protocol HTTP
request /
with timeout 3 seconds
then restart
if cpu > 80% for 10 cycles then restart
module ActiveRecord::ConnectionAdapters
class Mysql2Adapter
alias_method :execute_without_retry, :execute
def execute(*args)
execute_without_retry(*args)
rescue Mysql2::Error => e
if e.message =~ /server has gone away/i
warn "Server timed out, retrying"
reconnect!
@fcoury
fcoury / alias.sh
Created March 30, 2012 19:42
Starts foreman when there are multiple Procfiles
#
# zsh function to start Foreman based on whether or not
# you have multiple Procfiles
#
# we are adopting this schema of having environment
# specific Procfiles:
#
# config/development.proc
# config/stage.proc
# config/production.proc
@rooftopsparrow
rooftopsparrow / gist:2956428
Created June 19, 2012 20:42
Telling TextMate to ignore <script type="text/template"> tags as javascript and instead highlight as html.

TextMate by default will highlight anything in a <script> tag as javascript. But for Backbone.js and other javascript MVC frameworks, the script tag is used as a template container. So this will remove javascript highlighting and use html highlighting instead for any <script type="text/template"> tag.

Replace this line in the Bundle Editor for HTML language:

begin = '(?:^\s+)?(<)((?i:script))\b(?![^>]*/>)';

with this line:

@koenpunt
koenpunt / basename.conf
Created October 29, 2012 16:38
Quick Server Setup
# Gets the basename of the original request
map $request_uri $request_basename {
~/(?<captured_request_basename>[^/?]*)(?:\?|$) $captured_request_basename;
}
# Gets the basename of the current uri
map $uri $basename {
~/(?<captured_basename>[^/]*)$ $captured_basename;
}