Skip to content

Instantly share code, notes, and snippets.

View cyberhck's full-sized avatar

Nishchal Gautam cyberhck

View GitHub Profile
public class ContactChooser extends ActionBarActivity{
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_contact_chooser);
Cursor cursor=getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,null,null,null,null
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hash Tag Demo</title>
<script>
function parse() {
text = document.getElementById("postToorq").value;
res = text.replace(/#[a-z0-9][a-z0-9\-_]*/gi, "<strong>$&</strong>");
res = res.replace(/ /g, "&nbsp;");
@cyberhck
cyberhck / isPrime.c
Created December 25, 2014 09:41
A better than our lab isPrime function.
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main(){
int n;
printf("Enter a number\n");
scanf("%d",&n);
if(isPrime(n)){
printf("Is prime number\n");
}else{
@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();
@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 / 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 / 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));
}
}
}
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)
namespace Micro.Starter.Api {
public interface IService {
string Greet(string name);
}
public class Service : IService {
public string Greet(string name) {
return $"Hello {name}";
}
}
}
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);