Skip to content

Instantly share code, notes, and snippets.

View abjerner's full-sized avatar

Anders Bjerner abjerner

View GitHub Profile
@abjerner
abjerner / Dropbox
Created March 2, 2014 13:14
Small snippet for finding the path to the user's local Dropbox folder.
private static string GetDropboxPath() {
string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string dbPath = Path.Combine(appDataPath, "Dropbox\\host.db");
if (!File.Exists(dbPath)) return null;
string[] lines = File.ReadAllLines(dbPath);
return Encoding.UTF8.GetString(Convert.FromBase64String(lines[1]));
}
@abjerner
abjerner / Rss.cshtml
Created March 13, 2014 23:10
Very small amount of code required to create a RSS feed in Umbraco.
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@using Bjerner.Website.Web
@{
Layout = null;
RssFeed feed = new RssFeed {
Title = "Bjerner.dk Blog",
Link = "http://blog.bjerner.dk/",
PubDate = DateTime.Now,
};
foreach (IPublishedContent child in Model.Content.Children.OrderByDescending(x => x.CreateDate).Take(20)) {
@abjerner
abjerner / RssFeed + RssItem
Created March 14, 2014 08:05
RssFeed and RssItem classes for easily generating RSS feeds.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Linq;
namespace Bjerner.Website.Web {
public class RssFeed {
@abjerner
abjerner / OAuth.aspx.cs
Created March 31, 2014 21:19
Twitter OAuth using Skybrud.Social
using System;
using Skybrud.Social.OAuth;
using Skybrud.Social.Twitter;
using Skybrud.Social.Twitter.OAuth;
using Skybrud.Social.Twitter.Objects;
namespace Skybrud.Social.Test.Twitter {
public partial class OAuth : System.Web.UI.Page {
@abjerner
abjerner / Twitter OAuth.aspx..cs
Last active August 29, 2015 13:59
WebForms example using Skybrud.Social for Twitter OAuth authentication
using System;
using Skybrud.Social.OAuth;
using Skybrud.Social.Twitter;
using Skybrud.Social.Twitter.OAuth;
using Skybrud.Social.Twitter.Objects;
namespace Skybrud.Social.Test.Twitter {
public partial class OAuth : System.Web.UI.Page {
@abjerner
abjerner / FacebookMeEmail.cs
Created July 27, 2014 16:03
Current FacebookMeResponse class in Skybrud.Social doesn't expose an email property. Using this little hack the email adress can be obtained given that the Facebook app can access the email of the user.
// Get the raw string
string response = service.Methods.Raw.Me();
// Parse the JSON
JsonObject obj = JsonObject.ParseJson(response);
// Parse the JSON object (use as normal)
FacebookMeResponse me = FacebookMeResponse.Parse(obj);
// Get email
@abjerner
abjerner / TwitterEntities.cs
Last active August 15, 2016 18:03
Formatting entities in a Twitter status message (tweet)
private string FormatStatusMessageText(TwitterStatusMessage tweet) {
// Normally we should be able to call tweet.Entities.GetAllReversed() but that method
// will throw an exception if the array of media entities is NULL (which it is if there
// are no media attached to the tweet).
List<TwitterBaseEntity> entities = new List<TwitterBaseEntity>();
entities.AddRange(tweet.Entities.HashTags);
entities.AddRange(tweet.Entities.Urls);
entities.AddRange(tweet.Entities.Mentions);
if (tweet.Entities.Media != null) entities.AddRange(tweet.Entities.Media);
@abjerner
abjerner / HtmlHelperExtensionMethods.cs
Created September 14, 2014 13:01
A set of extension methods to help with fingerprinting (cache busting) of static resources in ASP.NET MVC views. In your view, just call @Html.GetCacheableUrl("~/css/default.css") and the timestamp will be appended to the query string.
using System;
using System.IO;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;
namespace Skybrud.Umbraco.ExtensionMethods {
public static class HtmlHelperExtensionMethods {
@abjerner
abjerner / Editor.js
Created September 27, 2014 23:08
Example controller for a AngularJS property editor in Umbraco 6
angular.module('umbraco').controller('GoogleAddressSearchController', ['$scope', '$http', function ($scope, $http) {
if (!$scope.model.address) $scope.model.address = '';
$scope.address = $scope.model.address;
$scope.suggestions = [];
$scope.addressKeyDown = function () {
public class ParentPage {
public int Id { get; set; }
public string Name { get; set; }
public string Url { get; set; }
public IEnumerable<TestPage> Pages { get; set; }