Skip to content

Instantly share code, notes, and snippets.

View ashish173's full-sized avatar
🏠
Working from home

Ashish Singh ashish173

🏠
Working from home
View GitHub Profile
@ashish173
ashish173 / gisted
Last active December 10, 2015 17:58
this is simple gist
def get_page():
import urllib2
f = urlib2.urlopen("https://www.google.com")
content = f.read()
return content
content = get_page()
@ashish173
ashish173 / npj1
Created October 8, 2013 21:32
Network programming in java
try { // starts a server socket on port 4444
serverSocket = new ServerSocket(4444); // socket listens on 4444
}
catch(IOException e) {
System.err.println("Could not listen on port : 4444");
System.exit(1);
}
@ashish173
ashish173 / voting_sol_2
Last active December 25, 2015 11:19
voting algo my solution
int[] count = new int[cast.length]; // cast array is votes casted
int count1, num;
for(int i=0; i<cast.length; i++) {
num = ++count[cast[i]]; // increments count on vote cast in array
if(num > cast.length/2) {
System.out.println("Winner is candidate " + cast[i]); // returns the index of winner
break;
}
}
@ashish173
ashish173 / voting_sol_3.
Last active December 25, 2015 17:48
moore's voting algo
int count = 1, majorityIndex = 0;
for(int i=1; i<cast.length; i++) {
if(cast[i]==cast[majorityIndex])
count++;
else
count--;
if(count==0) { // no majority at this point
majorityIndex=i;
count=1;
}
@ashish173
ashish173 / testfile
Created August 21, 2014 17:45
simple go programe
package main
import "fmt"
func main() {
fmt.Println("this is a simple go file")
}
console.clear();
var source = Rx.Observable.create(observer => {
Rx.Observable.range(0,5).subscribe(
data => {
console.log(data)
if(data > 2) {
// conveys to the subscriber of source
// that values has changed
observer.next("greater than 2");
@ashish173
ashish173 / observable_101.ts
Created December 8, 2016 19:52
Observable 101
var obs = Rx.Observable.range(0, 10);
obs.subscribe(
data => {
console.log(data);
}
);
@ashish173
ashish173 / observable_102.ts
Created December 8, 2016 20:43
Manual observable emit value
var source = Rx.Observable.create((observer) => {
setTimeout(() => {
console.log('timeout hit');
observer.onNext('Observable 101');
}, 1000);
console.log('observable initialized');
});
source.subscribe(x => console.log(x));
@ashish173
ashish173 / observable_103.ts
Last active December 8, 2016 21:16
Buffer operator
//Create an observable that emits a value every second
const myInterval = Rx.Observable.interval(1000);
//Create an observable that emits every time button is clicked
var button = document.getElementById('clickButton');
const bufferBy = Rx.Observable.fromEvent(button, 'click');
/*
Collect all values emitted by our interval observable until we click document. This will cause the bufferBy Observable to emit a value, satisfying the buffer. Pass us all collected values since last buffer as an array.
@ashish173
ashish173 / map.ts
Created December 8, 2016 21:26
Map operator
//emit (1,2,3,4,5)
const source = Rx.Observable.from([1,2,3,4,5]);
//add 10 to each value
const example = source.map(val => val + 10);
//output: 11,12,13,14,15
const subscribe = example.subscribe(val => console.log(val));
//emit ({name: 'Joe', age: 30}, {name: 'Frank', age: 20},{name: 'Ryan', age: 50})
const sourceTwo = Rx.Observable.from([{name: 'Joe', age: 30}, {name: 'Frank', age: 20},{name: 'Ryan', age: 50}]);
//grab each persons name