Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View cnayan's full-sized avatar

Nayan Choudhary cnayan

View GitHub Profile
@cnayan
cnayan / FastDel.bat
Created April 19, 2022 17:39
FastDel Windows
DEL /F/Q/S "%1" > NUL
RMDIR /Q/S "%1"
@cnayan
cnayan / GitHub API call samples.txt
Last active April 20, 2022 09:39
Enterprise GitHub REST APIs for automation
Year 2022!
Here is how to make repos private:
curl -u <user_name>:<POWERFUL_PAT> -X PATCH -H "Accept: application/vnd.github.nebula-preview+json" -d "{\"visibility\":\"private\"}" https://<org_server>/api/v3/repos/{user_name}/{repo_name}
And this is how you move a repo to another user
curl -u <user_name>:<POWERFUL_PAT> -X POST -H "Accept: application/vnd.github.nebula-preview+json" -d "{\"new_owner\":\"platts\",\"team_ids\":[278,186]}" https://<org_server>/api/v3/repos/{user_name}/{repo_name}/transfer
Get the ID of a team by using
curl -u <user_name>:<POWERFUL_PAT> -H "Accept: application/vnd.github.nebula-preview+json" https://<org_server>/api/v3/orgs/platts/teams/{team_name}
@cnayan
cnayan / Monaco Suggestion Provider With All Words.js
Last active February 16, 2022 16:45
Monaco - Editor (v 0.21.2) Autocomplete Suggestion Provider With All Words
// Javascript code
const snippets = [
{
label: "fk",
kind: monaco.languages.CompletionItemKind.Snippet,
insertText: "fk ${1:table_name}.${2:field}",
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
documentation: "Foreign key to table field statement"
},
{
@cnayan
cnayan / Impersonator.cs
Last active October 23, 2020 05:57
Impersonates as a user like "runas /netonly" feature.
// Check http://pinvoke.net/default.aspx/advapi32/LogonUser.html for Win32 functions and structures.
// Code based on answer on SO: https://stackoverflow.com/a/11672293/315151
// Impersonates as a user like "runas /netonly" feature.
public static void Impersonate(string userName, string password, string domain, Action action)
{
if (action == null)
{
return;
@cnayan
cnayan / run_as_with_modified_path.bat
Created June 19, 2020 09:20
Launch CMD with modified path, as another user.
REM Example: Launching CMD with modified path, as another user.
runas /netonly /user:DOMAIN\user_name "C:\Windows\System32\cmd.exe /K set \"PATH=%%PATH%%;C:\Program Files (x86)\Microsoft SQL Server Management Studio 18\Common7\IDE\""
@cnayan
cnayan / main.js
Created August 29, 2019 06:55
NodeJS Kerberos authentication
var Kerberos = require('kerberos').Kerberos;
var kerberos = new Kerberos();
var Ssip = require('kerberos').SSIP;
var http = require('http');
var urlParser = require('url');
var curl = urlParser.parse("http://<your SPNEGO protected endpoint>/");
var requestOptions = {
host: curl.hostname,
@cnayan
cnayan / main.js
Created December 7, 2017 11:13
"Is a" type check in complex object's hierarchy
const check = require('./typeCheck');
const Base = () => {
console.log("base");
return this;
}
const Derived = function () {
Base.call(this);
@cnayan
cnayan / main.js
Created December 7, 2017 10:56
JavaScript "request" callbacks transformed to async/await
const requestAsync = require('./requestAsync');
let options = {
uri: 'http://localhost:3000/endpoint',
method: 'POST',
json: {} // your data
};
async function main() {
let result = await requestAsync(options);