Skip to content

Instantly share code, notes, and snippets.

View kgashok's full-sized avatar
🎯
Focusing

Ashok Bakthavathsalam kgashok

🎯
Focusing
View GitHub Profile
@ahmedahamid
ahmedahamid / C++Example.cpp
Last active May 10, 2016 02:57
Why I started to feel differently about C# | Using STL map
//
// (1) C++: - Defining a dictionary [key type=string, value type=int]
// - No easy way to initialize.
//
map<string, int> dict;
//
// (1`) C++11: Defining and initializing a dictionary [key type=string, value type=int]
//
map<string, int> dict
{
@ahmedahamid
ahmedahamid / C#Example.cs
Last active May 10, 2016 02:58
Why I started to feel differently about C# | Using Dictionaries
//
// (1) C#: Defining an initializing a dictionary [key type=string, value type=int]
//
Dictionary<string, int> dict = new Dictionary<string, int>()
{
{"Eve", 101},
{"George", 150},
{"Emma", 200}
};
//
@swlaschin
swlaschin / enterprise-tic-tac-toe-2.fsx
Last active June 5, 2023 22:16
Follow up to the example of implementing "enterprise" tic-tac-toe in a functional way.
(*
enterprise-tic-tac-toe-2.fsx
Follow up to the example of implementing "enterprise" tic-tac-toe in a functional way.
* Added true capability based security.
Related blog post: http://fsharpforfunandprofit.com/posts/enterprise-tic-tac-toe-2/
*)
@ctran
ctran / fizzbuzz.elm
Last active May 6, 2016 12:11
Fizz Buzz in elm
import Graphics.Element (Element, flow, down)
import List (map)
import Text (asText)
main : Element
main =
let fizzBuzz n = case (n % 3, n % 5) of
(0, 0) -> "FizzBuzz"
(0, _) -> "Fizz"
(_, 0) -> "Buzz"
@JulienPalard
JulienPalard / curry.py
Created August 1, 2014 10:51
KISS Python curry
#!/usr/bin/env python
def curry(func):
"""
Decorator to curry a function, typical usage:
>>> @curry
... def foo(a, b, c):
... return a + b + c
@rohit-jamuar
rohit-jamuar / balanced_delimiters.py
Last active September 7, 2023 19:27
balanced_delimiters
#!/usr/bin/python
def balanced_delimiters(s):
'''
This function determines if the input string ('s') has balanced number of braces.
All the opening braces are appended to 'data'. As soon as a closing brace is
encountered, the last entry in 'data' is matched with it. If the closing brace is
the opposite of the last element in 'data' - opening braces and their corresponding
closing braces are stored in 'braces', we have a match and the the last element
is popped-off 'data'. This process is continued till either all the elements of 's'
#include <iostream>
#include <map>
#include <stack>
bool IsBalanced(const char delimStr[]) {
using std::make_pair;
std::map< char, char > delims;
const char* curChar = delimStr;
std::stack< char > store;
@renatoathaydes
renatoathaydes / webServer.groovy
Last active October 23, 2023 15:28
A simple web server written in Groovy that provides static and code-generated content
#!/usr/bin/env groovy
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.servlet.*
import groovy.servlet.*
@Grab(group='org.eclipse.jetty.aggregate', module='jetty-all', version='7.6.15.v20140411')
def startJetty() {
def server = new Server(8080)
@dhh
dhh / test_induced_design_damage.rb
Last active June 22, 2023 06:18
This is an extraction from Jim Weirich's "Decoupling from Rails" talk, which explained how to apply the hexagonal design pattern to make every layer of your application easily unit testable (without touching the database etc). It only seeks to extract a single method, the EmployeesController#create method, to illustrate the design damage that's …
# Original Rails controller and action
class EmployeesController < ApplicationController
def create
@employee = Employee.new(employee_params)
if @employee.save
redirect_to @employee, notice: "Employee #{@employee.name} created"
else
render :new
end
@zsup
zsup / ddd.md
Last active April 17, 2024 14:35
Documentation-Driven Development (DDD)

Documentation-Driven Development

The philosophy behind Documentation-Driven Development is a simple: from the perspective of a user, if a feature is not documented, then it doesn't exist, and if a feature is documented incorrectly, then it's broken.

  • Document the feature first. Figure out how you're going to describe the feature to users; if it's not documented, it doesn't exist. Documentation is the best way to define a feature in a user's eyes.
  • Whenever possible, documentation should be reviewed by users (community or Spark Elite) before any development begins.
  • Once documentation has been written, development should commence, and test-driven development is preferred.
  • Unit tests should be written that test the features as described by the documentation. If the functionality ever comes out of alignment with the documentation, tests should fail.
  • When a feature is being modified, it should be modified documentation-first.
  • When documentation is modified, so should be the tests.