Skip to content

Instantly share code, notes, and snippets.

@loonison123
loonison123 / c#_snippets_1.cs
Created August 23, 2014 23:05
C# Object Cloning Snippets
// Source - http://social.msdn.microsoft.com/Forums/en-US/a967b44b-c85c-4afd-a499-f6ff604e2139/how-to-cloneduplicate-an-entity?forum=adodotnetentityframework
private static T DataContractSerialization<T>(T obj) {
DataContractSerializer dcSer = new DataContractSerializer(obj.GetType());
MemoryStream memoryStream = new MemoryStream();
dcSer.WriteObject(memoryStream, obj);
memoryStream.Position = 0;
T newObject = (T)dcSer.ReadObject(memoryStream);
return newObject;
@loonison123
loonison123 / 0_reuse_code.js
Created August 20, 2014 12:04
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@loonison123
loonison123 / angular_snippets_1.js
Last active August 29, 2015 14:04
Angular.js snippets
// $watch inside a service
// Source: http://stackoverflow.com/questions/17806600/angularjs-watch-inside-a-service
$rootScope.$watch(function() {
return //value to be watched;
}, function watchCallback(newValue, oldValue) {
//react on value change here
}, true); // true if you want it to watch object properties
// Refreshing your current state. Such as you are in the ItemView state, and you are $state.go('ItemView')
$state.go($state.current, {}, {reload: true});
@loonison123
loonison123 / aspnet_c#_snippets_1.cs
Last active August 29, 2015 14:04
Useful ASP.NET Web Forms C# Snippets
// Execute javascript function on postback
// Source: http://stackoverflow.com/questions/4223837/run-javascript-function-after-postback
ClientScriptManager.RegisterStartupScript(this.GetType(), "AKey", "MyFunction();", true);
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate >
<asp:HyperLink ID="HyperLink2" runat=server NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "YourField", "Reply.aspx?query={0}") %>'>Reply</asp:HyperLink>
<asp:HyperLink ID="HyperLink1" runat=server NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "YourField", "Desc.aspx?query={0}") %>'>Desc</asp:HyperLink>
</ItemTemplate>
</asp:Repeater>
@loonison123
loonison123 / customExceptionExample_1.cs
Created August 1, 2014 13:43
Basic Custom Exception in C#
// Source: http://msdn.microsoft.com/en-us/library/vstudio/ms229064(v=vs.100).aspx
public class NewException : BaseException, ISerializable
{
public NewException() { }
public NewException(string message) { }
public NewException(string message, Exception inner) { }
// This constructor is needed for serialization.
protected NewException(SerializationInfo info, StreamingContext context) { }
@loonison123
loonison123 / commonMongo_1.js
Last active August 29, 2015 14:04
Common Mongo Snippets
// Some data
{ "_id" : 4, "grades" : [ { grade: 80, mean: 75, std: 8 },
{ grade: 85, mean: 90, std: 5 },
{ grade: 90, mean: 85, std: 3 } ] }
// Update records based on multiple field matches
db.studenst.update(
grades: {
$elemMatch: {
'grade': {
@loonison123
loonison123 / commonSql_1.sql
Last active August 29, 2015 14:03
Common Sql Snippets
-- Update statement with join
UPDATE Table1
SET Table1.LastName = 'DR. XXXXXX'
FROM Table1 T1, Table2 T2
WHERE T1.id = T2.id
and T1.id = '010008'
-- Alter column on existing table
ALTER TABLE {TABLENAME}
ADD {COLUMNNAME} {TYPE} {NULL|NOT NULL}
@loonison123
loonison123 / breezeSnippets_1.js
Created July 15, 2014 12:45
Common breeze.js snippets
predicate.create('Price', '==', parseFloat(engineSize));
@loonison123
loonison123 / keysCssExample.html
Created June 27, 2014 02:58
Keys css example
<!-- Source: https://github.com/michaelhue/keyscss -->
<link rel="stylesheet" href="styles/keys.css" />
<!-- Dark keys: -->
<kbd>ctrl</kbd> + <kbd>S</kbd>
<!-- ...or... -->
<kbd class="dark">ctrl</kbd> + <kbd class="dark">S</kbd>
<!-- ...or... -->
<span class="dark-keys">
<kbd>ctrl</kbd> + <kbd>S</kbd>
@loonison123
loonison123 / newWayLoadJsonFileMVC.cs
Created May 18, 2014 04:56
New way of loading a menu from json file in MVC BaseController
public class BaseController : System.Web.Mvc.Controller
{
public BaseController()
{
Initialize();
}
protected void Initialize()
{
// ...