Do you want to use ssh in python? I needed to do! I use server hosting, but there is no authority for using crontab. Beacause of that I need ssh in python! In my server I can use crontab so I can write my script using ssh with python. After that I registered that script in my crontab. Now I can fulfill my purpose through that script.
We need paramiko module for using ssh in python. Let's install paramiko
Then we will get paramiko.
For now, write python code!
Can you understand this? Import paramiko module and create paramiko SSHClient object with name ssh. And set AutoAddPolicy. When you access some server with ssh first time. You can see the message "do you trust this host and use connection?" like that. AutoAddPolicy is for that, it will trust host automatically. Next, you have to access to a server computer with connection function. After that you can execute shell command with exec_command function.
If you need to print out result. Use "stdout.readlines()"
Did you execute this? Let's do this!
You can get every computer informations. Programming, Application, Utilities. Come and see! If you have any question? Contact to me!.
Showing posts with label Programming Languages. Show all posts
Showing posts with label Programming Languages. Show all posts
Thursday, February 5, 2015
Tuesday, February 3, 2015
[Javascript] Google Map display and Marker pin up with JS API
Do you want to display google map in your website or pages? If you do, follow this posting.
Step 01. You need google map js api at your html file.
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
It is google map apis js file.
Step 02. You make div for google map at your page what you want to see.
Like this <div id="my_google_map"></div>
Step 03. Copy & Paste
function initialize() { var mapOptions = { center: { lat: -34.397, lng: 150.644}, zoom: 8 }; var map = new google.maps.Map(document.getElementById('my_google_map'), mapOptions); }
google.maps.event.addDomListener(window, 'load', initialize);
'my_google_map' is your div's id. That's it. It's done.
Do you want to pin up some markers on your map????
Step 01. Make your coordinate variable.
var locationCoordinates = [[37.511058, 127.044718], [37.511058, 127.044718], [37.511058, 127.044718]];
Step 02. Make markers with for sentence.
for (var i in locationCoordinates) { var p = locationCoordinates[i]; var latlng = new google.maps.LatLng(p[0], p[1]); var marker = new google.maps.Marker({ position: latlng, map: map }); }
Then you will get markers on your map.
Monday, February 2, 2015
[Python] Where is my python? How can I find python path?
Do you want to find your python path? (It doesn't matter what is your os).
Step 01. Open your terminal(command line prompt) type python.
Then you get python REPL.
Step 02. Type import sys. Press Enter key. You can use sys module.
Step 03. Type sys.executable. Press Enter key. Yeah! Finally you get python path!! Did you see that? '/home/bin/python'? That is my python path. You get same thing or other thing.
Go ahead!!!
Tuesday, January 27, 2015
[MySQL] How to know AUTO_INCREMENT value on some tables?
Hi there~! Today we will study about mysql auto_increment value. When you create some tables that needs index number column, you will set auto_increment on that column. Yeah it's natural. Sometimes we need to know auto_increment value. Then after insert date, you call mysql_insert_id() function or like that. But if you need to know auto_increment value before inserting?
If you want to know auto_increment value, you have to know this query.
SELECT AUTO_INCREMENT FROM information_schema.TABLES WHERE TABLE_SCHEMA = "databaseName" AND TABLE_NAME = "tableName"
In addition, you have only one database, you can use this query.
SELECT AUTO_INCREMENT FROM information_schema.TABLES WHERE TABLE_NAME = "tableName"
Did you get it? Go and Testing!
If you want to know auto_increment value, you have to know this query.
SELECT AUTO_INCREMENT FROM information_schema.TABLES WHERE TABLE_SCHEMA = "databaseName" AND TABLE_NAME = "tableName"
[Execution query in phpmyadmin]
SELECT AUTO_INCREMENT FROM information_schema.TABLES WHERE TABLE_NAME = "tableName"
[Execution query in phpmyadmin]
Monday, January 26, 2015
[Javascript] The best way for to catch is mobile browser!
Are you web programmer? If so, when you make mobile web site you want to know what is mobile browser. There is many way, but here is simple & best way with javascript.
First best way!
Make isMobile function. Add it to your js file or section.
function isMobile() {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
}
Second best way with css.
Step 01. In your css section or file, add it.
@media only screen and (max-width: 760px) { #mobile_flag { display: none; } }
* you can change screen size 760 to some other size.
Step 02. In your html file add it.
<div id="mobile_flag"></div>
Step 03. In your js file or section, add it.
function isMobile() {
if( $('#mobile_flag').css('display')=='none') {
First best way!
Make isMobile function. Add it to your js file or section.
function isMobile() {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
}
[Code testing in desktop browser - return false]
Second best way with css.
Step 01. In your css section or file, add it.
@media only screen and (max-width: 760px) { #mobile_flag { display: none; } }
* you can change screen size 760 to some other size.
Step 02. In your html file add it.
<div id="mobile_flag"></div>
Step 03. In your js file or section, add it.
function isMobile() {
if( $('#mobile_flag').css('display')=='none') {
return true;
}
return false;
}Tuesday, December 23, 2014
[Wordpress Tips] How to scale up featured post thumbnail?
WordPress is one of the most powerful CMS! In that, sometimes we want to make featured image to scale up. That moment we write some code in to the functions.php file.
You can find functions.php in directory wp-content/themes/[your theme]. If you find that open it!
If you want to add some image size, insert this code.
add_image_size( '[name you choose]', [image width], [image height], [do you want to crop?] );
ex) add_image_size( 'sliderthumb', 740, 400, true );
Then you can use 'sliderthumb' image size!
Do you use any thumbnail image rebuilder? Go to their configure page. You can see all image size lists.
But, this time you can not make full size image. That generated images are weired. So let's do insert more code!
In functions.php insert follow codes.
function image_crop_fulldimensions($default, $orig_w, $orig_h, $new_w, $new_h, $crop){
if ( !$crop ) return null; // let the wordpress default function handle this
$aspect_ratio = $orig_w / $orig_h;
$size_ratio = max($new_w / $orig_w, $new_h / $orig_h);
$crop_w = round($new_w / $size_ratio);
$crop_h = round($new_h / $size_ratio);
$s_x = floor( ($orig_w - $crop_w) / 2 );
$s_y = floor( ($orig_h - $crop_h) / 2 );
return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h );
}
add_filter('image_resize_dimensions', 'image_crop_fulldimensions', 10, 6);
After this, you can get full dimensions images!!
Let you apply this code!!!
Sunday, December 21, 2014
[Programming Algorithms Training Service!] http://exercism.io/ gogo!
If you want to be good programmer, You have to study algorithms. You know that? Then how to study algorithms? Just read books? Watch videos? Yeah that's the way normal.
But if you want to be smarter~! Pay attension here! Here is excellent service for algorithms training! You can drill with 20 languages!
Let's go to http://exercism.io
Looks like "Devil" :)
We can log in with Github account.
Here is languages list! Wow that so many!
This is my list that I submitted.
If you submitted some codes, other programmers send their opinions about your program. And you can reply on that.
After that, you can see others' program. It's very helpful to your programming skill.
If you don't get any opinion more, make your problem closed. After that, you get next programming problems! Let you take problems! And grow up!!!
Friday, October 3, 2014
[C Data structures and Algorithms] Single Linked List (Circular Linked List)
Hi~! We are here! I will let you know what about Linked List. Exactly Single Circular Linked List with C!
Linked List is so simple and basic data structure. It has front, end node for expression start node and end node. And each nodes have data variable and next pointer variable. Next pointer variable has address next node. End node's next pointer variable point front node.
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct _Node { char *Name; struct _Node *Next; } Node; Node *front, *end; // head & tail int currPos, listLength; void initList(void); int insertNode(char *); int afterNode(char *,char *); Node* findNode(char *); Node* findNodeAt(int); void printList(void); int removeNode(char *); void clearList(void); int next(); int prev(); void setFront(); void setEnd(); Node* getNode();
Above source code is ADT for a Single Linked List.
There has to be struct for node. I made _Node struct with Name char pointer variable and Next _Node pinter variable. And define _Node to Node.
Also made front,end currPos, listLength variables. Front and end is for list's start, end. CurrPos and ListLength is for list searcing.
Here is realization source code.
#include "CList.h" void initList(void) { front = (Node*)malloc(sizeof(Node)); end = (Node*)malloc(sizeof(Node)); front->Next = end; front->Name = ""; end->Next = end; end->Name = ""; currPos = 0; listLength = 0; }
initList do initialization list. Do memory alllocate for front, end vars, and set to front's Next point end node, end's Next point front node. This time currPost has 0, listLength is 0.
int insertNode(char *Name) { Node *temp_node = (Node *)malloc(sizeof(Node)); Node *position = front; temp_node->Name = Name; while(position->Next!=end) { position = position->Next; } temp_node->Next = position->Next; position->Next = temp_node; listLength++; return 1; }
Function insertNode has Name argument. If you call insertNode with string. It make temp_node and set Name with string you sent. And temp_node's Next point end. After that last node's Next point temp_node.
And insertion some node between other nodes is same. If you want to insert C node between A,B. C's Next point B after that A's Next point C.
int afterNode(char *Name,char *targetName) { Node *temp_node = (Node *)malloc(sizeof(Node)); Node *position = findNode(targetName); temp_node->Name = Name; if(position!=end) { temp_node->Next = position->Next; position->Next = temp_node; listLength++; return 1; } return -1; } Function afterNode has two arguments Name and targetName. It find the node has targetName and save into position var. And make a temp_node has Name arg. After that, insert temp_node after position.
Node* findNode(char *Name) { Node *start; for(start = front;start!=end;start=start->Next) { if(strcmp(start->Next->Name,Name)==0) { break; } } return start->Next; } Fucntion findNode search whole list and whether node is same Name with Name argument or not. If find node return that.
Node* findNodeAt(int indexAt) { Node *temp_node = front->Next; int index; for(index = 0;index<listLength&&temp_node!=end;index++) { if(index==indexAt) { return temp_node; } temp_node = temp_node->Next; } return NULL; } Function findNodeAt is similar with findNode. But it return node is at some index.
void printList(void) { Node *start; printf("%s","\n\n\nList Items\n"); setFront(); while((start=getNode())!=NULL&&next()) { printf("%s \n",start->Name); } } Function printList print out all list. In here call setFront function.
int removeNode(char *Name) { Node *start = front; Node *target; if((target=findNode(Name))!=start) { while(strcmp(start->Next->Name,Name)!=0) { start = start->Next; } start->Next = target->Next; free(target); listLength--; return 1; } return -1; } Function remove is simple too. find target node and arrange Next pointer. And do memory free.
Arranging Next pointer A node point C, after that clean up B.
void clearList(void) { Node *start = front->Next; Node *next = start->Next; while(next!=end) { free(start); start = next; next = next->Next; } free(front); free(end); initList(); } Function clearList is do memory clean up and call initList function.
Here is next, prev, setFront, setEnd function. These are for changing list position.
int next() { if(currPos < listLength) { currPos++; return currPos; } return -1; } int prev() { if(currPos > 0) { currPos--; return currPos; } return -1; } void setFront() { currPos = 0; } void setEnd() { currPos = listLength-1; } Node* getNode() { return findNodeAt(currPos); }
List is basic data structure. If you want to learn another data structure or algorithms? You have to know List and Pointer. I hope it easy to you. Next posting is Doubly Linked List.
* If you run this program use this main function.
#include "CList.h" int main() { Node* temp; initList(); printf("%s","List Test Program\n"); insertNode("Jake Song"); insertNode("Alex Song"); insertNode("Minhee Kim"); printList(); removeNode("Alex Song"); printList(); clearList(); printList(); return 0; }
Wednesday, October 1, 2014
[Javascript Data Structures & Algorithms] List
Here is List data structure with js.
reference is Data Structures & Algorithms with JavaScript.
In the book, there is some error and needless codes. I fix and cut off that.
function List() { this.listSize = 0; this.pos = 0; this.dataStore = []; this.clear = clear; this.find = find; this.toString = toString; this.insert = insert; this.append = append; this.remove = remove; this.contains = contains; this.front = front; this.end = end; this.prev = prev; this.next = next; this.length = length; this.currPos = currPos; this.moveTo = moveTo; this.getElement = getElement; } function append(element) { this.dataStore[this.listSize++] = element; } function remove(element) { var foundAt = this.find(element); if (foundAt > -1) { this.dataStore.splice(foundAt,1); --this.listSize; return true; } return false; } function find(element) { for(var i=0; i<this.dataStore.length; ++i) { if(this.dataStore[i]==element) { return i; } } return -1; } function length() { return this.listSize; } function toString() { return this.dataStore; } function insert(element, after) { var insertPost = this.find(after); if(insertPost > -1 ) { this.dataStore.splice(insertPos+1,0, element); ++this.listSize; return true; } return false; } function clear() { delete this.dataStore; this.dataStore.length = 0; this.listSize = this.pos = 0; } function contains(element) { if(this.find(element)>-1) { return true; } return false; } function front() { this.pos = 0; } function end() { this.pos = this.listSize-1; } function prev() { if(this.pos>=0) { --this.pos; } } function next() { if(this.pos < this.listSize) { ++this.pos; } } function currPos() { return this.pos; } function moveTo(position) { this.pos = position; } function getElement() { return this.dataStore[this.pos]; } var names = new List(); names.append("Carrot Carrot"); names.append("Flash Maestro"); names.append("Jake Song"); for(names.front(); names.currPos() < names.length(); names.next()) { print(names.getElement()); } for(names.end(); names.currPos()>=0; names.prev()) { print(names.getElement()); }
It is realized with Array. But in js, array and list are very similar. It's just example. If you want to realize List, Make it with C, C++, Java something like that.
My next post is List with C.
Subscribe to:
Posts (Atom)