Skip to content

Instantly share code, notes, and snippets.

View chuchuva's full-sized avatar

Pavel Chuchuva chuchuva

View GitHub Profile
@chuchuva
chuchuva / multiply.cs
Created August 22, 2024 23:53
How to multiply all values in SVG path by 10
Regex.Replace("M87.3,41.08v26.68c0,9.08-7.41C79.89,24.61,87.3,32,87.3,41.08z", "([0-9\\.]{0,})", (m) =>
{
decimal i;
if (decimal.TryParse(m.Value, out i))
{
return (i*10).ToString("0.##");
}
return m.Value;
}, RegexOptions.None)
@chuchuva
chuchuva / .env.sample
Last active June 24, 2024 01:40
Import Mixpanel events to Google BigQuery
MIXPANEL_AUTH=my.mp-service-account:MYTOKEN
@chuchuva
chuchuva / filter.jq
Created June 22, 2024 22:46
jq query to move Mixpanel properties up one level
({event:.event} + (.properties | with_entries(.key |= gsub("\\$"; ""))))
| .time |= .-36000 | select(.time>=($day|tonumber) and .time<($day|tonumber+86400))
| .time |= todateiso8601
#!/usr/bin/env node
const path = require('path');
const fs = require('fs');
let iconList = [];
function fromDir(startPath, filter, callback) {
if (!fs.existsSync(startPath)) {
console.warn(`Not a valid directory: ${startPath}`);
@chuchuva
chuchuva / convert.ps1
Created November 13, 2023 23:50
Convert JSON files to CSV using PowerShell
Set-Content ".\subscriptions.csv" -Value $null
#$subscriptions = [System.Collections.ArrayList]@()
Get-ChildItem ".\" -Filter *.json |
Foreach-Object {
$myJson = Get-Content $_.FullName -Raw | ConvertFrom-Json
foreach ($subscription in $myJson.data.subscriptions) {
"$($subscription.id),$($subscription.subscriber.email_address)" | Add-Content ".\subscriptions.csv"
}
}
@chuchuva
chuchuva / stripe.rb
Created November 8, 2023 21:37
How to test Stripe webhook from Postman
# instead of event = Stripe::Webhook.construct_event(payload, signature, ENDPOINT_SECRET)
data = JSON.parse(payload, symbolize_names: true)
event = Stripe::Event.construct_from(data)
@chuchuva
chuchuva / test.js
Created May 3, 2023 01:49
How to format XML string in JavaScript
function formatXML(xml, tab = ' ', nl = '\n') {
let formatted = '', indent = '';
const nodes = xml.slice(1, -1).split(/>\s*</);
if (nodes[0][0] == '?') formatted += '<' + nodes.shift() + '>' + nl;
for (let i = 0; i < nodes.length; i++) {
const node = nodes[i];
if (node[0] == '/') indent = indent.slice(tab.length); // decrease indent
formatted += indent + '<' + node + '>' + nl;
if (node[0] != '/' && node[node.length - 1] != '/' && node.indexOf('</') == -1) indent += tab; // increase indent
}
@chuchuva
chuchuva / melbourne_suburbs.txt
Last active March 21, 2023 00:10
List of Melbourne Suburbs
Abbotsford
Aberfeldie
Aintree
Airport West
Albanvale
Albert Park
Albion
Alphington
Altona
Altona Meadows
@chuchuva
chuchuva / walk.rb
Created May 8, 2021 23:25
How to import walks from JSON file
class Walk < ApplicationRecord
has_many :photos
def self.import
file = File.read('./walks-in-victoria.json')
walks = JSON.parse(file)
walks.each do |w|
walk = Walk.create(title: w['title'], grade: w['grade'],
grade_note: w['gradeNote'], encoded_line: w['encodedLine'])
w['images'].each do |image_url|
@chuchuva
chuchuva / ExtractLolCats.cs
Last active August 16, 2019 01:29
HtmlExtractor lolcats
using HtmlAgilityPack;
using Newtonsoft.Json.Linq;
using System.IO;
using System.Linq;
namespace HtmlExtractor
{
class Program
{
static void Main(string[] args)