Skip to content

Instantly share code, notes, and snippets.

View gotraveltoworld's full-sized avatar
:octocat:
Keeping mind to learn Anything!

traveler gotraveltoworld

:octocat:
Keeping mind to learn Anything!
View GitHub Profile
@gotraveltoworld
gotraveltoworld / JS_varSample
Created May 26, 2017 03:51
Is JavaScript a pass-by-reference or pass-by-value language?
function changeStuff(a, b, c)
{
a = a * 10;
b.item = "changed";
c = {item: "changed"};
}
var num = 10;
var obj1 = {item: "unchanged"};
var obj2 = {item: "unchanged"};
@gotraveltoworld
gotraveltoworld / imagick-gradient
Created August 17, 2017 05:13
PHP Imagick gradient example
<?php
// Some PHP variable
// $compositeArr = [
// Imagick::COMPOSITE_DEFAULT,
// Imagick::COMPOSITE_UNDEFINED,
// Imagick::COMPOSITE_NO,
// Imagick::COMPOSITE_ADD,
// Imagick::COMPOSITE_ATOP,
// Imagick::COMPOSITE_BLEND,
// Imagick::COMPOSITE_MULTIPLY,
@gotraveltoworld
gotraveltoworld / GitHubSSHkeys.md
Last active August 30, 2017 06:57
Set single SSH key & multi-SSH keys for GitHub

Set single SSH key & multi-SSH keys for GitHub

Date : 2017/08/30.


Steps

  1. Create GitHub account.
  2. Generate SSH key.
    ssh-keygen -t rsa -b 4096 -C "name@xxx.com" -f github
  3. Look and copy SSH public key.
@gotraveltoworld
gotraveltoworld / python_list_out_of_index.md
Last active February 23, 2018 06:07
Python list out of index handler by iter(Facebook ads insights report)

Online ENV(repl.it): Python 3.6.1

ad = {
  'insights': {
    'outbound_clicks': [
      {
        'value': 1.0
      }
    ]
 }
@gotraveltoworld
gotraveltoworld / pybisect.py
Last active April 16, 2018 16:56
Python bisect practice
from bisect import bisect, insort
# Return the index.
def in_bisect(sorted_list, target_value):
i = bisect(sorted_list, target_value)
return i
# Return the new list.
def insert_by_bisect(sorted_list, target_value):
i = insort(sorted_list, target_value)
return sorted_list
@gotraveltoworld
gotraveltoworld / py_generator_expressions.py
Created May 1, 2018 16:11
Generator expressions of python
# generator expressions
x_iter = (x for x in range(5))
print(x_iter)
# <generator object <genexpr> at 0x7fd7339355c8>
for x in x_iter:
print(x)
# 0 - 4
print(next(x_iter))
# Traceback (most recent call last): File "python", line 5, in <module>
@gotraveltoworld
gotraveltoworld / py_aws_auto_snapshot.py
Last active August 29, 2018 17:37
To use the python for auto-snapshot.
import os
import datetime
from datetime import timezone
import boto3 # Import from basic library (base on aws lambda)
"""
os.environ: {
'aws_access_key_id', <= aws's id.
'aws_secret_access_key', <= aws's key.
'retention_days', <= this is a retention.
@gotraveltoworld
gotraveltoworld / py_property.py
Created September 10, 2018 15:09
Use the 'property' to build a simply class.
# Basic's getter and setter.
class Car(object):
__wheels = 4
def get_wheels(self):
return self.__wheels
def set_wheels(self, value=4):
self.__wheels = value
car = Car()
@gotraveltoworld
gotraveltoworld / filter_text.py
Created September 12, 2018 14:12
Emojis and Punctuations filter base on python.
import re
import string
import emoji
from zhon import hanzi
class Filter_Text:
def filter_emoji(fun):
def wrapper(self, text=''):
@gotraveltoworld
gotraveltoworld / scp_upload.sh
Created October 26, 2018 02:47
Use 'git status' to upload files that have modified.
#!/bin/bash
local_path='Your local path' # ex: /home/your_projects/test
remote_path='Your cloud path' # ex: /var/www/api
remote_con='Your ssh connection' # ex: user@192.168.1.1
# Get the content in 'src/', because I only need to upload the content of 'src/' folder.
for file in $(git status --porcelain | grep "src/")
do
file_name=${file/'^M$'/} # Get to a Modified file.
local_file="$local_path$file_name"
remote_file="$remote_path$file_name"