Skip to content

Instantly share code, notes, and snippets.

View bagpack's full-sized avatar

bagpack bagpack

View GitHub Profile
@bagpack
bagpack / print_bch_parity.py
Created October 19, 2016 04:51
Print BCH parity list
'''
Print BCH parity list
'''
def bch_parity(data, gx, data_len):
parity_len = data_len * 2
data = data << parity_len
for i in range(data_len + parity_len, parity_len - 1, -1):
if data & (1 << i) != 0:
data ^= (gx << (i - parity_len))
@bagpack
bagpack / reedsolomon_parity.py
Created October 18, 2016 09:03
Calcurate reedsolomon parity
'''
Calcurate reedsolomon parity
'''
from collections import OrderedDict
def gen_exp_table():
alpha = 1
table = []
for i in range(256):
@bagpack
bagpack / gen_polynomial.py
Last active October 18, 2016 02:30
calcurate generator polynomial g(x)
'''
calcurate generator polynomial g(x)
'''
from collections import OrderedDict
def gen_exp_table():
alpha = 1
table = []
for i in range(256):
@bagpack
bagpack / gf2_8.py
Last active October 17, 2016 04:51
Print GF(2^8) list
alpha = 1
for i in range(256):
print("%d\t%d\t%s" % (i, alpha, format(alpha, 'b').zfill(8)))
alpha = alpha << 1
if alpha & (1 << 8) != 0:
alpha = alpha & ~(1 << 8) ^ (1 << 4) ^ (1 << 3) ^ (1 << 2) ^ 1
@bagpack
bagpack / Dockerfile-mysql
Last active February 21, 2020 11:01
docker-lamp-development-environment(Apache,PHP,MySQL Stacks)
FROM mysql:5.6.23
COPY ./my.cnf /etc/mysql/my.cnf
COPY ./docker-entrypoint-initdb.d/* /docker-entrypoint-initdb.d/
@bagpack
bagpack / simple.agent.js
Last active April 20, 2016 06:28
simple promisify XMLHttpRequest
(function(global, Promise) {
'use strict';
var DEFAULT_TIMEOUT = 10000; // millisec
// Class ------------------------------------------------
function SimpleAgent(params) {
params = !params || {};
this.timeout = params.timeout || DEFAULT_TIMEOUT;
this.headers = params.headers || {};
@bagpack
bagpack / UIImage+Snapshot.m
Last active September 9, 2015 01:21 — forked from anthonycastelli/UIImage+Snapshot.m
Snapshotting on iOS
+ (UIImage *)snapshotView:(UIView *)view {
UIGraphicsBeginImageContextWithOptions(view.frame.size, NO, [[UIScreen mainScreen] scale]); //0
[view drawViewHierarchyInRect:view.frame afterScreenUpdates:YES];
UIImage *snapshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return snapshot;
}
+ (UIImage *)snapshot {
CGSize imageSize = CGSizeZero;
@bagpack
bagpack / playbook.yml
Last active August 29, 2015 14:22
My first ansible.
---
- hosts: all
sudo: yes
tasks:
- name: Add repository 'epel-repo'
yum: name=http://ftp-srv2.kddilabs.jp/Linux/distributions/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm state=present
- name: Add repository 'rpmforge-repo'
yum: name=http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm state=present
@bagpack
bagpack / .eslintrc
Last active August 29, 2015 14:22
My first webpack.
{
"parser": "babel-eslint",
"rules": {
"no-extra-strict": 0,
"dot-notation": 0,
"quotes": 0
},
"globals": {
"global": true,
},
@bagpack
bagpack / gist:cfb67fa31c8e5a863750
Created May 15, 2015 02:32
Twitter Kit For Android:Support media/upload
public class TwitterUploadClient {
private final String UPLOAD_ENDPOINT = "https://upload.twitter.com";
MediaService service;
final RestAdapter adapter;
TwitterUploadClient(TwitterAuthConfig authConfig, Session session, SSLSocketFactory sslSocketFactory, ExecutorService executorService) {
if(session == null) {
throw new IllegalArgumentException("Session must not be null.");