Skip to content

Instantly share code, notes, and snippets.

@sunny1304
sunny1304 / hello.c
Created Jul 2, 2014
Very basic char device driver
View hello.c
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/fs.h>
#include <linux/cdev.h>
#include <linux/semaphore.h>
#include <asm/uaccess.h>
View keybase.md

Keybase proof

I hereby claim:

  • I am sunny1304 on github.
  • I am sunny1304 (https://keybase.io/sunny1304) on keybase.
  • I have a public key ASCH7fSzZ6ZVa4AsvhI8-aalUTBvlf1Q2godjAIrL8_pSwo

To claim this, I am signing this object:

@sunny1304
sunny1304 / pthread_create.c
Created Jan 14, 2014
POSIX Pthread_create example
View pthread_create.c
#include <pthread.h>
#include <stdio.h>
typedef struct student{
char *name;
int age;
}Student;
void *show_student(void *student);
@sunny1304
sunny1304 / echo_avg.rs
Last active Jan 3, 2016
get avarage of the number argumants
View echo_avg.rs
use std::{os};
fn args_avg(vec: &[~str]) -> int {
let mut sum = 0;
let mut count = 0;
for i in vec.iter(){
let x:Option<int> = from_str(*i);
if x != None{
sum += x.unwrap();
count += 1;
@sunny1304
sunny1304 / mongoose_promise.js
Created Dec 5, 2013
promise example for mongoose
View mongoose_promise.js
var relationPromise = ArticleRelation.findOne({parentArticleGuid: oldArticle.guid}).exec();
relationPromise
.then(function(relation){
if (relation == null){
relation = new ArticleRelation({
parentArticleGuid: oldArticle.guid,
organization: task.organization._id
});
}
@sunny1304
sunny1304 / csv_product_upload.js
Last active Dec 30, 2015
Read Product list from a csv file and save them using async.js
View csv_product_upload.js
var csv = require('csv'),
async = require('async'),
fs = require('fs'),
path = require('path'),
root = __dirname,
data = [],
maxconcurrency = 5;
var mongoose = require('mongoose');
mongoose.set('debug', true);
@sunny1304
sunny1304 / model_generator.js
Last active Dec 29, 2015
Rails like model generator for Node js
View model_generator.js
// node fname.js g model user name
var fs =require('fs');
var os = require('os');
var args_list = process.argv;
var folder = args_list[3]
var model_name = args_list[4]
var model_attrs = args_list.slice(5);
var eol = os.EOL;
// console.log(folder, model_name, model_attrs);
@sunny1304
sunny1304 / searchresource_api.py
Created Aug 22, 2012 — forked from MacMaru/searchresource_api.py
Tastypie (non-model) Resource example with a listfield populated with m2m data
View searchresource_api.py
class SimpleOwnerAuthorization(Authorization):
'''
Does what it says: filters objects by their owner (user).
'''
def __init__(self, ownerfilter=None, *args, **kwargs):
self.ownerfilter = ownerfilter # the user field i.e. 'person__user'
def is_authorized(self, request, object=None):
return True # for now
@sunny1304
sunny1304 / typecheck_macro.c
Last active Aug 29, 2015
Typecheck macro in C (from Linux Source)
View typecheck_macro.c
//Use -Werror in GCC to get error, otherwise it will be a warning
/*
Constraints
One of the following shall hold:
both operands have arithmetic type;
both operands are pointers to qualified or unqualified versions of compatible types;
one operand is a pointer to an object or incomplete type and the other is a pointer to a qualified or unqualified version of void; or
@sunny1304
sunny1304 / word_count.c
Created Oct 25, 2014
Word count [seperator: ' ', '\t', '\n', '\r']
View word_count.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int word_count(const char* str)
{
size_t word_count = 0;
size_t char_counter = 0;
size_t str_length = strlen(str);