Skip to content

Instantly share code, notes, and snippets.

@matklad
matklad / result_iterator.rs
Last active November 13, 2017 15:48
Extension traits to work with Rust Iterators of Results conveniently
use result_iterator::ResultIterator;
use std::fs::{self, DirEntry};
use std::io;
use std::path::Path;
fn file_names(path: &Path) -> Result<Vec<String>, io::Error> {
let result = fs::read_dir(path)?
.map_then(|entry| {
let is_file = entry.file_type()?.is_file();
@am4dr
am4dr / javafx_screen-capture_with_awt-robot.groovy
Last active July 1, 2019 23:13
JavaFX screen capture sample (with java.awt.Robot)
/**
* JavaFX Screen Capture with java.awt.Robot
* run: groovy javafx_screen-capture_with_awt-robot.groovy
*/
import javafx.application.Application
import javafx.application.Platform
import javafx.embed.swing.SwingFXUtils
import javafx.geometry.Insets
import javafx.scene.Parent
import javafx.scene.Scene
@bvssvni
bvssvni / main.rs
Created January 15, 2017 19:31
LLVM takes a long time to optimize this
extern crate piston_meta;
extern crate range;
extern crate dyon;
use std::sync::Arc;
use self::piston_meta::MetaData;
use self::range::Range;
use self::dyon::{error, load_meta, Module, Runtime};
fn main() {
@hcl337
hcl337 / MovePhotosToDirectoriesYearMonth.py
Last active November 11, 2017 19:10
Here is a simple script to organize pictures by year and month updating their metadata for creation date to be on the modified date if it is incorrect. I used it to organize the 29,000 images I exported from iPhoto to use in Lightroom. Wrote it in a few minutes so no warranty... :-)
import os
import sys
import time, json, datetime
import ntpath
import subprocess
maxFiles = 100000000
@mmstick
mmstick / mimetypes.rs
Last active November 13, 2017 15:42
Rust Mime Types Detection (Videos)
use std::fs;
use std::io::Read;
/// Obtains a list of video extensions from the `/etc/mime.types` file on Linux.
pub fn get_video_extensions() -> Result<Vec<String>, &'static str> {
fs::File::open("/etc/mime.types").ok()
// Return an error if /etc/mime.types could not be found.
.map_or(Err("tv-renamer: unable to open /etc/mime.types"), |mut file| {
// Create a buffer with the capacity of the file
let mut contents = String::with_capacity(file.metadata().map(|x| x.len()).unwrap_or(0) as usize);
@psychoss
psychoss / file-dealer.rs
Last active November 13, 2017 15:52
Something about deal with file system with Rust
use std::thread;
use std::fs::{self, DirEntry};
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex};
use std::io;
macro_rules! or_return {
($expr:expr) => (match $expr {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) =>{
@JIghtuse
JIghtuse / model.rs
Last active August 7, 2018 20:35
Rust' Path usage example
use std::path::{Path, PathBuf};
struct Model {
u: f32,
}
fn texture_fname(path: &Path) -> PathBuf {
let fullname = format!("{}{}", path.file_stem().unwrap().to_str().unwrap(), "_diffuse");
let mut buf = PathBuf::from(path);
@davidhooey
davidhooey / oracle_blocker_blocked_sessions.sql
Last active July 21, 2020 17:24
Oracle blocker and blocked session information.
select
-- Session causing the block
blockers.blocker_instance_id as blocker_instance_id,
blocker.sid as blocker_sid,
blocker.serial# as blocker_serial#,
blocker.username as blocker_username,
blocker.status as blocker_status,
blocker.machine as blocker_machine,
blocker.program as blocker_program,
blocker.sql_id as blocker_sql_id,
@edumelzer
edumelzer / ExemploActionsController.groovy
Last active November 11, 2017 19:07
Actions declaration SwingBuilder / Griffon
package org.example
import griffon.core.artifact.GriffonController
import griffon.metadata.ArtifactProviderFor
@ArtifactProviderFor(GriffonController)
class ExemploActionsController {
ExemploActionsModel model
void somarAction() {
#![feature(globs)]
#![feature(if_let)]
extern crate piston;
extern crate gfx;
mod snakeapp;
mod object;
mod settings;
mod text;