Skip to content

Instantly share code, notes, and snippets.

View choipd's full-sized avatar

choipd choipd

View GitHub Profile
export const bibleNumberOfVerseByChapter = [
[
31,
25,
24,
26,
32,
22,
24,
22,
@choipd
choipd / gist:587ce9823856c05d15e0a73c80a4d35d
Created February 10, 2020 04:38
cors in firebase functions
// httpHelper에 아래와 같이 정의하고
const corsRoutine = (req, res, func) => {
cors(req, res, () => {
func(req, res);
});
}
// functions 구현할 때 corsRoutine으로 감싸서 쓰고 있습니다.
'use strict'
// solution from https://stackoverflow.com/questions/49701000/how-to-do-unit-testing-in-react-native-that-uses-firebase
export class Database {
ref = (path) => {
if (!this[path]) {
this[path] = new Reference(path)
}
return this[path]
}
@choipd
choipd / rnfirebaseMock.js
Created August 7, 2018 07:02
react-native-firebase mock
jest.mock('react-native-firebase', () => {
return {
messaging: jest.fn(() => {
return {
hasPermission: jest.fn(() => Promise.resolve(true)),
subscribeToTopic: jest.fn(),
unsubscribeFromTopic: jest.fn(),
requestPermission: jest.fn(() => Promise.resolve(true)),
getToken: jest.fn(() => Promise.resolve('myMockToken'))
};
@choipd
choipd / update_batch.js
Created March 26, 2018 14:37
Firestore batch update
function updateCollection(db, collectionRef, newData, batchSize) {
// console.log('updateCollection')
var query = collectionRef.orderBy('__name__').limit(batchSize);
return new Promise(function(resolve, reject) {
updateQueryBatch(db, query, batchSize, newData, resolve, reject);
});
}
function updateQueryBatch(db, query, batchSize, newData, resolve, reject) {
shouldComponentUpdate(nextProps, nextState){
console.log("component should update")
if(nextProps.status === POST_STATUS.POST_STATUS_SAVED) {
this._closePost()
}
return true
}
const mapStateToProps = (state, props) => {
ESC ! n
[Name] Select print mode(s)
[Format]
ASCII ESC ! n
Hex 1B 21 n
Decimal 27 33 n
[Range] 0≤n≤255
[Description] Selects print mode(s) using n as follows:
@choipd
choipd / printer_helloworld_with_style.m
Created May 13, 2016 14:53
Write to ESC/POS protocol to BLE printer
- (IBAction)printHelloWorld:(id)sender {
NSString * str = @"Hello World\n\r";
NSString *command = @"1B2100";
NSMutableData *commandToSend= [[NSMutableData alloc] init];
unsigned char whole_byte;
char byte_chars[3] = {'\0','\0','\0'};
int i;
@choipd
choipd / ble_print_out.m
Last active May 13, 2016 14:45
Write something to BLE printer.
- (IBAction)printHelloWorld:(id)sender {
NSString * str = @"Hello World\n\r";
NSData* data = [str dataUsingEncoding:NSUTF8StringEncoding];
[self.printerPeripheral writeValue:data forCharacteristic:self.writeCharacteristic type:CBCharacteristicWriteWithoutResponse];
}
@choipd
choipd / unzip_cp949.rb
Created April 21, 2016 14:29
한글 CP949 압축된 파일 풀기
#!/usr/bin/ruby
require 'fileutils'
require 'zip'
def unzip
Zip::File.open(ARGV[0]) { |zipfile|
zipfile.each {|f|
# cp949 파일 이름을 utf-8로 변환
utf_string = f.name.force_encoding("CP949").encode("UTF-8", :invalid => :replace, :undef => :replace, :replace => "_") # for ruby1.9 or higher
FileUtils.mkdir_p(File.dirname(utf_string))