Skip to content

Instantly share code, notes, and snippets.

@kascote
kascote / schemes_registered.sh
Created May 23, 2024 15:53
Check urls schemes registered on MacOS
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -dump | grep -B3 "bindings:.*:"
@kascote
kascote / list_path.dart
Created February 17, 2024 22:01
simple array path traversal
/// Traverse the list by the given path.
/// ex: listPath<int>([1, 2, [3, 4]], '2.1') => 4
T? listPath<T>(Object list, String path) {
if (path.isEmpty) return null;
var result = list;
for (final part in path.split('.')) {
if (result is! List) return null;
final idx = int.tryParse(part);
if (idx == null || idx < 0 || result.length <= idx) return null;
#!/bin/bash
brew deps --installed --dot --graph | pbcopy
# And paste it in https://dreampuf.github.io/GraphvizOnline
# https://twitter.com/kevmoo/status/1612939071982297089
@kascote
kascote / json_sqlite.md
Last active May 22, 2022 22:03
SQlite JSON queries

JSON and virtual columns in SQLite

reference: https://antonz.org/json-virtual-columns/

select value from events;

{"timestamp":"2022-05-15T09:31:00Z","object":"user","object_id":11,"action":"login","details":{"ip":"192.168.0.1"}}
{"timestamp":"2022-05-15T09:32:00Z","object":"account","object_id":12,"action":"deposit","details":{"amount":"1000","currency":"USD"}}
{"timestamp":"2022-05-15T09:33:00Z","object":"company","object_id":13,"action":"edit","details":{"fields":["address","phone"]}}
@kascote
kascote / spinner.dart
Created July 11, 2019 16:45
flutter icon spinner
//
// https://stackoverflow.com/questions/55431496/font-awesome-spinners-icons-not-spinning-in-flutter
//
// Usage:
// Spinner(
// icon: FontAwesomeIcons.spinner,
// )
//
class Spinner extends StatefulWidget {
final IconData icon;
@kascote
kascote / blob_authenticatable.rb
Created September 4, 2018 15:53 — forked from dommmel/blob_authenticatable.rb
Devise authentication for Rails' ActiveStorage
# Rails controller concern to enable Devise authentication for ActiveStorage.
# Put it in +app/controllers/concerns/blob_authenticatable.rb+ and include it when overriding
# +ActiveStorage::BlobsController+ and +ActiveStorage::RepresentationsController+.
#
# Optional configuration:
#
# Set the model that includes devise's database_authenticatable.
# Defaults to Devise.default_scope which defaults to the first
# devise role declared in your routes (usually :user)
#
@kascote
kascote / uglifier.rb
Created December 7, 2017 21:31
Uglifiers don't return the filename with the error
JS_PATH = "app/assets/javascripts/**/*.js";
Dir[JS_PATH].each do |file_name|
puts "\n#{file_name}"
puts Uglifier.compile(File.read(file_name))
end
@kascote
kascote / msgbox.js
Created October 2, 2017 19:42
Replace Rails 5 alert dialog
promiseBasedConfirmPopup = new Promise((resolve) => {
// Show a nice popup and resolve to true/false
setTimeout(() => resolve(true), 2000)
})
$("a[data-confirm]").on("confirm", function(evt) {
// evt.target hold the clicked anchor from where
// can be extracted some data to build the popup
@kascote
kascote / dnsmasq
Last active July 22, 2017 22:39
add TLD to local dnsmask
# /etc/NetworkManager/dnsmasq.d/hosts.conf
address=/dev/127.0.0.1
address=/spk/192.168.1.98
address=/nfx/192.168.1.99
address=/spk2/192.168.1.97
@kascote
kascote / sql.sh
Created May 24, 2017 19:15
Parse Rails's database.yml and start psql
#!/bin/bash
parse_yaml() {
local prefix=$2
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
awk -F$fs '{
indent = length($1)/2;
vname[indent] = $2;