Skip to content

Instantly share code, notes, and snippets.

You-wei Teng youweit

Block or report user

Report or block youweit

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@youweit
youweit / appendLog.java
Created Jan 26, 2014
android log to file, will create a log file in sdcard root directory.
View appendLog.java
public void appendLog(String text) {
String logFileName = "AppLog.txt";
SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm:ss", Locale.getDefault());
String currentDateandTime = sdf.format(new Date());
File logFile = new File(Environment.getExternalStorageDirectory()
+ "/" + logFileName);
if (!logFile.exists()) {
try {
logFile.createNewFile();
View gist:7893622
public static int parseColor(String colorString) {
if (colorString.charAt(0) == '#') {
// Use a long to avoid rollovers on #ffXXXXXX
long color = Long.parseLong(colorString.substring(1), 16);
if (colorString.length() == 7) {
// Set the alpha value
color |= 0x00000000ff000000;
} else if (colorString.length() != 9) {
throw new IllegalArgumentException("Unknown color");
}
View gist:7869338
public class DiscoveryThread implements Runnable {
private static String TAG = "DiscoveryThread";
private DatagramSocket c;
pirvate static Context mContext;
private static int PORT = 5549;
@Override
public void run() {
byte[] bytes = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
View LinkedList.h
/*
* DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
* Version 2, December 2004
*
* Copyright(C) 2013 You-wei Teng
*
* Everyone is permitted to copy and distribute verbatim or modified
* copies of this license document, and changing it is allowed as long
* as the name is changed.
*
View gist:7306258
//Call with [self quickSort:0 withHigh:[scanpleFileList count]-1];
-(void)quickSort:(int)low withHigh:(int)high;{
int i = low,j = high;
int pivot = [[[scanpleFileList objectAtIndex:(low+high)/2]time]intValue];
while(i <= j){
while([[[scanpleFileList objectAtIndex:i]time]intValue] < pivot) i++;
View AndroidManifext.xml
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
@youweit
youweit / gist:6878683
Last active Dec 24, 2015
Arduino breath led!
View gist:6878683
#include <math.h>
void setup()
{
pinMode(11, OUTPUT);
}
void loop()
{
float val = (exp(sin(millis()/2000.0*PI)) - 0.365)*100.0;
View gist:6710109
//
// StickyHeaderLayout.h
// Wombat
//
// Created by Todd Laney on 1/9/13.
// Copyright (c) 2013 ToddLa. All rights reserved.
//
// Modified from http://blog.radi.ws/post/32905838158/sticky-headers-for-uicollectionview-using THANKS!
//
@youweit
youweit / gist:6594204
Created Sep 17, 2013
256 bit key generate example
View gist:6594204
import random
import hashlib
import base64
base64.b64encode(hashlib.sha256( str(random.getrandbits(256)) ).digest(), random.choice(['rA','aZ','gQ','hH','hG','aR','DD'])).rstrip('==')
View gist:6228826
<!doctype html>
<html>
<head>
<script src='//code.jquery.com/jquery-1.7.2.min.js'></script>
<script src="//localhost:3000/socket.io/socket.io.js" type="text/javascript"></script>
<script>
var socket = io.connect('//localhost:3000');
socket.on('welcome', function(data) {
$('#messages').append('<li>' + data.message + '</li>');
You can’t perform that action at this time.