Skip to content

Instantly share code, notes, and snippets.

@SpeedOfSpin
SpeedOfSpin / ICacheService.cs
Created December 5, 2013 15:21
Simple wrapper for HTTP cache object.
public class InMemoryCache : ICacheService
{
public T Get<T>(string cacheID, TimeSpan duration, Func<T> getItemCallback) where T : class
{
T item = HttpRuntime.Cache.Get(cacheID) as T;
if (item == null)
{
item = getItemCallback();
HttpContext.Current.Cache.Insert(cacheID, item, null, System.Web.Caching.Cache.NoAbsoluteExpiration, duration);
}
@SpeedOfSpin
SpeedOfSpin / gist:510897268803ca9ced2c7f8aaadef109
Created January 8, 2018 15:59
setTimeout equivalent in C#
var cancellationTokenSource = new CancellationTokenSource();
var cancellationToken = cancellationTokenSource.Token;
Task.Delay(2000).ContinueWith(async (t) =>
{
//Do stuff
}, cancellationToken);
@SpeedOfSpin
SpeedOfSpin / gist:ab3db7718aedc6c1f8192a73797fe172
Created January 8, 2018 16:00
Get query parameters as dictionary in javascript
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
@SpeedOfSpin
SpeedOfSpin / gist:dff77c3b47ea9cec88d1da69a8cc0efe
Created January 8, 2018 16:01
Wait for a file to be ready
public static void WaitFileReady(string fileName)
{
while (true)
{
try
{
using (Stream stream = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
if (stream != null)
{
@SpeedOfSpin
SpeedOfSpin / gist:5760559b34e1c8c1523d9ab5a178f29f
Created January 8, 2018 16:02
Strip all characters except Alpha
public string strip(string str)
{
char[] arr = str.ToCharArray();
arr = Array.FindAll<char>(arr, (c => (char.IsLetter(c))));
str = new string(arr);
return str.ToLowerInvariant();
}
@SpeedOfSpin
SpeedOfSpin / gist:ba8fec1fc522311b0e0742325eb453ac
Created January 10, 2018 16:37
Tensorflow and Keras in Conda
conda create --name tensorflow python=3.5
activate tensorflow
conda install jupyter
conda install scipy
conda install spyder
conda install pip
pip install tensorflow
pip install pyyaml h5py
pip install keras
pip install opencv-python
var locale = "en-GB";
//IE
if ((<any>(navigator)).browserLanguage) {
locale = (<any>navigator).browserLanguage;
}
//All other vendors
else if (navigator.language) {
locale = (<any>navigator).language;
}
@SpeedOfSpin
SpeedOfSpin / installing_caffe.md
Last active August 1, 2018 14:17 — forked from nikitametha/installing_caffe.md
Installing Caffe on Ubuntu 16.04 and above (CPU ONLY, WITHOUT CUDA OR GPU SUPPORT)

This is a guide on how to install Caffe for Ubuntu 16.04 and above, without GPU support (No CUDA required).

Prerequisites:

OpenCV

sudo apt-get install libopencv-dev python-opencv opencv-contrib-python

OpenBLAS OR Atlas

@SpeedOfSpin
SpeedOfSpin / gist:e089345663f7510742b9aafb76aa22fa
Last active July 26, 2018 14:39
Get VSCode working on XFCE
#Install XFCE4
sudo apt install xfce4
sudo apt-add-repository ppa:x2go/stable
sudo apt-get update
sudo apt-get install x2goserver x2goserver-xsession
#Intsall VSCode
sudo add-apt-repository ppa:ubuntu-desktop/ubuntu-make
sudo apt-get update
sudo apt-get install ubuntu-make
@SpeedOfSpin
SpeedOfSpin / gist:400bfd7a7199eabcb12ba078f8ab6254
Created July 6, 2018 11:26
Untrack and retrack files for Git
git rm -r --cached .
git add .
git commit -m "untrack files contained in the .gitignore file"