Rust has many postfix combinators, for example the
.unwrap_or(x)
and .unwrap_or_else(|| x)
functions.
They are useful if you want to extract some value from
an optionally present value, or if not, provide an
alternative value. It's really nice and tidy to read:
This file contains hidden or 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
''' | |
1. Open src.c in lang shift lib and add this function right next to the 'lang_activate' function | |
######################################## | |
void lang_toggle(int externalLang) { | |
if (lang_current == lang_should_be && timer_read() - lang_timer >= 200) { | |
if (externalLang == 0){ | |
layer_off(2); | |
} else if (externalLang == 1){ | |
layer_on(2); |
This file contains hidden or 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
fn cut_repeating_prefix(source: &str) -> Option<(char, usize, &str)> { | |
let mut chars = source.char_indices(); | |
let first = chars.next()?.1; | |
let len = chars | |
.find_map(|(i, ch)| if ch != first { Some(i) } else { None }) | |
.unwrap_or(source.len()); | |
let count = len / first.len_utf8(); | |
let (_pre, post) = source.split_at(len); | |
Some((first, count, post)) | |
} |
This file contains hidden or 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
#include <ApplicationServices/ApplicationServices.h> | |
#include <iostream> | |
#include <string> | |
///print out location in a nice way to std cout | |
void fancyPrintLocation(CGPoint location); | |
/// This callback will be invoked every time the mouse moves. | |
CGEventRef myCGEventCallback(CGEventTapProxy proxy, CGEventType type, | |
CGEventRef event, void *refcon) |
This file contains hidden or 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
// Code from: http://patshaughnessy.net/2020/1/20/downloading-100000-files-using-async-rust | |
// | |
// Cargo.toml: | |
// [dependencies] | |
// tokio = { version = "0.2", features = ["full"] } | |
// reqwest = { version = "0.10", features = ["json"] } | |
// futures = "0.3" | |
use std::io::prelude::*; | |
use std::fs::File; |
This file contains hidden or 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
// | |
// if_value.h | |
// Brandon Azad | |
// | |
// Public domain | |
// | |
#ifndef IF_VALUE | |
/* |
This file contains hidden or 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
#include <random> | |
double random(void) { | |
static std::mt19937 generator(time(0)); | |
static std::uniform_real_distribution<double> distribution(0, 1); | |
return distribution(generator); | |
} |
This file contains hidden or 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 python3 | |
import http.server | |
import socketserver | |
PORT = 8000 | |
Handler = http.server.SimpleHTTPRequestHandler | |
Handler.extensions_map.update({ | |
'.wasm': 'application/wasm', |
This file contains hidden or 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
import http.server | |
import socketserver | |
from http import HTTPStatus | |
class Handler(http.server.SimpleHTTPRequestHandler): | |
def do_GET(self): | |
self.send_response(HTTPStatus.OK) | |
self.end_headers() | |
self.wfile.write(b'Hello world') |
This file contains hidden or 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
# Build neural network | |
net = tflearn.input_data(shape=[None, 5]) | |
net = tflearn.fully_connected(net, 32) | |
net = tflearn.fully_connected(net, 32) | |
net = tflearn.fully_connected(net, 2, activation='softmax') | |
net = tflearn.regression(net) | |
# Define model and setup tensorboard | |
model = tflearn.DNN(net, tensorboard_dir='tflearn_logs') | |
# Start training (apply gradient descent algorithm) |
NewerOlder