Skip to content

Instantly share code, notes, and snippets.

View lajunta's full-sized avatar
🌴
On vacation

lajunta lajunta

🌴
On vacation
View GitHub Profile
@lajunta
lajunta / mac_zip.txt
Created April 30, 2015 07:28
mac zip command
zip data.zip file.txt -rq9
zip data.zip 2015* -rq9
-r recusive directory
-q quit
-9 best compress
#!/usr/bin/env ruby
point = Time.now.strftime("%Y%m%d%H")
backpath="/backup/dbback/"
path="/tmp/"+point
fpath=backpath+point+".tar.gz"
`mkdir -p #{path}`
`mongodump --out #{path} --quiet`
`tar -C /tmp -czvf #{fpath} #{point}`
require 'mail'
@lajunta
lajunta / netsocket.rb
Last active August 29, 2015 14:06
loop within loop
#encoding: utf-8
require "socket"
if Gem::Platform.local.os == "darwin"
CurrentPath = "/Users/zxy/current"
command_path = "/Users/zxy/command"
else
CurrentPath = "/root/current"
command_path = "/root"
end
@lajunta
lajunta / javascript time format yyyy-mm-dd hh:ss validation
Created April 22, 2014 14:06
javascript time format yyyy-mm-dd hh:ss validation
var patt=/2\d{3}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])[\s+](0[0-9]|1[0-9]|2[0-3]):(0[0-9]|[1-5][0-9])/;
$(document).ready(function(){
$("#settings").submit(function(){
var tk=true;
$("#settings input[type=text]").each(function(){
result = patt.exec($(this).val());
if(result==null){
var txt=$(this).parent().prev("td").text();
alert(txt+"格式不对");
tk=false;
@lajunta
lajunta / gist:8214228
Created January 2, 2014 02:46
自由软件中国镜像站点汇总
阿里云镜像:http://mirrors.aliyun.com/
网易开源镜像站:http://mirrors.163.com/
搜狐开源镜像站:http://mirrors.sohu.com/
北京交通大学开源镜像站:http://mirror.bjtu.edu.cn
兰州大学开源软件镜像站:http://mirror.lzu.edu.cn/
厦门大学开源软件镜像站:http://mirrors.xmu.edu.cn/
上海交通大学开源软件镜像站:http://ftp.sjtu.edu.cn/
清华大学开源软件镜像站:http://mirrors.tuna.tsinghua.edu.cn/
天津大学开源软件镜像站:http://mirror.tju.edu.cn/
中国科学技术大学开源软件镜像站:http://mirrors.ustc.edu.cn/
<xml>
<ToUserName>#{@to_user}</ToUserName>
<FromUserName>#{@from_user}</FromUserName>
<CreateTime>#{Time.now.to_i}</CreateTime>
<MsgType>news</MsgType>
<ArticleCount>1</ArticleCount>
<Articles>
<item>
<Title>凤城文化节有奖问答</Title>
<Description>快来参加吧</Description>
<xml>
<ToUserName>#{@to_user}</ToUserName>
<FromUserName>#{@from_user}</FromUserName>
<CreateTime>#{Time.now.to_i}</CreateTime>
<MsgType>news</MsgType>
<ArticleCount>#{@articles.count}</ArticleCount>
<Articles>
- @articles.each do |article|
- unless article.media_infos.blank?
- theone=article.media_infos.sample
#encoding: utf-8
require "net/http"
require "json"
require "xmlsimple"
class YixinController < ApplicationController
layout nil
skip_before_filter :verify_authenticity_token
#encoding: utf-8
require "net/http"
require "json"
require "xmlsimple"
def get_access_token
appid="your appid"
appsecret="your appsecret"
uri_string="https://api.yixin.im/cgi-bin/token?grant_type=client_credential&appid=#{appid}&secret=#{appsecret}"
uri=URI.parse(uri_string)
#encoding: utf-8
require "json"
require "rest_client"
def get_access_token
appid="your appid"
appsecret="your appsecret"
uri = "https://api.yixin.im/cgi-bin/token?grant_type=client_credential&appid=#{appid}&secret=#{appsecret}"
res = RestClient.get(uri)
hsh = JSON.parse(res)