Skip to content

Instantly share code, notes, and snippets.

@yodalee
yodalee / randomgen.rs
Created Jun 23, 2020
Random number generator in Rust with stated structure
View randomgen.rs
use std::time::{SystemTime, UNIX_EPOCH};
const SEED_MAX:u64 = 9999997;
struct RandomGen {
seed: u64
}
impl RandomGen {
pub fn new(seed: u64) -> Self {
@yodalee
yodalee / fastfib.c
Created Feb 11, 2019
Fast Fibonacci and Fomula Solution
View fastfib.c
// file: fastfib.c
// compile with gcc -lgmp fastfib.c
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <math.h>
#include <gmp.h>
#include <ctype.h>
View fish-not-in-net.html
<div data-fte="1" data-ftr="1" class="_5jmm _5pat _3lb4 g_yvbt0g4s4" id="hyperfeed_story_id_5bba1b28a1f901a21693682" data-testid="fbfeed_story" data-cursor="MTUzODkyMzMwMjoxNTM4OTIzMzAyOjM6LTkzNzU4OTg3MzMxMTUzNDQzNTowOjY2MDk2MjUyNTQ5NDU2MjkxMTY=" data-dedupekey="-937589873311534435" data-timestamp="1538644175" aria-posinset="3" aria-setsize="12" data-referrer="hyperfeed_story_id_5bba1b28a1f901a21693682" role="article" aria-labelledby="js_si" aria-describedby="js_sj js_sk" data-insertion-position="2">
<div class="_4-u2 mbm _4mrt _5v3q _4-u8" id="u_jsonp_8_1">
<div class="_3ccb" data-ft="{&quot;tn&quot;:&quot;-R&quot;}" data-gt="{&quot;type&quot;:&quot;click2canvas&quot;,&quot;fbsource&quot;:703,&quot;ref&quot;:&quot;nf_generic&quot;}" id="u_jsonp_8_2">
<div></div>
<div></div>
<div class="_5pcr userContentWrapper" style="" data-ft="{&quot;tn&quot;:&quot;-R&quot;}">
<div class="_1dwg _1w_m _q7o">
<div class="_4r_y" id="u_jsonp_8_
@yodalee
yodalee / q1.cpp
Last active Mar 25, 2017
Some algorithm problem solve
View q1.cpp
#include <iostream>
#include <vector>
using namespace std;
void peak(vector<vector<int>> &table, int row, int col) {
for (int i = 0; i < row; ++i) {
for (int j = 0; j < col; ++j) {
cout << table[i][j] << " ";
@yodalee
yodalee / syscall_test.c
Created Nov 11, 2016
AOS HW2 test our system call
View syscall_test.c
#include <stdio.h>
#include <linux/kernel.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include "dummysyscall.h"
@yodalee
yodalee / dummysyscall.c
Created Nov 11, 2016
AOS HW2 system call that collect info of caller process
View dummysyscall.c
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/sched.h>
#include <linux/syscalls.h>
#include <uapi/linux/errno.h>
#include <asm/uaccess.h>
#include <linux/string.h>
#include <linux/list.h>
#include <linux/sched.h>
View ClangQQ.c
#include <stdio.h>
int main(int argc, const char *argv[])
{
int n = 1;
// little endian if true
if(*(char *)&n == 1)
printf("Litt\n");
else
printf("Big\n");
signed int lval = 0xFEDCBA98 << 32;
View swap_list.c
#include <stdio.h>
#include <stddef.h>
typedef struct _List {
struct _List *next;
int val;
} List;
enum {
SWAPSUCCESS,
@yodalee
yodalee / text decode serialize
Created Apr 26, 2015
Discuss the implementation of textdecoder serialize function
View text decode serialize
fn serialize(mut self, stream: &[u8]) -> &[u8] {
match self.encoding.name() {
"utf-8" | "utf-16be" | "utf-16le" if (!self.ignoreBOM && !self.BOMseen) => {
match stream.get(0) {
Some(token) => {
self.BOMseen = true;
if *token == 0xFEFF {
stream.slice_from(1)
} else {
stream
View fifo.c
uint32_t working_thread = 0;
working_thread = htonl(check_working(global_server->pool)); //get working thread num
fd = open(global_server->arg.fifofile, O_WRONLY | O_NONBLOCK);
if (fd == -1) {
fprintf(stderr, "open fifo file fail\n");
return;
}
write(fd, &working_thread, sizeof(uint32_t));
close(fd);
You can’t perform that action at this time.