Skip to content

Instantly share code, notes, and snippets.

@Jamesits
Jamesits / Adb_sms
Last active August 29, 2015 13:55 — forked from anonymous/gist:5989569
adb_sms
/*
以下是MainActivity.java的内容
建议在第34行之后加一句 this.finish();
*/
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@Jamesits
Jamesits / abs_sort.c
Created December 7, 2014 09:04
对大小为 10 的 int 数组进行绝对值从小到大排序。
//#define USE_QSORT
// 上面一行取消注释就调用 C 自带的快速排序算法,否则使用手写的冒泡排序
#include <stdio.h>
#include <stdlib.h>
int iabs(int a)
{
return a > 0 ? a : -a;
}
@Jamesits
Jamesits / arduino.ino
Last active August 29, 2015 14:12
红外线遥控发声发光装置 Arduino 程序
#include <IRremotea.h>
#include <Wire.h>
#include <avr/pgmspace.h> //to use PROGMEM
//#define USE_LED
#define LEDMAX 255
#define LEDMIN 0
#define LEDSTEP 3
#define LEDSTEP2 20
@Jamesits
Jamesits / discoveryd_checker.sh
Last active August 29, 2015 14:19
Check if discoveryd on OS X 10.10.3 has too high CPU usage and restart it.
#!/bin/bash
# Copyright (c) 2015, James Swineson <jamesswineson@gmail.com>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
@Jamesits
Jamesits / Qujing Cached PAC 20150711.js
Last active March 17, 2017 12:10
PAC script downloaded at Jul 11, 2015 5:04:17 PM
dnsDomainIs = function (h, d) {
return h.indexOf(d, h.length - d.length) !== -1 && (d.length === h.length || h.indexOf("." + d, h.length - ("." + d).length) !== -1)
}
function FindProxyForURL(u, h) {
h = h.toLowerCase();
if (h === "appdownload.itunes.apple.com" || dnsDomainIs(h, "battlenet.com.cn") || dnsDomainIs(h, "dist.blizzard.com.edgesuite.net") || /us-ore-\d+\.s3\.amazonaws\.com/.test(h) || /\w{2}-\w{3}-\d{5}\.s3\.amazonaws\.com/.test(h)) {
return "DIRECT"
}
a = []; // user ignore list
@Jamesits
Jamesits / my.cnf
Created August 4, 2015 13:30
A good /etc/mysql/my.cnf replacement which solves mysql/percona fail to start problem. Worked for me.
# https://www.digitalocean.com/community/questions/mysql-server-keeps-stopping-unexpectedly
# http://pastie.org/8665237
# Generated by Percona Configuration Wizard (http://tools.percona.com/) version REL5-20120208
[mysql]
# CLIENT #
port = 3306
socket = /var/run/mysqld/mysqld.sock
@Jamesits
Jamesits / loveometer.ino
Created October 13, 2015 09:08
Love-o-meter Arduino Project rewritten
// Love-o-meter rewritten code
// by James Swineson, 2015-10-13
// For demonstration use only.
// =========== Settings ===========
// Total LED number
#define LEDCOUNT 5
// Which digital pins are LEDs connected to. They will light up from left to right.
@Jamesits
Jamesits / update.sh
Created October 13, 2015 13:58
Update dnsmasq additional hosts file on OpenWRT from https://github.com/StevenBlack/hosts
#!/bin/bash
echo "Updating hosts..."
wget --show-progress -O hosts -- https://github.com/StevenBlack/hosts/raw/master/hosts && /etc/init.d/dnsmasq restart
echo "Update finished. "
@Jamesits
Jamesits / string-padding.js
Last active January 20, 2016 08:45
String padding for JavaScript: Make a string fixed length by adding blank chars before or after it.
/*
String padding
by James Swineson (@Jamesits)
https://gist.github.com/Jamesits/30acd725d5fdfb67eae4
Make a string fixed length by adding blank chars between or after it.
Usage:
"123".lpadding(5) // returns " 123"
"123".lpadding(5, "0") // returns "00123"
"123".lpadding(2) // returns "23"
"123".rpadding(5) // returns "123 "
@Jamesits
Jamesits / py-gene-t-tester.py
Last active January 27, 2016 16:04
This script has been used to analysis some gene test result in "tab separated value" format from some lab of ZJU. It saves tons of silly people's labor pasting two rows from two different xlsx to graphpad, click some analysis button and copy result back to the third xlsx. However, there is a drawback of this script: it's not parallel.
#!/usr/bin/env python3
# James' Gene T-tester
# Written by James Swineson <jamesswineson@gmail.com>, 2016-01-27
# All rights reserved.
#
# Install dependencies:
# pip3 install numpy scipy
#
# Tested to work under Python 3.5.1 on OS X 10.11.3