Skip to content

Instantly share code, notes, and snippets.

View yangsibai's full-sized avatar
🎯
Focusing

sibo yangsibai

🎯
Focusing
  • Chengdu
View GitHub Profile
@yangsibai
yangsibai / auth.go
Created February 1, 2016 14:48 — forked from tristanwietsma/auth.go
Golang web server example
package main
import (
"encoding/base64"
"net/http"
"strings"
)
type handler func(w http.ResponseWriter, r *http.Request)
package main
import (
"bufio"
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
"crypto/sha512"
"encoding/hex"
"fmt"
@yangsibai
yangsibai / image_helper.go
Last active August 23, 2023 07:17
Getting an Images Type and Size in Golang (or any other language)
// from: <http://openmymind.net/Getting-An-Images-Type-And-Size/>
func getFormat(file *os.File) (string) {
bytes := make([]byte, 4)
n, _ := file.ReadAt(bytes, 0)
if n < 4 { return "" }
if bytes[0] == 0x89 && bytes[1] == 0x50 && bytes[2] == 0x4E && bytes[3] == 0x47 { return "png" }
if bytes[0] == 0xFF && bytes[1] == 0xD8 { return "jpg" }
if bytes[0] == 0x47 && bytes[1] == 0x49 && bytes[2] == 0x46 && bytes[3] == 0x38 { return "gif" }
if bytes[0] == 0x42 && bytes[1] == 0x4D { return "bmp" }
{
"Users": ["UserA","UserB"],
"Groups": ["GroupA"]
}
@yangsibai
yangsibai / README.md
Created December 23, 2015 12:43 — forked from fuermosi777/README.md
React ScrollView Component

To use:

import ScrollView from 'ScrollView.jsx`;
...
render() {
    return (
    <ScrollView>
        {aListThatScrolls}
     </ScrollView>
    );
.
├── actions
├── stores
├── views
│   ├── Anonymous
│   │   ├── __tests__
│   │   ├── views
│   │   │   ├── Home
│   │   │   │   ├── __tests__
│   │   │   │   └── Handler.js
@yangsibai
yangsibai / reflux.js
Created November 2, 2015 09:30 — forked from spoike/reflux.js
A simpler implementation of React.JS's Flux
var EventEmitter = require('events').EventEmitter,
_ = require('lodash');
/**
* Creates an action functor object
*/
exports.createAction = function() {
var action = new EventEmitter(),
eventLabel = "action",
@yangsibai
yangsibai / pptpd.sh
Last active August 29, 2015 14:26 — forked from alvin2ye/pptpd.sh
Automaticlly install pptpd on Amazon EC2 Amazon Linux
# Automaticlly install pptpd on Amazon EC2 Amazon Linux
#
# Ripped from http://blog.diahosting.com/linux-tutorial/pptpd/
# pptpd source rpm packing by it's authors
#
# WARNING:
# first ms-dns setting to 172.16.0.23, 172.16.0.23 was showing on my
# /etc/resolv.conf, I'm not sure this is the same on all Amazon AWS zones.
#
# You need to adjust your "Security Groups" which you are using too.
@yangsibai
yangsibai / Makefile
Last active August 29, 2015 14:19 — forked from isaacs/Makefile
# Hello, and welcome to makefile basics.
#
# You will learn why `make` is so great, and why, despite its "weird" syntax,
# it is actually a highly expressive, efficient, and powerful way to build
# programs.
#
# Once you're done here, go to
# http://www.gnu.org/software/make/manual/make.html
# to learn SOOOO much more.
# OSX for Hackers (Mavericks/Yosemite)
#
# Source: https://gist.github.com/brandonb927/3195465
#!/bin/sh
# Some things taken from here
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
# Ask for the administrator password upfront