Skip to content

Instantly share code, notes, and snippets.

Dan Tanner dtanner

Block or report user

Report or block dtanner

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View game-example.py
from __future__ import print_function
from math import ceil, log
print("\n Welcome to Up-To-9-Cards Game!")
print("\n================================\n")
def get_cards():
valid_count = 0
View game-example.kt
import java.lang.Math.ceil
import java.lang.Math.pow
import kotlin.math.log2
fun main() {
println("\n Welcome to Up-To-9-Cards Game!")
println("\n================================\n")
displayCards(getCards())
println("\n\nDone!\n")
View game-example.c
#include <stdio.h>
#include <math.h>
#include <string.h>
#define NUMCARDS 9
#define PRODUCTION 1 /** 0=debug-mode | 1=production mode **/
int getCards(int *);
void displayCards(int *, int);
int getSuit(int codedNumber);
@dtanner
dtanner / ratpack-config-usage.groovy
Created Apr 18, 2016
Example of bad vs good ratpack configuration usage
View ratpack-config-usage.groovy
// a config class with a default value
class LogConfig {
boolean logRequestBody = false
}
// in ratpack, the LogConfig is bound with a prefix of `/logging`
Ratpack.groovy {
bindings {
bindInstance(serverConfig.get('/logging', LogConfig))
}
@dtanner
dtanner / DateManipulation.groovy
Created Apr 12, 2016
Example showing some java.time date manipulation
View DateManipulation.groovy
import java.time.LocalDate
import java.time.temporal.TemporalAdjusters
LocalDate localDate = LocalDate.now()
println localDate // 2016-04-12
println localDate.plusMonths(1).withDayOfMonth(1) // 2016-05-01
println localDate.minusMonths(1).with(TemporalAdjusters.lastDayOfMonth()) // 2016-03-31
View LocalAndZonedDates.groovy
import java.time.LocalDate
import java.time.ZonedDateTime
import java.time.ZoneId
import java.time.format.DateTimeFormatter
import java.time.temporal.TemporalAdjusters
// If you have a date without time information, use a LocalDate. e.g. someone's birthday
LocalDate localDate = new LocalDate(2016, 4, 12)
println localDate.toString() // 2016-04-12
@dtanner
dtanner / osx-10.9-setup.md
Last active Mar 20, 2016 — forked from kevinelliott/osx-10.9-setup.md
Clean Install – Mac OS X 10.9 Mavericks
View osx-10.9-setup.md

Install Homebrew / Cask

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
brew install caskroom/cask/brew-cask

todo - replace this with brewfile

Install common applications via Homebrew

@dtanner
dtanner / RemoteConfigService.groovy
Created Apr 30, 2015
Example of a basic utility class to interact with etcd
View RemoteConfigService.groovy
package com.foo.config
import com.foog.util.TomcatDatasourceUtil
import grails.plugins.rest.client.RestBuilder
import groovy.json.JsonSlurper
/**
* Application service to get and set values from a centralized remote configuration service.
*/
class RemoteConfigService {
@dtanner
dtanner / Config.groovy
Created Apr 30, 2015
Example of loading a Grails configuration value from etcd
View Config.groovy
import groovy.json.JsonSlurper
dataSource {
// most properties are directly set
pooled = true
// ...
// the url is retrieved from etcd...make sure the etcd resource is properly protected
def jsonSlurper = new JsonSlurper()
def catalogUrlConfig = jsonSlurper.parseText(new URL("http://etcdlocation:2379/v2/keys/dataSource/url").text)
@dtanner
dtanner / TomcatDatasourceUtil.groovy
Last active Aug 29, 2015
Grails Tomcat Datasource Utility
View TomcatDatasourceUtil.groovy
package com.foo.util
import groovy.util.logging.Log4j
import org.apache.tomcat.jdbc.pool.ConnectionPool
import org.codehaus.groovy.grails.commons.GrailsApplication
@Log4j
class TomcatDatasourceUtil {
static void ensureCurrentDatasources(GrailsApplication application, List datasourceNames) {
You can’t perform that action at this time.