Skip to content

Instantly share code, notes, and snippets.

View dpyro's full-sized avatar

Sumant Manne dpyro

  • Facebook
  • New York
View GitHub Profile
@dpyro
dpyro / africa.py
Created October 25, 2018 22:23
Toto
import africa
from time import sleep
from weather import rain
is_dragged = False
while africa:
if rain in africa:
@dpyro
dpyro / tsconfig.json
Created August 11, 2018 21:17
Sample tsconfig.json
{
"compilerOptions": {
"allowJs": true,
"alwaysStrict": true,
"checkJs": true,
"downlevelIteration": true,
"emitDecoratorMetadata": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"lib": [ "es2017" ],
@dpyro
dpyro / cli.js
Created April 13, 2017 23:05
simple readline cli for node.js
const readline = require('readline')
/**
* Create an active bound readline interface using `stdin` and `stdout`.
*
* @param {function(string): void} callback handler for each inputed line
* @returns {readline.ReadLine} the active configured interface
*/
function createReadlineInterface(callback) {
const rl = readline.createInterface({
@dpyro
dpyro / rexray_macos.md
Created April 5, 2017 03:48
how to build and install rexray for macos

Building & Installing REX-Ray on macOS

  1. Install GNU Make if gmake is not available:
    brew install make
  2. Clone the repository:
    git clone https://github.com/codedellemc/rexray
@dpyro
dpyro / notify.py
Created March 15, 2017 20:02
function to display notification on macOS
import os
import sys
def notify(text, title=None, subtitle=None, sound_name=None):
"""
Displays a notification on macOS systems using AppleScript.
"""
if sys.platform.startswith('darwin'):
cmd = "osascript -e 'display notification \"{}\"".format(text)
@dpyro
dpyro / RandomSubset.java
Created March 3, 2017 05:56
return a random subset of a given stream
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.Arrays;
public class RandomSubset {
// Returns a random subset of a given stream.
static <E> List<E> getRandomSubset(Stream<E> stream) {
@dpyro
dpyro / strrev.c
Last active March 3, 2017 00:02
in-place reverse of a null-terminated string
#include <string.h>
// In-place reverse a null-terminated string.
// Note: The behavior is undefined if str is not null-terminated.
void strrev(char* str) {
size_t n = strlen(str);
char *end = &str[n-1];
char tmp;
while (str < end) {
@dpyro
dpyro / malloc2d.c
Created March 2, 2017 23:12
malloc single-call for a 2D array
#include <stdlib.h>
// Allocates a 2D array that can be accessed in the form arr[r][c].
// The caller is responsible for calling free() when done.
void** malloc2d(size_t rows, size_t cols, size_t element_size) {
size_t header = rows * sizeof(void*);
size_t body = rows * cols * element_size;
size_t needed = header + body;
void** mem = malloc(needed);
@dpyro
dpyro / english_phrase.py
Created March 1, 2017 01:47
produces an English phrase given an integer
#!/usr/local/bin/python3
# pylint: disable=C0103, C0111
def english_phrase(num):
"""Returns an English phrase string for an integer n."""
n = int(num)
negative_name = "negative"
names = {
@dpyro
dpyro / max.c
Created February 28, 2017 21:24
returns the maximum of two ints without a comparison operator
#define INT_MIN 1 << (sizeof(int)*8 - 1)
int max(int a, int b) {
unsigned int ua = (unsigned int) a - INT_MIN;
unsigned int ub = (unsigned int) b - INT_MIN;
int k = ((ub-ua) >> (sizeof(int)*8 - 1)) & (0x1);
return k*a + (1-k)*b;
}