Skip to content

Instantly share code, notes, and snippets.

@sunny1304
sunny1304 / hello.c
Created July 2, 2014 16:22
Very basic char device driver
#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>

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 January 14, 2014 06:41
POSIX Pthread_create example
#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 January 3, 2016 00:19
get avarage of the number argumants
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 December 5, 2013 14:56
promise example for mongoose
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 December 30, 2015 02:49
Read Product list from a csv file and save them using async.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 December 29, 2015 11:09
Rails like model generator for Node 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 August 22, 2012 20:26 — forked from MacMaru/searchresource_api.py
Tastypie (non-model) Resource example with a listfield populated with m2m data
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 August 29, 2015 14:08
Typecheck macro in C (from Linux Source)
//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 October 25, 2014 04:42
Word count [seperator: ' ', '\t', '\n', '\r']
#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);