Skip to content

Instantly share code, notes, and snippets.

View arpan-ghosh's full-sized avatar

Arpan Ghosh arpan-ghosh

  • Johns Hopkins University
  • Washington, D.C./Baltimore
View GitHub Profile
@arpan-ghosh
arpan-ghosh / various_var_declarations.go
Last active November 19, 2020 02:00
various_var_declarations.go
package main
import "fmt"
func var_dump(expression interface{}) {
fmt.Printf("(%v, %T)\n", expression, expression)
}
func var_dump_empty_interface(expression ...interface{}) {
fmt.Printf("(%v, %T)\n", expression, expression)
@arpan-ghosh
arpan-ghosh / gist:1e91076cbd4e2078a50c1ee65e8f0d94
Created September 14, 2018 19:26
forking process of dnsResolver
/**
* Process in parallel via forking (PHP)
*/
public function processDNSResolutionsParallel(array $hostnames,$ipInfo,&$hostnameMap,$processes=4) {
$hostnameChunks = array_chunk($hostnames,ceil((count($hostnames)/$processes)));
$pid = -1;
$children = array();
$ip = [];
$resolveChunk=[];
function is_administrator($user_id=0)
{
$user = new WP_User( intval($user_id) );
$admin = false;
if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
foreach ( $user->roles as $role ) {
if ( strtolower($role) == 'administrator') {
$admin = true;
}
@arpan-ghosh
arpan-ghosh / jquery-form-question-toggle.php
Created July 8, 2017 03:08
simple jQuery implementation of question toggle based on any form variable input
<fieldset>
<legend>Research Summary</legend>
<label for="science_objective">
<span class="groups_text">Problem Statement, Scientific Objectives, and Scientific Needs <br/><span>State the key aspect(s) and scientific objective(s) of the task. </span></span>
<span class="metals_text" style="display: none;" >Metals Objectives</span>
</label>
@arpan-ghosh
arpan-ghosh / FizzBuzz.java
Created January 24, 2017 02:52
fizzbuzz from leetcode (partial complete)
/*
* Write a program that outputs the string
* representation of numbers from 1 to n.
* But for multiples of three it should output “Fizz”
* instead of the number and for the multiples of five output “Buzz”.
* For numbers which are multiples of both three and five output “FizzBuzz”.
*/
import java.util.ArrayList;
import java.util.List;
@arpan-ghosh
arpan-ghosh / FastComplement.java
Created January 23, 2017 04:12
Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.
//LeetCode exercise FindComplement
//fastest way to solve it
public class FastComplement {
public int complement(int num) {
return ~num & ((Integer.highestOneBit(num) << 1) - 1);
}
}
@arpan-ghosh
arpan-ghosh / RLEEncoder.java
Created January 21, 2017 22:45
Given a string, encodes the string into a compressed, Run Length Encoded (RLE) format, and returns this encoded string.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
/**
* Encodes a string to RLE
**/
public final class RLEEncoder {
private RLEEncoder() { }
@arpan-ghosh
arpan-ghosh / HelloWorld.java
Created January 21, 2017 22:43
Write a function that greets the user by name, or by saying "Hello, World!" if no name is given.
/**
* This simple Hello World programs
* takes the name as an input and will
* return "Hello, [name]!" or will just
* print "Hello, World" if given nothing.
*
* @author Arpan Ghosh
*/
public class HelloWorld {
@arpan-ghosh
arpan-ghosh / Acronym.java
Created January 21, 2017 22:31
Convert a long phrase to its acronym
public class Acronym {
static String output = "";
public static String generate(String input) {
output += input.charAt(0);
for (int i = 1; i < input.length(); i++) {
if (Character.isWhitespace(input.charAt(i))) {