Skip to content

Instantly share code, notes, and snippets.

@sunny1304
sunny1304 / moving_balls.cpp
Last active August 29, 2015 13:56
example of simulating moving balls with Box2D and SFML
#include <SFML/Graphics.hpp>
#include "Box2D/Box2D.h"
static const float SCALE = 30.f;
void create_balls_and_move_them()
{
// define the world;
b2Vec2 gravity(b2Vec2(0.f,9.8f)); // check if it dont work
b2World world(gravity);
@sunny1304
sunny1304 / find_deviation.cpp
Created February 3, 2014 06:22
finding_deviation C++11
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int find_deviation(vector<int> &, int);
int main(int argc, char const *argv[])
{
@sunny1304
sunny1304 / find_deviation.js
Last active August 29, 2015 13:55
finding_deviation
function find_deviation(v, d)
{
if (v.length <= 0) return 0;
start = 0;
medians = [];
arr_length = v.length;
loop_time = arr_length/d;
for(var i=0; i< loop_time; i++){
temp_arr = v.slice(start, start+d);
find_max = Math.max.apply(null, temp_arr);
@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