Skip to content

Instantly share code, notes, and snippets.

View xdumaine's full-sized avatar
🦄

Xander Dumaine xdumaine

🦄
View GitHub Profile
public string GetUsername()
{
var url = new Uri(API_URL_BASE);
var client = new HttpClient() { BaseAddress = url };
var response = client.GetAsync(url).Result;
response.EnsureSuccessStatusCode();
return response.Content.ReadAsStringAsync().Result;
}
// Create an OpenFilePicker starting in the pictures library, viewing thumbnails
var filePicker = new FileOpenPicker();
filePicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
filePicker.ViewMode = PickerViewMode.Thumbnail;
// Filter to include a sample subset of file types
filePicker.FileTypeFilter.Clear();
filePicker.FileTypeFilter.Add(".bmp");
filePicker.FileTypeFilter.Add(".png");
filePicker.FileTypeFilter.Add(".jpeg");
public void AddPhoto()
{
DispatcherHelper.CheckBeginInvokeOnUI(() => { PickPhoto(); });
}
var uri = new Uri(API_URL_MEDIA);
var content = new MultipartFormDataContent();
content.Add(new StringContent(caption), ""caption"");
var t = new StreamContent(photoContents);
t.Headers.ContentType
= new System.Net.Http.Headers.MediaTypeHeaderValue(contentType);
fileName = string.IsNullOrEmpty(fileName) ? ""img.png"" : fileName;
content.Add(t, ""media"", """ + fileName + """);
var response = PostBuffer(uri, content);
response.EnsureSuccessStatusCode();
var baseAddress = new Uri(API_URL_BASE);
var cookieContainer = new CookieContainer();
using (var handler = new HttpClientHandler() { CookieContainer = cookieContainer })
using (var client = new HttpClient(handler) { BaseAddress = baseAddress })
{
// some defaults, add a header and cookie for authenticating with the API
client.DefaultRequestHeaders.Add("User-Agent", USER_AGENT);
client.DefaultRequestHeaders.Add("X-AvoSig", AvoSignature);
cookieContainer.Add(baseAddress, new Cookie(COOKIE_NAME, CookieValue));
// Post the content and return the result
for(i=1;i<101;i++){r=i%3?'':'fizz';r+=i%5?'':'buzz';!r||console.log(r)}
@xdumaine
xdumaine / gist:6993196
Created October 15, 2013 15:15
Inject viewport with javascript
function injectViewportMetaTag() {
var meta = $(document.createElement('meta'));
meta.name = 'viewport';
meta.content = 'width=device-width, initial-scale=1';
$$('head')[0].insert(meta);
};
@xdumaine
xdumaine / gist:6993239
Created October 15, 2013 15:16
inject redmine signature
function injectSignature() {
var footer = $(document.getElementById('footer'));
footer.appendChild(document.createTextNode
("Responsive Theme by Xander Dumaine 2011"));
}
@xdumaine
xdumaine / inject-icons.js
Created October 15, 2013 15:18
Inject apple touch icons with javascript
function injectAppleTouchIcons() {
var link = $(document.createElement('link'));
link.setAttribute('rel', 'apple-touch-icon');
link.setAttribute('href', '/themes/mobile/images/touch/apple-touch-icon.png');
$$('head')[0].insert(link);
link = $(document.createElement('link'));
link.setAttribute('rel', 'apple-touch-icon');
link.setAttribute('href', '/themes/mobile/images/touch/apple-touch-icon-72x72-precomposed.png');
link.setAttribute('sizes', '72x72');
@xdumaine
xdumaine / media-queries.css
Created October 15, 2013 15:19
css media queries
@media only screen and (min-device-width: 480px) { ... }
@media only screen and (min-device-width: 600px) { ... }
@media only screen and (min-width: 770px) { ... }