Skip to content

Instantly share code, notes, and snippets.

View JustLoveBen's full-sized avatar

张永彬 JustLoveBen

  • Meituan-Dianping
  • Beijing, China
View GitHub Profile
@JustLoveBen
JustLoveBen / wave.js
Last active December 2, 2019 12:28 — forked from also/wave.js
Generate WAVE file headers in JavaScript
// https://ccrma.stanford.edu/courses/422/projects/WaveFormat/
function buildWaveHeader(opts) {
var dataSize = opts.dataSize;
var numChannels = opts.numChannels || 1;
var sampleRate = opts.sampleRate || 16000;
var bytesPerSample = opts.bytesPerSample || 2;
var blockAlign = numChannels * bytesPerSample;
var byteRate = sampleRate * blockAlign;
var buffer = new ArrayBuffer(44);
@JustLoveBen
JustLoveBen / time_profiler.h
Created December 19, 2017 16:23
time_profiler benchmark
//
// time_profiler.h
// time_profiler
//
// Created by JustBen on 22/03/2017.
// Copyright © 2017 JustBen. All rights reserved.
//
#ifndef time_profiler_h
#define time_profiler_h
@JustLoveBen
JustLoveBen / url_regex.swift
Last active July 19, 2023 08:51
URL正则表达式-iOS
//: Playground - noun: a place where people can play
import UIKit
import UIKit
var regex = "(((http[s]{0,1}|ftp)://)?(([\\W\\.\\-]+\\.([a-zA-Z]{2,4}))|((::)?[0-255]\\.[0-255]\\.[0-255]\\.[0-255])|((([a-zA-Z0-9]{4})?:)?(([a-zA-Z0-9]{4})?:)?(([a-zA-Z0-9]{4})?:)?(([a-zA-Z0-9]{4})?:)?(([a-zA-Z0-9]{4})?:)?(([a-zA-Z0-9]{4})?:)?(([a-zA-Z0-9]{4})?:)?([a-zA-Z0-9]{4})?))(:\\d+)?(/[a-zA-Z0-9\\W\\.\\-~!@#$%^&*+?:_/=<>()]*)?)"
var available_urls = ["http://foo.com/blah_blah",
"http://foo.com/blah_blah/",
@JustLoveBen
JustLoveBen / gist:b32e08cab81e3473de5302f249dedb4f
Created April 14, 2016 12:23 — forked from iwasrobbed/gist:5528897
UICollectionView w/ NSFetchedResultsController & NSBlockOperation. Idea originated from Blake Watters (https://github.com/AshFurrow/UICollectionView-NSFetchedResultsController/issues/13)
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller
{
self.shouldReloadCollectionView = NO;
self.blockOperation = [[NSBlockOperation alloc] init];
}
- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id<NSFetchedResultsSectionInfo>)sectionInfo
atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type
{
__weak UICollectionView *collectionView = self.collectionView;