Skip to content

Instantly share code, notes, and snippets.

View sccheruku's full-sized avatar

Sai Chaitanya sccheruku

View GitHub Profile
class BaseApiController < ApplicationController before_filter :parse_request, :authenticate_user_from_token! private def authenticate_user_from_token! if !@json['api_token'] render nothing: true, status: :unauthorized else @user = nil User.find_each do |u| if Devise.secure_compare(u.api_token, @json['api_token']) @user = u end end end end def parse_request @json = JSON.parse(request.body.read) end end
@sccheruku
sccheruku / FindMissingNumberInList
Created January 6, 2016 14:52
Finds the missing number in a list
//Find the missing number in a list
//http://stackoverflow.com/questions/2113795/quickest-way-to-find-missing-number-in-an-array-of-numbers
//list can start anywhere, assumes arithmetric series where n, n+1,n+2 etc..
function getMissingNum() {
var start = Math.floor(Math.random() * 150) / 1;
var nElem = Math.floor(Math.random() * 20) / 1;
var set = [];
var rand = Math.floor(Math.random() * nElem) + start / 1;
for (var i = start; i <= start + nElem; i++) {
@sccheruku
sccheruku / readme.md
Last active February 3, 2016 13:14 — forked from jobsamuel/readme.md
Run NodeJS as a Service on Ubuntu 14.04 LTS

Run NodeJS as a Service on Ubuntu 14.04 LTS

With Node you can write very fast JavaScript programs serverside. It's pretty easy to install Node, code your program, and run it. But > how do you make it run nicely in the background like a true server?

  • Go to /etc/init/
  • $ sudo vim yourapp.conf
  • Paste script.conf
  • $ sudo start yourapp
  • And when you wanna kill the process $ sudo stop yourapp
@sccheruku
sccheruku / registry.conf
Created February 4, 2016 22:17
registry.conf for nginx docker-repo
upstream docker-registry {
server registry:5000;
}
server {
listen 443;
server_name myregistrydomain.com;
# SSL
# ssl on;
@sccheruku
sccheruku / rps.js
Created March 14, 2016 16:42
rock paper scissors
var choices = [{choice: "r", beats: "s", losesTo: "p"},
{choice: "p", beats: "r", losesTo: "s"},
{choice: "s", beats: "p", losesTo: "r"}];
function rps(c){
var i = Math.floor(Math.random() * 3)
var myC = choices[i];
if (myC.choice == c) return "Draw";
else if (myC.beats == c) return "Win";
else if (myC.losesTo == c) return "Lose";
@sccheruku
sccheruku / nginx_basics.md
Created June 30, 2016 10:30 — forked from leommoore/nginx_basics.md
Nginx Basics

#Nginx Basics for Ubuntu

Please see http://wiki.nginx.org/Main for more information. See http://arstechnica.com/gadgets/2012/11/how-to-set-up-a-safe-and-secure-web-server/ for a tutorial on how to install Nginx.

##Installation To install, you can install the version which is in the standard Ubuntu repositories but it is normally quite old and will not have the latest security patches. The best way is to update the repositories first:

apt-get update
apt-get install python-software-properties

apt-get upgrade

@sccheruku
sccheruku / AmazonMSP
Created March 20, 2018 10:33
marketApp
{
"name": "AsusAmazon",
"mspid": "AmazonMSP",
"roles": null,
"affiliation": "",
"enrollmentSecret": "",
"enrollment": {
"signingIdentity": "50af112175657b319a236bde7cdf245c0eb12af036760431b7bc0802df9c4585",
"identity": {
"certificate": "-----BEGIN CERTIFICATE-----\nMIICBzCCAa6gAwIBAgIRANxDdNx/o7m53RCykHobac0wCgYIKoZIzj0EAwIwZzEL\nMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG\ncmFuY2lzY28xEzARBgNVBAoTCkFtYXpvbi5jb20xFjAUBgNVBAMTDWNhLkFtYXpv\nbi5jb20wHhcNMTgwMzE3MjM1MDQxWhcNMjgwMzE0MjM1MDQxWjBVMQswCQYDVQQG\nEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNj\nbzEZMBcGA1UEAwwQQWRtaW5AQW1hem9uLmNvbTBZMBMGByqGSM49AgEGCCqGSM49\nAwEHA0IABKOeiUtW4iA2HRRuC9bDRox1AdrRKXGDeiCPOAVDsNbEHQJsPgbSwehT\n1kBYbgIuG8uKLZ/N1bgYvgajOtGZB2ejTTBLMA4GA1UdDwEB/wQEAwIHgDAMBgNV\nHRMBAf8EAjAAMCsGA1UdIwQkMCKAIGwvSD5ZPhUQXbCxBPXrMSiqiZ69yWH3pz66\nFp9RroNCMAoGCCqGSM49BAMCA0cAMEQCIEQGiHQkl8+CB0VYuUZ4jJ26MJKSnDgp\no/wZfTANz1AgAiBqiJjBf+ADRr8aVBXtgzmmvnVEfkQf+Vrf64TreArvKw=
@sccheruku
sccheruku / prismatest.ts
Created May 8, 2022 16:32
Using prisma to figure out when a cert should be invalid
import { PrismaClient, Prisma } from "@prisma/client";
import Dayjs from "dayjs";
const prisma = new PrismaClient();
const account_id = "gtacodingtutor.testnet";
const issueDate = new Date("2021-09-21");
const expiryDate = new Date("2022-03-20");
const today = new Date("2022-03-01");
const inactivePeriodInDays = 180;
@sccheruku
sccheruku / example.rs
Created May 17, 2022 16:30
near protocol contract built using templates and building blocks
// To conserve gas, efficient serialization is achieved through Borsh (http://borsh.io/)
use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize};
use near_sdk::collections::{LookupMap, UnorderedMap};
use near_sdk::json_types::U128;
use near_sdk::serde_json::json;
use near_sdk::{assert_one_yocto, env, near_bindgen, setup_alloc, AccountId, Balance};
use std::collections::HashMap;
use near_contract_standards::fungible_token::FungibleToken;
use near_contract_standards::fungible_token::metadata::{
FungibleTokenMetadata, FungibleTokenMetadataProvider, FT_METADATA_SPEC,
We couldn’t find that file to show.