Skip to content

Instantly share code, notes, and snippets.

View AdityaSoni19031997's full-sized avatar
🎯
Focusing

Aditya Soni AdityaSoni19031997

🎯
Focusing
View GitHub Profile
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Update 7 Oct 2010:
# - This example does *not* appear to work with Chrome >=6.0. Apparently,
# the WebSocket protocol implementation in the cramp gem does not work
# well with Chrome's (newer) WebSocket implementation.
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby
@nerdsrescueme
nerdsrescueme / regex.txt
Created September 23, 2011 16:08
Common Regex
Perl and PHP Regular Expressions
PHP regexes are based on the PCRE (Perl-Compatible Regular Expressions), so any regexp that works for one should be compatible with the other or any other language that makes use of the PCRE format. Here are some commonly needed regular expressions for both PHP and Perl. Each regex will be in string format and will include delimiters.
All Major Credit Cards
This regular expression will validate all major credit cards: American Express (Amex), Discover, Mastercard, and Visa.
//All major credit cards regex
'/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6011[0-9]{12}|622((12[6-9]|1[3-9][0-9])|([2-8][0-9][0-9])|(9(([0-1][0-9])|(2[0-5]))))[0-9]{10}|64[4-9][0-9]{13}|65[0-9]{14}|3(?:0[0-5]|[68][0-9])[0-9]{11}|3[47][0-9]{13})*$/'
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Opinion Lexicon: Positive
;
; This file contains a list of POSITIVE opinion words (or sentiment words).
;
; This file and the papers can all be downloaded from
; http://www.cs.uic.edu/~liub/FBS/sentiment-analysis.html
;
; If you use this list, please cite one of the following two papers:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Opinion Lexicon: Negative
;
; This file contains a list of NEGATIVE opinion words (or sentiment words).
;
; This file and the papers can all be downloaded from
; http://www.cs.uic.edu/~liub/FBS/sentiment-analysis.html
;
; If you use this list, please cite one of the following two papers:
@Nicksil
Nicksil / gist:5646003
Created May 24, 2013 19:40
Python - Knuth-Morris-Pratt (KMP) string-matching algorithm
# File: KnuthMorrisPratt.py
# Author: Keith Schwarz (htiek@cs.stanford.edu)
#
# An implementation of the Knuth-Morris-Pratt (KMP) string-matching algorithm.
# This algorithm takes as input a pattern string P and target string T, then
# finds the first occurrence of the string T in the pattern P, doing so in time
# O(|P| + |T|). The logic behind the algorithm is not particularly complex,
# though getting it to run in linear time requires a few non-obvious tricks.
#
# To motivate KMP, consider the naive algorithm for trying to match a pattern
@rvanbruggen
rvanbruggen / foodimport.cql
Last active May 1, 2021 08:37
Food network import instructions
// create nodes
// create BaseNodes
import-cypher -d ; -i ./IMPORT/INPUT/1-basenodes.csv -o ./IMPORT/OUTPUT/nodeoutput.csv create (n:#{type} {id:{id},name:{name}}) return n
// create indexes
create index on :INGREDIENT_CATEGORY(name);
create index on :INGREDIENT(name);
create index on :INGREDIENT(id);
create index on :COMPOUND(name);
create index on :COMPOUND(id);
@mooware
mooware / colorstreamhandler.py
Last active July 20, 2023 16:16
Colored log output for Python logging framework. Works on Windows, Linux, and probably Mac as well.
# colored stream handler for python logging framework (use the ColorStreamHandler class).
#
# based on:
# http://stackoverflow.com/questions/384076/how-can-i-color-python-logging-output/1336640#1336640
# how to use:
# i used a dict-based logging configuration, not sure what else would work.
#
# import logging, logging.config, colorstreamhandler
#
@Dissimilis
Dissimilis / CircularBufferPeriodCounter.cs
Last active January 18, 2024 11:52
Efficient Circular buffer counter to calculate events per time
/*
Implementation of circular buffer counter for counting events per time.
It is thead safe and has high increment/add performance and good enough avg/count performance.
Usage is as simple as:
var counter = new CircularBufferCounter(TimeSpan.FromSeconds(1), TimeSpan.FromHours(2));
counter.Increment();
var avgPerMinuteLastHour = counter.Avg(TimeSpan.FromMinutes(1), TimeSpan.FromHours(1));
*/
@karpathy
karpathy / min-char-rnn.py
Last active June 11, 2024 01:44
Minimal character-level language model with a Vanilla Recurrent Neural Network, in Python/numpy
"""
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy)
BSD License
"""
import numpy as np
# data I/O
data = open('input.txt', 'r').read() # should be simple plain text file
chars = list(set(data))
data_size, vocab_size = len(data), len(chars)
@vasanthk
vasanthk / System Design.md
Last active June 11, 2024 09:51
System Design Cheatsheet

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?