Skip to content

Instantly share code, notes, and snippets.

@agilehands
agilehands / SOM-color_step1.groovy
Last active August 29, 2015 13:56
Groovy script for learning self organizing map step one for this blog post: http://www.earnestmind.com/2014/02/self-organizing-map-grid-initialization.html
import javax.swing.JFrame
import javax.swing.JPanel
import java.awt.Color
import java.awt.Graphics
import java.awt.Graphics2D
/**
* Created by aman on 1/29/14.
*/
@agilehands
agilehands / CropVideo.m
Last active August 29, 2015 14:15 — forked from zrxq/CropVideo.m
@import MobileCoreServices;
@import AVFoundation;
@import AssetsLibrary;
// ...
- (void)cropVideoAtURL:(NSURL *)videoURL toSquareWithSide:(CGFloat)sideLength completion:(void(^)(NSURL *resultURL, NSError *error))completionHander {
/* asset */
@agilehands
agilehands / JiraSprintNewStories.scala
Last active February 1, 2016 22:06
A Scala script to process JIRA Sprint XML exported file to count number of stories created during the sprint.
import java.io.File
import java.time.LocalDate
import java.util.Locale
import java.time.format.DateTimeFormatter
// Get the path from command line argument
val path = args(0) // no check!
// Step 1: Get sprint file names and start date
val sprints = new File(path).listFiles.filter(_.getName.endsWith(".xml")).map{ file => (file.getName.dropRight(4), path+"/"+file.getName ) }.toList
@agilehands
agilehands / strategy-pattern.swift
Last active May 23, 2017 15:06
Strategy Pattern with Swift
// This is the protocol, that defines family of weapon
protocol Weapon{
func fire(); // Weapon can be fire
}
// This is the player definition
class Player{
// Current weapon i.e. the current strategy/algorithm
var currentWeapon:Weapon?;
protocol Blade{
func stab();
}
struct Knife:Blade{
func stab(){
print("Stabing with Knife!")
}
}
struct BladeAdapterForWeapon:Weapon{
var blade:Blade
func fire(){
self.blade.stab()
}
}
struct ExplosiveAdapterForWeapon:Weapon{
var explosive:Explosive
func fire(){
// This is the protocol, that defines family of weapon
protocol Weapon{
func fire(); // Weapon can be fire
}
// This is the player definition
class Player{
// Current weapon i.e. the current strategy/algorithm
var currentWeapon:Weapon?;
// This is the player definition
class Player{
// Current weapon i.e. the current strategy/behavior
var currentWeapon:Weapon?;
// Dynamically sets the current weapon
func select(weapon:Weapon){
self.currentWeapon = weapon;
}
class Player{
var currentWeapon:Weapon?;
var currentBlade:Blade?;
var currentExplosive:Explosive?;
func select(weapon:Weapon){
self.currentWeapon = weapon;
}
func select(blade:Blade){
self.currentBlade = blade;
// Entity One: Weapon
protocol Weapon{
func fire(); // Weapon can be fire
}
// The Context: Player, who can fire a weapon
class Player{
var currentWeapon:Weapon?;
// Fire: call the `fire` method of the weapon