Skip to content

Instantly share code, notes, and snippets.

View kristianmandrup's full-sized avatar

Kristian Mandrup kristianmandrup

  • Freelancer
  • Copenhagen
View GitHub Profile
@kristianmandrup
kristianmandrup / app.js
Last active December 27, 2015 11:09
An attempt to refactor the racer-example by @Sebmaster to make for a more scalable example code that can be more easily be extended to include more models and should also make the code easier to understand. This example is partly inspired by the todos example that comes with racer. See https://github.com/codeparty/racer/tree/master/examples/todos
# refactoring of https://github.com/Sebmaster/racer-example/blob/master/app.js
var racer = require('racer');
var express = require('express');
var app = express();
var http = require('http');
var server = http.createServer(app);
var store = racer.createStore({
@kristianmandrup
kristianmandrup / pdf_converter.rb
Last active May 31, 2019 09:29
Jekyll PDF Converter using PDFKit
require 'pdfkit'
require 'nokogiri'
require 'haml'
# config/initializers/pdfkit.rb
PDFKit.configure do |config|
# Note: Often required for Windows OS configuration
# config.wkhtmltopdf = '/path/to/wkhtmltopdf'
@kristianmandrup
kristianmandrup / csv_to_fixture
Created November 21, 2011 12:35
Rake task to convert CSV table export to fixture
# Originally written by http://redartisan.com/tags/csv
# Added and minor changes by Gavin Laking
# Rewritten by Andrew Bennett for Ruby 1.9
#
# Usage: rake csv_to_fixture[file.csv]
# Usage (format): rake csv_to_fixture[file.csv,json]
#
# "id","name","mime_type","extensions","icon_url"
# "1","unknown","unknown/unknown","||","/images/icon/file_unknown.gif"
@kristianmandrup
kristianmandrup / Damn resque_mailer :(
Created August 5, 2011 12:03
Resque mailer debugging - trying to make it work with resque_spec
Gemfile
<pre>
gem 'resque_mailer', '2.0.0', :path => '/Users/kmandrup/private/repos/resque_mailer' # , :git => 'git://github.com/kristianmandrup/resque_mailer.git'
</pre>
My own debugging... (resque_mailer.rb)
<pre>
def method_missing(method_name, *args)
autoload_modules [:a, :b, :c, ...,], 'base'
=>
autoload :A, 'base/a'
...
in sugar-high
isolate all file operations into SugarHigh::File, SugarHigh::FileMutate etc
then
@kristianmandrup
kristianmandrup / GeoVector PointAdd
Created May 11, 2011 16:39
Applying a Vector to a Point on a globe
class GeoVector
module Math
# Add Vector v1 to a GeoPoint
# This module should be included in the GeoPoint class !!!
module PointAdd
def apply! vector
raise ArgumentError, "Argument must be a GeoVector" if !vector.kind_of?(GeoVector)
@lat = lat + vector.lat
@lng = lng + vector.lng
Inline Rails 3 templating solution : for ActionView RSpec testing etc.
require 'action_view'
require 'action_view/context'
class TestERBTemplate
ERBHandler = ActionView::Template::Handlers::ERB
attr_accessor :output_buffer, :rendered
# Functioning RSpec 2 spec for ActiveView helper
require 'spec_helper'
require 'action_view/template/handlers/erb'
module MyViewHelper
def tab_for(clazz, &block)
content = with_output_buffer(&block)
content_tag :li, content, :class => clazz
end
# Minimal TDD for extending Rails components
require 'active_support/railtie'
module Minimal
class Application < Rails::Application
config.active_support.deprecation
end
end
# Please me
*Note: The following is planned functionality only. I have not really started to implement it yet!*
This is a project that tries to please you in any way possible. This is done by executing a number of steps (kinda scripts) based on one or more configured profiles.
Each 'please-me request' can be customized to override the defaults as per defined in the profile(s).
## COMMANDS
- please [command] [name] [options...]