Skip to content

Instantly share code, notes, and snippets.

View usametov's full-sized avatar

Ulan Sametov usametov

  • Asta Nova Enterprise Solutions
View GitHub Profile
@usametov
usametov / 82.clj
Created July 14, 2016 17:04
4clojure solution to problem 82
(defn chk-ins [w1 w2]
(when (< (count w1) (count w2))
(some #(= w1 %)
(for [i (range (count w2))]
(str (subs w2 0 i) (subs w2 (inc i))))
)
))
(defn chk-subs [w1 w2]
(when (= (count w1) (count w2))
@usametov
usametov / chrome-bookmarks
Created May 12, 2017 02:23 — forked from selvan/chrome-bookmarks
Chrome extension to export all bookmarks
//manifest.json
{
"name": "bookmark-search-export",
"version": "1.0",
"manifest_version": 2,
"description": "This extention will dump all bookmarks",
"browser_action": {
"default_icon": "icon.png"
},
"background": {
@usametov
usametov / search-datetime-min.sql
Last active October 20, 2017 16:23
search invalid dates in SQL server
--this scripts searches for DateTime.Min dates in the whole database
declare @SearchDate [date] = CONVERT(DATE, '0001-01-01',120);
IF OBJECT_ID('tempdb.dbo.#Results', 'U') IS NOT NULL
DROP TABLE dbo.#Results
CREATE TABLE #Results (ColumnName nvarchar(370), ColumnValue [date] )
SET NOCOUNT ON
@usametov
usametov / export-chrome-bookmarks.js
Created October 29, 2017 02:44 — forked from bgrins/export-chrome-bookmarks.js
Reminder of how to export bookmarks from Chrome as text.
/*
Export bookmarks from Chrome as text.
Go to Bookmarks Manager->Organize->Export to HTML file.
Then open that file, open console and run this command:
*/
[].map.call(document.querySelectorAll("dt a"), function(a) {
return a.textContent + " - " + a.href
}).join("\n");
module Hamming
let distance (strand1: string) (strand2: string): int option =
if strand1.Length = strand2.Length
then
Some(Seq.zip strand1 strand2 |> Seq.sumBy (fun (a, b) -> if a = b then 0; else 1))
else None
const features = [{
'name': 'feature1',
'tags': [{
'weight': 10,
'tagName': 't1'
}, {
'weight': 20,
'tagName': 't2'
}, {
'weight': 30,
@usametov
usametov / search-everywhere.js
Last active April 1, 2018 01:07
mongodb snippet: search for a value in all fields
db.somethings.find({$where: function() {
var deepIterate = function (obj, value) {
for (var field in obj) {
if (obj[field] == value){
return true;
}
var found = false;
if ( typeof obj[field] === 'object') {
found = deepIterate(obj[field], value)
if (found) { return true; }
@usametov
usametov / destructure-first-and-rest.js
Created April 1, 2018 14:40
ES6 pattern matching using destructuring
const map = (f, [x, ...xs]) => (
(x === undefined && xs.length === 0) ? []
: [f(x), ...map(f, xs)]
);
@usametov
usametov / destructuring.js
Created April 1, 2018 14:44 — forked from mikaelbr/destructuring.js
Several demos and usages for ES6 destructuring. Runnable demos and slides about the same topic: http://git.mikaelb.net/presentations/bartjs/destructuring
// === Arrays
var [a, b] = [1, 2];
console.log(a, b);
//=> 1 2
// Use from functions, only select from pattern
var foo = () => [1, 2, 3];
@usametov
usametov / traverse.ts
Last active April 3, 2018 05:27
traverse object tree in javascript
//this will hopefully run in debug mode
//https://www.jetbrains.com/help/webstorm/running-and-debugging-node-js.html#ws_node_debugging_debugger_console
function traverse(o ) {
for (i in o) {
if (!!o[i] && typeof(o[i])=="object") {
// use typescript instanceof operator here
// we should be able to travel to desired type
console.log(i, o[i])
traverse(o[i] );
}