Skip to content

Instantly share code, notes, and snippets.

package main
import (
"fmt"
"time"
)
func worker(id int, jobs <-chan int, results chan<- int) {
for j := range jobs {
fmt.Println("worker", id, "processing job", j)
package main
import (
"errors"
"sync"
)
func test(i int) (int, error) {
if i > 2 {
return 0, errors.New("test error")
package main
import (
"errors"
"fmt"
"reflect"
)
//func foo() (arr string) {
// arr="foo called"
@jayjayswal
jayjayswal / teserflow_gpu_test.py
Last active December 29, 2018 11:18
teserflow gpu test
import tensorflow as tf
with tf.device('/gpu:0'):
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
with tf.Session() as sess:
print (sess.run(c))
# https://medium.com/@omar.merghany95/how-to-install-tensorflow-gpu-with-cuda-toolkit-9-0-and-cudnn-7-2-1-on-aws-ec2-ubuntu-16-04-c46b469a7358
@jayjayswal
jayjayswal / lambdaAMICleanup.py
Created August 19, 2018 07:14 — forked from bkozora/lambdaAMICleanup.py
AWS Lambda Function to Delete AMIs and Snapshots
# Automated AMI and Snapshot Deletion
#
# @author Robert Kozora <bobby@kozora.me>
#
# This script will search for all instances having a tag with "Backup" or "backup"
# on it. As soon as we have the instances list, we loop through each instance
# and reference the AMIs of that instance. We check that the latest daily backup
# succeeded then we store every image that's reached its DeleteOn tag's date for
# deletion. We then loop through the AMIs, deregister them and remove all the
# snapshots associated with that AMI.
@jayjayswal
jayjayswal / lambdaAMIBackups.py
Created August 19, 2018 07:10 — forked from bkozora/lambdaAMIBackups.py
AWS Lambda AMI Backups
# Automated AMI Backups
#
# @author Robert Kozora <bobby@kozora.me>
#
# This script will search for all instances having a tag with "Backup" or "backup"
# on it. As soon as we have the instances list, we loop through each instance
# and create an AMI of it. Also, it will look for a "Retention" tag key which
# will be used as a retention policy number in days. If there is no tag with
# that name, it will use a 7 days default value for each AMI.
#
@jayjayswal
jayjayswal / Synchronization.md
Last active August 29, 2015 14:15
Version Control System and Synchronization System between Desktop and Web applications

Version Control System and Synchronization System between Desktop and Web applications

Activity log created at local desktop database

Steps:

  1. When internet connected, first update all activity log from local database to server.
  2. Download snippet info(xml) from database
  3. Compare it with local database (update newly created snippet from server to DA and delete snippet if it’s exist on DA but not at server.
@jayjayswal
jayjayswal / stohi.c
Created February 21, 2015 18:35
Convert IP address to integer and convert it back in c
#include <stdio.h>
#include <stdlib.h>
union
{
unsigned int integer;
unsigned char byte[4];
} itoch;
main(){
printf("Converting IP: 32.0.45.54\n");
@jayjayswal
jayjayswal / php mysql utc to local timestamp
Last active August 29, 2015 14:12
Convert mysql UTC timestamp to Local timestamp PHP
function convert_time($timestamp,$timezone)
{
date_default_timezone_set("UTC");
$time_object = new DateTime($timestamp, new DateTimeZone('UTC'));
$time_object->setTimezone(new DateTimeZone($timezone));
return $time_object->format('Y-m-d g:i A');
}
@jayjayswal
jayjayswal / get Height of Document any Browser
Last active August 29, 2015 14:12
Get Height of document in any browser
function getDocHeight() {
var D = document;
return Math.max(
D.body.scrollHeight, D.documentElement.scrollHeight,
D.body.offsetHeight, D.documentElement.offsetHeight,
D.body.clientHeight, D.documentElement.clientHeight
);
}