Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://unpkg.com/vue"></script>
<script src="https://cdn.jsdelivr.net/lodash/4.17.4/lodash.core.min.js"></script>
</head>
@srkama
srkama / custom_logging.py
Created March 31, 2017 03:35
Custom log Adapter with customer logger
import logging
import logging.config
LOG_SETTINGS = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'standard': {
'format': "%(asctime)s %(levelname)-8s%(module)s:%(lineno)s:%(funcName)s %(message)s",
},
@srkama
srkama / custom_log_level.py
Created March 15, 2017 04:29
creating new custom level logger
import logging
DEBUG_LEVELV_NUM = 35
logging.DEBUG_LEVELV_NUM = DEBUG_LEVELV_NUM
logging.addLevelName(DEBUG_LEVELV_NUM, "DEBUGV")
def debugv(self, message, *args, **kws):
# Yes, logger takes its '*args' as 'args'.
if self.isEnabledFor(DEBUG_LEVELV_NUM):
self._log(DEBUG_LEVELV_NUM, message, args, **kws)
@srkama
srkama / partialfunction.js
Created March 16, 2016 05:36
Create a function that sums two arguments together. If only one argument is provided, then return a function that expects one argument and returns the sum.
function add() {
function checkNum(num) {
if (typeof num != 'number') {
return false;
}
return true;
}
if(arguments.length == 1) {
var c=arguments[0];
if (checkNum(c)) {
@srkama
srkama / binaryAgent.js
Created March 14, 2016 04:46
binary to string.
function binaryAgent(str) {
actualStr=""
str.split(" ").map(function(val) {
actualStr += String.fromCharCode(parseInt(val,2));
})
return actualStr;
}
@srkama
srkama / flatten.js
Created March 14, 2016 04:38
flattening the array
function steamroller(arr) {
// I'm a steamroller, baby
return flatten(arr);
}
function flatten(a, r){
if(!r){ r = [];}
for(var i=0; i<a.length; i++){
if(Array.isArray(a[i])){
flatten(a[i], r);
@srkama
srkama / drop.js
Created March 14, 2016 04:17
Drop the elements of an array (first argument), starting from the front, until the predicate (second argument) returns true. Return the rest of the array, otherwise return an empty array.
function drop(arr, func) {
for(i=0;i<=arr.length;i++) {
if (func(arr[i])) {
return arr.slice(i);
}
}
return [];
}
drop([1, 2, 3], function(n) {return n < 3; });
function find(arr, func) {
var num = 0;
for(i=0;i<=arr.length;i++) {
if (func(arr[i])) {
return arr[i];
}
}
}
@srkama
srkama / lcm.js
Created March 14, 2016 04:06
Find the smallest common multiple of the provided parameters that can be evenly divided by both, as well as by all sequential numbers in the range between these parameters. The range will be an array of two numbers that will not necessarily be in numerical order. e.g. for 1 and 3 - find the smallest common multiple of both 1 and 3 that is evenly…
function smallestCommons(arr) {
if(arr[0]>arr[1]) {
min = arr[1];
max = arr[0];
} else {
min = arr[0];
max = arr[1];
}
function range(min, max) {
var arr = [];
@srkama
srkama / sum_all_prime.js
Created March 3, 2016 13:58
Sum All Primes - freecodecamp
function isPrime(n) {
if (n==1 || n == 2 || n == 3) {
return true;
} else {
for(i=Math.floor(Math.sqrt(n));i>=2;i--){
if(n%i == 0 || n%2 == 0 || n%3 == 0) {return false;}
}
}
return true;
}