Skip to content

Instantly share code, notes, and snippets.

function isPrime(num) {
let prime = true;
for (let d = 2; d <=
Math.sqrt(num); d++) {
if (num % d == 0) {
prime = false;
break;
}
}
// Your code here!
extern crate rustc_version;
fn main(){println!("XXXXXXXX");
otherFun();
}
fn otherFun(){
@ls404
ls404 / LeapYear.js
Created March 9, 2018 14:28
Leap year finder
function isLeap(x) {
let leap = (x % 4 == 0 && x % 100 != 0) || x % 400 == 0;
console.log(leap ? "yes" : "no");
}
isLeap(['2016']);
DECLARE @s VARCHAR(50)= 'City-Of-Style'
SELECT SUBSTRING(@s,0,CHARINDEX('-',@s,0)) AS firstPart,
SUBSTRING(@s,CHARINDEX('-',@s,0)+1,LEN(@s)) AS secondPart
>>> a = [1, 2, 3, 4, 5]
>>> b = [9, 8, 7, 6, 5]
>>> set(a) & set(b)
{5}
@ls404
ls404 / scratch.py
Last active June 23, 2017 07:37
Find dublicates in two python lists.Easy but not effective solution
def dub(li, li1: list):
#find dublicates in two list, easy but not effective solution
print(set(li) & set(li1))
dub(["a","b","c","c","d","d","c","f","l"],["a","b","a"])
@ls404
ls404 / print_filter.js
Created May 18, 2017 07:58
print crosfilter results in console
/**
* Created by user on 18/05/17.
*/
// Super useful for debug in web console
function print_filter(filter){
var f=eval(filter);
if (typeof(f.length) != "undefined") {}else{}
if (typeof(f.top) != "undefined") {f=f.top(Infinity);}else{}
if (typeof(f.dimension) != "undefined") {f=f.dimension(function(d) { return "";}).top(Infinity);}else{}
console.log("DC DEBUG: "+filter+"("+f.length+") = "+JSON.stringify(f).replace("[","[\n\t").replace(/}\,/g,"},\n\t").replace("]","\n]"));
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="ticks")
# Create a dataset with many short random walks
rs = np.random.RandomState(4)
pos = rs.randint(-1, 2, (20, 5)).cumsum(axis=1)
pos -= pos[:, 0, np.newaxis]
"""
Example demonstrating a Bokeh plot in Flexx, using a Phosphor dock panel
layout. Includes client-side interaction with sliders.
"""
import numpy as np
from bokeh.plotting import figure
from flexx import app, ui, react