This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A demonstration of the SQLite `database is locked` error, and its fix. | |
# For more detail see | |
# | |
# to see the error, run: | |
# `python lock.py` | |
# | |
# and to see the fix, run: | |
# `python lock.py correct` | |
import logging |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use sqlx::sqlite::SqliteQueryResult; | |
use sqlx::{Executor, SqliteConnection}; | |
use std::future::Future; | |
use std::ops::{Deref, DerefMut}; | |
pub(crate) trait SqliteConnectionExt { | |
fn begin_immediate(&mut self) -> impl Future<Output = sqlx::Result<Transaction>>; | |
} | |
impl SqliteConnectionExt for SqliteConnection { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env awk | |
BEGIN { | |
print "principal", "interest_rate", "term", "monthly_payment", "total_paid", "interest_paid" | |
} | |
NR == 1 && NF == 0 { | |
print "use:" | |
print "\tawk -f amortize" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE f (id integer primary key, value text, inserted_at default current_timestamp); | |
INSERT INTO f VALUES(1,'{"a":1}','2022-05-16 04:24:48'); | |
INSERT INTO f VALUES(2,'{"a":2}','2022-05-16 04:25:11'); | |
INSERT INTO f VALUES(3,'{"a":2, "b":3}','2022-05-16 04:25:15'); | |
INSERT INTO f VALUES(4,'{"a":2, "b":99}','2022-05-16 04:25:18'); | |
INSERT INTO f VALUES(5,'{"a":3}','2022-05-16 04:25:32'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
g = :digraph.new() | |
v1 = :digraph.add_vertex(g, "v1") | |
v2 = :digraph.add_vertex(g, "v2") | |
v3 = :digraph.add_vertex(g, "v3") | |
v4 = :digraph.add_vertex(g, "v4") | |
:digraph.add_edge(g, v2, v1) | |
:digraph.add_edge(g, v3, v2) | |
:digraph.add_edge(g, v4, v2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Debug, PartialEq, PartialOrd, Eq, Ord)] | |
pub enum Bencode<'a> { | |
String(&'a [u8]), | |
Integer(isize), | |
List(Vec<Bencode<'a>>), | |
Dictionary(BTreeMap<&'a [u8], Bencode<'a>>), | |
} | |
#[macro_export] | |
macro_rules! get_in { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env elixir | |
Mix.install(httpoison: "~> 1.0", floki: "~> 0.30") | |
%_{body: body} = HTTPoison.get!("https://fastradius.com", [], follow_redirect: true) | |
body | |
|> Floki.parse_document!() | |
|> Floki.find("a") | |
|> Floki.attribute("href") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn primes<const N: usize>() -> Vec<usize> { | |
let primes_array = sieve_of_eratosthenes::<N>(); | |
std::array::IntoIter::new(primes_array) | |
.enumerate() | |
.filter_map(|(i, is_prime)| if is_prime { Some(i + 2) } else { None }) | |
.collect() | |
} | |
pub const fn sieve_of_eratosthenes<const N: usize>() -> [bool; N] { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
regex_str = "[a-z]+\\s+\\d+" | |
small_hit_str = "abc 123 def 456" | |
big_hit_str = Enum.reduce(1..1000, "", fn _val, acc -> | |
"#{acc}#{small_hit_str}" | |
end) | |
small_miss_str = "abc abc abc abc" | |
big_miss_str = Enum.reduce(1..1000, "", fn _val, acc -> | |
"#{acc}#{small_miss_str}" | |
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
last_n=$1 | |
commits=$(git log -n "$last_n" | awk '$1 == "commit" { print $2 }') | |
for commit in $commits | |
do | |
git checkout "$commit" >/dev/null 2>&1 |
NewerOlder