Skip to content

Instantly share code, notes, and snippets.

View csotiriou's full-sized avatar

Christos Sotiriou csotiriou

View GitHub Profile
@csotiriou
csotiriou / ovhcloud.file-provider.js
Last active July 19, 2021 00:33
Upload file provider for Strapi - OVH with OpenStack. Article https://oramind.com/develop-strapi-upload-provider/
const pkgcloud = require('pkgcloud');
const streamifier = require('streamifier');
module.exports = {
init(providerOptions) {
const client = pkgcloud.storage.createClient(providerOptions);
const options = { container: providerOptions.defaultContainerName }
const remoteURL = () =>
@csotiriou
csotiriou / axios_download_node10+.ts
Created May 27, 2020 08:28
Proper way of downloading a large file using NodeJS and Axios (NodeJS 10+)
import * as stream from 'stream';
import { promisify } from 'util';
const finished = promisify(stream.finished);
export async function downloadFile(fileUrl: string, outputLocationPath: string): Promise<any> {
const writer = createWriteStream(outputLocationPath);
return Axios({
method: 'get',
url: fileUrl,
responseType: 'stream',
}).then(async response => {
@csotiriou
csotiriou / axios_download_node8.ts
Last active February 20, 2023 08:09
Proper way of downloading a large file using NodeJS and Axios (NodeJS 8 and earlier)
export async function downloadFile(fileUrl: string, outputLocationPath: string) {
const writer = createWriteStream(outputLocationPath);
return Axios({
method: 'get',
url: fileUrl,
responseType: 'stream',
}).then(response => {
//ensure that the user can call `then()` only when the file has
//been downloaded entirely.
@csotiriou
csotiriou / lbl_rxjs.java
Created May 21, 2020 06:55
Sample RxJava large file process line-by-line
/**
* Opens a file at a specified URL and returns a Flowable ready to emit
* its contents line by line.
*
* @param filepath the file path to open
* @return a stream ready to be consumed. Its output will be a file line on each emission.
*/
public Flowable<String> openFileAsStream(String filepath) {
return Flowable.using(
() -> new BufferedReader(new FileReader(filepath)),
@csotiriou
csotiriou / largefile_read_backpressure.ts
Created May 21, 2020 06:51
Reading a file with backpressure using NodeJS
type PromiseThunk = (lineBatch: string[]) => Promise<any>;
/**
*
* @param filePath the file to open
* @param promiseThunk A function that returns a promise. This function will be called with the current batch lines as the arcument.
* @param bufferSize how many lines should we process at a time
*/
export async function streamFile2(filePath: string, promiseThunk: PromiseThunk, bufferSize: number = 100) {
return new Promise<unknown>((resolve, reject) => {
//create the NodeJS read stream
@csotiriou
csotiriou / MainAppComponent.js
Last active November 27, 2016 10:15
Example React Native Navigator using NavigatorExperimental
class MyApp extends Component {
constructor(props) {
super(props);
this.state = {
// This defines the initial navigation state.
navigationState: {
index: 0, // starts with first route focused.
routes: [{key: 'LaunchScreen'}], // starts with only one route.
}
@csotiriou
csotiriou / upsert.js
Last active August 27, 2016 18:18 — forked from plurch/upsert.js
PostgreSQL 9.5 Upsert using Knex.js
exports.knex = require('knex')({
client: 'pg',
connection: {
host : '127.0.0.1',
user : 'your_database_user',
password : 'your_database_password',
database : 'myapp_test'
}
});
@csotiriou
csotiriou / recosamplecode.mm
Last active September 26, 2015 17:04
Vuforia cloud reco sample OnQCarUpdate
// Initialize the application trackers
- (BOOL) doInitTrackers {
// // Initialize the image or marker tracker
QCAR::TrackerManager& trackerManager = QCAR::TrackerManager::getInstance();
//
// // Image Tracker...
QCAR::Tracker* trackerBase = trackerManager.initTracker(QCAR::ObjectTracker::getClassType());
if (trackerBase == NULL)
{