Skip to content

Instantly share code, notes, and snippets.

View jamesmcm's full-sized avatar

James McMurray jamesmcm

View GitHub Profile
@jamesmcm
jamesmcm / Xorg.0.log
Created April 18, 2020 19:10
Xorg.0.log
[ 1090.825] (WW) Failed to open protocol names file lib/xorg/protocol.txt
[ 1090.826]
X.Org X Server 1.20.8
X Protocol Version 11, Revision 0
[ 1090.826] Build Operating System: Linux Alpine Linux
[ 1090.826] Current Operating System: Linux falco 3.4.113 #6-postmarketOS SMP PREEMPT Tue Nov 5 06:54:09 UTC 2019 armv7l
[ 1090.826] Kernel command line: androidboot.bootdevice=msm_sdcc.1 androidboot.hardware=qcom vmalloc=400M utags.blkdev=/dev/block/platform/msm_sdcc.1/by-name/utags buildvariant=userdebug androidboot.bootdevice=msm_sdcc.1 androidboot.hardware=qcom vmalloc=400M utags.blkdev=/dev/block/platform/msm_sdcc.1/by-name/utags buildvariant=userdebug androidboot.emmc=true androidboot.serialno=TA92903XW6 androidboot.baseband=msm androidboot.mode=normal androidboot.device=falcon androidboot.hwrev=0x83C0 androidboot.radio=0x1 androidboot.powerup_reason=0x00100000 bootreason=hardware_reset androidboot.write_protect=0 restart.download_mode=0 androidboot.fsg-id= androidboot.secure_hardware=1 androidboot.cid=0
@jamesmcm
jamesmcm / alien_dictionary.rs
Created April 14, 2020 19:40
alien_dictionary.rs
use std::mem::MaybeUninit;
impl Solution {
pub fn is_alien_sorted(words: Vec<String>, order: String) -> bool {
let order_arr = Solution::get_order_arr(order);
words
.as_slice()
.windows(2)
.map(|x| Solution::check_pair(x[0].as_bytes(), x[1].as_bytes(), &order_arr))
@jamesmcm
jamesmcm / SARIMAX_example.py
Created March 6, 2020 09:18
SARIMAX_example.py
model = SARIMAX(data1, exog=data2, order=(1, 1, 2), seasonal_order=(1, 1, 1, 52))
model_fit = model.fit(disp=False)
print(f"Global: {model_fit.summary()}")
for site in sites:
# make prediction
newdfinner = df_site.loc[df_site.site == site, :].fillna(0).reset_index(drop=True)
exog2 = newdfinner.loc[
newdfinner["start_week_dt"] >= last_sunday, ["exog1", "exog2"]
@jamesmcm
jamesmcm / split_with_matches.rs
Created February 23, 2020 11:33
split_with_matches.rs
fn split_with_matches<'a, F>(s: &'a str, f: F) -> Vec<&'a str>
where
F: Fn(char) -> bool,
{
let mut out: Vec<&'a str> = Vec::new();
let mut prevpos: usize = 0;
for (pos, c) in s.bytes().enumerate() {
if f(c as char) {
if prevpos != pos {
@jamesmcm
jamesmcm / networkns.sh
Created January 26, 2020 13:35
networkns.sh
# Running specific applications through a VPN with network namespaces
# Initial state
curl ifconfig.co/city
sudo ip link list
sudo ip netns list
# Disable Uncomplicated Firewall (Ubuntu)
sudo ufw disable
@jamesmcm
jamesmcm / binary_tree_bfs.rs
Created January 14, 2020 21:33
binary_tree_bfs.rs
// Definition for a binary tree node.
#[derive(Debug, PartialEq, Eq)]
pub struct TreeNode {
pub val: i32,
pub left: Option<Rc<RefCell<TreeNode>>>,
pub right: Option<Rc<RefCell<TreeNode>>>,
}
impl TreeNode {
#[inline]
@jamesmcm
jamesmcm / move_child.rs
Created December 6, 2019 00:41
move_child.rs
struct Node {
value: Symbol,
children: (Option<Box<Node>>, Option<Box<Node>>),
}
let movechild = ((&root).as_ref().unwrap().children).1;
(&mut root).as_mut().unwrap().children.1 = Some(Box::new(Node::new(symbol, (movechild, None))));
@jamesmcm
jamesmcm / split_with_matches_broken.rs
Created December 5, 2019 20:55
split_with_matches_broken.rs
fn split_with_matches<F>(s: &str, f: F) -> Vec<&str> where
F: Fn(char) -> bool {
let mut out: Vec<&str> = vec![];
let mut curstring: String = String::new();
for c in s.chars() {
if f(c) {
out.push(&curstring);
out.push(&c.to_string());
} else {
curstring.push(c);
@jamesmcm
jamesmcm / abstract_type.scala
Created November 15, 2019 21:31
abstract_type.scala
abstract class SpaceObject() {
type T <: SpaceObject
def ===(that: T): Boolean
}
class Sphere(val transform: Matrix, val material: Material) extends SpaceObject {
type T = Sphere
@jamesmcm
jamesmcm / scalaq.scala
Created October 12, 2019 17:54
scalaq.scala
def encodePair(pair: (Char, Char)): (Char, Char) = {
(findLetterInSquare(pair._1), findLetterInSquare(pair._2)) match {
case ((A, B), (A, D)) => (indexToLetter((A, (B+1)%5)), indexToLetter((A, (D+1)%5))) // same row
case ((A, B), (C, B)) => (indexToLetter(((A + 1)%5, B)), indexToLetter(((C+1)%5, B))) // same column
case ((A, B), (C, D)) => (indexToLetter((A, D)),indexToLetter((C, B)))
}
}