Skip to content

Instantly share code, notes, and snippets.

View darklight721's full-sized avatar
👨‍💻

Roy Evan Sia darklight721

👨‍💻
  • Cebu City, Philippines
  • X @pr00t
View GitHub Profile
@darklight721
darklight721 / INSTRUCTIONS.md
Last active December 7, 2020 12:57
Using MobX with decorators in React Native

Using MobX with decorators in React Native

The following instructions should work with React Native v0.32:

  1. Install mobx libraries.

    npm install mobx --save
    npm install mobx-react --save
@darklight721
darklight721 / init.coffee
Last active February 7, 2017 16:05
An atom command and keymap to quickly end lines with semicolons. Only applies for javascript files. Code is based from turbo-javascript package.
# Open up your atom's init script file and add the following lines, then restart atom.
path = require 'path'
endLine = (insertNewLine) ->
editor = atom.workspace.activePaneItem
if path.extname(editor.getPath()) is '.js'
editor.getCursors().forEach((cursor) ->
editor.moveCursorToEndOfLine()
line = cursor.getCurrentBufferLine().trim()
@darklight721
darklight721 / .bash_profile
Created July 12, 2016 08:02
Some git commands
gitr() {
local branch=`git branch | sed -n '/\* /s///p'`
local stashed=`git stash`
git fetch
git reset --hard origin/"$branch"
if [[ "$stashed" != "No local changes to save" ]]; then
git stash pop
fi
}
@darklight721
darklight721 / Result.js
Created June 16, 2016 14:21
Here's a sample react native code from my app.
import React, { Component, StyleSheet, View } from 'react-native';
import Text from '../components/Text';
import Icon from '../components/Icon';
import Button from '../components/Button';
import AdMobBanner from '../components/AdMobBanner';
import Analytics from 'react-native-google-analytics-bridge';
import { openUrl, wikiUrl, mapsUrl } from '../utils/urls';
import { connect } from 'react-redux';
import { nextLevel, getRegion } from '../actions';
import { PRIMARY_DARKER } from '../utils/colors';
function sumf(n) {
let sum = 0;
for (let i = n; i > 0; i--) {
sum += i * (n - i + 1);
}
return sum;
}
@darklight721
darklight721 / AdMobBanner.h
Last active March 31, 2016 19:33
Using AdMob in React Native [see my comment below for instructions]
#ifndef AdMobBanner_h
#define AdMobBanner_h
@import GoogleMobileAds;
@interface AdMobBanner : GADBannerView
@property NSArray *testDevices;
@end
@darklight721
darklight721 / d8s.js
Last active December 20, 2015 10:59
d8s.js - A simple js date formatter
/*
* d8s.js - a simple js date formatter
* Usage:
* d8s().print('MM-DD-YY hh:mm:ss'); // outputs: 07-21-13 10:25:01
* d8s('2013/7/21' ,'YYYY/M/D').print('DDD of MMMM, YYYY'); // outputs: 21st of July, 2013
* d8s('Sep. 5, 2013 13:30', 'MMM. D, YYYY HH:mm').date(); // returns the Date object with the set date
* d8s(new Date(1995,11,17)).print('DD.MM.YYYY'); // outputs: 17.11.1995
*/
window.d8s = window.d8s || (function(){
@darklight721
darklight721 / quicksort.c
Last active December 12, 2015 10:39
Quicksort implementation in C.
void quick_sort(int list[], int left, int right)
{
if (left < right) {
int pivot = (left + right) / 2; // left + (right - left) / 2 is safer to use for large lists
pivot = partition(list, left, right, pivot);
quick_sort(list, left, pivot - 1);
quick_sort(list, pivot + 1, right);
}
}
#include <stdio.h>
#include <stdlib.h>
int ** makeGrid(int size, int *startX, int *startY, int *endX, int *endY)
{
// allocate memory for the grid
int **grid = (int**)malloc(sizeof(int*) * size);
int x, y;
for (x = 0; x < size; x++) {
grid[x] = (int*)malloc(sizeof(int) * size);
@darklight721
darklight721 / sort1.c
Last active December 12, 2015 09:39
Insertion Sort in C using array and linked list. I'm pretty sure my implementation in linked list isn't the most efficient.
void insertion_sort(int list[], int size)
{
int i, j, insertVal;
for (i = 1; i < size; i++) {
insertVal = list[i];
for (j = i; j > 0 && insertVal < list[j - 1]; j--) {
list[j] = list[j - 1];
}
list[j] = insertVal;