Skip to content

Instantly share code, notes, and snippets.

@shenmao1989
shenmao1989 / gist:3662682
Created September 7, 2012 02:50
用UglifyJS解析/压缩/格式化你的Javascript
UglifyJS是基于 NodeJS 的Javascript语法解析/压缩/格式化工具,它支持任何CommonJS模块系统的Javascript平台(实现自己的CommonJS平台也非难事)。
UglifyJS通过解析重新生成JS代码的语法树,你可以通过AST以了解更多代码情况,或者自己来做一个不同的实现。UglifyJS解析器是在 parse-js.js 中实现的,它是非常优秀的 parse-js Common Lisp Library 的一部分。
(如果你正在查找UglifyJS的Common Lisp版本,点击 这里 )
UglifyJS的另一个重要部分是在 process.js 实现的,它用于检查并实现解析生成的AST:
通过AST进行Javascript代码的重新生成 :如果你想格式化已经被压缩过的代码,可以选择缩进参数。你也可以打印出无空白(whitespace)的AST,以达到压缩的目的。
缩短变量名 :UglifyJS通过分析代码并生成新的变量名称,依赖于作用域,这些名称通常被简化为单一字符,并能足够智能的处理全局变量,或者eval()调用及with{}块。换句话说,如果在某个作用域内使用了eval()或with{},那么该作用域的所有变量及其父作用域的变量都不会被重新命名,并且所有指向这类变量的引用也不会被改变。
@steveliles
steveliles / Foreground.java
Created April 20, 2014 15:30
Class for detecting and eventing the foreground/background state of an Android app - API-level 14+
package com.sjl.util;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import java.util.List;
@soulmachine
soulmachine / WordCountPercentage.java
Last active November 12, 2019 18:50
Calculate Word Count Percentage
package me.soulmachine;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
@iest
iest / BzIframe.js
Created January 7, 2015 16:43
Basic react iframe with onLoad handler
'use strict';
var React = require('react');
var BzIframe = React.createClass({
propTypes: {
src: React.PropTypes.string.isRequired,
onLoad: React.PropTypes.func
},
@romannurik
romannurik / CharsPerLineActivity.java
Last active December 17, 2021 03:15
Demonstrates how to identify and avoid line-length issues with TextView. The measure, or characters per line, of a block of text plays a key role in how comfortable it is to read (sometimes referred to as readability). A widely accepted optimal range for a text block's measure is between 45 and 75 characters. This code demonstrates two phases of…
/*
* Copyright 2013 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@ZkHaider
ZkHaider / expand-collapse.java
Last active January 30, 2022 02:31
Simple Expand / Collapse RecyclerView Item
public static class ExampleViewHolder extends RecyclerView.ViewHolder
implements View.OnClickListener {
private int originalHeight = 0;
private boolean isViewExpanded = false;
private YourCustomView yourCustomView
public ExampleViewHolder(View v) {
super(v);
v.setOnClickListener(this);
@chenwery
chenwery / iframeclick.js
Created February 20, 2014 06:21
javascript:监听页面中iframe被点击
var IframeOnClick = {
resolution : 200,
iframes : [],
interval : null,
Iframe : function() {
this.element = arguments[0];
this.cb = arguments[1];
this.hasTracked = false;
},
track: function(element, cb) {
@cloudsben
cloudsben / md-menu.html
Last active June 14, 2023 07:46
markdown menu
<link rel="stylesheet" href="http://yandex.st/highlightjs/6.2/styles/googlecode.min.css">
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="http://yandex.st/highlightjs/6.2/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<script type="text/javascript">
$(document).ready(function(){
$("h2,h3,h4,h5,h6").each(function(i,item){
var tag = $(item).get(0).localName;
@pyricau
pyricau / OomExceptionHandler.java
Created May 6, 2015 17:18
Dump the heap on OutOfMemoryError crashes in your debug builds.
import android.content.Context;
import android.os.Debug;
import java.io.File;
public class OomExceptionHandler implements Thread.UncaughtExceptionHandler {
private static final String FILENAME = "out-of-memory.hprof";
public static void install(Context context) {
Thread.UncaughtExceptionHandler defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
chrome.webRequest.onHeadersReceived.addListener(
function (details) {
for (var i = 0; i < details.responseHeaders.length; ++i) {
if (details.responseHeaders[i].name.toLowerCase() == 'x-frame-options') {
details.responseHeaders.splice(i, 1);
return {
responseHeaders: details.responseHeaders
};
}
}