Skip to content

Instantly share code, notes, and snippets.

@miroslavradojevic
miroslavradojevic / copy-random-selected-files.r
Created February 10, 2018 19:38
Script selects N random jpg unique files from given source directory and copies them to the given destination directory. Source dir needs to have at least N files if sampled withoud replacement.
rm(list=ls(all=TRUE))
N = 500;
dirSrc <- "/Users/miroslav/ndethcmml/ScSPM/image/patch/0"
dirDst <- "/Users/miroslav/ndethcmml/ScSPM/image/patch_1k_1/0"
# check if the directory exists and create one if not
dir.create(dirDst, recursive = T, showWarnings = F) # file.path(mainDir, subDir)
fSrcList <- list.files(dirSrc, pattern = "\\.jpg$", ignore.case = T, full.names = T)
@miroslavradojevic
miroslavradojevic / self-host-program.cs
Created February 12, 2018 09:23
Self Host application using OWIN
class Program
{
static void Main(string[] args)
{
string baseUrl = "http://localhost:9090"; // webserver running on port 9090
using (WebApp.Start<Startup>(baseUrl))
{
Console.WriteLine(baseUrl);
Process.Start(baseUrl); // open the page from the application
Console.WriteLine("Press Enter to quit.");
@miroslavradojevic
miroslavradojevic / self-host-setup-configuration
Last active February 12, 2018 09:54
Method to configure the Startup class for initializing the self host.
class Startup {
public void Configuration(IAppBuilder app) {
//...
// configure web api
// configure file server
//...
}
}
@miroslavradojevic
miroslavradojevic / self-host-configuration-fileserve
Created February 12, 2018 10:05
Add file server from relative path, named wwwroot.
class Startup {
public void Configuration(IAppBuilder app){
if (!Directory.Exists("wwwroot")) Directory.CreateDirectory("wwwroot");
var physicalFileSystem = new PhysicalFileSystem("./wwwroot");
// file server options
var options = new FileServerOptions
{
EnableDefaultFiles = true,
@miroslavradojevic
miroslavradojevic / createXml.js
Created March 9, 2018 12:02
Create XML in JavaScript
var xmlDoc = document.implementation.createDocument(null, "devices");
var elements = xmlDoc.getElementsByTagName("devices");
var node = xmlDoc.createElement("DeviceA"); // do not use the methods provided by the document namespace
node.setAttribute('ID', 1000);
node.setAttribute('DESCRIPTION', 'NameA');
elements[0].appendChild(node); // add the element
var node = xmlDoc.createElement("DeviceB");
node.setAttribute('ID', 2000);
using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Linq;
namespace GetAudio
{
using System;
using System.Diagnostics;
using System.Threading;
using System.Timers;
namespace TryTiming
{
class Program
{
static void Main(string[] args)
@miroslavradojevic
miroslavradojevic / TimerPeriodic.cs
Last active August 2, 2018 09:25
Timer triggers some action every 500ms and can be stopped or started with button press.
namespace TimerElapsed
{
using System;
using System.Timers;
public class Program
{
static Timer myTimer;
static void Main(string[] args)
@miroslavradojevic
miroslavradojevic / TimerElpased.cs
Created August 2, 2018 09:32
Timer activated, triggering action after 5000ms. Needs another activation to start interval count again.
namespace TimerElapsed
{
using System;
using System.Timers;
public class Program
{
private static bool elapsed = false;
@miroslavradojevic
miroslavradojevic / mycnn.py
Last active November 27, 2018 09:02
Convolutional network used to quantify and identify bacteria colony patches.
from keras.models import Sequential
from keras.layers.convolutional import Conv2D, MaxPooling2D, ZeroPadding2D
from keras.constraints import maxnorm
from keras.layers import Flatten, Dense, Dropout, Activation
from keras import backend as K
from keras.layers.normalization import BatchNormalization
from keras.regularizers import l2
def mycnn(img_shape=(32, 32, 1), n_classes=2, l2_reg=0.0, weights=None):
K.set_image_data_format("channels_last")