Skip to content

Instantly share code, notes, and snippets.

View ThorstenHans's full-sized avatar
🍒

Thorsten Hans ThorstenHans

🍒
View GitHub Profile
@ThorstenHans
ThorstenHans / DnrMailer.rb
Created July 18, 2011 12:28
Rails2.x ActionMailer with attachments...
require 'net/smtp'
class DotNetRocksMailer
def self.send_email(from, to, subject, message, attachmentFileName, mailServer)
filename = attachmentFileName
filecontent = File.read(filename)
fileNameOnly = File.basename(attachmentFileName)
encodedcontent = [filecontent].pack("m") # base64
marker = "AUNIQUEMARKER"
@ThorstenHans
ThorstenHans / sexy.rb
Created July 21, 2011 09:35
Ruby is sexy :)
class CommandLineExecuter
def self.execute(cli,props = {},nameless_param)
parameters = props.collect { |key,value| "/#{key}=#{value}" }.join " "
exec("#{cli} #{nameless_param} #{parameters}")
end
end
#Sample usage
CommandLineExecuter.execute "notepad"
@ThorstenHans
ThorstenHans / Site.jade
Created July 28, 2011 15:33
Jade Question
h3 my site
p hello
teaser this is my optional teaser
@ThorstenHans
ThorstenHans / gist:1219551
Created September 15, 2011 15:27
Generic Service Locator
public class ServiceLocator
{
//Some kind of singleton is here...
// only the stuff that matters
public static void For<T>(params Func<T>[] regs)
{
// ...
}
public static T Use<T>()
@ThorstenHans
ThorstenHans / IsAnEmptyArrayFalsy.js
Created November 14, 2011 10:39
is an js array falsy?
var sut = [];
if(!sut){
console.log("An empty array is false");
}else{
console.log("An empty array is true");
}
@ThorstenHans
ThorstenHans / udf.js
Created November 21, 2012 12:51
JavaScript UDF wrapper
var ewa = null;
// Add event handler for onload event.
if (window.attachEvent) {
window.attachEvent("onload", ewaOnPageLoad);
}
else {
window.addEventListener("DOMContentLoaded", ewaOnPageLoad, false);
}
@ThorstenHans
ThorstenHans / JSRedirect.js
Last active December 14, 2015 21:39
JS Redirect for @szu :)
var browserLanguage = window.navigator.userLanguage || window.navigator.language;
var redirectTo = "http://www.google.";
// add some logic which will be executed based on users browser! language
switch (browserLanguage) {
case "de":
redirectTo = "http://www.bing.de";
break;
default:
redirectTo += browserLanguage;
@ThorstenHans
ThorstenHans / Link.html
Last active December 26, 2015 05:49
Generating Tags with Attributes
@ThorstenHans
ThorstenHans / AppChrome.js
Created October 29, 2013 15:43
ShareCoffee Samples for my blog
var chromeSettings = new ShareCoffee.ChromeSettings("", "My AutoHosted SharePoint App",
new ShareCoffee.SettingsLink("foo.html", "Foo", true),
new ShareCoffee.SettingsLink("bar.html", "Bar", true)
);
var onAppChromeLoaded = function () {
console.log("chrome should be loaded now!");
};
ShareCoffee.UI.loadAppChrome("chrome-placeholder-id", chromeSettings, onAppChromeLoaded);
@ThorstenHans
ThorstenHans / UDF.js
Created November 11, 2013 20:54
Creating an JavaScript UDF for SharePoint 2013 Excel Services
window.ExpertsInside = {
makeUpperString: function(input){
return input.toUpperString();
}
};
if(window.attachEvent){
window.attachEvent("onload", registerUserDefinedFunction);
}else{
window.addEventListener("DOMContentLoaded", registerUserDefinedFunction, false);