Skip to content

Instantly share code, notes, and snippets.

@s4553711
s4553711 / gist:9488399
Created March 11, 2014 15:41
Some example for subprocess.Popen exception example
#!/usr/bin/python
import subprocess
import os
import sys
#res = subprocess.Popen(['ls','-al','/ahome'],stdout=subprocess.PIPE,stderr=subprocess.PIPE);
#output,error = res.communicate()
#if res.returncode:
# #raise Exception(error)
@s4553711
s4553711 / blast.java
Created June 16, 2013 16:39
A simple program for submitting ncbi blast search in Java
package Bio;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.util.Hashtable;
@s4553711
s4553711 / DiscardServer.java
Created June 19, 2016 16:41
A netty server example
package com.ck.server;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.FixedRecvByteBufAllocator;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
#include <zlib.h>
#include <time.h>
#include <stdio.h>
#include <stdbool.h>
#include <sys/uio.h>
#include <fcntl.h>
#include <unistd.h>
#include <inttypes.h>
#include "kseq.h"
#include "kstring.h"
@s4553711
s4553711 / gist:5167381
Created March 15, 2013 03:57
Render a picture in non-public folder in Mojolicious
#!/usr/bin/env perl
use Mojolicious::Lite;
get '/' => sub {
my $self = shift;
$self->render('clock');
};
get '/pic' => sub {
my $self = shift;
library(ggplot2)
library(scales)
library(ggpubr)
k = read.csv('iostat.tsv')
k$datetime <- as.POSIXct(k$time, origin="1970-01-01", tz="GMT")
s1 <- ggplot(k, aes(datetime)) +
geom_line(aes(y = rs, colour="rs"), alpha=0.4, size=1) +
geom_line(aes(y = ws, colour="ws"), alpha=0.4, size=1) +
class Solution {
public:
int trailingZeroes(int n) {
if (n < 5) return 0;
int count = 0;
while(n >= 5) {
count += floor(n/5);
n /= 5;
}
return count;
vector<vector<int> > C(s1.length() + 1, vector<int>(s2.length() + 1, 0));
// initial
for (int i = 1; i < s2.length() + 1; ++i) {
C[0][i] = C[0][i - 1] + s2[i - 1];
}
for (int i = 1; i < s1.length() + 1; ++i) {
C[i][0] = C[i - 1][0] + s1[i - 1];
}
for (int i = 1; i < s1.length() + 1; ++i) {
for (int j = 1; j < s2.length() + 1; ++j) {
class Solution {
public:
int numberOfArithmeticSlices(vector<int>& A) {
int count = 0;
int added = 0;
int n = A.size();
for(int i = 2; i < n; i++) {
if (A[i-1] - A[i] == A[i-2] - A[i-1]) {
count += ++added;
} else {
class Solution {
public:
int reverse(int x) {
int rev = 0;
while (x != 0) {
int pop = x % 10;
x /= 10;
if (rev > INT_MAX/10 || rev == INT_MAX/10 && pop > 7) return 0;
if (rev < INT_MIN/10 || rev == INT_MIN/10 && pop < -8) return 0;
rev = rev * 10 + pop;