Skip to content

Instantly share code, notes, and snippets.

View alopatindev's full-sized avatar

Alexander Lopatin alopatindev

View GitHub Profile
#!/usr/bin/env python2
# https://www.youtube.com/watch?v=tIpKfDc295M
# https://www.youtube.com/watch?v=umAeJ7LMCfU
import numpy as np
f = lambda x, y: x * x + 2.0 * y
d_dx = lambda x, y: 2.0 * x
d_dy = lambda x, y: 2.0
#!/usr/bin/env python2
# https://www.youtube.com/watch?v=YEBfamv-_do
from random import randrange
public_prime = 67280421310721 # aka p
public_base = 3 # aka g
def generate_key():
@alopatindev
alopatindev / Kmeans.scala
Last active May 7, 2017 22:33
K-means clustering algorithm
// https://www.youtube.com/watch?v=_aWzGGNrcic
// https://www.youtube.com/watch?v=RD0nNK51Fp8
import scala.io.Source
import scala.util.Random
import java.io.{BufferedWriter, FileWriter}
object Kmeans extends App {
case class Point(val x: Double, val y: Double) {
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
let val = 'global 1'
this.val = 'global 2'
console.log('val = ' + val)
class Foo {
constructor() {
this.val = 'property'
}
}
@alopatindev
alopatindev / fib.hs
Created October 15, 2016 21:11
Fibonacci numbers with Lambda Calculus
fix :: (a -> a) -> a
fix = \f -> f $ fix f
fib :: Int -> Int
fib = \n -> fix (\f n -> if n <= 2 then 1 else f (n - 2) + f (n - 1)) n
main = putStrLn $ show $ map fib [1..10]
@alopatindev
alopatindev / .gdbinit
Last active October 12, 2016 20:32
~/.gdbinit enables colors; requires colout
set height 0
set pagination off
set disassembly-flavor intel
# Don't wrap line or the coloring regexp won't work.
set width 0
# Create a named pipe to get outputs from gdb
shell test -e /tmp/coloutPipe && rm /tmp/coloutPipe
shell mkfifo /tmp/coloutPipe
warning: file found to be present in multiple build targets: /tmp/quickcheck/quickcheck_macros/examples/attribute.rswarning: file found to be present in multiple build targets: /tmp/quickcheck/quickcheck_macros/examples/attribute.rs
Updating registry `https://github.com/rust-lang/crates.io-index`
Updating registry `https://github.com/rust-lang/crates.io-index`
Compiling regex-syntax v0.3.4
Compiling regex-syntax v0.3.4
Compiling winapi Compiling winapi v0.2.8 v0.2.8
Compiling Compiling log v0.log v0.3.3.6
6
@alopatindev
alopatindev / TextView.html
Last active July 3, 2016 14:34
QDeviceMonitor: possible solution for memory leak and performance issues
<!DOCTYPE html>
<html>
<head>
<script>
var colors = {};
var elementsPerLine = 8;
function createSpanElement (color, text) {
var element = document.createElement('span');
element.setAttribute('style', 'color:' + color);
@alopatindev
alopatindev / remove_all_spaces.c
Last active June 7, 2016 11:23
Remove all spaces
// cc -std=c99 -g -O0 -Wall remove_all_spaces.c -o remove_all_spaces && gdb -ex r -ex q ./remove_all_spaces
// cc -DENABLE_BENCHMARK -std=c99 -O3 -Wall remove_all_spaces.c -o remove_all_spaces && ./remove_all_spaces | gnuplot -p -
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>