This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
import os | |
import tempfile | |
import sqlite3 | |
class DBExportor(object): | |
def __init__(self, db=None): | |
if not db: | |
db = self.pull_db() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
array = [10, 9, 2, 5, 3, 7, 101, 18, 31, 25, 68, 45, 12] | |
# O(n^2) | |
def longest_seqs(seqs): | |
l = [] | |
for i in range(len(seqs)): | |
l.append(max([l[j] for j in range(i) if l[j][-1] < seqs[i]] or [[]], | |
key=len) + [seqs[i]]) | |
return len(max(l, key=len)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
### BEGIN INIT INFO | |
# Provides: | |
# Required-Start: $remote_fs $syslog | |
# Required-Stop: $remote_fs $syslog | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Start daemon at boot time | |
# Description: Enable service provided by daemon. | |
### END INIT INFO |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StaticFileRes(object): | |
def __init__(self, static_root='.'): | |
self.static_root = os.path.abspath(static_root) | |
def on_get(self, req, resp): | |
path = req.path | |
if path == '/': # handle default page | |
path = '/index.html' | |
full_path = self.static_root + path | |
if os.path.isfile(full_path): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from falcon.routing import DefaultRouter | |
class ReverseRouter(DefaultRouter): | |
url_map = {} | |
# override add_route to add our map | |
def add_route(self, uri_template, method_map, resource, name=None): | |
if name: | |
self.url_map[name] = uri_template |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void cos_curve(float a_max, float w_start, float w_max, int total, int pin) { | |
#define STATE_ACC 0 | |
#define STATE_CONST 1 | |
#define STATE_DEC 2 | |
if (w_start > w_max) w_start = w_max; | |
float w_i = w_start; | |
float t_i = 0.000001; | |
int count = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
amax: max of velocity accelerator | |
aa: accelerator of v accelerator | |
vm: max of velocity | |
s: total lenght of distance | |
pin: pluse pin of stepper controller | |
In order to improve performance, let's re-define the unit system: | |
time -- us | |
length -- step |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedInputStream; | |
import java.io.ByteArrayOutputStream; | |
import java.io.FileOutputStream; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.net.URL; | |
public class DownloadFile { | |
public static void download(String fileName, String url) throws IOException { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<onlinemapsources> | |
<onlinemapsource uid="0"> | |
<name>Google Maps</name> | |
<url><![CDATA[http://mt{$s}.google.cn/vt/lyrs=m@121&hl={$l}&x={$x}&y={$y}&z={$z}]]></url> | |
<minzoom>0</minzoom> | |
<maxzoom>19</maxzoom> | |
<projection>MERCATORESFERICA</projection> | |
<servers>0,1,2,3</servers> | |
<httpparam name=""></httpparam> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* stolen from input command | |
* but have some limitation: | |
* since it can use "android.permission.INJECT_EVENTS", (only system apps can do that) | |
* Inject event to other apps will raise a exception of no permission | |
*/ | |
import android.hardware.input.InputManager; | |
import android.os.SystemClock; | |
import android.util.Log; | |
import android.view.InputDevice; |
NewerOlder