Skip to content

Instantly share code, notes, and snippets.

@giuliano-macedo
giuliano-macedo / download_file.rs
Last active January 25, 2024 08:52
Download large files in rust with progress bar using reqwest, future_util and indicatif
// you need this in your cargo.toml
// reqwest = { version = "0.11.3", features = ["stream"] }
// futures-util = "0.3.14"
// indicatif = "0.15.0"
use std::cmp::min;
use std::fs::File;
use std::io::Write;
use reqwest::Client;
use indicatif::{ProgressBar, ProgressStyle};
use std::task::{Context, Poll};
use futures_util::future::{ok, FutureExt, LocalBoxFuture, Ready};
use actix_web::{
body::{Body, ResponseBody},
dev::{Service, ServiceRequest, ServiceResponse, Transform},
error::{Error, Result},
};
use serde_json::json;
@jianwu
jianwu / mshell
Last active October 27, 2021 12:50
mshell: to run jshell for a maven project with all the dependancies injected.
# Run this script from the maven module directory to start a jshell with
# all dependent class paths injected.
# Please never run it on the parent maven project directory.
# It depends on java9 or above
if [ ! -d "target" ]; then
echo "Please run it under a module directory. And make sure it's not parent module directory. And make a maven install first"
exit
fi
@tkh44
tkh44 / Animation.jsx
Last active September 13, 2022 01:31
react-router v4 animated with data-driven-motion
import React from 'react'
import { BrowserRouter as Router, Route, Link, Redirect, matchPath } from 'react-router-dom'
import { Motion } from 'data-driven-motion' // https://github.com/tkh44/data-driven-motion
const WOBBLY_SPRING = { stiffness: 200, damping: 15, precision: 0.1 }
const AnimationExample = () => (
<Router>
<div>
<ul>
@johndoe46
johndoe46 / hierarchical_data.sql
Last active May 18, 2018 20:49
Closure Table method for hierarchical data with PostGreSQL
DROP TABLE IF EXISTS page CASCADE;
CREATE TABLE IF NOT EXISTS page
(
id serial NOT NULL PRIMARY KEY,
title character(64) NOT NULL,
parent_id integer REFERENCES page
);
DROP TABLE IF EXISTS page_hierarchy;
CREATE TABLE IF NOT EXISTS page_hierarchy(
defmodule Sheetly.Schema.Types do
@moduledoc """
Types used by GraphQL endpoint
"""
import Canada, only: [can?: 2]
use Absinthe.Schema.Notation
use Absinthe.Relay.Schema.Notation
alias Ecto.{Date, DateTime}
alias Sheetly.{
ContractResolver,
defmodule Sheetly.Schema do
@moduledoc """
GraphQL schema
"""
use Absinthe.Schema
use Absinthe.Relay.Schema
import_types Sheetly.Schema.Types
alias Sheetly.{
ProjectMembershipResolver,
AuthenticationResolver,
@ahmadshah
ahmadshah / README.md
Last active January 6, 2021 15:21
Ecto Soft Delete

Soft Delete Ecto Repo

The goal is to support soft delete functionality in Ecto.Repo. With the suggestion by @imranismail, another repo is created and the remaining functionalities are delegate to the original MyApp.Repo.

The new repo get/2 and all/1 functions will exclude the soft deleted record by default. delete/1 and delete_all/1 will update the delete_at column by default instead of deleting.

Example

MyApp.Repo.get(MyApp.User, 1) //will return nil if record is in soft delete state
@miguelcma
miguelcma / DeviceUID.m
Created May 25, 2015 15:09
iOS Unique Device ID that persists between app reinstalls
/* DeviceUID.h
#import <Foundation/Foundation.h>
@interface DeviceUID : NSObject
+ (NSString *)uid;
@end
*/
// Device.m
@mremond
mremond / README
Last active May 4, 2020 16:57
Phoenix Elixir framework with ejabberd - Tutorial
Please read original blog post for reference:
http://blog.process-one.net/embedding-ejabberd-into-an-elixir-phoenix-web-application/