Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@yuanyan
yuanyan / loadStyles.js
Created September 19, 2014 14:45
Injects the CSS into the <head> DOM node.
/**
* 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 September 11, 2014 15:55
Glitch effects
.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 November 20, 2015 15:55
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 March 20, 2014 12:22
Fix Duplicate "Open With"
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 March 4, 2014 11:38
Ruby Snippets for Atom
'.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'
var template = 'hi';
exports.run = function(){
template('hi')
}
exports.template = function(hi){
console.log(hi)
}
@yuanyan
yuanyan / console.js
Last active December 19, 2015 05:09
console API
// 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;")
@yuanyan
yuanyan / node-fs.js
Last active December 18, 2015 17:39
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 August 12, 2012 15:34
Third-party JavaScript
<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>
@yuanyan
yuanyan / gist:1240875
Created September 25, 2011 17:34
Object.clone
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{