Skip to content

Instantly share code, notes, and snippets.

View mishin's full-sized avatar
💭
if you fail to prepare you prepare to fail

Nikolay Mishin mishin

💭
if you fail to prepare you prepare to fail
View GitHub Profile
@mishin
mishin / ScalaFuture.scala
Created July 18, 2016 21:45 — forked from tkfx/ScalaFuture.scala
Scala Future
import scala.util.{Success, Failure}
val f: Future[List[String]] = Future {
session.getRecentPosts
}
f onComplete {
case Success(posts) => for (post <- posts) println(post)
case Failure(t) => println("An error has occured: " + t.getMessage)
}
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
EntityGraph<?> graph = em.getEntityGraph("graph.AuthorBooks");
HashMap<String, Object> properties = new HashMap<>();
properties.put("javax.persistence.fetchgraph", graph);
Author a = em.find(Author.class, 1L, properties);
em.getTransaction().commit();
#!/usr/bin/perl
use strict;
use warnings FATAL => 'all';
use feature 'say';
use utf8;
use open qw(:std :utf8);
use Carp;
use HTTP::Tiny;
#!/usr/bin/perl
use strict;
use warnings FATAL => 'all';
use feature 'say';
say '1';
if (1) {{
say '2';
@mishin
mishin / A.markdown
Created May 30, 2016 10:33 — forked from larrybotha/A.markdown
Merge wiki updates that are on a fork of your repo.

Merge Wiki Changes From A Forked Github Repo

This is inspired (or basically copied) from How To Merge Github Wiki Changes From One Repository To Another, by Roman Ivanov, and serves to ensure that should something happen to the original article, the information remains nice and safe here.

Terminology

OREPO: original repo - the repo created or maintained by the owner

FREPO: the forked repo that presumably has updates to its wiki, not yet on the OREPO

@mishin
mishin / selenium-screenshotting.md
Created March 24, 2016 17:38 — forked from dannguyen/selenium-screenshotting.md
Using Selenium and Python to screenshot a javascript-heavy page

Using Selenium and Python to screenshot a javascript-heavy page

As websites become more JavaScript heavy, it's harder to automate things like screenshotting for archival purposes. I've seen examples and suggestions to use PhantomJS for visual testing/archiving of websites, but have run into issues such as the non-rendering of webfonts. I've never tried out Selenium until today...and while I'm not thinking about performance implications yet, Selenium seems far more accurate than PhantomJS...which makes sense since it actually opens a real browser. And it's not too hard to script to do complex interactions: here's an [example of how to log in to Twitter, write a tweet, upload an image, and send a tweet via Selenium and DOM element selection](https://gist.github.com/dannguyen/8a6fa49253c1d6a0eb92

@mishin
mishin / tweet-selenium.py
Created March 24, 2016 17:36 — forked from dannguyen/tweet-selenium.py
how to send a tweet through Firefox using Python + Selenium
"""
Tweeting by controlling Firefox via Python + selenium
http://selenium-python.readthedocs.org/
Obviously you should be using tweepy + the Twitter API if you actually
want to programmatically work with Twitter data and be efficient about it
But it's fun watching Python control the browser interactively...
"""
from selenium import webdriver
@mishin
mishin / websocket3.pl
Created January 23, 2016 22:56 — forked from adam-stokes/websocket3.pl
mojo::useragent websocket
#!/usr/bin/env perl
use strict;
use warnings;
use Mojo::Base -base;
use Mojo::UserAgent;
my $ua = Mojo::UserAgent->new;
$ua->websocket(
'wss://10.0.3.1:17070' => sub {
my ($ua, $tx) = @_;
@mishin
mishin / squrt-newton-method.lisp
Created January 21, 2016 14:53 — forked from maksimr/squrt-newton-method.lisp
Ньютонов метод последовательных приближений для вычисления квадратного корня
; Ньютонов метод последовательных приближений
; для вычисления квадратного корня.
; ----
;
; Основан на том, что имея некоторое неточное значение y
; для квадратного корня из числа x, мы можем с помощью
; простой манипуляции получить более точное значение (более близкое к настоя-
; щему квадратному корню), если возьмем среднее между y и x/y.
;
; Например, мы можем вычислить квадратный корень из 2 следующим образом: предположим,
@mishin
mishin / gist:dc738f72fc875bd8d00a
Created January 21, 2016 12:12 — forked from berlinbrown/gist:1073659
Scala : Insertion Sort in Scala, Basic code, Java to Scala
/**
* Berlin Brown , berlin dot brown at gmail.com
*
* Scala Insertion Sort based on Haskell impl (Convert from Haskell to Scala).
*
*/
package org.berlin.algo.scala;
/**
* Insertion Sort using list of integers.