This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Usage: setNestedValue(<object>, <array>, <value>) | |
| const object = { | |
| key1: { | |
| key11: 'nested-value' | |
| } | |
| } | |
| const newObject = setNestedValue(object, ['key1', 'key12'], 'another-nested-value') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Just include this function in the .bash_profile (or equivalent) file | |
| math() { | |
| # Use python to perform mathematics | |
| if [ -z $1 ]; then | |
| echo "Usage: math [expression]" | |
| return 1 | |
| fi | |
| python -c "print $1" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| try: | |
| from functools import reduce | |
| except ImportError: | |
| pass | |
| # How to use | |
| # foo = { "a": "a1", "b": "a2", "c": { "d": "a3" } } | |
| # bar = ["c", "d"] | |
| # nested_value = get_nested_value(foo, bar) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require "net/http" | |
| require "json" | |
| # Execute HTTP requests | |
| # How to use | |
| # http_request({ | |
| # "uri" => "...", # Use URI::Parser | |
| # "method" => "...", | |
| # "payload" => "...", | |
| # "headers" => "...", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| ##this script will check mongodb and apache | |
| ##if that service is not running | |
| ##it will start the service and send an email to you | |
| ##if the restart does not work, it sends an email and then exits | |
| ##set the path ##this works for Ubuntu 14.04 and 16.04 | |
| PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Usage: getNestedValue(<object>, <array>) | |
| const object = { | |
| key1: { | |
| key11: 'nested-value' | |
| } | |
| } | |
| const nestedValue = getNestedValue(object, ['key1', 'key11']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require "rmagick" | |
| # Define class UniformImage | |
| class UniformImage | |
| def initialize(image, suffix="_uniform", extension="jpg") | |
| # Instance variables | |
| @image = image | |
| if self.exists? |
NewerOlder