Skip to content

Instantly share code, notes, and snippets.

View leopard627's full-sized avatar

Leopard627 leopard627

  • South Korea
  • 21:01 (UTC +09:00)
View GitHub Profile
#[derive(Debug)]
struct Computer {
name: String,
serial: String,
cpu_cnt: u8,
ram_size: u64,
}
#[test]
fn build_computer_test() {
let computer = build_computer("apple".to_string(), "abcde-100".to_string());
let copy_cat = Computer{
name: "Capple".to_string(),
..computer
};
println!("{:?}", copy_cat);
}
#[test]
fn build_computer_test() {
let computer = build_computer("apple".to_string(), "abcde-100".to_string());
println!("name {}", computer.name);
println!("serial {}", computer.serial);
println!("cpu_cnt {}", computer.cpu_cnt);
println!("ram_size {}", computer.ram_size);
let copy_cat = Computer{
fn first_blank_finder(s: &String) -> Option<usize> {
let bytes = s.as_bytes();
for (i, &item) in bytes.iter().enumerate() {
if item == b' ' {
Some(i)
}
}
Some(0 as usize)
}
fn first_blank_finder(s: &String) -> Option<usize> {
let bytes = s.as_bytes();
for (i, &item) in bytes.iter().enumerate() {
if item == b' ' {
return Some(i)
}
}
Some(0 as usize)
}
@leopard627
leopard627 / search_foo.rs
Last active January 13, 2019 15:44
search worlds
fn search_foo(s: &String, word: &'static str) -> &'static str {
for (i, item) in s.chars().enumerate() {
if &s[i..i+3] == word {
return word
}
}
""
}
let mut s = String::from("hello world");
let r1 = &s;
let r2 = &s;
let r3 = &mut s;
r3.push_str("Possible?");
@leopard627
leopard627 / posts_thired.jsx
Created September 1, 2018 17:10
매우 허접하지만.... drf 에서 단순 post 가져오는 테이블이다.
import React, { Component } from "react";
import axios from "axios";
import { getPosts } from "../services/postService";
const apiEndpoint = "http://localhost:8000";
class Posts extends Component {
state = {
count: 0,
next: "",
@leopard627
leopard627 / posts_2.jsx
Created September 1, 2018 11:06
react post
import React, { Component } from "react";
import axios from "axios";
const apiEndpoint = "http://localhost:8000";
class Posts extends Component {
state = {
posts: []
};
@leopard627
leopard627 / posts.jsx
Last active September 1, 2018 10:06
react async fetch data from API
import React, { Component } from "react";
import axios from "axios";
class Posts extends Component {
state = {
posts: []
};
async componentDidMount() {
const response = await axios.get("http://localhost:8000/posts");