Skip to content

Instantly share code, notes, and snippets.

View asimmon's full-sized avatar

Anthony Simmon asimmon

View GitHub Profile
@asimmon
asimmon / eventtocommand-xamarin-forms-example-wm.cs
Created November 20, 2015 15:55
EventToCommand Xamarin Forms - Example ViewModel
public class HomeViewModel : ViewModelBase
{
public ObservableCollection<PersonViewModel> People { get; set; }
public RelayCommand<PersonViewModel> SayHelloCommand { get; set; }
public HomeViewModel()
{
People = new ObservableCollection<PersonViewModel>
{
@asimmon
asimmon / cache-result-aop-src-autofac-cfg.cs
Created November 20, 2015 15:52
Caching method results with AOP - Autofac Configuration
public class MyModule : Module
{
protected override void Load(ContainerBuilder builder)
{
builder.RegisterType<MemoryCacheProvider>()
.As<ICacheProvider>()
.SingleInstance();
builder.RegisterType<CacheResultInterceptor>()
.SingleInstance();
@asimmon
asimmon / cache-result-aop-src-cache-interceptor.cs
Created November 20, 2015 15:51
Caching method results with AOP - CacheResultInterceptor
public class CacheResultInterceptor : IInterceptor
{
private readonly ICacheProvider _cache;
public CacheResultInterceptor(ICacheProvider cache)
{
_cache = cache;
}
public CacheResultAttribute GetCacheResultAttribute(IInvocation invocation)
@asimmon
asimmon / cache-result-aop-src-cache-attr.cs
Created November 20, 2015 15:50
Caching method results with AOP - CacheResultAttribute
public class CacheResultAttribute : Attribute
{
public int Duration { get; set; }
}
@asimmon
asimmon / cache-result-aop-src-cache-provider.cs
Created November 20, 2015 15:49
Caching method results with AOP - Cache Provider
public interface ICacheProvider
{
object Get(string key);
void Put(string key, object value, int duration);
bool Contains(string key);
}
public class MemoryCacheProvider : ICacheProvider
@asimmon
asimmon / cache-result-aop-example-call.cs
Last active October 25, 2016 14:27
Caching method results with AOP, call
Console.WriteLine(worker.Process("foo"));
Console.WriteLine(worker.Process("foo"));
Console.WriteLine(worker.Process("foo"));
Console.WriteLine("Sleeping 2 seconds...");
Thread.Sleep(2000);
Console.WriteLine(worker.Process("foo"));
// result
@asimmon
asimmon / cache-result-aop-example-attr.cs
Created November 20, 2015 15:34
Caching method results with AOP (decorate)
[CacheResult(Duration = 1000)]
public string Process(string arg)
{
return Guid.NewGuid().ToString("N");
}
@asimmon
asimmon / oracle-sql-to-csv-cursor-src.sql
Created November 20, 2015 15:13
SQL query results to CSV source code
FUNCTION cursor_to_csv (
p_cursor IN OUT SYS_REFCURSOR
)
RETURN CLOB
IS
l_cursor_id INTEGER DEFAULT dbms_sql.open_cursor;
l_colval VARCHAR2 (2096);
l_buffer VARCHAR2 (32767) DEFAULT '';
l_status INTEGER;
i_colcount NUMBER DEFAULT 0;
@asimmon
asimmon / oracle-sql-to-csv-result.txt
Last active November 20, 2015 15:15
SQL query results to CSV result
ITEM_ID;NAME;PRICE
1;mi;328
2;Duis gravida praesent;5
3;ac mattis semper;353
4;volutpat nunc sit;431
5;pede blandit;433
6;eros;452
7;ac orci;243
8;felis ullamcorper viverra;250
9;lorem, luctus ut;494
@asimmon
asimmon / oracle-sql-to-csv-raw-query.sql
Created November 20, 2015 15:10
SQL query results to CSV using raw queries
DECLARE
v_csv CLOB;
BEGIN
SELECT query_to_csv('SELECT * FROM items') INTO v_csv FROM dual;
END;