Skip to content

Instantly share code, notes, and snippets.

@mverzilli
mverzilli / gist:1105181
Created July 25, 2011 20:53
Context aware entities in Entity Framework
public partial class CountryShardedDatabase
{
public static CountryShardedDatabase FromCountry(string country)
{
var db = new CountryShardedDatabase(string.Format("name={0}", ConfigurationManager.ConnectionStrings[country].Name));
db.Country = country;
db.ObjectMaterialized += new System.Data.Objects.ObjectMaterializedEventHandler(db_ObjectMaterialized);
return db;
@mverzilli
mverzilli / CoffeeScriptvsJavascriptarraypopulation
Created October 8, 2011 21:43
CoffeeScript vs. Javascript array population
JavaScript:
var data = []
for (var i = 0; i < 84; i++) {
data.push(i * 10 / 84);
}
CoffeeScript:
data = (i * 10 / 84 for i in [0..83])
width = 760
height = 260
xmin = -1.2
xmax = 5
x_scale = d3.scale.linear()
x_scale.domain([xmin, xmax])
.range [0, width]
@mverzilli
mverzilli / gist:2216540
Created March 27, 2012 14:48
Original service method
public User GetUserByEmail(string email)
{
var key = email;
var user = Cache.Cache.Get<User>(key);
if (user == null)
{
try
{
user = builder.BuildFromNewDbs(email);
@mverzilli
mverzilli / gist:2217535
Created March 27, 2012 16:07
Storified service method
public User GetUserByEmail(string email)
{
/*
* I use the email param as a key to get a user from cache,
* so I store the email in a variable called "key".
* If the user is in cache, we're done! If the user isn't in cache,
* I try to get it from the new database.
* If the user isn't in the new database, everything may blow up,
* so I have to be careful just in case it does.
* There's no way for me to know whether the user
@mverzilli
mverzilli / gist:2217613
Created March 27, 2012 16:17
Storified service method
public User GetUserByEmail(string email)
{
/*
* I use the email param as a key to get a user from cache,
* so I store the email in a variable called "key".
* If the user is in cache, we're done! If the user isn't in cache,
* I try to get it from the new database.
* If the user isn't in the new database, everything may blow up,
* so I have to be careful just in case it does.
* There's no way for me to know whether the user
@mverzilli
mverzilli / gist:2217677
Created March 27, 2012 16:25
Service method target story
public User GetUserByEmail(string email)
{
/*
* You give me an email and I'll give you a user.
* By the way, I'll make use of a cache layer so that
* your request doesn't result in performance issues.
* It's not a wonderful world (sorry, Louis Armstrong),
* so in case something goes wrong I'll just write it down
* for someone to take a look at it later.
*/
@mverzilli
mverzilli / gist:3962611
Created October 27, 2012 01:39
Compute columns
@columns = []
ConditionCodeProperty.select('property, format, field_name').select('GROUP_CONCAT(condition_code) as conditions').group('property, format, field_name').where(condition_code: current_user.condition_codes).each do |condition_code_property|
unless Result.is_common(condition_code_property.property)
common = Result.is_extended_common(condition_code_property.property)
column = {
property_name: condition_code_property.property,
value_accessor: condition_code_property.property,
human_name: Result.human_name_for(condition_code_property.property),
field_name: condition_code_property.field_name,
extended: !common,
@mverzilli
mverzilli / test.erl
Created March 20, 2013 21:36
Mi primer programa Erlang :)
-module(test).
-export([get_layers/2]).
auth_header(User, Pass) ->
Encoded = base64:encode_to_string(lists:append([User, ":", Pass])),
{"Authorization", "Basic " ++ Encoded}.
get_layers(User, Pass) ->
Headers = [auth_header(User, Pass)],
httpc:request(get, {"http://facilities.moh.gov.rw/collections/26/layers.json", Headers}, [], []).
@mverzilli
mverzilli / gist:6873028
Last active December 24, 2015 22:29
Limit number of results shown in "MyReportsView"
public class AllReportsByTimestampDesc extends UnicefGisView {
...
...
...
public List<Map<String, Object>> query() {
view.updateIndex();
CBLQueryOptions options = new CBLQueryOptions();
options.setDescending(true);