Skip to content

Instantly share code, notes, and snippets.

View anka's full-sized avatar

Andreas anka

View GitHub Profile
@anka
anka / MainActivity.kt
Created November 27, 2019 15:51
Android main activity implementing a Flutter method channel for file sharing
class MainActivity : FlutterActivity() {
private val SHARE_CHANNEL = "jademind.com/share"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
GeneratedPluginRegistrant.registerWith(this)
MethodChannel(flutterView, SHARE_CHANNEL).setMethodCallHandler { call, result ->
if (call.method.equals("share-file")) {
val argsMap = call.arguments as HashMap<String, String>
@anka
anka / AppDelegate.swift
Created November 27, 2019 15:55
iOS app delegate implementing a Flutter method channel for file sharing
@objc class AppDelegate: FlutterAppDelegate {
override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Receive the share method channel
let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
let shareChannel = FlutterMethodChannel(name: "jademind.com/share", binaryMessenger: controller.binaryMessenger)
// Register a callback handler
shareChannel.setMethodCallHandler({
(call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
@anka
anka / AppDelegatePart.swift
Created November 27, 2019 15:57
iOS share method for sharing a file through Flutter's platform channel using UIActivityViewController
func shareFile(arguments:Any?) -> Void {
let argsMap = arguments as! NSDictionary
let subject = argsMap.value(forKey: "subject") as? String
let filepath = argsMap.value(forKey: "filepath") as? String
let x = argsMap.value(forKey: "x") as? NSNumber
let y = argsMap.value(forKey: "y") as? NSNumber
let width = argsMap.value(forKey: "width") as? NSNumber
let height = argsMap.value(forKey: "height") as? NSNumber
@anka
anka / share.dart
Created November 27, 2019 16:02
Dart class implementation to share files with platform-specific code using a MethodChannel
/// The Share class provides capabilities to share
/// content with platform-specific sharing dialogs
/// using a method channel.
class Share {
static const MethodChannel _channel = const MethodChannel('jademind.com/share');
/// Share a file with other apps.
///
/// Pass a [rect] to indicate the position a share
/// action was initiated from.
@anka
anka / .gitlab-ci.yml
Created April 12, 2019 13:10
GitLab CI configuration to lint and build Docker images and push them to AWS ECR
stages:
- Lint images
- Build and publish images
## Load a node.js image, install dockerlint and lint all Dockerfiles
linting:
stage: Lint images
image: node:4-alpine
script:
- npm install -g dockerlint && npm cache clean
@anka
anka / schedule.rb
Last active July 15, 2021 07:42
Example schedule.rb to use flock as a background job mutex
# frozen_string_literal: true
require 'digest'
# The command pattern to use. Note that placeholders like :path
# :task and :output will be replaced by whenever.
RAKE_COMMAND = 'cd :path && bundle exec rails :task --silent :output'
# Helper method for uniq file locks
def wrap_with_lock(prefix, command)
@anka
anka / custom.js
Created June 1, 2022 08:52
Hubspot custom workflow function to send transactional email with custom data
const hubspot = require('@hubspot/api-client');
exports.main = async (event, callback) => {
// initialize the hubspot api client with your api secret
const hubspotClient = new hubspot.Client({
apiKey: process.env.API_KEY
});
// the ID of the email template
const EMAIL_TEMPLATE_ID = 82546305923;
@anka
anka / currency_input.rb
Created June 18, 2022 19:35
Custom currency input using SimpleForm
class CurrencyInput < SimpleForm::Inputs::StringInput
def input(wrapper_options)
input_options = input_html_options.merge({data: {autonumeric: true}})
merged_input_options = merge_wrapper_options(input_options, wrapper_options)
template.content_tag(:div, class: 'input-group') do
template.concat span_currency_sign
template.concat @builder.text_field(attribute_name, merged_input_options)
end
end
@anka
anka / azure-py-func-setup.sh
Last active August 2, 2022 07:49
Workaround for running a Python Azure Function locally on an M1
# Install Python
brew install python@3.9
# Install NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
# Update/check your source files (.zshrc, .bashrc, etc.)
export PATH="~/.nvm/current/bin:$PATH"
# Install specific Node version
@anka
anka / slack-files-download.py
Created June 29, 2022 15:25
Downloads all files of messages of your Slack (workspace) JSON export.
#!/usr/bin/python
import argparse
import json
import os
import sys
from typing import List, Optional
from urllib.request import urlopen
"""Downloads all files of messages of your Slack (workspace) JSON export. Each channel