Cool Javascript transitions
http://animejs.com/
Tuesday, February 6, 2018
Thursday, February 1, 2018
Visual Studio hangs - Touch Screen bug Cause and fix
This is a known issue that will be addressed in an upcoming Windows Update.
Until the fix is available, to work around this issue, turn off all pen and touch support for Visual Studio. To do this,
- Find the devenv.exe.config file. It is located in the folder <VS Install Location>\Common7\IDE.
- Copy devenv.exe.config to a non-protected folder, for example your Documents folder, and then create a backup copy of devenv.exe.config.
- Open devenv.exe.config, and modify the <AppContextSwitchOverrides> element to add “Switch.System.Windows.Input.Stylus.DisableStylusAndTouchSupport=true”
- For example
<AppContextSwitchOverrides value="Switch.System.Threading.ThrowExceptionIfDisposedCancellationTokenSource=false;Switch.System.Windows.Forms.DoNotSupportSelectAllShortcutInMultilineTextBox=false;Switch.System.Windows.Input.Stylus.DisableStylusAndTouchSupport=true" />
- For example
- Copy the edited devenv.exe.config into <VS Install Location>\Common7\IDE.
Once the update to .NET Framework 4.7 is available, remove this property from the “value” string to restore pen and touch input to Visual Studio.
NOTE: because this file is replaced with each update to Visual Studio, you must re-apply this workaround after updating Visual Studio until the update to .NET Framework 4.7 is available.
Friday, January 26, 2018
C# - Implement Generic IEnumerable in Simple Example
class MyList<T> : IEnumerable<T>
{
T[] m_Items = null;
int freeIndex = 0;
public MyList()
{
// For the sake of simplicity lets keep them as arrays
// ideally it should be link list
m_Items = new T[100];
}
public void Add(T item)
{
// Let us only worry about adding the item
m_Items[freeIndex] = item;
freeIndex++;
}
#region IEnumerable<T> Members
public IEnumerator<T> GetEnumerator()
{
foreach (T t in m_Items)
{
// Lets check for end of list (its bad code since we used arrays)
if (t == null) // this wont work is T is not a nullable type
{
break;
}
// Return the current element and then on next function call
// resume from next element rather than starting all over again;
yield return t;
}
}
#endregion
#region IEnumerable Members
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
// Lets call the generic version here
return this.GetEnumerator();
}
#endregion
}
Use it:
{
T[] m_Items = null;
int freeIndex = 0;
public MyList()
{
// For the sake of simplicity lets keep them as arrays
// ideally it should be link list
m_Items = new T[100];
}
public void Add(T item)
{
// Let us only worry about adding the item
m_Items[freeIndex] = item;
freeIndex++;
}
#region IEnumerable<T> Members
public IEnumerator<T> GetEnumerator()
{
foreach (T t in m_Items)
{
// Lets check for end of list (its bad code since we used arrays)
if (t == null) // this wont work is T is not a nullable type
{
break;
}
// Return the current element and then on next function call
// resume from next element rather than starting all over again;
yield return t;
}
}
#endregion
#region IEnumerable Members
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
// Lets call the generic version here
return this.GetEnumerator();
}
#endregion
}
Use it:
MyList<string> myListOfStrings = new MyList<string>();
myListOfStrings.Add("one");
myListOfStrings.Add("two");
myListOfStrings.Add("three");
myListOfStrings.Add("four");
foreach (string s in myListOfStrings)
{
Console.WriteLine(s);
}
myListOfStrings.Add("one");
myListOfStrings.Add("two");
myListOfStrings.Add("three");
myListOfStrings.Add("four");
foreach (string s in myListOfStrings)
{
Console.WriteLine(s);
}
Wednesday, January 24, 2018
C# - Return and Yield differences
static int SimpleReturn()
{
return 1;
return 2;
return 3;
}
static void Main(string[] args)
{
// Lets see how simeple return works
Console.WriteLine(SimpleReturn());
Console.WriteLine(SimpleReturn());
Console.WriteLine(SimpleReturn());
Console.WriteLine(SimpleReturn());
}
The reason for this is that the normal return statement does not preserve the state of the function while returning. i.e. every call to this function is a new call and it will return the first value only.
-----------------------------------------------------------------------------------------------------------------------
Where as if I replace the return keyword by yield return then the function will become capable of saving its state while returning the value. i.e. when the function is called second time, it will continue the processing from where is has returned in the previous call.
static IEnumerable<int> YieldReturn()
{
yield return 1;
yield return 2;
yield return 3;
}
static void Main(string[] args)
{
// Lets see how yield return works
foreach (int i in YieldReturn())
{
Console.WriteLine(i);
}
}
{
return 1;
return 2;
return 3;
}
static void Main(string[] args)
{
// Lets see how simeple return works
Console.WriteLine(SimpleReturn());
Console.WriteLine(SimpleReturn());
Console.WriteLine(SimpleReturn());
Console.WriteLine(SimpleReturn());
}
The reason for this is that the normal return statement does not preserve the state of the function while returning. i.e. every call to this function is a new call and it will return the first value only.
-----------------------------------------------------------------------------------------------------------------------
Where as if I replace the return keyword by yield return then the function will become capable of saving its state while returning the value. i.e. when the function is called second time, it will continue the processing from where is has returned in the previous call.
static IEnumerable<int> YieldReturn()
{
yield return 1;
yield return 2;
yield return 3;
}
static void Main(string[] args)
{
// Lets see how yield return works
foreach (int i in YieldReturn())
{
Console.WriteLine(i);
}
}
Friday, January 19, 2018
Razor - Verbatim String in Razor Example
@(SiteSettings.SettingsPage.Debug == true ? @"data-debug=""true""" : @"data-debug=""false""")
Tuesday, January 16, 2018
Javascript, jQuery - Toggle Between Two Functions
let Partner = {
init() {
const $ = require('jquery');
var $selector = 11;
var $link = document.querySelector('[data-clickme]');
var $list = $('.partnerblock__grid a');
var $listSize = $('.partnerblock__grid a:visible').length;
hideListVisibility($, $list, $selector);
$($link).on('click', function(e) {
e.preventDefault();
if ($(this).attr('data-click-state') == 1) {
$(this).attr('data-click-state', 0)
hideListVisibility($, $list, 11);
} else {
$(this).attr('data-click-state', 1)
showListVisibility($, $list, 48);
}
})
}
};
function hideListVisibility($, $list, $selector) {
$($list).each(function() {
var $elem = $(this);
if ($elem.index() > $selector) {
$elem.addClass("hide");
};
});
}
function showListVisibility($, $list, $selector) {
$($list).each(function() {
var $elem = $(this);
if ($elem.index() < $selector) {
$elem.removeClass("hide");
};
});
}
export default Partner;
Friday, January 12, 2018
Subscribe to:
Posts (Atom)
