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 main() { | |
give(); | |
} | |
fn give(){ | |
let mut vec = Vec::new(); | |
vec.push(1); | |
vec.push(2); | |
take(vec); | |
vec.push(3); |
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
#[allow(dead_code)] | |
fn encrypt(plaintext: &str, key: usize){ | |
let plaintext = &plaintext.to_uppercase(); | |
let alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
let mut cipher = String::from(""); | |
for each_char in plaintext.chars(){ | |
match alphabet.find(each_char) { | |
Some(index) => { | |
let char_index = (index + key) % 26; | |
let char_place = alphabet.chars().nth(char_index).unwrap(); |
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
use std::time::Duration; | |
use std::sync::Arc; | |
use std::sync::atomic::{AtomicBool, Ordering}; | |
use std::thread; | |
fn main() { | |
// Play with this flag | |
let fatal_flag = true; | |
let do_stop = true; |
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
#[warn(unused_variables)] | |
#[warn(unused_must_use)] | |
use std::thread; | |
fn main(){ | |
let mut c = vec![]; | |
for i in 0..10{ | |
c.push(thread::spawn(move || { | |
println!("thread number {}", i); |
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 React from 'react' | |
import { Link } from 'react-router' | |
import getRouteHandlerBaseUrl from 'js/helpers/get-route-handler-base-url' | |
class Something extends React.Component { | |
componentWillMount() { | |
this._baseUrl = getRouteHandlerBaseUrl(this.props) | |
} |
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
use std::sync::{Arc, Mutex, Condvar}; | |
use std::thread; | |
struct Producer { | |
cvar: Arc<(Mutex<bool>, Condvar)> | |
} | |
impl Producer { | |
pub fn new(cvar: Arc<(Mutex<bool>, Condvar)>) -> Producer { | |
Producer { |
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
def find(key, dictionary): | |
for k, v in dictionary.iteritems(): | |
if k == key: | |
yield v | |
elif isinstance(v, dict): | |
for result in find(key, v): | |
yield result | |
elif isinstance(v, list): | |
for d in v: | |
for result in find(key, d): |
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
let a = "29"; | |
for c in a.chars() { | |
println!("{}", c as u32 - 48); | |
} | |
let mut sum = 0; | |
let x = 14183; | |
let x = x.to_string(); | |
for y in x.chars() { | |
// converting `y` to string and then to integer |
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 sys, ldap | |
# DN = [email protected], secret = password, un = username | |
DN, secret, un = sys.argv[1:4] | |
server = "ldap://server.com" | |
port = 389 | |
base = "dc=example,dc=com" | |
scope = ldap.SCOPE_SUBTREE |
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
use std::fmt; | |
pub struct JoinMyVec { | |
myvec : Vec<u32>, | |
} | |
impl fmt::Display for JoinMyVec { | |
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | |
let s = fmt.write_str(&join(&self.myvec[..], &""))?; | |
Ok(s) |