Posts

Calling an external command in Python

Here's a summary of the ways to call external programs and the advantages and disadvantages of each: os.system("some_command with args")  passes the command and arguments to your system's shell. This is nice because you can actually run multiple commands at once in this manner and set up pipes and input/output redirection. For example, os.system("some_command < input_file | another_command > output_file") However, while this is convenient, you have to manually handle the escaping of shell characters such as spaces, etc. On the other hand, this also lets you run commands which are simply shell commands and not actually external programs. see documentation stream = os.popen("some_command with args")  will do the same thing as  os.system  except that it gives you a file-like object that you can use to access standard input/output for that process. There are 3 other variants of popen that all handle the i/o slightly differently. If you pa...

Robomongo and MongoDB - initial setup on Mac

Image
1. Install MongoDB : Download tgz or zip file from MongoDB website   Extract tgz or zip file in home directory eg : /Users/userName/mongodb_x86_64-3.0.0 Add path of mongoDB directory in PATH 2. Run MongoDB server : Create a directory for primary DB path. /Users/userName/mongodb_x86_64-3.0.0/data/db Run Command /Users/userName/mongodb_x86_64-3.0.0/bin/mongod --dbpath /Users/userName/mongodb_x86_64-3.0.0/data/db  --bind_ip 0.0.0.0 -v 3. Install RoboMongo : Download RoboMongo from http://robomongo.org/ Drop downloaded/extracted folder in Applications folder (/Applications) 4. Run RoboMongo and Connect with MongoDB : 5. Create Example Database in RoboMongo : Step 1 : Create Database Step 2 : Create Collection ( Collection of Documents/Tables ) Step 3 : Create Document/Table  Step 4 : Insert data in Document Query Test in Python ( using pymongo) import pymongo # Connecting with server client = p...

Dictionary vs KeyValuePair vs Struct - C#

Dictionary :  //   Declare   Dictionary and assign value Dictionary < string ,  object >  parameter  =  new   Dictionary < string ,  object >(); parameter [ " View " ] =  viewComp ; parameter [ " Play " ] =  true ; FunctionName( parameter ); //   Use   Dictionary private   void   FunctionName ( object   parameter ) {      Dictionary < string ,  object >  dict  = ( Dictionary < string ,  object >) parameter ;      GameObject   viewComp  = ( GameObject ) dict  [ " View " ];      bool   play  = ( bool ) dict [ " Play " ];      UseValuesInFunction ( viewComp ,  play ); } KeyValuePair : KeyValuePair < GameObject ,  bool >  parameter  =  new   KeyValuePair < GameObject ,  bool >( viewComp ,...

PyDev with Eclipse on Mac

Image
Step 1 : Install Eclipse Step 2 : Install PyDev Here is the easiest way of drag-n-drop : http://marketplace.eclipse.org/content/pydev-python-ide-eclipse Step 3 : Configure Python Interpreter Path to MayaPy's python interpreter : /Applications/Autodesk/maya2014/Maya.app/Contents/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python Extras : 1. For Autocompletion, add following line in "Forced Builtins" : maya.cmds,maya.mel,maya.standalone,maya.app,maya.OpenMaya,maya.OpenMayaAnim,maya.OpenMayaCloth,maya.OpenMayaFX,maya.OpenMayaMPx,maya.OpenMayaRender,maya.OpenMayaUI which will add following libraries : maya.cmds maya.mel maya.standalone maya.app maya.OpenMaya maya.OpenMayaAnim maya.OpenMayaCloth maya.OpenMayaFX maya.OpenMayaMPx maya.OpenMayaRender maya.OpenMayaUI Another Resource :  http://sourceforge.net/p/pydev/discussion/293649/thread/fb1b2e45

How curves are drawn by your computer ?

Image
Cubic Bezier Curves - Under the Hood from Peter Nowell

Simple explanation of Physics based motion in games

http://www.richardlord.net/presentations/physics-for-flash-games http://www.richardlord.net/images/slides/physics2007.swf
Image
Unity Editor Scripting : If you ever have to create an instance (in hierarchy) from an .fbx file and a prefab from an instance, you can use following commands. 1 .fbx to instance      :  PrefabUtility . InstantiatePrefab 2 instance to .prefab :  PrefabUtility . CreatePrefab Creating AnimatorController file :  AssetDatabase . CreateAsset  

Conditional / Ternary Operator

Conditional Operator / Ternary Operator : condition ? true_expression : false_expression; bool x = condition ? true : false; eg : string   result  = (percentage  >= 36)  ?  "pass"  :  "fail" ; -------------------------------------------------------- NullCoalesce (??) int totalMarks = marks ?? 0 ; The  ??  operator is called the null-coalescing operator. It returns the left-hand operand if the operand is not null; otherwise it returns the right hand operand. eg:  int ? x = null ; int y = x ?? -1; int? is a shorthand for Nullable, which itself is shorthand of Nullable. eg Nullable a = null; A nullable type can represent the correct range of values for its underlying value type, plus a additional null value. --------------------------------------------------------

Installing Ant, Svn and Git on Mac

Install home-brew if not already installed ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" or ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" sudo brew update brew install ant brew install svn brew install git Install  JDK 7 ( If apache doesn't work in Sierra here is a usefull article : https://getgrav.org/blog/macos-sierra-apache-multiple-php-versions)
           Great trick for optimization so that code doesn't have to count size of array/list again and again.    for  ( int   i  =  0 ,  count  =  objectList . Count ;  i  <  count ;  i ++)             {                 .......  =  objectList [ i ];                  if  ( .... )                 {                     ........                 }             }

Intro to Objective-C

Intro to Objective-C :  http://cocoadevcentral.com/d/learn_objectivec/

Unity - Pixel/Fragment Shader

Image
Shader   " Custom /SamplePixelShader "  {      Properties {          _Color  ( " Main   Color " ,  Color ) = ( 1 , 0 , 1 , 1 )          _MainTex  ( " Texture   RGBA " ,  2D ) =  " white "  {}          // _Alpha (" Alpha " , Range ( 0 , 1 )) =  0 . 5          // _SpecColor  (" Spec   Color ",  Color ) = ( 1 , 1 , 1 , 0 )          // _Emission  (" Emissive   Color ",  Color ) = ( 0 , 0 , 0 , 0 )          // _Shininess  (" Shininess ",  Range  ( 0 . 1 ,  1 )) =  0 . 7     }      Category {         ...