Skip to content

Instantly share code, notes, and snippets.

View fahadsiddiqui's full-sized avatar

Fahad Siddiqui fahadsiddiqui

View GitHub Profile
// https/http is a must. works for com, net URls
val urlRegex1 = r"""https?:\/\/(.*)?[a-z]*.(com|net)(\/(.*))?"""
// works for any URL
val urlRegex2 = r"""^(?:https?:\/\/)?(?:www\.)?[a-zA-Z0-9.]+\/?$"""
@fahadsiddiqui
fahadsiddiqui / csv_file_to_json_string.scala
Last active February 16, 2018 10:43
CSV file to JSON string using Jackson
import com.fasterxml.jackson.dataformat.csv.CsvSchema
import com.fasterxml.jackson.dataformat.csv.CsvMapper
import com.fasterxml.jackson.databind.ObjectMapper
import java.io.File
/*
maven dependencies =>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
NEW_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
@fahadsiddiqui
fahadsiddiqui / reset_permissions.sh
Last active May 17, 2018 07:32
Reset folder and file permissions after copying from old storage.
#!/bin/bash
PATH_TO_RESET=~
# reset folder permissions
find $PATH_TO_RESET -type d -exec chmod 775 {} \;
# reset file permissions
find $PATH_TO_RESET -type f -exec chmod 664 {} \;
@fahadsiddiqui
fahadsiddiqui / neo4j_cypher_cheatsheet.md
Created August 27, 2018 05:03 — forked from DaniSancas/neo4j_cypher_cheatsheet.md
Neo4j's Cypher queries cheatsheet

Neo4j Tutorial

Fundamentals

Store any kind of data using the following graph concepts:

  • Node: Graph data records
  • Relationship: Connect nodes (has direction and a type)
  • Property: Stores data in key-value pair in nodes and relationships
  • Label: Groups nodes and relationships (optional)
@fahadsiddiqui
fahadsiddiqui / rr.sh
Created November 6, 2018 11:58
Pass file path as an argument like ./rr.sh fileinput_word_per_line
#!/bin/bash
while IFS='' read -r line || [[ -n "$line" ]]; do
if [ ! -z $line ]
then
QUERY="your_query to be run on each $line here"
PGPASSWORD=your_password psql -U your_user -d your_db -c "$QUERY"
fi
done < "$1"
systemctl is-active --quiet postgresql && echo "Running..."
val sentence = "10-Q 1 flws20180930_10q.htm FORM 10-Q UNITED STATES SECURITIES AND EXCHANGE COMMISSION WASHINGTON, D.C. 20549 FORM 10-Q X QUARTERLY REPORT PURSUANT TO SECTION 13 OR 15(d) OF THE SECURITIES EXCHANGE ACT OF 1934 For the quarterly period ended September 30, 2018 or ___ TRANSITION REPORT PURSUANT TO SECTION 13 OR 15(d) OF THE SECURITIES EXCHANGE ACT OF 1934 For the transition period from ___ to ___ Commission File No. 0-26841 1-800-FLOWERS.COM, Inc.;"
val word = "D.C."
// sentence
// //.replace("( )+", " ")
// .replace("\n", " ")
// .replace("\t", " ")
// .replaceAll("\\p{C}", "?")
// .split(" ")
// .map {
@fahadsiddiqui
fahadsiddiqui / case_converter_scala.scala
Last active December 6, 2018 13:00
Capital, camel, snake, title case converter and sanatizer.
def sanatizer(string: String) = {
var punctuationRegEx = "[!@#$%^&*()_+=_`~{};:\"\'/?><,.]"
string.replaceAll(punctuationRegEx, "").split("( )+")
}
def toSnakeCase(string: String) = {
val words = sanatizer(string)
words.headOption.getOrElse("").toLowerCase + "_" + words.drop(1).map(word => word.head.toString.toLowerCase + word.drop(1).toLowerCase).mkString("_")
}
@fahadsiddiqui
fahadsiddiqui / implicits.scala
Created December 19, 2018 12:49
Useful implicit functions.
import scala.concurrent.{ExecutionContext, Future}
object MyImplicits {
implicit def optionalFutureToFuture[A](obj: Option[Future[A]])(implicit ec: ExecutionContext): Future[Option[A]] = {
obj match {
case Some(t) => t.map(Some(_))
case None => Future.successful(None)
}
}
}