Skip to content

Instantly share code, notes, and snippets.

@yuanyan
yuanyan / loadStyles.js
Created Sep 19, 2014
Injects the CSS into the <head> DOM node.
View loadStyles.js
/**
* Injects the CSS into the <head> DOM node.
*
* @param {String} css CSS string to add to the <style> tag.
* @param {Document} doc document instance to use.
*/
function loadStyles(css, doc) {
// default to the global `document` object
if (!doc) doc = document;
@yuanyan
yuanyan / glitch.scss
Created Sep 11, 2014
Glitch effects
View glitch.scss
.glitch{
color:white;
font-size:100px;
position:relative;
width:400px;
margin:0 auto;
}
@keyframes noise-anim{
$steps:20;
@for $i from 0 through $steps{
@yuanyan
yuanyan / fixaudio.applescript
Last active Nov 20, 2015
fixaudio.applescript
View fixaudio.applescript
on run {input, parameters}
do shell script "" with administrator privileges
set the rootPwd to text returned of (display dialog "请输入您的管理员密码:" default answer "" with hidden answer)
try
do shell script "echo " & rootPwd & "|sudo -S killall coreaudiod"
do shell script "echo " & rootPwd & "|sudo -S kextunload /System/Library/Extensions/AppleHDA.kext"
do shell script "echo " & rootPwd & "|sudo -S kextload /System/Library/Extensions/AppleHDA.kext"
do shell script "sudo -k" --logout root
display dialog "操作已经成功完成,您的系统应该能够恢复声音。
如果问题依旧,请直接重启系统。" buttons {""} with icon 1 with title "成功"
@yuanyan
yuanyan / fixow.sh
Created Mar 20, 2014
Fix Duplicate "Open With"
View fixow.sh
alias fixow='/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain local -domain user;killall Finder;echo "Open With has been rebuilt, Finder will relaunch"'
@yuanyan
yuanyan / atom-ruby-snippets.cson
Created Mar 4, 2014
Ruby Snippets for Atom
View atom-ruby-snippets.cson
'.source.ruby':
'describe (String)':
'prefix': 'des'
'body': 'describe "${1:subject}" do\n $0\nend'
'describe (type)':
'prefix': 'dest'
'body': 'describe ${1:Type} do\n $0\nend'
'describe (type, string)':
'prefix': 'dests'
'body': 'describe ${1:Type}, "${2:description}" do\n $0\nend'
View node-exports.js
var template = 'hi';
exports.run = function(){
template('hi')
}
exports.template = function(hi){
console.log(hi)
}
@yuanyan
yuanyan / console.js
Last active Dec 19, 2015
console API
View console.js
// http://getfirebug.com/wiki/index.php/Console_API
// https://developers.google.com/chrome-developer-tools/docs/console-api#consolelogobject_object
// https://developer.mozilla.org/en-US/docs/Web/API/console
console.log("%cRed text, %cgreen text, %cblue text", "color:red", "color:green", "color:blue");
console.log("%c",
"font-size: 1px; padding: 130px 232px; line-height: 260px;background: url(http://i.imgur.com/oGiMR.gif); background-size: 464px 260px; color: transparent;")
View node-fs.js
var fs = require("fs");
var path = require("path");
// mian code, 请替换路径地址
ncp('./path/to/source', './path/to/dest', function(){
rmrf('./path/to/source');
})
// copy from ncp, 请折叠
function ncp (source, dest, options, callback) {
@yuanyan
yuanyan / disqus.html
Created Aug 12, 2012
Third-party JavaScript
View disqus.html
<script type="text/javascript">
var disqus_shortname = 'madscript'; // required: replace example with your forum shortname
/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
View gist:1240875
Object.clone(obj,deep){
if(obj == null || typeof(obj) != 'object')
return obj;
if(deep){
var temp = obj.constructor(); // changed
for(var key in obj)
temp[key] = clone(obj[key]);
return temp;
}else{
You can’t perform that action at this time.