Skip to content

Instantly share code, notes, and snippets.

package kata.string;
import java.util.Map;
import java.util.HashMap;
public class Anagram {
private static Map<Character, Integer> toMap(String str) {
Map<Character, Integer> map = new HashMap<>();
@nashid
nashid / ReverseKNodeLinkedList.java
Last active November 8, 2016 22:01
Reverse every k nodes in linked list
package kata.linkedlist;
public class ReverseKNodeLinkedList {
public static Node reverseKNodes(Node node, int k) {
if (node == null || node.getNext() == null) {
return node;
}
@nashid
nashid / LPS.java
Created November 8, 2016 22:37
Longest Palindromic Subsequence
package kata;
public class LPS {
public static int lps(char[] ch, int i, int j) {
// Base Case 1: If there is only 1 character
if (i == j) {
return 1;
}
@nashid
nashid / sequence.scala
Created March 4, 2019 23:50 — forked from cb372/sequence.scala
Using Cats Traverse to turn a List of Try into a Try of List
Welcome to the Ammonite Repl 0.8.0
(Scala 2.11.8 Java 1.8.0_91)
@ import scala.util.Try
import scala.util.Try
@ val listOfTries: List[Try[String]] = List(Try("a"), Try("b"), Try("c"))
listOfTries: List[Try[String]] = List(Success("a"), Success("b"), Success("c"))
// I have a List[Try[String]] but I actually want a Try[List[String]].
@nashid
nashid / MonadAndFs2Ops.md
Created March 6, 2019 19:48 — forked from Daenyth/MonadAndFs2Ops.md
Cheat sheet for common cats monad and fs2 operation shapes
Operation Input Result Notes
map F[A] , A => B F[B] Functor
apply F[A] , F[A => B] F[B] Applicative
(fa, fb, ...).mapN (F[A], F[B], ...) , (A, B, ...) => C F[C] Applicative
(fa, fb, ...).tupled (F[A], F[B], ...) F[(A, B, ...)] Applicative
flatMap F[A] , A => F[B] F[B] Monad
traverse F[A] , A => G[B] G[F[A]] Traversable; fa.traverse(f) == fa.map(f).sequence; "foreach with effects"
sequence F[G[A]] G[F[A]] Same as fga.traverse(identity)
. . . .
@nashid
nashid / XAMPP on MAC
Created July 17, 2020 22:42
Manage XAMPP on MAC
* Install XAMPP on MAC:
* `brew cask install xampp`
* Stat/Stop Apache:
* sudo /Applications/XAMPP/xamppfiles/bin/apachectl start
*
@nashid
nashid / XAMPP on MAC
Created July 17, 2020 22:42
Manage XAMPP on MAC
* Install XAMPP on MAC:
* `brew cask install xampp`
* Stat/Stop Apache:
* sudo /Applications/XAMPP/xamppfiles/bin/apachectl start
*
@nashid
nashid / aws tidbits
Last active January 13, 2021 04:46
aws snippets
Query AWS regions for active EC2 instances:
aws ec2 describe-instances --region us-east-1
# read from s3 triggered events
def s3_file_name(event):
records = [x for x in event.get('Records', []) if x.get('eventName') == 'ObjectCreated:Put']
sorted_events = sorted(records, key=lambda e: e.get('eventTime'))
latest_event = sorted_events[-1] if sorted_events else {}
info = latest_event.get('s3', {})
file_key = info.get('object', {}).get('key')
@nashid
nashid / .gitconfig
Last active February 22, 2021 08:18 — forked from lifuzu/.gitconfig
Three levels of GIT config
# There are 3 levels of git config: global, project, and system.
# global: Global configs are available for all projects for the current user and stored in ~/.gitconfig.
# project: Project configs are only available for the current project and stored in .git/config in the project's directory.
# system: System configs are available for all the users/projects and stored in /etc/gitconfig.
# Create a global config
$ git config --global user.name "John Doe"
# Create a project specific config, you have to execute this under the project's directory.