Skip to content

Instantly share code, notes, and snippets.

@n3rd
n3rd / backup.sh
Created April 24, 2019 18:31
Script for scheduled recursive FTP backup
#!/bin/bash
# backups a ftp host (complete all recursive)
# currently does not support the backup of a specified directory
cd "$(dirname "$0")"
backupfile=$(date +%Y%m%d)
savetodir=./backup-$(date +%Y)/
host=ftp.site.com
@n3rd
n3rd / Base10ToBase64Url.cs
Last active August 12, 2017 17:13
Base10ToBase64Url
public static string Base10ToBase64Url(ulong base10)
{
char[] base64url = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".ToCharArray();
var res = new List<char>();
for (ulong remainder = base10, mod = remainder % 64; remainder > 0; remainder = remainder / 64, mod = remainder % 64)
{
res.Add(base64url[mod]);
}
res.Reverse();
return new String(res.ToArray());
@n3rd
n3rd / IQueryableExtensions.cs
Created February 12, 2017 11:58
OrderBy string (NET Core)
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
internal static class IQueryableExtensions
{
public static IQueryable<T> OrderBy<T>(this IQueryable<T> source, string ordering)
{
return source.OrderBy(ordering, "OrderBy");
@n3rd
n3rd / HttpAuthModule.cs
Created August 6, 2016 17:07
HttpAuthModule
using System;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading;
using System.Web;
namespace HttpAuthModule
{
public class HttpAuthModule : IHttpModule
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using System;
using System.IO;
using System.Net.Mime;
using System.Threading.Tasks;
namespace N3rd.Storage
{
public interface IStorageProvider
@n3rd
n3rd / RotaryEncoder.py
Last active December 3, 2019 14:26
Raspberry Pi + KY040 Rotary Encoder (+ S/W Volume Control)
#!/usr/local/bin/python
import RPi.GPIO as GPIO
class RotaryEncoder:
DIRECTION_CLOCKWISE = 1
DIRECTION_COUNTERCLOCKWISE = 3
prv_seq = 0
@n3rd
n3rd / gist:5c29fd1ccd23852e050c
Last active August 29, 2015 14:06
jQuery X-HTTP-Method-Override for all requests (using ajaxSetup)
$.ajaxSetup({
beforeSend: function (jqXHR, settings) {
var types = ['DELETE', 'HEAD', 'PUT'];
if ($.inArray(settings.type, types) !== -1) {
jqXHR.setRequestHeader('X-HTTP-Method-Override', settings.type);
settings.type = 'POST';
}
}
});
@n3rd
n3rd / sortableListBindingHandler.js
Created April 27, 2014 10:59
Knockout BindingHandler for jQuery UI sortalble
ko.bindingHandlers.sortableList = {
init: function (element, valueAccessor, allBindings) {
var items = allBindings.get('items') || 'li';
var update = allBindings.get('update') || 'Index';
var disable = allBindings.get('disable') || false;
$(element).sortable({
items: items,
update: function ($e, $ui) {
$ui.item.parent().children(items).each(function (k, v) {
@n3rd
n3rd / AuthenticationHandler.cs
Created March 13, 2014 20:56
Google OAuth 2.0 DelegatingHandler
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Security.Claims;
using System.Security.Principal;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
@n3rd
n3rd / Rx-Test.cs
Last active December 30, 2015 17:29
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Reactive.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Rx_Test