Skip to content

Instantly share code, notes, and snippets.

View jfbueno's full-sized avatar
🏠
Working from home

Jéf Bueno jfbueno

🏠
Working from home
View GitHub Profile
// JS array equivalents to C# LINQ methods - by Dan B.
// Here's a simple array of "person" objects
var people = [
{ name: "John", age: 20 },
{ name: "Mary", age: 35 },
{ name: "Arthur", age: 78 },
{ name: "Mike", age: 27 },
{ name: "Judy", age: 42 },
{ name: "Tim", age: 8 }
protected static T GetFromEntityModel<T>(Entity entityModel) where T : EntityBaseViewModel, new()
{
var derivedTypes = GetDerivedClasses<T>().ToList();
var typeToConvert = (from type in derivedTypes
let properties = type.GetProperties().Where(prop => Attribute.IsDefined(prop, typeof(SpecificInfoPerCountryAttribute)))
where properties != null
where entityModel.SpecificInfoPerCountry.Count > 0 &&
entityModel.SpecificInfoPerCountry.All(attr => properties.Any(prop => prop.Name == attr.Description))
select type).SingleOrDefault() ?? typeof(T);
@jfbueno
jfbueno / Customer.cs
Created June 1, 2016 12:54
Relação pro mesmo model
[Key, ForeignKey("Entity")]
public int EntityId { get; set; }
public virtual Entity Entity { get; set; }
[ForeignKey("Headquarter")]
public int HeadquarterId { get; set; }
public virtual Customer Headquarter { get; set; }
public virtual List<Customer> Branches { get; set; }
public class CamelCaseControllerConfigAttribute : Attribute, IControllerConfiguration
{
public void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor)
{
var formatter = controllerSettings.Formatters.OfType<JsonMediaTypeFormatter>().Single();
controllerSettings.Formatters.Remove(formatter);
formatter = new JsonMediaTypeFormatter
{
SerializerSettings = { ContractResolver = new CamelCasePropertyNamesContractResolver() }
public static class DatabaseLogger
{
public static void Log(string query)
{
var words = query.Split(' ');
if (words.FirstOrDefault()?.ToUpper() == "UPDATE")
{
//aqui salva o log de update
}
@jfbueno
jfbueno / Pessoa.cs
Created April 15, 2016 19:09
Teste-Pessoa-Com-EAV
[Table("Pessoas")]
public class Pessoa
{
[Key]
public int Id { get; set; }
public string NomePrincipal { get; set; }
public string Nome { get; set; }
public bool Ativo { get; set; }
public virtual List<PessoaAtributoValor> Atributos { get; set; }
@jfbueno
jfbueno / lista.py
Last active February 28, 2016 15:07
values = [1, 4, 5, 2, 3, 6, 9, 7, 8]
for i in sorted(values):
print(i)
#[print(v) for v in sorted(values)] ou assim usando compreensão
soma = sum(values)
print('soma %d' % soma)
public class FormMain : Form
{
private void btLupa_Click(object sender, EventArgs e)
{
var form = new FormPesquisa(umaListaComOsDados);
form.ShowDialog();
if(!string.IsNullOrEmpty(form.Retorno))
textBox.Text = form.Retorno;
}