Skip to content

Instantly share code, notes, and snippets.

View satbirdd's full-sized avatar

liu lei satbirdd

  • Changsha, China
View GitHub Profile
@satbirdd
satbirdd / bytes_split.go
Created October 25, 2017 01:38 — forked from xlab/bytes_split.go
Golang split byte slice in chunks sized by limit
func split(buf []byte, lim int) [][]byte {
var chunk []byte
chunks := make([][]byte, 0, len(buf)/lim+1)
for len(buf) >= lim {
chunk, buf = buf[:lim], buf[lim:]
chunks = append(chunks, chunk)
}
if len(buf) > 0 {
chunks = append(chunks, buf[:len(buf)])
}
@satbirdd
satbirdd / golang-gql-client.go
Created September 7, 2017 06:41 — forked from rms1000watt/golang-gql-client.go
Golang GraphQL Client
package main
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"strconv"
)
gnome-terminal\
--tab\
--title="Rails"\
--working-directory="/home/username/works/project"\
-e "bash -c 'rails s;bash'"\
#the gnome-terminal closes after the somecommand terminates, the reason being gnome-terminal not running the bash as it's default shell.
#To get the bash prompt($) after the command command completes, you need to trigger it back.
@satbirdd
satbirdd / Ubuntu12.04-g++4.8
Created April 23, 2016 05:41 — forked from akoluthic/Ubuntu12.04-g++4.8
Install g++ 4.8 on Ubuntu 12.04
*Add the toolchain/test PPA*
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install g++-4.8
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 50
*If you ever want to update symlinks for a future version:*
sudo rm /usr/bin/g++
sudo ln -s /usr/bin/g++-4.XXX /usr/bin/g++
@satbirdd
satbirdd / js_id.js
Created September 24, 2014 13:57
generate id for javascript class
function A () {
this.generateId();
}
A.prototype.generateId = (function () {
var count = 0;
return function () {
count ++;
this.id = count;
<div style='position: relative; overflow: hidden;'>
<div style="width:130px; height: 130px; cursor: pointer;
background-size: contain;
background-repeat: no-repeat;
background-position: 50% 50%;"
class='image' />
</div>
<input type='file' style="position: absolute; top: 0; left: 0; margin: 0; opacity: 0; -ms-filter: 'alpha(opacity=0)'; font-size: 130px; overflow: hidden; width: 130px; height: 130px; direction: ltr; cursor: pointer;">
上传最好是本人的个人照</br>
头像支持图像格式:jpeg, png,git,大小不超过4M<br>
@satbirdd
satbirdd / setup_work.sh
Created June 20, 2014 01:34
ubuntu(gnome) teminate setup bash script
#!/bin/bash
gnome-terminal\
--tab\
--title="Neil"\
--working-directory="/home/robin/works/neil-rails-app"\
-e "bash -c 'rails s -p 4000'"\
--tab\
--title="Front"\
--working-directory="/home/robin/works/neil-rails-app/vendor/frontend"\
-e "bash -c 'PORT=5000 grunt serve:proxy'"\
function get_async_data(url, callback) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (4 === xmlhttp.readyState && 200 === xmlhttp.status) {
// console.log(xmlhttp.response);
callback(JSON.parse(xmlhttp.response));
}
}
xmlhttp.open("GET", url, true);
xmlhttp.send()
#!/bin/bash
cd /vagrant
bundle
bundle exec rake db:create RAILS_ENV=production
bundle exec rake db:migrate RAILS_ENV=production
bundle exec sidekiq
rails s -p 5000 -e production
# !/bin/bash
# postgresql apt-get repository
# sudo touch /etc/apt/sources.list.d/pgdg.list
# echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" | sudo tee -a /etc/apt/sources.list.d/pgdg.list
# wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
# redis apt-get repository
echo "deb http://archive.ubuntu.com/ubuntu precise main universe" | sudo tee -a /etc/apt/sources.list