Skip to content

Instantly share code, notes, and snippets.

View the-vampiire's full-sized avatar
💭
ive lost a shade of color in my life. rest in peace.

the-vampiire

💭
ive lost a shade of color in my life. rest in peace.
View GitHub Profile

Ok, so, you might know about JavaScript regular expressions. Well, here is a tutorial about them, but written by a 13 year old, so it isn't actually any good!

Regular expressions go between / characters. Here is an exampe, /hi/.

Ok, now then. Let's learn how to match the string abc. Well, that's quite simple.

/abc/. Yey! So putting letters next to each other makes them match one after the other.

Ok, now, after the second / we can put a g to make it match globally, that is, we can extract abc from xyzabcghi.

@the-vampiire
the-vampiire / WikiFinder.js
Last active April 17, 2017 03:33
Corrected WikiFinder Javascript
// jQuery Shortcuts
var search_bar = $('#search_bar');
var search_button = $('#search_button');
var search_query = $('[name=search_query]')[0];
var links = $('#links');
var random = $('#random_button');
// Animations
// activate search on click
@the-vampiire
the-vampiire / WikiFinder.js
Last active April 17, 2017 03:34
Wikipedia Viewer Javascript
// jQuery Shortcuts
var search_bar = $('#search_bar');
var search_button = $('#search_button');
var search_query = $('[name=search_query]')[0];
var links = $('#links');
var random = $('#random_button');
// Animations
// activate search on click
search_button.click(show_and_hide);
@the-vampiire
the-vampiire / Twitch.js
Created April 21, 2017 17:32
Convert and Callback Stream Details
// Stream Channel Names Array
var channel_names = ["ESL_SC2", "OgamingSC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas"];
// Stream Name to ID Conversion Request
function convert_username(arr){
var i = 0;
for(i; i < arr.length; i++){
$.ajax({
@the-vampiire
the-vampiire / Twitch.js
Last active April 22, 2017 04:17
Modified status_details function
// Stream Status and Details Request
function status_details(data) {
// pulls ID attribute from convert_name data return which is passed to this request function
var id = data.users[0]._id;
$.ajax({
type: "GET",
url: "https://api.twitch.tv/kraken/streams/" + id,
// jQuery shortcuts
var online = $('#jumbotron_online'),
offline = $('#jumbotron_offline'),
channel_banner = $('.channel_banner'),
channel_logo = $('.channel_logo');
var channel_names = ["ESL_SC2", "OgamingSC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas"];
var channel_ids = ["79776140", "30220059", "71852806", "90401618", "152475255", "6726509", "82534701", "54925078"];
@the-vampiire
the-vampiire / Twitch.js
Created April 24, 2017 19:38
Get User by OAuth Token
// Convert username to ID using OAuth (for logged in user)
function convert_username_OAuth(token){
$.ajax({
type: "GET",
url: "https://api.twitch.tv/kraken/user",
headers: {
"Client-ID": "vaiynh6nnd2nxpf6wshnj4v4zxxqz2",
"Accept": "application/vnd.twitchtv.v5+json",
@the-vampiire
the-vampiire / Twitch.js
Created April 24, 2017 19:45
Twitch JS SDK Authentication
// Document Ready (execute on page load completion)
$( function(){
// Twitch JS SDK looks for authenticated login status
Twitch.init({clientId: 'YOUR CLIENT ID HERE'}, function(error, status) {
if (status.authenticated) {
@the-vampiire
the-vampiire / Twitch.js
Created April 24, 2017 19:54
Final Code
// jQuery shortcuts
var online = $('#jumbotron_online'),
channel_names = ['freecodecamp', 'ESL_SC2'];
// Hide Modal Instructions
$('.modal').click(function(){
$(this).toggle();
});
@the-vampiire
the-vampiire / Twitch.css
Created April 24, 2017 19:56
Multi Twitch Final CSS
body{
background-color: rgba(100,65,164,1);
}
.modal{
display:none;
background-color: rgba(0,0,0,0.7);
width: 100vw;
height: 100vh;
}