Skip to content

Instantly share code, notes, and snippets.

View kimenye's full-sized avatar

Trevor Kimenye kimenye

View GitHub Profile
@kimenye
kimenye / gist:1916174
Created February 26, 2012 11:23
Opensource GEO Utility to convert csv file to KML
def file = new File(args[0])
def mb = new groovy.xml.StreamingMarkupBuilder()
new OutputStreamWriter(new FileOutputStream(args[1]),'utf-16') << mb.bind {
mkp.xmlDeclaration()
mkp.declareNamespace( kml: "http://earth.google.com/kml/2.0" )
kml {
Document {
Folder {
@kimenye
kimenye / MongoEngineGridFS Server
Created March 15, 2012 14:53
Serve GridFs files from mongo engine with flask
from flask import Flask, request, redirect, url_for, make_response, abort
from mongoengine.fields import get_db
from bson import ObjectId
from gridfs import GridFS
from gridfs.errors import NoFile
from <your_app> import app
@app.route('/files/<oid>')
def serve_gridfs_file(oid):
try:
@kimenye
kimenye / MongoHQURL
Created March 15, 2012 14:54
A utility for converting a MONGOHQ url to an object so that mongo engine can connect to it.
# -*- coding: utf-8 -*-
"""
MongoHQURL
~~~~~~~~~~
A utility for converting a MONGOHQ url to an object so that mongo engine can connect to it.
usage:
------
from util import MongoHQURL
@kimenye
kimenye / heroku_mongomapper
Created July 16, 2012 06:08
Sinatra + MongoMapper + MongoHQ + Heroku
if ENV['MONGOHQ_URL']
uri = URI.parse(ENV['MONGOHQ_URL'])
MongoMapper.connection = Mongo::Connection.from_uri(ENV['MONGOHQ_URL'])
MongoMapper.database = uri.path.gsub(/^\//, '')
puts ">> db is #{uri.path.gsub(/^\//, '')}"
end
@kimenye
kimenye / first_non_repeating_character
Created September 17, 2012 12:59
How to detect the first non-repeating character in a line
def detect_character_that_occurs_only_once line
if !line.nil?
the_char = line.each_char.detect { |char| line.count(char) == 1}
end
the_char
end
@kimenye
kimenye / Supermarket
Created October 3, 2012 11:13
Supermarket
class Fruit
attr_accessor :type, :unit_price, :discount_quantity, :discount_price, :offer
def initialize(type,unit_price, discount_quantity=nil, discount_price=nil, offer=false)
@type = type
@unit_price = unit_price
@discount_quantity = discount_quantity
@discount_price = discount_price
@offer = offer
end
@kimenye
kimenye / jQuery Wiggle
Created October 10, 2012 08:35
jQuery Wiggle using JQUERY Transit
/*!
* jQuery Wiggle
* http://www.userdot.net/#!/jquery
*
* Copyright 2011, UserDot www.userdot.net
* Licensed under the GPL Version 3 license.
* Version 1.0.0
*
* Updated by http://github.com/kimenye
*
RailsAdmin.config do |config|
config.actions do
dashboard
index
new
show
edit
delete
collection :upload_renewals do
@kimenye
kimenye / _navigation_links.html.erb
Last active December 28, 2015 20:59
Creating the NDS library application
@kimenye
kimenye / jquery.smint.js
Created May 20, 2014 10:33
Modified version of SMIT
/*
SMINT V1.0 by Robert McCracken
SMINT V2.0 by robert McCracken with some awesome help from Ryan Clarke (@clarkieryan) and mcpacosy ‏(@mcpacosy)
SMINT is my first dabble into jQuery plugins!
http://www.outyear.co.uk/smint/
If you like Smint, or have suggestions on how it could be improved, send me a tweet @rabmyself