Skip to content

Instantly share code, notes, and snippets.

@akhikhl
akhikhl / physical_ball_2d_graphics.groovy
Created December 31, 2013 16:53
2d graphics simulation of a ball in gravity field. Energy conservation law is respected.
import javax.swing.*;
import java.awt.Color;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
public class Ball extends JComponent {
@bvssvni
bvssvni / gist:9343353
Last active November 11, 2017 19:32
How To Organize Code in Rust per Object or Function
//! rustc 0.10-pre (ee8f45e 2014-02-18 13:41:49 -0800)
//!
//! Before you bite my head off, this is NOT a recommend way of organizing code!
//! It is only a demonstration what you can do in Rust! (wish I put this comment in earlier)
//! My intention with this example is to show new people the features of the module system.
//!
//! The module system in Rust gives you precise control
//! over the interface when writing libraries.
//! You can write the layout independent of how you organize the code!
//! In this example two different conventions are explored.
use std::sync::arc::UnsafeArc;
use std::cast;
use std::comm::Chan;
pub struct ArcRefCell<T> {
priv inner: UnsafeArc<T>
}
impl<T: Send> ArcRefCell<T> {
pub fn new(value: T) -> ArcRefCell<T> {
@davidhooey
davidhooey / oracle_tablespace_usage.sql
Created April 11, 2014 19:43
Oracle Tablespace Usage
select
d.tablespace_name tn,
d.block_size bs,
d.extent_management lm,
d.segment_space_management assm,
d.status st,
to_char(f.bytes/1024,'999,999,999')||'K' bts,
to_char((f.bytes-s.free_bytes)/1024,'999,999,999')||'K' used,
to_char(round((f.bytes-s.free_bytes)/f.bytes*100),'990.9')||'%' pct,
case trunc(33*(f.bytes-s.free_bytes)/f.bytes)
#![feature(globs)]
#![feature(if_let)]
extern crate piston;
extern crate gfx;
mod snakeapp;
mod object;
mod settings;
mod text;
@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() {
@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,
@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);
@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) =>{
@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);