Skip to content

Instantly share code, notes, and snippets.

@liu7yong
liu7yong / DropDownAnimation
Last active December 21, 2015 12:19
An android animation that collapse or expand a View object.
/**
*
*/
package us.liuyong.widget;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.Animation;
import android.view.animation.Transformation;
@liu7yong
liu7yong / RotateDrawable
Last active December 21, 2015 12:19
If you has your own custom View who has a RotateDrawable and want to make it rotate, following code may help. The trick is to call Drawable.setLevel() on the drawable.
private Drawable mLoadingDrawable;
private Transformation mTransformation;
private AlphaAnimation mAnimation;
private boolean mHasAnimation;
private Interpolator mInterpolator;
private long mLastDrawTime;
private static final int ANIMATION_RESOLUTION = 200;
private static final int MAX_LEVEL = 10000;
@liu7yong
liu7yong / unpack_plist.py
Last active April 3, 2019 02:00 — forked from wonkwh/unpack_plist.py
extract image from plist,png file created by texturepacker
#/usr/local/bin/python
import os,sys
from xml.etree import ElementTree
from PIL import Image
def tree_to_dict(tree):
d = {}
for index, item in enumerate(tree):
if item.tag == 'key':
if tree[index+1].tag == 'string':
@liu7yong
liu7yong / resize.py
Last active December 23, 2015 03:49
batch resize images.
import os
import sys
from PIL import Image
def resize(folder, fileName, factor):
filePath = os.path.join(folder, fileName)
im = Image.open(filePath)
w, h = im.size
newIm = im.resize((int(w*factor), int(h*factor)), Image.ANTIALIAS)
# i am saving a copy, you can overrider orginal, or save to other folder
@liu7yong
liu7yong / gif.cpp
Created September 17, 2013 03:45
animate each image as a frame (like gif) in cocos2d-x
CCSprite *pSkill = (CCSprite *) getChildByTag(TAG_MENU)->getChildByTag(tag);
CCSprite *pHighLight = CCSprite::createWithSpriteFrameName("point1.png");
this->addChild(pHighLight, Z_ORDER_TITLE, TAG_SKILL_HIGHLIGHT);
pHighLight->setPosition(pSkill->getPosition());
CCArray *walkAnimFrames = CCArray::create();
for (int i = 1; i<= 4; i++)
{
walkAnimFrames->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(CCString::createWithFormat("point%d.png", i)->getCString()));
}
@liu7yong
liu7yong / unpack_atlas.py
Created February 15, 2014 16:07
unpack png from atlas images (such as flappy bird)
#/usr/local/bin/python
import os, sys, math
from PIL import Image
def config_to_dict(atlas_entry):
d = {}
list = atlas_entry.split(" ")
d["frameName"] = list[0]
d["width"] = int(list[1])
d["height"] = int(list[2])
/*
* Copyright (C) 2014 Chris Banes
*
* 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
@liu7yong
liu7yong / canvas.html
Last active August 29, 2015 14:13
html5 canvas test
<!DOCTYPE HTML>
<html>
<body>
<p>Original Image: </p>
<img id="demo_img" src="demo_small.png" alt="Original Image"/>
<p>Canvas:</p>
<canvas id="myCanvas" style="border:1px solid #000000;">your browser does not support the canvas tag </canvas>
<script type="text/javascript">
@liu7yong
liu7yong / WifiConnection.java
Last active November 7, 2021 14:45
How to connect to a specific wifi network in Android programmatically?
WifiConfiguration wifiConfig = new WifiConfiguration();
wifiConfig.SSID = String.format("\"%s\"", ssid);
wifiConfig.preSharedKey = String.format("\"%s\"", key);
WifiManager wifiManager = (WifiManager)getSystemService(WIFI_SERVICE);
//remember id
int netId = wifiManager.addNetwork(wifiConfig);
wifiManager.disconnect();
wifiManager.enableNetwork(netId, true);
wifiManager.reconnect();
@liu7yong
liu7yong / gitproxy-socat
Created April 25, 2020 06:55 — forked from sit/gitproxy-socat
A simple wrapper around socat to use as a git proxy command
#!/bin/sh
# Use socat to proxy git through an HTTP CONNECT firewall.
# Useful if you are trying to clone git:// from inside a company.
# Requires that the proxy allows CONNECT to port 9418.
#
# Save this file as gitproxy somewhere in your path (e.g., ~/bin) and then run
# chmod +x gitproxy
# git config --global core.gitproxy gitproxy
#
# More details at http://tinyurl.com/8xvpny