Skip to content

Instantly share code, notes, and snippets.

View squiidz's full-sized avatar

JChaput squiidz

  • Joliette
View GitHub Profile
@squiidz
squiidz / playground.rs
Created January 24, 2017 17:33 — forked from anonymous/playground.rs
Shared via Rust Playground
trait Entity {
fn walk(&self) -> String;
}
struct Dog {
name: String,
age: i32
}
impl Dog {
@squiidz
squiidz / playground.rs
Created January 27, 2017 19:52 — forked from anonymous/playground.rs
Shared via Rust Playground
fn main() {
let text = "ありがとうございます";
let words = text.split("").map(|w| w.as_bytes()).collect::<Vec<&[u8]>>();
let length = words.iter().fold(0, |acc, val| acc + val.len());
println!("Input Text: {}", text);
println!("Bytes: {:?}", words);
println!("Text is {} bytes long", length);
let mut inline_bits = String::new();
@squiidz
squiidz / playground.rs
Created March 6, 2017 18:51 — forked from anonymous/playground.rs
Shared via Rust Playground
#[derive(Debug, PartialEq, Eq, Clone)]
struct Node<T: Clone> {
name: String,
value: T,
next: Option<Box<Node<T>>>
}
impl<T: PartialEq + Clone> Node<T> {
fn new(name: &str, value: T) -> Self {
Node {
@squiidz
squiidz / playground.rs
Created March 9, 2017 19:52 — forked from anonymous/playground.rs
Shared via Rust Playground
use std::io::{self, Read, Write};
struct StringRW {
value: String,
buffer: Vec<u8>,
}
impl StringRW {
fn new(value: &str) -> Self {
StringRW {
@squiidz
squiidz / armstrong_numbers.rb
Last active March 25, 2017 22:00
armstrong numbers in ruby
# num = 1234
# num_length = Math.log(num, 10).ceil => 4
# base = 10 ** (num_length - 1) => 1000
def is_armstrong(num)
if (1..9).include?(num)
return true
elsif num == 10
return false
end
@squiidz
squiidz / narci.cc
Created March 27, 2017 13:20
narcissistic numbers
#include <vector>
#include <math.h>
namespace number {
bool is_narci(int num) {
int num_cp = num;
int num_length = num == 1 ? 1 : ceil(log10(num));
int length = num_length;
int acc = 0;
@squiidz
squiidz / balanced.rs
Last active April 18, 2017 03:43
balanced symbols
#[macro_use]
extern crate lazy_static;
use std::collections::HashMap;
lazy_static!(
static ref MAPPING: HashMap<char, char> = [('}', '{'), (')', '('), (']', '[')]
.iter()
.cloned()
.collect();
);
@squiidz
squiidz / main.c
Last active August 23, 2017 21:20
Clang double pointer linked list
#include "stdio.h"
#include "stdlib.h"
typedef struct _node {
int value;
struct _node *next;
} node;
// Create a new node with the provided value
node *new_node(int _value) {
@squiidz
squiidz / btree.c
Last active January 31, 2023 15:22
Btree implementation in C
#include "stdio.h"
#include "stdlib.h"
#define M 3
typedef struct _node {
int n; /* n < M No. of keys in node will always less than order of B tree */
int keys[M - 1]; /*array of keys*/
struct _node *p[M]; /* (n+1 pointers will be in use) */
} node;
@squiidz
squiidz / doubleLinkedList.cpp
Last active August 29, 2017 22:13
Virtual Double Linked List C++
#include <iostream>
#include "node.h"
#include "nodeValue.h"
using namespace std;
struct animal: public nodeValue {
int age;