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
| def blank? | |
| self.respond_to?(:empty?) ? self.empty? : !self | |
| end |
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
| def is_blank(value): | |
| return False if value is not False and value in [0, 0.0] else not 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
| <?php | |
| function a($href, $text=NULL, $attributes=NULL) { | |
| if (!isset($text)) | |
| $text = strpos((string)$href, 'mailto:') !== FALSE ? substr($href, 7) : $href; | |
| $attributes = compact('href') + (array)$attributes; | |
| return sprintf('<a%s>%s</a>', join_attributes($attributes), (string)$text); | |
| } | |
| function join_attributes($attributes) { | |
| $attrs = array(); | |
| foreach ((array)$attributes as $key => $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
| <?php | |
| function hsc($value, $args=NULL) { | |
| $default_args = array('flags'=>ENT_COMPAT, 'encoding'=>'UTF-8', 'double_encode'=>FALSE); | |
| extract(array_merge($default_args, (array)$args)); | |
| return htmlspecialchars((string)$value, (int)$flags, (string)$encoding, (bool)$double_encode); | |
| } |
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
| <?php | |
| /** | |
| * Select a subset of an associative array by providing the keys. | |
| * | |
| * @param array $assoc | |
| * @param array $keys | |
| * @return array | |
| */ | |
| function array_select(array $assoc, array $keys) { | |
| return array_intersect_key($assoc, array_flip($keys)); |
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
| <?php | |
| /** | |
| * Remove a subset of an associative array by providing the keys. | |
| * | |
| * @param array $assoc | |
| * @param array $keys | |
| * @return array | |
| */ | |
| function array_remove(array $assoc, array $keys) { | |
| return array_diff_key($assoc, array_flip($keys)); |
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
| <?php | |
| function mb_substr_replace($string, $replacement, $start, $length=NULL) { | |
| if (is_array($string)) { | |
| $num = count($string); | |
| // $replacement | |
| $replacement = is_array($replacement) ? array_slice($replacement, 0, $num) : array_pad(array($replacement), $num, $replacement); | |
| // $start | |
| if (is_array($start)) { | |
| $start = array_slice($start, 0, $num); | |
| foreach ($start as $key => $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
| Markdown: | |
| [JP Markdown](https://wordpress.org/plugins/jetpack-markdown){.target-blank .rel-nofollow} | |
| JavaScript (just before the closing </body> tag): | |
| <script> | |
| jQuery('.target-blank').attr('target', '_blank').removeClass('target-blank').filter('[title=""]').removeAttr('title').filter('[class=""]').removeAttr('class'); | |
| jQuery('.rel-nofollow').attr('rel', 'nofollow').removeClass('rel-nofollow').filter('[title=""]').removeAttr('title').filter('[class=""]').removeAttr('class'); | |
| </script> | |
| Post-jQuery HTML: |
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: "abc{def}ghi".p({def:"xyz"}); => "abcxyzghi" | |
| String.prototype.p = function(obj) { | |
| return this.replace(/\{[^\}]+\}/g, function(key) { | |
| return obj[key.replace(/^\{([^\}]+)\}$/, "$1")] || key; | |
| }); | |
| }; |
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
| window.location.href returns the URL of the current page | |
| http://www.example.org:8888/foo/bar/index.html?q=baz&w=io#bang | |
| window.location.origin returns the protocol, hostname and port number of a URL | |
| http://www.example.org:8888 | |
| window.location.protocol returns the web protocol used (http:// or https://) | |
| http: | |
| window.location.hostname returns the domain name of the web host |
OlderNewer