This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fs = require('fs') | |
| util = require('util') | |
| path = require('path') | |
| flatten = (a, b) -> | |
| if typeof b is 'undefined' | |
| b = a | |
| a = [] | |
| b = b.reduce(flatten, []) if typeof b is 'object' | |
| a = [a] if typeof a isnt 'object' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require 'nokogiri' | |
| require 'active_record' | |
| require "sqljdbc4.jar" | |
| ActiveRecord::Base.establish_connection( | |
| :adapter => "jdbcmssql", | |
| :driver => "com.microsoft.sqlserver.jdbc.SQLServerDriver", | |
| :url => "jdbc:sqlserver://192.168.0.18;databaseName=oms_db_cod_12", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'benchmark' | |
| N = 50000 | |
| STRING = "asd sda sda sd" | |
| Benchmark.bm do |b| | |
| b.report('gsub, s') do | |
| N.times { STRING.gsub(/\s/, '') } | |
| end | |
| b.report('gsub, s+') do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'spec_helper' | |
| class TheCopenhagenModel < Restish::Model | |
| end | |
| describe Restish::Errors do | |
| context '#from_hash' do | |
| let(:model) { TheCopenhagenModel.new(owner: 'Schrödinger', name: 'cat', alive: true) } | |
| let(:errors) { { 'alive' => ['is invalid'], 'cyanide_flask' => ["can't be empty"] } } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module ActiveAdmin | |
| class Resource | |
| module Controllers | |
| # Returns a properly formatted controller name for this | |
| # config within its namespace | |
| def controller_name | |
| [namespace.module_name, resource_name.plural.camelize + "Controller"].compact.join('::') | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class EnumType < DelegateClass(Symbol) | |
| # ... | |
| end | |
| Symbol.instance_eval do | |
| def ===(other) | |
| if other.kind_of?(EnumType) | |
| true | |
| else | |
| super(other) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Compiled source # | |
| ################### | |
| *.com | |
| *.class | |
| *.dll | |
| *.exe | |
| *.o | |
| *.so | |
| # Packages # |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| object Trampolines { | |
| def odd[A](as: List[A]): TailRec[Boolean] = | |
| as match { | |
| case Nil => Return(false) | |
| case _ :: xs => Suspend(() => even(xs)) | |
| } | |
| def even[A](as: List[A]) = as match { | |
| case Nil => Return(true) | |
| case _ :: xs => Suspend(() => odd(xs)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.io.{DataOutputStream, ByteArrayOutputStream} | |
| import java.nio.ByteBuffer | |
| import java.security.{KeyPairGenerator, SecureRandom} | |
| import javax.crypto.{KeyGenerator, Cipher} | |
| import javax.crypto.spec.IvParameterSpec | |
| import akka.actor.{ ActorRef, ActorSystem, Props, Actor } | |
| sealed trait Message | |
| case class Start(visavis: ActorRef) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'socket' | |
| address = Addrinfo.tcp('224.0.0.1', 5670) | |
| socket = UDPSocket.open | |
| socket.setsockopt(:IPPROTO_IP, :IP_MULTICAST_TTL, 1) | |
| socket.send("From Sergey with love: " + Time.now.to_s, 0, address.ip_address, address.ip_port) | |
| socket.close |
OlderNewer