Skip to content

Instantly share code, notes, and snippets.

@ravyg
ravyg / simple_to_nestedarray.php
Created March 19, 2012 08:06
takes in simple array to generate hierarchical nested array #tree #graph
<?php
function hierarchical_array_from_array($farray){
foreach ($flatArray as $key=>$flat) {
$nodes = array();
$tree = array();
foreach ($flatArray as $key=>&$node) {
$node["Children"] = array();
$id = $node["@id"];
$parent_id = $node["@parentId"];
$nodes[$id] =& $node;
@ravyg
ravyg / Drupal Theme Basics
Last active August 29, 2015 14:06
Drupal Theming Basics
- Knowing the ".info" files
Tell drupal about your theme.
- Playing with ".tpl.php" (Template) files
Place for your all HTML structure.
- Variables in ".tptl.php" files
Dynamic bits of content which is to be printed in your template file.
- Theme Functions overriding.
@ravyg
ravyg / Handy DRUSH Commands
Last active August 29, 2015 14:06
Geek Lyrics!
VARIABLE SET:
drush vset --yes file_private_path <path-to-private-files> | drush vset --yes file_temporary_path <path-to-temporary-file> |
NOT NEEDED ADMIN AND NEEDED ADMIN MENU
drush dis admin -y | drush en admin_menu diff field_ui -y
DRUSH KICKSTART
drush dl [drupal-version]
drush si --db-url=mysql://[dbusername]:[dbpassword]@localhost/[dbname]
drush upwd admin --password=[MyEasyDevPassword]
@ravyg
ravyg / README.md
Created November 19, 2015 18:18 — forked from lopezjurip/README.md
Write to NTFS on OSX Yosemite and El Capitan

Install Homebrew:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Update Homebrew formulae:

brew update
@ravyg
ravyg / Mongo commands
Last active January 22, 2017 15:20
AWS, Mongo, Dynamo Commands
# Importing a db with multiple bson files
# Note each bson is a collection.
mongorestore -d db_name path/
# To start db use:
mongo db_name
# To see collections use:
show collections
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
@ravyg
ravyg / Hadoop Commands
Last active November 12, 2016 02:57
Data Sciences Commands
# Command pipeline
# Non hadoop way using only linux commands.
cat data | map | sort | reduce
# some text to mapper.
echo "foo foo quux labs foo bar quux" | <dirto/>mapper.py
# Some text to mapper then sort and then reducer.
echo "foo foo quux labs foo bar quux" | <dirto/>mapper.py | sort-K1, 1 | <dirto/>reducer.py
# Doing with file.
cat myfilename.txt | <dirto/>mapper.py | sort-K1, 1 | <dirto/>reducer.py
@ravyg
ravyg / Terminal Commands
Last active May 25, 2018 16:05
General Unix Commands
# Find the number of line in a file type recuresively.
find . -name '*.php' | xargs wc -l
# Find occurence on on word say "carrot" in many files.
grep -ir carrot . | wc -l
# This helps in moving files so keep backup!!!
# Moves files with json extension from sub-folders recursively to single output folder.
find <parent/folders/subfolders> -type f -name '*.json' -exec mv -i {} <new/folder> \;
@ravyg
ravyg / word2vec_tweets_preprocessor.py
Created February 8, 2017 06:18
Clean tweets json for tensorflow or gensim based word2vec plain text
# -*- coding: utf-8 -*-
import json
import re
import os
import nltk
input_file = open('<JSON FILE To INPUT>','r').readlines()
for line in input_file:
try:
tweet = json.loads(line)
@ravyg
ravyg / dnn_ravyg.py
Last active February 15, 2017 16:56
[1,2,5 Layer] Deep Neural Network implementation NOTE: Use you own vector data [Read Comment to select number of layers]
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Parts of this code have be taken from Dr.Calix's ITS520 Class at Purdue University.
# Co-Authored: Ravish Gupta
##########################################################
import csv
import warnings
import matplotlib.pyplot as plt
import tensorflow as tf
import numpy as np