Skip to content

Instantly share code, notes, and snippets.

@riyadparvez
riyadparvez / BFS.cs
Last active March 19, 2024 20:44
An implementation of breadth first search or BFS in C#.
public class Tree<K, V>
where K : class, IComparable<K>
where V : class
{
private Node<K, V> root;
public V BFS(K key)
{
Queue<Node<K, V>> queue = new Queue<Node<K, V>>();
@riyadparvez
riyadparvez / StreamTokenizer.cs
Last active February 6, 2024 07:40
C# port of java's StreamTokenizer class. Everything kept same except some renaming for following C# naming convention. And it also implements IEnumerable for foreach support
/**
* The <code>StreamTokenizer</code> class takes an input stream and
* parses it into "tokens", allowing the tokens to be
* Read one at a time. The parsing process is controlled by a table
* and a number of flags that can be set to various states. The
* stream tokenizer can recognize identifiers, numbers, quoted
* strings, and various comment styles.
* <p>
* Each byte Read from the input stream is regarded as a character
* in the range <code>'&#92;u0000'</code> through <code>'&#92;u00FF'</code>.
@riyadparvez
riyadparvez / SqlTableCreator.cs
Last active August 12, 2022 12:41
Create Sql table based on given DataTable schema
// Copyright (c) 2012-2013, Riyad Parvez
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
@riyadparvez
riyadparvez / FloydCycleDetectionAlgorithm.cs
Created July 8, 2013 08:55
Floyd cycle detection algorithm in C#.
public static bool FloydCycleDetection<T>(LinkedList<T> list)
{
var tortoise = list.First;
var hare = list.First;
while (tortoise != null && hare != null)
{
if(tortoise == hare)
{
return true;
@riyadparvez
riyadparvez / Dockerfile
Created February 2, 2022 04:54 — forked from knowsuchagency/Dockerfile
Makefile Docker Git GitHub multi-stage build ssh private key recipe
FROM python:3 as build-system
RUN pip install -U pip
COPY requirements.txt requirements.txt
### create temporary image used to download and vendor packages using private key ###
FROM build-system as intermediate
# add credentials on build
@riyadparvez
riyadparvez / ReflectionUtilities.cs
Created January 6, 2013 14:50
Reflection utilities for C#. Get all fields, constructors, methods and properties
/// <summary>
/// Utilties for reflection
/// </summary>
public static class ReflectionUtils
{
/// <summary>
/// Get all the fields of a class
/// </summary>
/// <param name="type">Type object of that class</param>
/// <returns></returns>
@riyadparvez
riyadparvez / FacebookAutoCommenter.py
Last active July 14, 2021 05:41
This python script auto comment thanks on facebook wall posts
# Thanking everyone who wished me on my birthday
import requests
import json
from time import strftime
AFTER = #convert your time to iso 8601 time
TOKEN = ' <insert token here> '
def get_posts():
@riyadparvez
riyadparvez / CsvUtils.cs
Created January 6, 2013 14:48
DataTable to CSV extension methods. Export to CSV file, CSV string
public static class CSV
{
public static string ToCSV(this DataTable table)
{
var columnHeaders = (from DataColumn x in table.Columns
select x.ColumnName).ToArray();
StringBuilder builder = new StringBuilder(String.Join(",", columnHeaders));
builder.Append("\n");
foreach (DataRow row in table.Rows)
@riyadparvez
riyadparvez / DFS.cs
Last active August 28, 2019 00:30
Implementation of depth first search or DFS in C#.
public class Tree<K, V>
where K : class, IComparable<K>
where V : class
{
private Node<K, V> root;
public V DFS(K key)
{
Stack<Node<K, V>> stack = new Stack<Node<K, V>>();
@riyadparvez
riyadparvez / FixedSizeQueue.cs
Created July 3, 2013 09:00
Fixed size blocking queue in C#.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Queue
{
class FixedSizeQueue<T>