Skip to content

Instantly share code, notes, and snippets.

View stivio00's full-sized avatar
👾
Hey!

Stephen Krol stivio00

👾
Hey!
View GitHub Profile
@stivio00
stivio00 / graph.js
Created May 19, 2022 21:41
bfs dfs in js
// adj list graph representation:
const g = {
1: [2,3],
2: [4,3],
3: [5],
4: [1],
5: []
};
@stivio00
stivio00 / nodeUtils.cs
Created March 8, 2022 21:59
C# GraphUtils
class AdjListStorage : Dictionary<uint, List<uint>> {
public static AdjListStorage Random(int nodes, float density = .5f){
AdjListStorage storage = new AdjListStorage();
List<uint> nodeIds = Enumerable.Range(0, nodes - 1).Select(Convert.ToUInt32).ToList();
Random random = new Random();
foreach(var nodeId in nodeIds) {
var edges = nodeIds.OrderBy(x => random.Next()).Take((int)(nodes*density)).ToList();
storage.Add(nodeId, edges);
@stivio00
stivio00 / LevenshteinExtension.cs
Last active February 9, 2022 21:59
LINQ method for Edit Operations (inser, delet subst) using Levenshtein algo.
//Levenshtein distance. ->. "HolA".EditDifferences("Hola").Count()
//Optimal edit operations ->. "HolA".EditDifferences("Hola").Reverse()
// returns the list of operations as a 2-tuple (op_string, item)
// where op_string is "+" for insert, "-" deletions and "~" substitution
public static IEnumerable<(string, TSource)> EditDifferences<TSource>(this IEnumerable<TSource> input, IEnumerable<TSource> old){
TSource[] s1 = input.ToArray(), s2 = old.ToArray(); //cache for random access
int[,] matrix = new int[s1.Count()+1, s2.Count()+1];
using System;
using System.Reflection;
using System.Data;
using System.Linq;
using System.Collections.Generic;
namespace DataTableTools
{
static class DataTableTools
{
@stivio00
stivio00 / f.m
Created September 20, 2011 03:11
Matlab stuff
function y = f(x,m)
% f esta funcion la funcion impulso rectangulo respresentado en sus serie
% de fourier y consta de M componentes, para llamar esta funcion f(x,m)
% donde x es el valor en la funcion y m el numero de componentes.
% Si quiere ver la funcion con sus cuatros componentes seria f(x,4)
% ejemplo, para graficar con 4 componentes:
% x = 0: .001 : 10;
% plot(x, f(x,4);
y = 0;
for i =1:m
@stivio00
stivio00 / pwm_motor.cpp
Created September 5, 2011 02:03
A Speed driver ussing PWM and a Arduino
int pin = 11;
int val = 255;
int command;
void printMsg(){
Serial.println("Welcome to speed controller");
Serial.println(" type ");
Serial.println(" - z : to speed up ");
Serial.println(" - x : to speed down");
Serial.println(" - s : set manually(submenu)");
@stivio00
stivio00 / PwmMotorController.java
Created September 5, 2011 01:59
PWM Controller class for javelin stamp
import stamp.core.*;
/** PWM Controller class
* in main: enter to a mainloop , command from the serial
* is using pwm to control a dc motor
*/
class PwmMotorController {
PWM pwm;
char command;
@stivio00
stivio00 / gist:745769
Created December 17, 2010 21:54
loc at android v2
/**
* @author Stephen Krol (mlea)
*/
package org.mlea;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.GpsSatellite;
@stivio00
stivio00 / gist:744525
Created December 17, 2010 05:28
localization on android,
/**
* @author Stephen Krol
*/
package org.mlea;
import android.app.Activity;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.View;
# -*- coding: utf-8 -*-
#Stephen Krol
#Funciona con Python 2.6.x
#Metodo de secante
#Lab 3
c=0 # contador
# Asumiendo que la entrada debe de ser menor que 250 °C