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
<?php | |
// app/classes/myrules.php | |
class MyRules | |
{ | |
// note this is a static method | |
public static function _validation_unique($val, $options) | |
{ | |
list($table, $field, $id) = explode('.', $options); | |
$result = DB::select("LOWER (\"$field\")", 'id') |
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 'rails_helper' | |
feature "Login" do | |
background do | |
#Factory Girl | |
@user = create(:user) | |
end | |
scenario "With correct credentials" 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
npm config set registry https://registry.npmjs.org/ |
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
describe HappyNumber do | |
it "Is possible to chek if a number is happy?" do | |
happy_number = HappyNumber.new | |
expect(happy_number.happy?(7)).to be true | |
end | |
end | |
#happy_number.rb | |
class HappyNumber | |
def happy?(number) |
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
# How does it work? | |
# $ elixir -r chain.exs -e "Chain.run(1000)" to have one thousand processes. | |
defmodule Chain do | |
def counter(next_pid) do | |
receive do | |
n -> send next_pid, n + 1 | |
end | |
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
<?php | |
//file upload.php | |
$pic = $_FILES['pic']; | |
echo '<pre>'; | |
print_r($pic); | |
?> |
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
<?php | |
//phpinfo(); | |
$multiple_upload = function (array $inputs){ | |
$result = array(); | |
if($inputs){ | |
foreach($inputs as $key => $index){ | |
if(is_array($index)){ | |
foreach($index as $i => $value){ | |
$result[$i][$key] = $value; |
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
(defn to-int [x] (Integer/parseInt x) ) | |
(defn string-to-vector [x] (clojure.string/split x #" ")) | |
(def size (read-line)) | |
(def items (read-line)) | |
(println (reduce + (map to-int (string-to-vector items)))) | |
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
(defn to-int [x] | |
(Integer/parseInt x)) | |
(defn string-to-vector [x] | |
(clojure.string/split x #" ")) | |
(def alice-points (atom 0)) | |
(def bob-points (atom 0)) | |
(defn counter [points] |
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
(defn string-to-vector [x] | |
(clojure.string/split x #" ")) | |
(defn to-int [x] | |
(Integer/parseInt x)) | |
(defn divisible? [i j k] | |
(let [i (to-int i) | |
j (to-int j) | |
k (to-int k) |