Skip to content

Instantly share code, notes, and snippets.

View omsharp's full-sized avatar

Omar Rwemi omsharp

View GitHub Profile
@omsharp
omsharp / combine.ts
Created August 24, 2021 19:57
Combinations from n arrays picking one element from each array
export const combine = (arrays: string[][]) => {
// computing the total count of all combinations
let totalCount = arrays.reduce((count, array) => count * array.length, 1);
// initialize the result array
const result = new Array(totalCount);
for (let i = 0; i < totalCount; i++) {
result[i] = '';
}
@omsharp
omsharp / heroku_push
Last active October 11, 2020 22:44
Throwaway Commits for Heroku
#!/bin/bash
# Temporarily test current edits on Heroku
# https://rhodesmill.org/brandon/2012/quietly-pushing-to-heroku/
set -e
git add .
git commit -m 'Heroku temporary commit'
git push heroku master --force
@omsharp
omsharp / ImportMefComponent.cs
Created May 3, 2020 07:02 — forked from madskristensen/ImportMefComponent.cs
Import MEF components from non-MEF exported classes
using System.ComponentModel.Composition;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.TableManager;
public class ExtensionPackage : Package
{
[Import]
private ITableManagerProvider _tableManagerProvider;
protected override void Initialize()
@omsharp
omsharp / RestrictedInt.cpp
Last active April 23, 2016 15:37
A C++ template for restricted int.
template<int Min, int Max> class RestrictedInt {
private:
int value;
explicit RestrictedInt(int val) : value(val) {}
public:
int GetValue() const { return value; }
template<int Value> static RestrictedInt CreateObject() {
static_assert(Value >= Min && Value <= Max, "ResctrictedInt: value is out of range!");
@omsharp
omsharp / isHappy.rkt
Last active August 29, 2015 14:19
Displays "Happy :)" if n is a happy number, otherwise displays "Unhappy :("
#lang racket
; Is n a happy number.
(define (isHappy n)
; returns i squared.
(define (square i) (* i i))
; returns the last digit in n.
(define (getLastDigit n) (modulo n 10))
; returns n with the last digit omitted.
(define (omitLastDigit n) (truncate (/ n 10)))
; returns the square of the last digit in n.
@omsharp
omsharp / GZipper.cs
Last active August 29, 2015 14:19
Simple GZip Compressing Utility.
public static class GZipper
{
private const int BUFFER_SIZE = 64 * 1024;
public static byte[] Compress(byte[] data)
{
if (data == null)
throw new ArgumentNullException("data", "data can't be null!");
byte[] result;