Skip to content

Instantly share code, notes, and snippets.

@Flayed
Flayed / jquery-scrolllock.js
Last active December 21, 2015 22:49 — forked from theftprevention/jquery-scrolllock.js
Locks the mousewheel scrolling functionality to a particular element. This version also handles horizontal scrolling (that is, spinning the mouse wheel while holding the shift key).
$.fn.scrollLock = function () { return $(this).on("DOMMouseScroll mousewheel", function (h) { var g = $(this), s = h.shiftKey, f = (s ? this.scrollLeft : this.scrollTop), d = (s ? this.scrollWidth : this.scrollHeight), b = (s ? g.width() : g.height()), i = h.originalEvent.wheelDelta, a = i > 0, c = function () { h.stopPropagation(); h.preventDefault(); h.returnValue = false; return false }; if (!a && -i > d - b - f) { if (s) { g.scrollLeft(d); } else { g.scrollTop(d); } return c() } else { if (a && i > f) { if (s) { g.scrollLeft(0); } else { g.scrollTop(0); } return c() }}})}; $.fn.scrollRelease = function () { return $(this).off("DOMMouseScroll mousewheel") };
@Flayed
Flayed / hosts
Last active August 1, 2016 15:09 — forked from eyecatchup/hosts
Disable Skype ads: 1.) Add hosts to your hosts file 2.) Flush DNS resolver cache (ipconfig /flushdns)
# Block Skype ads
127.0.0.1 *.msads.net
127.0.0.1 *.msecn.net
127.0.0.1 *.rad.msn.com
127.0.0.1 a.ads2.msads.net
127.0.0.1 ac3.msn.com
127.0.0.1 ad.doubleclick.net
127.0.0.1 adnexus.net
127.0.0.1 adnxs.com
127.0.0.1 ads1.msn.com
@Flayed
Flayed / TestBase.cs
Created August 14, 2017 15:04
Unit Test Base
public class TestBase
{
private readonly ConcurrentDictionary<Type, object> _dependencies = new ConcurrentDictionary<Type, object>();
/// <summary>
/// Gets the substitute matching the provided type from the dependency list
/// </summary>
/// <typeparam name="T">The type of substitute to match</typeparam>
/// <returns>The substitute matching the provided type</returns>
public T GetSubstitute<T>()
@Flayed
Flayed / Defer.cs
Created September 15, 2017 02:39
Starts a task, deferring the action until a timeout has elapsed
private readonly ConcurrentDictionary<Guid, Task> _tasks = new ConcurrentDictionary<Guid, Task>();
public void Defer(Action action, int delay, CancellationToken cancellationToken)
{
if (action == null) return;
if (cancellationToken.IsCancellationRequested) return;
Guid key = Guid.NewGuid();
_tasks.TryAdd(key, Task.Run(async () =>
{
try
@Flayed
Flayed / jssd.cs
Created September 29, 2017 13:56
json.net serialize and deserialize
using Newtonsoft.Json;
T obj = JsonConvert.DeserializeObject<T>(json);
string json = JsonConvert.SerializeObject(obj);
@Flayed
Flayed / JsonConverter.cs
Last active September 29, 2017 14:08
JsonConverter
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Flayed.JsonConverterDemo
{
public class CustomJsonConverter : JsonConverter
{
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
@Flayed
Flayed / JsonProperty.cs
Created September 29, 2017 14:13
JsonProperty
using Newtonsoft.Json;
namespace Flayed.JsonConvertDemo
{
public class CustomFieldsDto
{
[JsonProperty("17040")]
public string CustomFieldOne { get; set; }
[JsonProperty("823")]
@Flayed
Flayed / LaunchAsAdmin.cmd
Last active October 19, 2017 22:31
Launches command prompt as Administrator
:: BatchGotAdmin
:-------------------------------------
REM Check for permissions
IF '%PROCESSOR_ARCHITECTURE%' EQU 'amd64' (
>nul 2>&1 "%SYSTEMROOT%\SysWOW64\icacls.exe" "%SYSTEMROOT%\SysWOW64\config"
) ELSE (
>nul 2>&1 "%SYSTEMROOT%\system32\icacls.exe" "%SYSTEMROOT%\system32\config"
)
REM If error flag set, we do not have admin.
@Flayed
Flayed / Client.cs
Created October 24, 2017 20:35
TcpClient fail
private TcpClient client = new TcpClient();
public async Task<string> ConnectSendReceive(string message, int port)
{
Connect(port);
await Write(message);
return await Read();
}
private void Connect(int port)
@Flayed
Flayed / Client.cs
Created October 24, 2017 20:41
TcpClient works
private TcpClient client = new TcpClient();
public async Task<string> ConnectSendReceive(string message, int port)
{
Connect(port);
await Write(message);
string response = await Read();
client.Close();
return response;