Skip to content

Instantly share code, notes, and snippets.

View zlsun's full-sized avatar

zlsun zlsun

  • China
View GitHub Profile
@zlsun
zlsun / vector.cpp
Last active December 29, 2016 18:22
vector.cpp
#include <iostream>
#include <algorithm>
using namespace std;
// 通用结构
template <class T, int N>
struct StructDefault {
T a[N];
};
#include<stdio.h>
extern int(a),(b);
typedef int(I);
struct A{
int(a);
};
struct B:A{
(B)(B(())):A{A{{}}}{};
};
int(main)(int(argc),char**argv){
@zlsun
zlsun / 2048.py
Last active March 10, 2016 08:54
Terminal 2048 game in 50 lines of Python
#!/bin/python3
from random import choice
from os import system
from readchar import readchar, readkey
from colorama import init
from termcolor import colored
from math import log2
N = 4
SEED = [2] * 9 + [4]
@zlsun
zlsun / webpack.config.js
Created January 14, 2016 17:55 — forked from alexesDev/webpack.config.js
React Native + Webpack (with babel6 and react-native v0.17)
var path = require('path');
var webpack = require('webpack');
var reactNativeExternalsPromise = (function () {
var reactNativeRoot = path.dirname(require.resolve('react-native/package'));
var blacklist = require('react-native/packager/blacklist');
var ReactPackager = require('react-native/packager/react-packager');
const rnEntryPoint = require.resolve('react-native');
return ReactPackager.getDependencies({

Usage

  1. npm install babel-loader imports-loader webpack --save
  2. Create webpack.config.js
  3. Move index.ios.js to src/index.ios.jsx
  4. webpack --watch

Example

src/index.ios.jsx

@zlsun
zlsun / fix-zip
Last active January 12, 2016 06:55
Fix mojibake zip file
#!/usr/bin/env bash
if [ $# -eq 0 ]; then
echo "Usage: $0 zip-file-to-fix"
exit
fi
log() {
printf "\e[1;31m[%s]\e[0m\t%s\n" "$1" "$2"
}
@zlsun
zlsun / vimura.md
Created January 11, 2016 13:04 — forked from vext01/vimura.md
Vim+Zathura+Synctex

Vim+Zathura+Synctex

  • In a script called 'vimura':
#!/bin/sh
echo $1
zathura -s -x "gvim --servername $1 -c \"let g:syncpdf='$1'\" --remote +%{line} %{input}" $*
#include <iostream>
#include <iomanip>
#include "date.h"
using namespace std;
using namespace date;
using namespace std::chrono;
int main(int argc, char *argv[])
@zlsun
zlsun / run-py-file-with-python2.sh
Last active December 25, 2015 09:04
The correct way to run py file with python2.
#!/usr/bin/env bash
SCRIPTPATH=`dirname "${BASH_SOURCE[0]}"`
cd "$SCRIPTPATH"
PYTHON=python
if hash python2 > /dev/null 2>&1; then
PYTHON=python2
fi
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
import requests
from path import Path
from sh import git
user = 'your username'