Skip to content

Instantly share code, notes, and snippets.

@kcochibili
kcochibili / commandline.md
Created July 21, 2017 16:46 — forked from evanwill/commandline.md
command line mini workshop

Intro to the Command Line

Does command line interface (CLI), REPL, terminal, console, or shell sound scary? Don't worry, we'll learn about the basic computer interface that gives you super powers! If you want to work with Raspberry Pi, Linux, or many programming languages you need a basic familiarity with the CLI. This MILL-Mini will demystify the terminal so you can use it to get things done.

What is the Shell?

The command line is a text-based interface for efficiently getting stuff done. It's often called the shell, terminal, console, cmd, or Bash, but ultimately the Shell is just a program on your computer like any other application. Its job is to act as a command shell, taking input from the user, ordering the computer's operating system (OS) to execute the instructions, and returning the outputs.

@mptap
mptap / setLikeDS.java
Last active October 14, 2018 16:43
Implement a set-like data structure that supports Insert, Remove, and GetRandomElement efficiently. Example: If you insert the elements 1, 3, 6, 8 and remove 6, the structure should contain [1, 3, 8]. Now, GetRandom should return one of 1, 3 or 8 with equal probability
public class SetLikeDS {
private List<Integer> list;
private Map<Integer, Integer> map;
public SetLikeDS() {
list = new ArrayList<>();
map = new HashMap<>();
}
public void insert(int num) {
@mptap
mptap / twoSum.java
Last active September 26, 2018 08:24
Given an array of integers, determine whether or not there exist two elements in the array (at different positions) whose sum is equal to some target value. Examples: [5, 4, 2, 4], 8 --> true [5, 1, 2, 4], 8 --> false
import javafx.util.Pair; //available in Java 1.8
public class Solution {
public static boolean twoSum(int[] a, int target) {
Map<Integer, Pair> map = new HashMap<>();
for(int i=0; i<a.length; i++) { //O(n) where n=a.length
if (!map.containsKey(a[i])) { //don't insert duplicates
map.put(a[i], new Pair<Integer, Integer>(target-a[i], i));
//key is every unique element, value is a pair of numberToFind and position of element first found
@evanwill
evanwill / gitBash_windows.md
Last active June 19, 2025 07:30
how to add more utilities to git bash for windows, wget, make

How to add more to Git Bash on Windows

Git for Windows comes bundled with the "Git Bash" terminal which is incredibly handy for unix-like commands on a windows machine. It is missing a few standard linux utilities, but it is easy to add ones that have a windows binary available.

The basic idea is that C:\Program Files\Git\mingw64\ is your / directory according to Git Bash (note: depending on how you installed it, the directory might be different. from the start menu, right click on the Git Bash icon and open file location. It might be something like C:\Users\name\AppData\Local\Programs\Git, the mingw64 in this directory is your root. Find it by using pwd -W). If you go to that directory, you will find the typical linux root folder structure (bin, etc, lib and so on).

If you are missing a utility, such as wget, track down a binary for windows and copy the files to the corresponding directories. Sometimes the windows binary have funny prefixes, so

@Moximillian
Moximillian / ClosureProtocolExtensions.swift
Last active February 17, 2021 03:47
Swift protocol and extensions for adding support to closures in UIKit classes. Extension support for UIButton, UIGestureRecognizer, UIBarButtonItem etc. Swift 3.0.
// Free to copy, use and modify for all types of software projects
import UIKit
// ************** Protocol ***************
/// Closurable protocol
protocol Closurable: class {}
// restrict protocol to only classes => can refer to the class instance in the protocol extension
extension Closurable {
@dominicthomas
dominicthomas / Android_play_video_intent
Created October 2, 2015 09:21
Used to play a video file from the file system.
private void playVideo(final File file) {
Uri intentUri = Uri.fromFile(file);
file.setReadable(true, false); // security?
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(intentUri, "video/*");
startActivity(intent);
}
@cbeyls
cbeyls / ContentLoadingProgressBar.java
Last active December 20, 2021 22:16
ContentLoadingProgressBar implemented The Right Way™
package be.digitalia.common.widgets;
import android.content.Context;
import android.os.SystemClock;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ProgressBar;
/**
* ContentLoadingProgressBar implements a ProgressBar that waits a minimum time to be
@dominicthomas
dominicthomas / json_from_raw
Created June 16, 2015 10:46
Open a json file from the android raw directory and construct using GSON.
public class JSONUtils {
/**
* Open a json file from raw and construct as class using Gson.
*
* @param resources
* @param resId
* @param classType
* @param <T>
* @return
@dominicthomas
dominicthomas / Rainbow_Brush_Demo
Last active March 26, 2018 09:22
A simple activity with a drawing view and a rainbow brush. Proof of concept. Potential to be improved.
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.MotionEvent;
import android.view.View;
@asifmujteba
asifmujteba / ASFUriHelper
Created April 22, 2015 06:31
Get Real Path from Uri
@TargetApi(Build.VERSION_CODES.KITKAT)
public static String getPath(final Context context, final Uri uri) {
final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
// DocumentProvider
if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
// ExternalStorageProvider
if (isExternalStorageDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);