Skip to content

Instantly share code, notes, and snippets.

@mverzilli
mverzilli / gist:1105181
Created Jul 25, 2011
Context aware entities in Entity Framework
View gist:1105181
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 Oct 8, 2011
CoffeeScript vs. Javascript array population
View CoffeeScriptvsJavascriptarraypopulation
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])
View gist:1273026
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 Mar 27, 2012
Original service method
View gist:2216540
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 Mar 27, 2012
Storified service method
View gist:2217535
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 Mar 27, 2012
Storified service method
View gist:2217613
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 Mar 27, 2012
Service method target story
View gist:2217677
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.
*/
View gist:3962611
@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 Mar 20, 2013
Mi primer programa Erlang :)
View test.erl
-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 Dec 24, 2015
Limit number of results shown in "MyReportsView"
View gist:6873028
public class AllReportsByTimestampDesc extends UnicefGisView {
...
...
...
public List<Map<String, Object>> query() {
view.updateIndex();
CBLQueryOptions options = new CBLQueryOptions();
options.setDescending(true);