Skip to content

Instantly share code, notes, and snippets.

@siongui
siongui / gist:8240270
Created January 3, 2014 15:55
使用Go并发下载图片资源 From: http://my.oschina.net/qbit/blog/189928
package img
import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
"io"
"log"
"net/http"
"os"
@binjoo
binjoo / CopyUtils.java
Last active December 12, 2018 12:56
JAVA:复制文件和文件夹
package com.utils;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
/***
*
* @ClassName CopyUtils
@makotom
makotom / isbn.js
Last active March 10, 2019 14:44
ISBN tools by JS
var ISBN = (function(){
"use strict";
var validateISBN13 = function(isbnChars){
var checksum = 0;
isbnChars.forEach(function(isbnChar, key){
checksum += parseInt(isbnChar, 10) * (key % 2 === 1 ? 3 : 1);
});
@shiny
shiny / 多维数组.php
Last active April 28, 2019 06:36
多维数组.php
<?php
$a = [ 'Date','Media','Geo' ];
$b = [ 'Num' ];
$subject = [ 'Date'=>'2019-04-26','Media'=>'AAA','Geo'=>'CN','Num'=>105 ];
// 多维数组的最后一项
$value = array_intersect_key($subject, array_fill_keys($b, 1));
// 生成多维数组
$res = createMultiArray($a, $value, $subject);
var_dump([
@lftbrts
lftbrts / gitignore_symlinks.txt
Created May 16, 2017 11:53
git ignore symlinks
@lifei6671
lifei6671 / snowflake.php
Created August 15, 2017 01:49
PHP实现的snowflake算法
/**
* 使用 snowflake 算法生成递增的分布式唯一ID.
* 该算法支持 15 条业务线,4 个数据中心,每个数据中心最多 128 台机器,每台机器每毫秒可生成 4096 个不重复ID.
*/
class Snowflake
{
const SEQUENCE_BITS = 12;
const MILLISECOND_BITS = 39;
const BUSINESS_ID_BITS = 4;
const DATA_CENTER_ID_BITS = 2;
@eligrey
eligrey / chrome-i18n.js
Last active January 11, 2020 11:16
Easy i18n for your Chrome extensions and apps' DOM.
/* Chrome DOM i18n: Easy i18n for your Chrome extensions and apps' DOM.
* 2011-06-22
*
* By Eli Grey, http://eligrey.com
* Public Domain.
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
*/
/*jslint laxbreak: true, strict: true*/
/*global self, chrome, document*/
@roylez
roylez / backup-db.sh
Created August 22, 2017 22:23
dokku postgres backupscript
#! /bin/bash
#
# to restore:
# gunzip XXX.db.gz
# dokku postgres:import <dbname> < XXX.db
# directory to save backups in, must be rwx by postgres user
BASE_DIR="/var/backups/postgres"
YMD=$(date "+%Y-%m-%d")
DIR="$BASE_DIR"
@banks
banks / ecdh.go
Last active April 23, 2020 02:12
// ecdh implements a simple way to perform Diffie-Hellman Key Exchange using
// Curve25519 on the command line.
//
// NOTE: this is a toy for fun. Don't use it.
//
// See https://godoc.org/golang.org/x/crypto/curve25519 and
// https://cr.yp.to/ecdh.html for more info.
//
// The final shared secret given is the raw shared secret bytes from DH and is
// not typically suitable for direct use as an encryption key as it can leak
@fhefh2015
fhefh2015 / label.m
Last active June 26, 2020 03:35
UILabel两端对齐
- (NSAttributedString *)textAligenJustifiedWith:(NSString *)text lineSpace:(CGFloat)lineSpace {
NSMutableAttributedString *mutableAttributedString = [[NSMutableAttributedString alloc] initWithString:text];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.alignment = NSTextAlignmentJustified;
paragraphStyle.paragraphSpacing = 11.0;
paragraphStyle.paragraphSpacingBefore = 10.0;
paragraphStyle.firstLineHeadIndent = 0.0;