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
| /** | |
| * <Professional Javascript for web developer v3 p736> | |
| * Reduce determine condition in every function execution. | |
| */ | |
| // bad ass | |
| function createXHR(){ | |
| if (typeof XMLHttpRequest != “undefined”){ | |
| return new XMLHttpRequest(); | |
| } else if (typeof ActiveXObject != “undefined”) { |
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
| # This program is free software. It comes without any warranty, to | |
| # the extent permitted by applicable law. You can redistribute it | |
| # and/or modify it under the terms of the Do What The Fuck You Want | |
| # To Public License, Version 2, as published by Sam Hocevar. See | |
| # http://sam.zoy.org/wtfpl/COPYING for more details. | |
| # Colors and formatting (16 colors) | |
| #Background | |
| for clbg in {40..47} {100..107} 49 ; do | |
| #Foreground |
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
| # from http://www.commandlinefu.com/commands/view/5879/show-numerical-values-for-each-of-the-256-colors-in-bash#comment | |
| for code in {0..255}; do echo -e "\e[38;05;${code}m $code: Test"; done |
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
| #! /bin/bash | |
| occur=$(head -n 1 $1 | grep -o "," | wc -l) | |
| sep=" --- |" | |
| seperator="" | |
| for ((i=0; i<$occur; i++)) | |
| do | |
| seperator+=$sep | |
| done | |
| lineno=0 | |
| file='' |
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
| // refer to http://ariya.ofilabs.com/2013/10/searching-using-array-prototype-reduce.html?utm_source=javascriptweekly&utm_medium=email | |
| // old story | |
| function findLongest(entries) { | |
| for (var i = 0, longest = ''; i < entries.length; ++i) | |
| if (entries[i].length > longest.length) longest = entries[i]; | |
| return longest; | |
| } | |
| // A version which relies on reduce is a single statement: | |
| function findLongest2(entries) { |
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
| # following class have a very long class name | |
| # and we have a factory method to create instance of this class | |
| # using following strategy to refer to constructor in static or instance method | |
| class first.second.third.longlonglongClassName | |
| constructor: -> | |
| Ctor = @ | |
| @create: -> | |
| new Ctor |
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
| var map = Array.prototype.map.call | |
| , reduce = Array.prototype.reduce.call | |
| , filter = Array.prototype.filter.call | |
| , concat = Array.prototype.concat.call; | |
| /** | |
| * Recursively get all windows of current window. | |
| * @param {Window} win Current window. | |
| * @param {Function} f Extra filter to throw away undesired frame. | |
| * @param {boolean} recursion Whether invocation is in recursion. | |
| * @returns {Array.<Window>} |
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
| /** | |
| * Mock new operator. | |
| * Worked just as new operator. | |
| * @param {Function} Type | |
| * @param {...*} opt_args | |
| * @return {*} | |
| */ | |
| var newFunc = function(Type, opt_args) { | |
| var Ctor, proto; | |
| Ctor = function(){}; |
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
| var prefix = Math.random(); | |
| function parse(obj) { | |
| var key, value, type, schema; | |
| type = obj.constructor.name; | |
| switch (type) { | |
| case 'Object': | |
| schema = {}; | |
| for (key in obj) { | |
| value = parseKey(key, obj); | |
| if (value !== undefined) schema[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
| # 重启声音驱动 | |
| sudo kextunload /System/Library/Extensions/AppleHDA.kext | |
| sudo kextload /System/Library/Extensions/AppleHDA.kext |