Skip to content

Instantly share code, notes, and snippets.

View sunkibaek's full-sized avatar
💻
Coding

Sunki Baek sunkibaek

💻
Coding
  • Calgary
View GitHub Profile
// load external data
$('input.typeahead-devs').typeahead({
name: 'accounts',
prefetch: 'countries.json'
});
@sunkibaek
sunkibaek / php_functions.php
Last active December 30, 2015 09:39
PHP Sessions
<?php
header("Location: file_name.php"); // redirect to file_name.php
?>
// 'angular way' to create a controller (prevent minification error)
// source: http://weblogs.asp.net/dwahlin/archive/2013/12/01/structuring-angularjs-code.aspx
angular.module('moduleName').controller('MainController', ['$scope', function($scope) {
//Code goes here
}]);
<?php
$_FILES['name-of-the-field']['tmp_name'];
$_FILES['name-of-the-field']['name'];
$_FILES['name-of-the-field']['type']; // "image/jpeg", "image/png", "image/gif"
$_FILES['name-of-the-field']['size'];
$_FILES['name-of-the-field']['error']; // returns 0 if there's no error
?>
class Bird {
public function sing () {
echo 'Tweet';
}
}
$bird = new Bird();
$bird->sing();
@sunkibaek
sunkibaek / Gemfile
Last active August 29, 2015 14:02
Use rubinius for Rails
# inside of Gemfile
ruby "2.1.0", engine: "rbx", engine_version: "2.2.7"
# update checks validation, updates the value on DB, returns the object
# Updating one record:
Person.update(15, :user_name => 'Samuel', :group => 'expert')
# Updating multiple records:
people = { 1 => { "first_name" => "David" }, 2 => { "first_name" => "Jeremy" } }
Person.update(people.keys, people.values)
# Or if you already got an object
person = Person.find(15)
@sunkibaek
sunkibaek / anagram.rb
Last active September 11, 2015 10:57
Some algorithm problems solved in Ruby
def anagram?(string, candidate)
string.chars.sort == candidate.chars.sort
end
require 'minitest/autorun'
class Test < MiniTest::Test
def test_anagram
assert anagram?('beta', 'bate')
assert anagram?('beta', 'beat')
@sunkibaek
sunkibaek / NullDateTime.rb
Created March 13, 2016 08:07
NullDateTime
class NullDateTime
def in_time_zone(_city = 'DefaultTimeZoneCity')
self
end
def to_s(_format = :default_date_time)
''
end
end
@import url(http://fonts.googleapis.com/earlyaccess/notosanskr.css);
$black: rgba(0, 0, 0, .87);
html {
color: $black;
font-family: "Noto Sans KR", sans-serif;
font-weight: normal;
line-height: 1.5;
}