Skip to content

Instantly share code, notes, and snippets.

View cyberhck's full-sized avatar

Nishchal Gautam cyberhck

View GitHub Profile
@cyberhck
cyberhck / Tile.tsx
Created January 23, 2024 13:55 — forked from paibamboo/Tile.tsx
Tile layout using display grid
import * as React from "react";
import {classes, style as typestyle} from "typestyle";
import {buildBreakpoints} from "../../../helpers/buildBreakpoints";
import {ITileBreakpoint} from "./interfaces";
export interface IProps {
spanColumn?: number;
spanRow?: number;
/**
* Internal usage
@cyberhck
cyberhck / main.go
Last active February 2, 2021 11:55
test
package main
import (
"github.com/cyberhck/local/tonic"
)
type User struct {
Name string `json:"name"`
Email string `json:"email"`
Authorization string `in:"header" name:"Authorization"`
@cyberhck
cyberhck / docker-compose-full.yml
Last active October 14, 2020 09:42
docker-compose feature.manager.ui
version: '3.0'
services:
api:
image: cyberhck/test.feature.manager
ports:
- 5001:5001
environment:
- DatabaseConfig__Host=api_db
- DatabaseConfig__Port=5432
- DatabaseConfig__User=api
const clean = (timeToWait, includeAbandoned = false) => {
if (!window.location.href.includes("/branches/stale")) {
return;
}
const branches = () => Array.from(document.querySelectorAll("li.Box-row.js-branch-row"));
const isMerged = (branch) => branch.querySelector("a.State.State--purple") !== null;
const isClosed = (branch) => branch.querySelector("a.State.State--red") !== null;
const isAbandoned = (branch) => branch.querySelector("a.btn.test-compare-link");
const isMergedOrClosed = (branch) => isMerged(branch) || isClosed(branch);
const isMergedClosedOrAbandoned = (branch) => isMergedOrClosed(branch) || isAbandoned(branch);
namespace Micro.Starter.Api {
public interface IService {
string Greet(string name);
}
public class Service : IService {
public string Greet(string name) {
return $"Hello {name}";
}
}
}
namespace Tests
{
public class BadClassTest
{
[Test]
public void TestGreetDoesNotThrowException()
{
var unit = new BadClass();
// var mock = new Mock<IService>(); (setup as well)
// use reflection to change the implementation under the hood, (unit._service = mock)
@cyberhck
cyberhck / BadClass.cs
Created April 16, 2020 02:03
Demonstration of bad code, and even worst way of testing bad code
using System;
namespace Micro.Starter.Api {
public class BadClass {
private IService _service = new Service(); // it's a bad idea to do new inside a class, remember, new is glue
public void Greet(string name) {
Console.WriteLine(_service.Greet(name));
}
}
}
@cyberhck
cyberhck / toHaveTypeStyleMatcher.test.ts
Created November 25, 2018 03:35
matcher for typestyle's style
import ToHaveTypeStyleMatcher from "./ToHaveTypeStyleMatcher";
describe("ToHaveTypeStyleMatcher", () => {
it("compare returns an object containing message and pass key", () => {
const prop = jest.fn(() => "TS-0000");
const typestyleErrorMessageSnip = "TypeStyle does not match with actual, instead found";
expect(typeof (ToHaveTypeStyleMatcher as any).toHaveTypeStyle().compare({prop}) === "object").toBeTruthy();
const compare = (ToHaveTypeStyleMatcher as any).toHaveTypeStyle().compare({prop});
expect(compare.message).toBeDefined();
expect(compare.pass).toBeDefined();
@cyberhck
cyberhck / simple_fetch.js
Created July 4, 2018 13:00
medium posts
fetch("api.example.com/user/1/posts", {header: {Authorization: "Bearer: <JWT TOKEN>"}})
.then(res => res.json())
.then(res => {
console.log(res)
})
@cyberhck
cyberhck / index.c
Last active June 10, 2016 07:58
webserver
#include<netinet/in.h>
#include<signal.h>
#include<stdio.h>
#include<stdlib.h>
#include<sys/socket.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<unistd.h>
#include<string.h>
void sig_handler();