Skip to content

Instantly share code, notes, and snippets.

@CVertex
CVertex / print-ordered-features.js
Created March 10, 2016 22:52
Prints the non-zero features in the console in BigML cluster console
var scores = [];
$('.kluster-fields').find('.numeric').each(function() {
var r = $(this);
var name = r.find('span:first').text().replace(":","");
var val = parseFloat(r.find('strong').text());
//console.log(name + ' ' + val);
var s = {name:name,score:val};
scores.push(s);
});
@CVertex
CVertex / debouncer.js
Created July 7, 2016 06:57 — forked from jasonwyatt/debouncer.js
How to **correctly** debounce an event that will be triggered many times with identical arguments.
function debounce(fn, debounceDuration){
// summary:
// Returns a debounced function that will make sure the given
// function is not triggered too much.
// fn: Function
// Function to debounce.
// debounceDuration: Number
// OPTIONAL. The amount of time in milliseconds for which we
// will debounce the function. (defaults to 100ms)
@CVertex
CVertex / OverlayWithLinearGradient.cs
Created August 13, 2016 04:05
My first imageprocessor IGraphicsProcessor
public class OverlayWithLinearGradient : IGraphicsProcessor
{
public OverlayWithLinearGradient()
{
this.DynamicParameter = Tuple.Create(Color.PaleVioletRed, Color.CornflowerBlue);
this.Settings = new Dictionary<string, string>();
}
public dynamic DynamicParameter
// srcColor:Color, destColor:Color
// We're converting everything to doubles [0,1.0], then performing multiply
// then converting back to byte
// These conversions are slow
var sr = Convert.ToDouble(srcColor.R) / 255.0;
var sg = Convert.ToDouble(srcColor.G) / 255.0;
var sb = Convert.ToDouble(srcColor.B) / 255.0;
@CVertex
CVertex / Effects.LinearGradient.cs
Created August 13, 2016 04:48
Linear gradient (left to right) using GDI
public static Bitmap LinearGradient(Image source, Color leftColor, Color rightColor)
{
// Create the gradient
//using (var grad = new )
// Mutate the source
using (Graphics graphics = Graphics.FromImage(source))
{
Rectangle bounds = new Rectangle(0, 0, source.Width, source.Height);
@CVertex
CVertex / load_spotify_markets.js
Created September 14, 2016 06:46
Read all Spotify Markets from Spotify Charts
// Visit https://spotifycharts.com/regional and run the following in console
var ts = '';
$('div[data-type=country] ul li').each(function(i,val) {
ts += 'new Market("' + $(val).text() + '","' + $(val).attr("data-value").toUpperCase() + '"),' + " ";
});
console.log(ts);
@CVertex
CVertex / DeliminatorSeparatedPropertyNamesContractResolver.cs
Created September 24, 2016 12:13 — forked from roryf/DeliminatorSeparatedPropertyNamesContractResolver.cs
Snake case (underscore separated) property name resolver for Newtonsoft.Json library
public class DeliminatorSeparatedPropertyNamesContractResolver : DefaultContractResolver
{
private readonly string _separator;
protected DeliminatorSeparatedPropertyNamesContractResolver(char separator) : base(true)
{
_separator = separator.ToString();
}
protected override string ResolvePropertyName(string propertyName)
@CVertex
CVertex / model_to_release.py
Created October 10, 2016 04:11 — forked from keunwoochoi/model_to_release.py
playlist generation model
import keras
from keras.models import Sequential
from keras.layers.core import Dense, Activation, Dropout, TimeDistributedDense
from keras.layers.recurrent import LSTM, SimpleRNN
def build_model(num_layers=2, num_units=256, maxlen_rnn=50, dim_label=50):
'''
num_layers: in [2, 3]
num_units: in [256, 512, 1024]
@CVertex
CVertex / Interval.cs
Created November 23, 2016 06:44 — forked from hongymagic/Interval.cs
Representing Intervals in C# with Generics support `Interval<T>`
using System;
namespace Hongy
{
/// <summary>
/// Represents vectorless interval of the form [a, b] or (a, b) or any
/// combination of exclusive and inclusive end points.
/// </summary>
/// <typeparam name="T">Any comparent type</typeparam>
/// <remarks>
@CVertex
CVertex / Storage.ts
Created January 3, 2017 06:36
Storage Typescript adapter layer. Use localStorage when useable, otherwise cookies
namespace Util {
// Contract for storage
export interface Storage {
getItem(key: string): any;
removeItem(key: string): void;
setItem(key: string, data: string): void;
}
// Borrowed from https://gist.github.com/wittnl/2890870