Skip to content

Instantly share code, notes, and snippets.

View davidsonsousa's full-sized avatar
🤓
Coding

Davidson Sousa davidsonsousa

🤓
Coding
View GitHub Profile
@davidsonsousa
davidsonsousa / project_name.wpp.targets
Created January 11, 2015 16:45
Example on how to create your <project_name>.wpp.targets to set folder permissions when using Web Deploy - davidsonsousa.net
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="SetupCustomAcls" AfterTargets="AddIisSettingAndFileContentsToSourceManifest">
<ItemGroup>
<MsDeploySourceManifest Include="setAcl">
<Path>$(_MSDeployDirPath_FullPath)\App_Data</Path>
<setAclAccess>Read,Write</setAclAccess>
<setAclResourceType>Directory</setAclResourceType>
<AdditionalProviderSettings>setAclResourceType;setAclAccess</AdditionalProviderSettings>
@davidsonsousa
davidsonsousa / bulk_insert_EF.cs
Last active August 29, 2015 14:13
Making Bulk Insert with Entity Framework
using (SqlConnection destinationConnection = new SqlConnection(connectionString))
{
destinationConnection.Open();
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(destinationConnection))
{
bulkCopy.DestinationTableName = "dbo.BulkCopyDemoMatchingColumns";
try
{
// Creates the script tag
var tag = document.createElement('script');
// Calls the API javascript
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
@davidsonsousa
davidsonsousa / load_single_video.js
Last active August 29, 2015 14:16
Load a predefined video from youtube
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: 'jU5i1WjRBhE'
});
}
@davidsonsousa
davidsonsousa / partial_for_custom_video.cshtml
Created March 29, 2015 15:14
Partial view which sets a video according to the value passed by the model
@model Youtube_API_Custom_Video.Models.Video
<script>
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '@Model.Height',
width: '@Model.Width',
videoId: '@Model.Id'
});
@davidsonsousa
davidsonsousa / video_model.cs
Created March 29, 2015 15:17
Video model or Youtube API usage
public class Video
{
public string Id { get; set; }
public string Title { get; set; }
public string Width { get; set; }
public string Height { get; set; }
}
public class Country
{
public Guid Id { get; set; }
public string Name { get; set; }
}
private List<Country> _countries;
public IEnumerable<SelectListItem> CountryItems
{
get
{
IEnumerable<SelectListItem> selectCountries = new List<SelectListItem>();
selectCountries = _countries.Select(x => new SelectListItem
{
Value = x.Id.ToString(),
Text = x.Name
public IEnumerable<SelectListItem> DefaultItem
{
get
{
return Enumerable.Repeat(new SelectListItem
{
Value = "",
Text = "- SELECT -"
}, count: 1);
}
public class GenericViewModel
{
[Display(Name = "Country")]
public Guid SelectedCountryId { get; set; }
public List<SelectListItem> CountryItems { get; set; }
public GenericViewModel()
{
var ddlHelper = new DropDownListHelper();
this.CountryItems = ddlHelper.CountryItems.ToList();