Skip to content

Instantly share code, notes, and snippets.

@Krizzzn
Krizzzn / download_file.rb
Created August 14, 2012 07:33
Ruby - download file over http
require 'net/http'
Net::HTTP.start("website.com") do |http|
resp = http.get("/episode_archive/s#{season}ep#{episode}.mp3")
open("s#{season}ep#{episode}.mp3", "w") do |file|
file.write(resp.body)
end
end
@Krizzzn
Krizzzn / app.config
Created July 17, 2012 07:33
C# - accessing service reference with the headers Negotiate, Ntlm
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="NintexWorkflowWSSoap" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
@Krizzzn
Krizzzn / LoadEmbeddedFile.cs
Created May 29, 2012 13:26
method that loads the contents of a embedded ressource into a string.
private string LoadEmbeddedFile(string fileNameInAssembly, Encoding encoding)
{
var assembly = Assembly.GetExecutingAssembly();
var resName = from name in assembly.GetManifestResourceNames()
where name.ToLower().EndsWith(fileNameInAssembly.ToLower())
select name;
string text = default(string);
var fullResourceName = resName.FirstOrDefault();
@Krizzzn
Krizzzn / jQuery.plugin.coffee
Created April 24, 2012 20:37
jQuery Plugin Boilerplate with CoffeeScript
(($) ->
self = null
local_variable = null
private_methods =
register_events: ->
self.bind 'started', -> console.log 'it was started!'
null
methods =
@Krizzzn
Krizzzn / gist:1249217
Created September 28, 2011 20:46
C#: EF Save Event Handler
public override int SaveChanges(SaveOptions options)
{
foreach (ObjectStateEntry entry in
ObjectStateManager.GetObjectStateEntries(
EntityState.Added | EntityState.Modified))
{
// Validate the objects in the Added and Modified state
// if the validation fails throw an exeption.
}
@Krizzzn
Krizzzn / gist:1216220
Created September 14, 2011 09:52
VisualStudio: Test Method Snippet
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>Test Method</Title>
<Shortcut>testm</Shortcut>
<Description>Code snippet for a test method</Description>
@Krizzzn
Krizzzn / gist:1213387
Created September 13, 2011 08:05
TSQL: Raise Error
RAISERROR ('fooo error', 16, 1)
@Krizzzn
Krizzzn / gist:1195836
Created September 5, 2011 20:23
Objective-C: Animation Block in Cocoa Touch
[UIView animateWithDuration: 1.0
delay: 0.0
options: UIViewAnimationOptionCurveEaseIn
animations:^{
self.view.alpha = 0.0;
drawingVC.view.alpha = 0.0;
drawingVC.view.frame = CGRectMake(400, 400, 400, 400);
}
completion:nil];
@Krizzzn
Krizzzn / gist:1192669
Created September 4, 2011 11:02
Objective-C: Dateformatter
- (NSString *)format: (NSDate*) date usingFormat:(NSString *)dateFormat
{
NSCalendar *cal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:dateFormat];
[formatter setCalendar:cal];
[formatter setLocale:[NSLocale currentLocale]];
NSString *ret = [formatter stringFromDate:date];
[formatter release];
[cal release];