Skip to content

Instantly share code, notes, and snippets.

View ihorbond's full-sized avatar
💻
Coding

Ihor Bodnarchuk ihorbond

💻
Coding
View GitHub Profile
@ihorbond
ihorbond / zip-code.directive.ts
Last active July 20, 2018 22:39
Angular FormControl ZipCode Directive for North America
import { Directive, ElementRef, Input, HostListener} from '@angular/core';
import { NgControl, ValidationErrors } from '@angular/forms';
/*
* Directive to format zip codes on FormControl
*/
@Directive({
selector: '[zipCode]'
})
@ihorbond
ihorbond / postgre to mssql
Last active March 7, 2019 22:00
Replace underscores and capitalize
let text = `
CREATE TABLE [dbo].[images]
(
[image_id] INT NOT NULL PRIMARY KEY,
[url] VARCHAR(200) NOT NULL,
[tour_id] INT NULL,
[user_id] INT NULL,
[created_on] DATETIME2(1) NULL DEFAULT GETDATE(),
CONSTRAINT [CK_images_tour_id] CHECK (tour_id is not null or user_id is not null),
CONSTRAINT [FK_images_users] FOREIGN KEY ([user_id]) REFERENCES [users]([user_id])
@ihorbond
ihorbond / form-control-decimal.directive.ts
Last active July 1, 2019 14:08
Angular 4 decimal directive
import { Input, Directive, HostListener } from "@angular/core";
import { NgControl } from "@angular/forms";
import { DecimalPipe } from "@angular/common";
/*
* Form control decimal directive.
* Pass optional custom regex and pipe expression.
* */
@Directive({
@ihorbond
ihorbond / EncryptionHelper.cs
Created April 26, 2020 21:25
Encrypt file with BouncyCastle and C#
using Org.BouncyCastle.Bcpg;
using Org.BouncyCastle.Bcpg.OpenPgp;
using Org.BouncyCastle.Security;
using System;
using System.IO;
namespace Helpers
{
public class EncryptionHelper
{
@ihorbond
ihorbond / Uploader.cs
Created April 27, 2020 17:32
Upload file anonymously with C#
private static async Task<string> UploadFile(byte[] bytes, string expiresParam = "1d", bool noIndexParam = true)
{
string res = null;
try
{
using (var client = new HttpClient())
using (var formData = new MultipartFormDataContent())
{
formData.Add(new StringContent(noIndexParam.ToString()), "no_index");
formData.Add(new StringContent(expiresParam), "expires");
@ihorbond
ihorbond / clamp-text.css
Created July 1, 2020 21:13
Clamp text with ellipsis after certain number of lines
.clamp {
display: -webkit-box;
overflow: hidden;
text-overflow: ellipsis;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
}
@ihorbond
ihorbond / GroupByDateTime.cs
Created July 1, 2020 21:16
How to group items by day, week and year
IEnumerable<dynamic> GetGroup()
{
return settings.GroupBy switch
{
GroupByEnum.Day => listOfObjects.GroupBy(x => new DateTime(x.StartDate.Year, x.StartDate.Month, x.StartDate.Day))
.Select(x => new
{
Date = x.Key.ToString("d"),
Items = x
}),
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
@ihorbond
ihorbond / solc-compiler.js
Created December 22, 2021 00:19
Solc compiler js
function findImports(missingImport) {
if (missingImport.startsWith('@openzeppelin')) {
console.log(`reading import ${missingImport}`)
return {
contents: fs.readFileSync(path.join('../node_modules', missingImport), 'utf8')
};
}
else {
console.log(`import ${missingImport} not found`);
return { error: 'File not found' };
@ihorbond
ihorbond / setRarities.js
Created December 30, 2021 23:27
Drop this file into your layers folder, set the percentages sorted alphabetically and run with node ./setRarities.js
const fs = require('fs');
const path = require('path')
function validate(basePath) {
console.log("running validation")
Object.entries(percentages).forEach(([key,val]) => {
const folderPath = path.join(basePath, key)
fs.readdir(folderPath, (err, files) => {